addons.js
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
define([], function () {
require([], function () {
//绑定data-toggle=addresspicker属性点击事件
$(document).on('click', "[data-toggle='addresspicker']", function () {
var that = this;
var callback = $(that).data('callback');
var input_id = $(that).data("input-id") ? $(that).data("input-id") : "";
var lat_id = $(that).data("lat-id") ? $(that).data("lat-id") : "";
var lng_id = $(that).data("lng-id") ? $(that).data("lng-id") : "";
var lat = lat_id ? $("#" + lat_id).val() : '';
var lng = lng_id ? $("#" + lng_id).val() : '';
var url = "/addons/address/index/select";
url += (lat && lng) ? '?lat=' + lat + '&lng=' + lng : '';
Fast.api.open(url, '位置选择', {
callback: function (res) {
input_id && $("#" + input_id).val(res.address);
lat_id && $("#" + lat_id).val(res.lat);
lng_id && $("#" + lng_id).val(res.lng);
try {
//执行回调函数
if (typeof callback === 'function') {
callback.call(that, res);
}
} catch (e) {
}
}
});
});
});
//修改上传的接口调用
require(['upload'], function (Upload) {
var _onUploadResponse = Upload.events.onUploadResponse;
Upload.events.onUploadResponse = function (response) {
try {
var ret = typeof response === 'object' ? response : JSON.parse(response);
if (ret.hasOwnProperty("code") && ret.hasOwnProperty("data")) {
return _onUploadResponse.call(this, response);
} else if (ret.hasOwnProperty("key") && !ret.hasOwnProperty("err_code")) {
ret.code = 1;
ret.data = {
url: '/' + ret.key
};
return _onUploadResponse.call(this, JSON.stringify(ret));
}
} catch (e) {
}
return _onUploadResponse.call(this, response);
};
});
require.config({
paths: {
'simditor': '../addons/simditor/js/simditor.min',
},
shim: {
'simditor': [
'css!../addons/simditor/css/simditor.min.css'
]
}
});
require(['form'], function (Form) {
var _bindevent = Form.events.bindevent;
Form.events.bindevent = function (form) {
_bindevent.apply(this, [form]);
if ($(".editor", form).size() > 0) {
//修改上传的接口调用
require(['upload', 'simditor'], function (Upload, Simditor) {
var editor, mobileToolbar, toolbar;
Simditor.locale = 'zh-CN';
Simditor.list = {};
toolbar = ['title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment'];
mobileToolbar = ["bold", "underline", "strikethrough", "color", "ul", "ol"];
$(".editor", form).each(function () {
var id = $(this).attr("id");
editor = new Simditor({
textarea: this,
toolbarFloat: false,
toolbar: toolbar,
pasteImage: true,
defaultImage: Config.__CDN__ + '/assets/addons/simditor/images/image.png',
upload: {url: '/'}
});
editor.uploader.on('beforeupload', function (e, file) {
Upload.api.send(file.obj, function (data) {
var url = Fast.api.cdnurl(data.url);
editor.uploader.trigger("uploadsuccess", [file, {success: true, file_path: url}]);
});
return false;
});
editor.on("blur", function () {
this.textarea.trigger("blur");
});
Simditor.list[id] = editor;
});
});
}
}
});
});