This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
92 lines (72 loc) · 2.94 KB
/
index.js
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
require.config({
packages: ['MediumEditor'],
paths: {
'medium-editor':
'https://cdn.bootcss.com/medium-editor/5.23.3/js/medium-editor.min',
'handlebars/runtime':
'https://cdn.bootcss.com/handlebars.js/4.0.10/handlebars.runtime.min',
'jquery-sortable':
'https://cdn.bootcss.com/jquery-sortable/0.9.13/jquery-sortable-min',
'jquery-ui/ui/widget':
'https://cdn.bootcss.com/blueimp-file-upload/9.19.1/js/vendor/jquery.ui.widget.min',
'jquery-iframe-transport':
'https://cdn.bootcss.com/blueimp-file-upload/9.19.1/js/jquery.iframe-transport.min',
'jquery-fileupload':
'https://cdn.bootcss.com/blueimp-file-upload/9.19.1/js/jquery.fileupload.min',
'medium-editor-insert-plugin':
'https://cdn.bootcss.com/medium-editor-insert-plugin/2.5.0/js/medium-editor-insert-plugin.min'
},
shim: {'jquery-sortable': ['jquery']}
});
define(
'blueimp-file-upload',
['jquery-fileupload', 'jquery-iframe-transport'],
function () { }
);
require(['jquery', 'EasyWebApp', 'MediumEditor'], function ($, EWA, MediumEditor) {
EWA.component(function (data) {
var VM = this, editor,
button = $.makeSet(
data.button ? data.button.split(',') : [
'bold', 'italic', 'underline', 'h4', 'fontsize', 'anchor',
'quote', 'orderedlist', 'unorderedlist',
'justifyLeft', 'justifyCenter', 'justifyRight', 'removeFormat'
]
),
$_Input = this.$_View.find('textarea');
data.countText = function () {
VM.plainText = $_Input.prev()
.children().not('[contenteditable="false"]')
.text().trim();
};
(
data.locale ?
require(['MediumEditor/Locale/' + data.locale]).then(
function (option) {
option = $.extend(true, { }, option);
option.toolbar.buttons = $.map(
option.toolbar.buttons, function () {
if (arguments[0].name in button)
return arguments[0];
}
);
return option;
}
) :
Promise.resolve({ })
).then(function (option) {
editor = MediumEditor.call(
$_Input, option, data.imageApi, data.countText
);
data.countText();
});
this.serialize = function () {
var data = editor.serialize();
for (var key in data) return data[ key ].value;
};
this.$_View.on('click', 'a[href]', false)
.parents('form').submit(function () {
$_Input[0].value = VM.serialize();
});
});
});