jodit 3.8.1 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/codeStyles/Project.xml +68 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/dictionaries/v_chupurnov.xml +10 -0
- package/.idea/encodings.xml +4 -0
- package/.idea/inspectionProfiles/Project_Default.xml +118 -0
- package/.idea/jodit.iml +12 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/markdown-navigator-enh.xml +29 -0
- package/.idea/markdown-navigator.xml +55 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/watcherTasks.xml +4 -0
- package/.idea/workspace.xml +1264 -0
- package/build/jodit.css +2 -2
- package/build/jodit.es2018.css +1 -1
- package/build/jodit.es2018.en.css +1 -1
- package/build/jodit.es2018.en.js +4 -4
- package/build/jodit.es2018.en.min.js +2 -2
- package/build/jodit.es2018.js +4 -4
- package/build/jodit.es2018.min.js +2 -2
- package/build/jodit.js +4 -4
- package/build/jodit.min.css +1 -1
- package/build/jodit.min.js +2 -2
- package/package.json +2 -2
- package/.travis.yml +0 -7
- package/bower.json +0 -33
- package/build.js +0 -39
- package/docker/Dockerfile +0 -11
- package/docker/README.md +0 -45
- package/docker/build +0 -3
- package/docker/install +0 -7
- package/docker/start +0 -3
- package/docker/test +0 -3
- package/docker/uninstall +0 -3
- package/examples/arabic.lang.html +0 -76
- package/examples/assets/app.css +0 -175
- package/examples/assets/app.js +0 -57
- package/examples/assets/download.jpg +0 -0
- package/examples/assets/icon.png +0 -0
- package/examples/assets/logo.png +0 -0
- package/examples/assets/prism.css +0 -200
- package/examples/assets/prism.js +0 -1254
- package/examples/color-picker.html +0 -139
- package/examples/custom-icons.html +0 -173
- package/examples/custom-toolbar.html +0 -80
- package/examples/example.default.html +0 -75
- package/examples/fullsize.html +0 -75
- package/examples/index.html +0 -176
- package/examples/inline-mode.html +0 -116
- package/examples/oneinstance.html +0 -125
- package/icons.html +0 -50
- package/karma.conf.js +0 -157
- package/make.js +0 -10
- package/server.js +0 -101
- package/test/bootstrap.js +0 -1167
- package/test/test.html +0 -102
- package/test/test.index.html +0 -11
- package/test/tests/acceptance/clipboardTest.js +0 -1234
- package/test/tests/acceptance/commandsTest.js +0 -647
- package/test/tests/acceptance/creatorTest.js +0 -103
- package/test/tests/acceptance/deleteBackSpaceTest.js +0 -1289
- package/test/tests/acceptance/dialogTest.js +0 -188
- package/test/tests/acceptance/editorTest.js +0 -855
- package/test/tests/acceptance/enterTest.js +0 -1088
- package/test/tests/acceptance/eventsTest.js +0 -1246
- package/test/tests/acceptance/filebrowserTest.js +0 -1309
- package/test/tests/acceptance/i18nTest.js +0 -81
- package/test/tests/acceptance/iframeTest.js +0 -306
- package/test/tests/acceptance/imageTest.js +0 -1649
- package/test/tests/acceptance/inlineModeTest.js +0 -826
- package/test/tests/acceptance/interfaceTest.js +0 -119
- package/test/tests/acceptance/mobileTest.js +0 -229
- package/test/tests/acceptance/plugins/classSpan.js +0 -220
- package/test/tests/acceptance/plugins/cleanHtml.js +0 -351
- package/test/tests/acceptance/plugins/color.js +0 -188
- package/test/tests/acceptance/plugins/dragAndDropElement.js +0 -172
- package/test/tests/acceptance/plugins/focus.js +0 -115
- package/test/tests/acceptance/plugins/font.js +0 -316
- package/test/tests/acceptance/plugins/image.js +0 -79
- package/test/tests/acceptance/plugins/indent.js +0 -179
- package/test/tests/acceptance/plugins/inline-popup.js +0 -578
- package/test/tests/acceptance/plugins/insert.js +0 -17
- package/test/tests/acceptance/plugins/limit.js +0 -164
- package/test/tests/acceptance/plugins/link.js +0 -1640
- package/test/tests/acceptance/plugins/orderedList.js +0 -290
- package/test/tests/acceptance/plugins/placeholder.js +0 -138
- package/test/tests/acceptance/plugins/resizer.js +0 -329
- package/test/tests/acceptance/plugins/search.js +0 -623
- package/test/tests/acceptance/plugins/size.js +0 -344
- package/test/tests/acceptance/plugins/source.js +0 -218
- package/test/tests/acceptance/plugins/stat.js +0 -120
- package/test/tests/acceptance/plugins/tooltip.js +0 -97
- package/test/tests/acceptance/plugins/wrapTextNodes.js +0 -105
- package/test/tests/acceptance/pluginsTest.js +0 -2219
- package/test/tests/acceptance/selectionTest.js +0 -862
- package/test/tests/acceptance/statesTest.js +0 -310
- package/test/tests/acceptance/tableTest.js +0 -1988
- package/test/tests/acceptance/toolbarTest.js +0 -1747
- package/test/tests/acceptance/undoredoTest.js +0 -217
- package/test/tests/acceptance/uploaderTest.js +0 -187
- package/test/tests/artio.jpg +0 -0
- package/test/tests/units/helpersTest.js +0 -771
- package/test/tests/units/modules/dom.js +0 -282
- package/test/tests/units/objectObserverTest.js +0 -533
- package/test/tests/units/popupTest.js +0 -211
- package/test/tests/units/positionTest.js +0 -238
- package/test/tests/units/styleTest.js +0 -1361
- package/webpack.config.js +0 -308
|
@@ -1,1246 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Jodit Editor (https://xdsoft.net/jodit/)
|
|
3
|
-
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
|
-
* Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
|
-
*/
|
|
6
|
-
describe('Jodit Events system Tests', function () {
|
|
7
|
-
describe('Native Events', function () {
|
|
8
|
-
it('Create simple event handler on some DOM element', function () {
|
|
9
|
-
const editor = getJodit(),
|
|
10
|
-
div = document.createElement('button');
|
|
11
|
-
|
|
12
|
-
let work = false;
|
|
13
|
-
|
|
14
|
-
document.body.appendChild(div);
|
|
15
|
-
|
|
16
|
-
editor.events.on(div, 'click', function () {
|
|
17
|
-
work = true;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
simulateEvent('click', 0, div);
|
|
21
|
-
|
|
22
|
-
expect(work).is.true;
|
|
23
|
-
|
|
24
|
-
div.parentNode.removeChild(div);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('Create simple event handler on some DOM element on few events', function () {
|
|
28
|
-
const editor = getJodit(),
|
|
29
|
-
div = document.createElement('button');
|
|
30
|
-
|
|
31
|
-
let work = 0;
|
|
32
|
-
|
|
33
|
-
document.body.appendChild(div);
|
|
34
|
-
|
|
35
|
-
editor.events.on(div, 'click dblclick keydown', function () {
|
|
36
|
-
work++;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
simulateEvent('click', 0, div);
|
|
40
|
-
simulateEvent('dblclick', 0, div);
|
|
41
|
-
simulateEvent('keydown', 0, div);
|
|
42
|
-
|
|
43
|
-
expect(work).equals(3);
|
|
44
|
-
div.parentNode.removeChild(div);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('Add and remove event handler', function () {
|
|
48
|
-
const editor = getJodit(),
|
|
49
|
-
div = document.createElement('button');
|
|
50
|
-
|
|
51
|
-
let work = 0;
|
|
52
|
-
|
|
53
|
-
document.body.appendChild(div);
|
|
54
|
-
|
|
55
|
-
editor.events.on(div, 'click', function () {
|
|
56
|
-
work++;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
simulateEvent('click', 0, div);
|
|
60
|
-
expect(work).equals(1);
|
|
61
|
-
|
|
62
|
-
editor.events.off(div, 'click');
|
|
63
|
-
|
|
64
|
-
simulateEvent('click', 0, div);
|
|
65
|
-
expect(work).equals(1);
|
|
66
|
-
|
|
67
|
-
div.parentNode.removeChild(div);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('Add a few handlers for several evens and remove all handlers', function () {
|
|
71
|
-
it('Should stop listening events', function () {
|
|
72
|
-
const editor = getJodit(),
|
|
73
|
-
div = document.createElement('button');
|
|
74
|
-
|
|
75
|
-
let work = 0;
|
|
76
|
-
|
|
77
|
-
document.body.appendChild(div);
|
|
78
|
-
|
|
79
|
-
editor.events.on(div, 'click', function () {
|
|
80
|
-
work++;
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
editor.events.on(div, 'dblclick', function () {
|
|
84
|
-
work++;
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
editor.events.on(div, 'mousedown', function () {
|
|
88
|
-
work++;
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
simulateEvent('click', 0, div);
|
|
92
|
-
simulateEvent('dblclick', 0, div);
|
|
93
|
-
simulateEvent('mousedown', 0, div);
|
|
94
|
-
|
|
95
|
-
expect(work).equals(3);
|
|
96
|
-
|
|
97
|
-
editor.events.off(div);
|
|
98
|
-
|
|
99
|
-
simulateEvent('click', 0, div);
|
|
100
|
-
simulateEvent('dblclick', 0, div);
|
|
101
|
-
simulateEvent('mousedown', 0, div);
|
|
102
|
-
|
|
103
|
-
expect(work).equals(3);
|
|
104
|
-
|
|
105
|
-
div.parentNode.removeChild(div);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('Add event handler for several elements', function () {
|
|
110
|
-
const editor = getJodit(),
|
|
111
|
-
div1 = editor.ed.createElement('button'),
|
|
112
|
-
div2 = editor.ed.createElement('button');
|
|
113
|
-
|
|
114
|
-
let work = '';
|
|
115
|
-
|
|
116
|
-
editor.ed.body.appendChild(div1);
|
|
117
|
-
editor.ed.body.appendChild(div2);
|
|
118
|
-
|
|
119
|
-
div1.textContent = 'test1';
|
|
120
|
-
div2.textContent = 'test2';
|
|
121
|
-
|
|
122
|
-
editor.events
|
|
123
|
-
.on([div1, div2], 'click', function () {
|
|
124
|
-
work += this.textContent;
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
.fire(div1, 'click');
|
|
128
|
-
|
|
129
|
-
editor.events.fire(div2, 'click');
|
|
130
|
-
|
|
131
|
-
expect(work).equals('test1test2');
|
|
132
|
-
|
|
133
|
-
div1.parentNode.removeChild(div1);
|
|
134
|
-
div2.parentNode.removeChild(div2);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('Fire trigger', function () {
|
|
138
|
-
const editor = getJodit(),
|
|
139
|
-
div = document.createElement('button');
|
|
140
|
-
|
|
141
|
-
let work = 0;
|
|
142
|
-
|
|
143
|
-
document.body.appendChild(div);
|
|
144
|
-
|
|
145
|
-
editor.events
|
|
146
|
-
.on(div, 'click', function () {
|
|
147
|
-
work++;
|
|
148
|
-
})
|
|
149
|
-
.fire(div, 'click');
|
|
150
|
-
|
|
151
|
-
expect(work).equals(1);
|
|
152
|
-
|
|
153
|
-
div.parentNode.removeChild(div);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('Remove all handlers using event namespace', function () {
|
|
157
|
-
it('Should Remove all handlers', function () {
|
|
158
|
-
let work = 0;
|
|
159
|
-
|
|
160
|
-
const editor = getJodit(),
|
|
161
|
-
div = document.createElement('button'),
|
|
162
|
-
inc = function () {
|
|
163
|
-
work++;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
document.body.appendChild(div);
|
|
167
|
-
|
|
168
|
-
editor.events.on(div, 'click', inc);
|
|
169
|
-
editor.events.on(div, 'mousedown', inc);
|
|
170
|
-
|
|
171
|
-
editor.events.on(div, 'click.test', inc);
|
|
172
|
-
editor.events.on(div, 'mousedown.test', inc);
|
|
173
|
-
|
|
174
|
-
editor.events.fire(div, 'click');
|
|
175
|
-
editor.events.fire(div, 'mousedown');
|
|
176
|
-
expect(work).equals(4); // 4 handlers
|
|
177
|
-
|
|
178
|
-
editor.events.fire(div, 'click.test');
|
|
179
|
-
editor.events.fire(div, 'mousedown.test');
|
|
180
|
-
expect(work).equals(8); // 4 handlers - because for DOM elements will fire all listeners
|
|
181
|
-
|
|
182
|
-
editor.events.off(div, '.test');
|
|
183
|
-
editor.events.fire(div, 'click');
|
|
184
|
-
editor.events.fire(div, 'mousedown');
|
|
185
|
-
expect(work).equals(10); // only 2 default handlers
|
|
186
|
-
|
|
187
|
-
div.parentNode.removeChild(div);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('Proxy event from iframe.window to main.window', function () {
|
|
192
|
-
let work = 0;
|
|
193
|
-
|
|
194
|
-
const editor = getJodit({
|
|
195
|
-
iframe: true
|
|
196
|
-
}),
|
|
197
|
-
mousedown = function () {
|
|
198
|
-
work++;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
window.addEventListener('mousedown', mousedown);
|
|
202
|
-
|
|
203
|
-
editor.events.fire(editor.ew, 'mousedown');
|
|
204
|
-
|
|
205
|
-
expect(work).equals(1);
|
|
206
|
-
|
|
207
|
-
window.removeEventListener('mousedown', mousedown);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
describe('Jodit Events', function () {
|
|
212
|
-
it('Event handler', function () {
|
|
213
|
-
let enable = false;
|
|
214
|
-
const editor = getJodit();
|
|
215
|
-
|
|
216
|
-
editor.events.on('keydown', function () {
|
|
217
|
-
enable = true;
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor);
|
|
221
|
-
expect(enable).is.true;
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe('one', function () {
|
|
225
|
-
it('should call handler only one time', function () {
|
|
226
|
-
let count = 0;
|
|
227
|
-
const editor = getJodit();
|
|
228
|
-
|
|
229
|
-
editor.events.one('keydown', function () {
|
|
230
|
-
count++;
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor);
|
|
234
|
-
simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor);
|
|
235
|
-
simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor);
|
|
236
|
-
simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor);
|
|
237
|
-
|
|
238
|
-
expect(count).equals(1);
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('Delete event handler', function () {
|
|
243
|
-
let enable = false;
|
|
244
|
-
const editor = getJodit(),
|
|
245
|
-
callback = function () {
|
|
246
|
-
enable = true;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
editor.events.on('keydown', callback);
|
|
250
|
-
editor.events.off('keydown', callback);
|
|
251
|
-
|
|
252
|
-
simulateEvent('keydown', 'y', editor.editor);
|
|
253
|
-
|
|
254
|
-
expect(enable).is.false;
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('Proxy events', function () {
|
|
258
|
-
const editor = getJodit();
|
|
259
|
-
|
|
260
|
-
let work = false;
|
|
261
|
-
|
|
262
|
-
editor.events.on('keydown', function () {
|
|
263
|
-
work = true;
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor);
|
|
267
|
-
|
|
268
|
-
expect(work).is.true;
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
describe('Combine events', function () {
|
|
273
|
-
describe('Pass arguments in handler', function () {
|
|
274
|
-
it('Should pass all Fire arguments in handler', function () {
|
|
275
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
276
|
-
simpleObject = {};
|
|
277
|
-
|
|
278
|
-
let clicked = 0;
|
|
279
|
-
|
|
280
|
-
eventEmmiter.on(simpleObject, 'click', function (count) {
|
|
281
|
-
clicked += count;
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
eventEmmiter.fire(simpleObject, 'click', 1);
|
|
285
|
-
eventEmmiter.fire(simpleObject, 'click', 2);
|
|
286
|
-
eventEmmiter.fire(simpleObject, 'click', 3);
|
|
287
|
-
|
|
288
|
-
expect(6).equals(clicked);
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
describe('Queue operations', function () {
|
|
293
|
-
it('Should call handlers in order how the were added but handler with onTop option should be called first', function () {
|
|
294
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
295
|
-
simpleObject = {},
|
|
296
|
-
clicked = [];
|
|
297
|
-
|
|
298
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
299
|
-
clicked.push(1);
|
|
300
|
-
});
|
|
301
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
302
|
-
clicked.push(2);
|
|
303
|
-
});
|
|
304
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
305
|
-
clicked.push(3);
|
|
306
|
-
});
|
|
307
|
-
eventEmmiter.on(
|
|
308
|
-
simpleObject,
|
|
309
|
-
'click',
|
|
310
|
-
function () {
|
|
311
|
-
clicked.push(4);
|
|
312
|
-
},
|
|
313
|
-
true
|
|
314
|
-
);
|
|
315
|
-
|
|
316
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
317
|
-
|
|
318
|
-
expect('4,1,2,3').equals(clicked.toString());
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
describe('Stop propagation', function () {
|
|
322
|
-
it('Should stop all calls for this event but another events should be called', function () {
|
|
323
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
324
|
-
simpleObject = {},
|
|
325
|
-
clicked = [];
|
|
326
|
-
|
|
327
|
-
eventEmmiter.on(simpleObject, 'lope', function () {
|
|
328
|
-
clicked.push(15);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
eventEmmiter.on(simpleObject, 'pop', function () {
|
|
332
|
-
clicked.push(16);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
336
|
-
clicked.push(1);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
340
|
-
clicked.push(2);
|
|
341
|
-
eventEmmiter.fire(simpleObject, 'pop');
|
|
342
|
-
eventEmmiter.stopPropagation(simpleObject, 'click');
|
|
343
|
-
eventEmmiter.fire(simpleObject, 'lope');
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
// this handler will not be called
|
|
347
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
348
|
-
clicked.push(3);
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
eventEmmiter.on(
|
|
352
|
-
simpleObject,
|
|
353
|
-
'click',
|
|
354
|
-
function () {
|
|
355
|
-
clicked.push(4);
|
|
356
|
-
},
|
|
357
|
-
true
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
361
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
362
|
-
|
|
363
|
-
expect('4,1,2,16,15,4,1,2,16,15').equals(
|
|
364
|
-
clicked.toString()
|
|
365
|
-
);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
describe('Default object', function () {
|
|
369
|
-
it('Should stop all calls for this event but another events should be called', function () {
|
|
370
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
371
|
-
clicked = [];
|
|
372
|
-
|
|
373
|
-
eventEmmiter.on('lope', function () {
|
|
374
|
-
clicked.push(15);
|
|
375
|
-
});
|
|
376
|
-
eventEmmiter.on('pop', function () {
|
|
377
|
-
clicked.push(16);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
eventEmmiter.on('click', function () {
|
|
381
|
-
clicked.push(1);
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
eventEmmiter.on('click', function () {
|
|
385
|
-
clicked.push(2);
|
|
386
|
-
eventEmmiter.fire('pop');
|
|
387
|
-
eventEmmiter.stopPropagation('click');
|
|
388
|
-
eventEmmiter.fire('lope');
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
// this handler will not be called
|
|
392
|
-
eventEmmiter.on('click', function () {
|
|
393
|
-
clicked.push(3);
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
eventEmmiter.on(
|
|
397
|
-
'click',
|
|
398
|
-
function () {
|
|
399
|
-
clicked.push(4);
|
|
400
|
-
},
|
|
401
|
-
undefined,
|
|
402
|
-
true
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
eventEmmiter.fire('click');
|
|
406
|
-
eventEmmiter.fire('click');
|
|
407
|
-
|
|
408
|
-
expect('4,1,2,16,15,4,1,2,16,15').equals(
|
|
409
|
-
clicked.toString()
|
|
410
|
-
);
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
describe('Short form', function () {
|
|
417
|
-
describe('Add event to simple object', function () {
|
|
418
|
-
it('Should work with on handler', function () {
|
|
419
|
-
const eventEmmiter = new Jodit.modules.EventsNative();
|
|
420
|
-
let clicked = false;
|
|
421
|
-
|
|
422
|
-
eventEmmiter.on('click', function () {
|
|
423
|
-
clicked = true;
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
eventEmmiter.fire('click');
|
|
427
|
-
|
|
428
|
-
expect(true).equals(clicked);
|
|
429
|
-
});
|
|
430
|
-
describe('Namespaces', function () {
|
|
431
|
-
describe('Add handler with namespace', function () {
|
|
432
|
-
describe('Remove event listener without namespace', function () {
|
|
433
|
-
it('Should remove handler with namespace', function () {
|
|
434
|
-
let clicked = 0;
|
|
435
|
-
const eventEmmiter =
|
|
436
|
-
new Jodit.modules.EventsNative(),
|
|
437
|
-
callback = function () {
|
|
438
|
-
clicked += 1;
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
eventEmmiter.on('click.jodit', callback);
|
|
442
|
-
eventEmmiter.fire('click');
|
|
443
|
-
eventEmmiter.fire('click.jodit');
|
|
444
|
-
|
|
445
|
-
expect(2).equals(clicked);
|
|
446
|
-
|
|
447
|
-
eventEmmiter.off('click');
|
|
448
|
-
|
|
449
|
-
eventEmmiter.fire('click.jodit');
|
|
450
|
-
eventEmmiter.fire('click');
|
|
451
|
-
|
|
452
|
-
expect(2).equals(clicked);
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
describe('Remove event listener with namespace', function () {
|
|
457
|
-
it('Should remove handler with namespace', function () {
|
|
458
|
-
const eventEmmiter =
|
|
459
|
-
new Jodit.modules.EventsNative();
|
|
460
|
-
|
|
461
|
-
let clicked = 0,
|
|
462
|
-
callback = function () {
|
|
463
|
-
clicked += 1;
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
eventEmmiter.on('click.jodit', callback);
|
|
467
|
-
eventEmmiter.fire('click');
|
|
468
|
-
eventEmmiter.fire('click.jodit');
|
|
469
|
-
|
|
470
|
-
expect(2).equals(clicked);
|
|
471
|
-
|
|
472
|
-
eventEmmiter.off('click.jodit');
|
|
473
|
-
|
|
474
|
-
eventEmmiter.fire('click.jodit');
|
|
475
|
-
eventEmmiter.fire('click');
|
|
476
|
-
|
|
477
|
-
expect(2).equals(clicked);
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
describe('Add handlers with and without namespace', function () {
|
|
483
|
-
describe('And fire without namespace', function () {
|
|
484
|
-
it('Should fire both handlers', function () {
|
|
485
|
-
const eventEmmiter =
|
|
486
|
-
new Jodit.modules.EventsNative();
|
|
487
|
-
let clicked = 0;
|
|
488
|
-
const callback = function () {
|
|
489
|
-
clicked += 1;
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
eventEmmiter.on('click', callback);
|
|
493
|
-
eventEmmiter.on('click.jodit', callback);
|
|
494
|
-
|
|
495
|
-
eventEmmiter.fire('click');
|
|
496
|
-
|
|
497
|
-
expect(2).equals(clicked);
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
describe('And fire with namespace', function () {
|
|
502
|
-
it('Should fire only one handler with namespace', function () {
|
|
503
|
-
let clicked = 0;
|
|
504
|
-
|
|
505
|
-
const eventEmmiter =
|
|
506
|
-
new Jodit.modules.EventsNative(),
|
|
507
|
-
callback = function () {
|
|
508
|
-
clicked += 1;
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
eventEmmiter.on('click', callback);
|
|
512
|
-
eventEmmiter.on('click.jodit', callback);
|
|
513
|
-
|
|
514
|
-
eventEmmiter.fire('click.jodit');
|
|
515
|
-
|
|
516
|
-
expect(1).equals(clicked);
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
describe('Remove event listeners', function () {
|
|
521
|
-
describe('Remove event listener with namespace', function () {
|
|
522
|
-
it('Should remove handler only with namespace', function () {
|
|
523
|
-
let clicked = 0;
|
|
524
|
-
|
|
525
|
-
const eventEmmiter =
|
|
526
|
-
new Jodit.modules.EventsNative(),
|
|
527
|
-
callback = function () {
|
|
528
|
-
clicked += 1;
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
eventEmmiter.on('click', callback);
|
|
532
|
-
eventEmmiter.on('click.jodit', callback);
|
|
533
|
-
|
|
534
|
-
eventEmmiter.fire('click');
|
|
535
|
-
expect(2).equals(clicked);
|
|
536
|
-
|
|
537
|
-
eventEmmiter.off('click.jodit');
|
|
538
|
-
|
|
539
|
-
eventEmmiter.fire('click.jodit');
|
|
540
|
-
eventEmmiter.fire('click');
|
|
541
|
-
|
|
542
|
-
expect(3).equals(clicked);
|
|
543
|
-
});
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
describe('Remove event listener without namespace', function () {
|
|
547
|
-
it('Should remove all handlers', function () {
|
|
548
|
-
let clicked = 0;
|
|
549
|
-
|
|
550
|
-
const eventEmmiter =
|
|
551
|
-
new Jodit.modules.EventsNative(),
|
|
552
|
-
callback = function () {
|
|
553
|
-
clicked += 1;
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
eventEmmiter.on('click', callback);
|
|
557
|
-
eventEmmiter.on('click.jodit', callback);
|
|
558
|
-
|
|
559
|
-
eventEmmiter.fire('click');
|
|
560
|
-
|
|
561
|
-
expect(2).equals(clicked);
|
|
562
|
-
|
|
563
|
-
eventEmmiter.off('click');
|
|
564
|
-
|
|
565
|
-
eventEmmiter.fire('click.jodit');
|
|
566
|
-
eventEmmiter.fire('click');
|
|
567
|
-
|
|
568
|
-
expect(2).equals(clicked);
|
|
569
|
-
});
|
|
570
|
-
});
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
});
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
describe('Return value', function () {
|
|
578
|
-
it('Should return last not undefined value from fire', function () {
|
|
579
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
580
|
-
simpleObject = {};
|
|
581
|
-
|
|
582
|
-
let clicked = 0;
|
|
583
|
-
|
|
584
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
585
|
-
return 50;
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
589
|
-
return 60;
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
eventEmmiter.on(simpleObject, 'click', function () {});
|
|
593
|
-
|
|
594
|
-
clicked = eventEmmiter.fire(simpleObject, 'click');
|
|
595
|
-
|
|
596
|
-
expect(60).equals(clicked);
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
describe('Add event to simple object', function () {
|
|
601
|
-
it('Should work with on handler', function () {
|
|
602
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
603
|
-
simpleObject = {};
|
|
604
|
-
|
|
605
|
-
let clicked = false;
|
|
606
|
-
|
|
607
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
608
|
-
clicked = true;
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
612
|
-
|
|
613
|
-
expect(true).equals(clicked);
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
it('Should work with several handlers', function () {
|
|
617
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
618
|
-
simpleObject = {},
|
|
619
|
-
clicked = [];
|
|
620
|
-
|
|
621
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
622
|
-
clicked.push(1);
|
|
623
|
-
});
|
|
624
|
-
eventEmmiter.on(simpleObject, 'click', function () {
|
|
625
|
-
clicked.push(2);
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
629
|
-
|
|
630
|
-
expect('1,2').equals(clicked.toString());
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
describe('Add event to simple object with namespace', function () {
|
|
634
|
-
describe('Fire event', function () {
|
|
635
|
-
it('Should work with namespace and without namespace', function () {
|
|
636
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
637
|
-
simpleObject = {};
|
|
638
|
-
|
|
639
|
-
let clicked = 0;
|
|
640
|
-
|
|
641
|
-
eventEmmiter.on(
|
|
642
|
-
simpleObject,
|
|
643
|
-
'click.jodit',
|
|
644
|
-
function () {
|
|
645
|
-
clicked += 1;
|
|
646
|
-
}
|
|
647
|
-
);
|
|
648
|
-
|
|
649
|
-
eventEmmiter.fire(simpleObject, 'click.jodit');
|
|
650
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
651
|
-
|
|
652
|
-
eventEmmiter.fire(simpleObject, 'click.test'); // should not work
|
|
653
|
-
|
|
654
|
-
expect(2).equals(clicked);
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
it('Should work only for current object', function () {
|
|
658
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
659
|
-
simpleObject = {},
|
|
660
|
-
simpleObject2 = {};
|
|
661
|
-
|
|
662
|
-
let clicked = 0;
|
|
663
|
-
|
|
664
|
-
eventEmmiter.on(
|
|
665
|
-
simpleObject,
|
|
666
|
-
'click.jodit',
|
|
667
|
-
function () {
|
|
668
|
-
clicked += 1;
|
|
669
|
-
}
|
|
670
|
-
);
|
|
671
|
-
|
|
672
|
-
eventEmmiter.fire(simpleObject, 'click.jodit');
|
|
673
|
-
eventEmmiter.fire(simpleObject2, 'click');
|
|
674
|
-
|
|
675
|
-
expect(1).equals(clicked);
|
|
676
|
-
});
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
describe('Remove event listener', function () {
|
|
680
|
-
it('Should remove handler without namespace', function () {
|
|
681
|
-
let clicked = 0;
|
|
682
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
683
|
-
simpleObject = {},
|
|
684
|
-
callback = function () {
|
|
685
|
-
clicked += 1;
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
eventEmmiter.on(simpleObject, 'click.jodit', callback);
|
|
689
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
690
|
-
|
|
691
|
-
expect(1).equals(clicked);
|
|
692
|
-
|
|
693
|
-
eventEmmiter.off(simpleObject, 'click.jodit');
|
|
694
|
-
|
|
695
|
-
eventEmmiter.fire(simpleObject, 'click.jodit');
|
|
696
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
697
|
-
|
|
698
|
-
expect(1).equals(clicked);
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
it('Should remove handler with namespace', function () {
|
|
702
|
-
let clicked = 0;
|
|
703
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
704
|
-
simpleObject = {},
|
|
705
|
-
callback = function () {
|
|
706
|
-
clicked += 1;
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
eventEmmiter.on(simpleObject, 'click', callback);
|
|
710
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
711
|
-
|
|
712
|
-
expect(1).equals(clicked);
|
|
713
|
-
|
|
714
|
-
eventEmmiter.off(simpleObject, 'click.jodit');
|
|
715
|
-
|
|
716
|
-
eventEmmiter.fire(simpleObject, 'click.jodit'); // should not work
|
|
717
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
718
|
-
|
|
719
|
-
expect(2).equals(clicked);
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
describe('with namespace', function () {
|
|
723
|
-
it('Should remove handler with namespace only for one event', function () {
|
|
724
|
-
const eventEmmiter =
|
|
725
|
-
new Jodit.modules.EventsNative(),
|
|
726
|
-
simpleObject = {},
|
|
727
|
-
clicked = [],
|
|
728
|
-
callback = function () {
|
|
729
|
-
clicked.push(1);
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
eventEmmiter.on(
|
|
733
|
-
simpleObject,
|
|
734
|
-
'click.jodit mousedown.jodit',
|
|
735
|
-
callback
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
eventEmmiter.on(
|
|
739
|
-
simpleObject,
|
|
740
|
-
'mousedown',
|
|
741
|
-
function () {
|
|
742
|
-
clicked.push(2);
|
|
743
|
-
}
|
|
744
|
-
);
|
|
745
|
-
|
|
746
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
747
|
-
|
|
748
|
-
expect('1').equals(clicked.toString());
|
|
749
|
-
|
|
750
|
-
eventEmmiter.off(simpleObject, 'click.jodit');
|
|
751
|
-
|
|
752
|
-
eventEmmiter.fire(simpleObject, 'click.jodit');
|
|
753
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
754
|
-
|
|
755
|
-
expect('1').equals(clicked.toString());
|
|
756
|
-
|
|
757
|
-
eventEmmiter.fire(simpleObject, 'mousedown');
|
|
758
|
-
|
|
759
|
-
expect('1,2,1').equals(clicked.toString());
|
|
760
|
-
|
|
761
|
-
eventEmmiter.off(simpleObject, 'mousedown');
|
|
762
|
-
|
|
763
|
-
eventEmmiter.fire(simpleObject, 'mousedown');
|
|
764
|
-
|
|
765
|
-
expect('1,2,1').equals(clicked.toString());
|
|
766
|
-
});
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
describe('Remove event listener for specific handler', function () {
|
|
770
|
-
it('Should remove only specific handler', function () {
|
|
771
|
-
const eventEmmiter =
|
|
772
|
-
new Jodit.modules.EventsNative(),
|
|
773
|
-
simpleObject = {},
|
|
774
|
-
clicked = [],
|
|
775
|
-
callback2 = function () {
|
|
776
|
-
clicked.push(2);
|
|
777
|
-
},
|
|
778
|
-
callback = function () {
|
|
779
|
-
clicked.push(1);
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
eventEmmiter.on(
|
|
783
|
-
simpleObject,
|
|
784
|
-
'click.jodit',
|
|
785
|
-
callback
|
|
786
|
-
);
|
|
787
|
-
eventEmmiter.on(simpleObject, 'click', callback2);
|
|
788
|
-
|
|
789
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
790
|
-
|
|
791
|
-
expect('2,1').equals(clicked.toString());
|
|
792
|
-
|
|
793
|
-
eventEmmiter.off(
|
|
794
|
-
simpleObject,
|
|
795
|
-
'click.jodit',
|
|
796
|
-
callback
|
|
797
|
-
);
|
|
798
|
-
eventEmmiter.off(
|
|
799
|
-
simpleObject,
|
|
800
|
-
'click.jodit',
|
|
801
|
-
callback2
|
|
802
|
-
);
|
|
803
|
-
|
|
804
|
-
eventEmmiter.fire(simpleObject, 'click.jodit');
|
|
805
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
806
|
-
expect('2,1,2').equals(clicked.toString());
|
|
807
|
-
|
|
808
|
-
eventEmmiter.off(simpleObject, 'click', callback2);
|
|
809
|
-
|
|
810
|
-
eventEmmiter.fire(simpleObject, 'click.jodit');
|
|
811
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
812
|
-
expect('2,1,2').equals(clicked.toString());
|
|
813
|
-
});
|
|
814
|
-
});
|
|
815
|
-
|
|
816
|
-
describe('Remove event listener for whole namespace', function () {
|
|
817
|
-
it('Should remove all handlers from namespace', function () {
|
|
818
|
-
let clicked = 0;
|
|
819
|
-
const eventEmmiter =
|
|
820
|
-
new Jodit.modules.EventsNative(),
|
|
821
|
-
simpleObject = {},
|
|
822
|
-
callback = function () {
|
|
823
|
-
clicked += 1;
|
|
824
|
-
};
|
|
825
|
-
|
|
826
|
-
eventEmmiter.on(
|
|
827
|
-
simpleObject,
|
|
828
|
-
'click.jodit',
|
|
829
|
-
callback
|
|
830
|
-
);
|
|
831
|
-
eventEmmiter.on(
|
|
832
|
-
simpleObject,
|
|
833
|
-
'mousedown.jodit',
|
|
834
|
-
callback
|
|
835
|
-
);
|
|
836
|
-
eventEmmiter.fire(simpleObject, 'click mousedown');
|
|
837
|
-
|
|
838
|
-
expect(2).equals(clicked);
|
|
839
|
-
|
|
840
|
-
eventEmmiter.off(simpleObject, '.jodit');
|
|
841
|
-
|
|
842
|
-
eventEmmiter.fire(simpleObject, 'click');
|
|
843
|
-
eventEmmiter.fire(simpleObject, 'mousedown');
|
|
844
|
-
|
|
845
|
-
expect(2).equals(clicked);
|
|
846
|
-
});
|
|
847
|
-
});
|
|
848
|
-
});
|
|
849
|
-
});
|
|
850
|
-
});
|
|
851
|
-
|
|
852
|
-
describe('Native Events', function () {
|
|
853
|
-
it('Create simple event handler on some DOM element', function () {
|
|
854
|
-
let work = false;
|
|
855
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
856
|
-
div = document.createElement('button');
|
|
857
|
-
|
|
858
|
-
document.body.appendChild(div);
|
|
859
|
-
|
|
860
|
-
eventEmmiter.on(div, 'click', function () {
|
|
861
|
-
work = true;
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
simulateEvent('click', 0, div);
|
|
865
|
-
|
|
866
|
-
expect(work).is.true;
|
|
867
|
-
|
|
868
|
-
div.parentNode.removeChild(div);
|
|
869
|
-
});
|
|
870
|
-
|
|
871
|
-
it('Create simple event handler on some DOM element on few events', function () {
|
|
872
|
-
let work = 0;
|
|
873
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
874
|
-
div = document.createElement('button');
|
|
875
|
-
|
|
876
|
-
document.body.appendChild(div);
|
|
877
|
-
|
|
878
|
-
eventEmmiter.on(div, 'click dblclick keydown', function () {
|
|
879
|
-
work++;
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
simulateEvent('click', 0, div);
|
|
883
|
-
simulateEvent('dblclick', 0, div);
|
|
884
|
-
simulateEvent('keydown', 0, div);
|
|
885
|
-
|
|
886
|
-
expect(work).equals(3);
|
|
887
|
-
div.parentNode.removeChild(div);
|
|
888
|
-
});
|
|
889
|
-
|
|
890
|
-
it('Add and remove event handler', function () {
|
|
891
|
-
let work = 0;
|
|
892
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
893
|
-
div = document.createElement('button');
|
|
894
|
-
|
|
895
|
-
document.body.appendChild(div);
|
|
896
|
-
|
|
897
|
-
eventEmmiter.on(div, 'click', function () {
|
|
898
|
-
work++;
|
|
899
|
-
});
|
|
900
|
-
|
|
901
|
-
simulateEvent('click', 0, div);
|
|
902
|
-
expect(work).equals(1);
|
|
903
|
-
|
|
904
|
-
eventEmmiter.off(div, 'click');
|
|
905
|
-
|
|
906
|
-
simulateEvent('click', 0, div);
|
|
907
|
-
expect(work).equals(1);
|
|
908
|
-
|
|
909
|
-
div.parentNode.removeChild(div);
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
it('Add a few handlers for several evens and remove all handlers', function () {
|
|
913
|
-
let work = 0;
|
|
914
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
915
|
-
div = document.createElement('button');
|
|
916
|
-
|
|
917
|
-
document.body.appendChild(div);
|
|
918
|
-
|
|
919
|
-
eventEmmiter.on(div, 'click', function () {
|
|
920
|
-
work++;
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
eventEmmiter.on(div, 'dblclick', function () {
|
|
924
|
-
work++;
|
|
925
|
-
});
|
|
926
|
-
|
|
927
|
-
eventEmmiter.on(div, 'mousedown', function () {
|
|
928
|
-
work++;
|
|
929
|
-
});
|
|
930
|
-
|
|
931
|
-
simulateEvent('click', 0, div);
|
|
932
|
-
simulateEvent('dblclick', 0, div);
|
|
933
|
-
simulateEvent('mousedown', 0, div);
|
|
934
|
-
|
|
935
|
-
expect(work).equals(3);
|
|
936
|
-
|
|
937
|
-
eventEmmiter.off(div);
|
|
938
|
-
|
|
939
|
-
simulateEvent('click', 0, div);
|
|
940
|
-
simulateEvent('dblclick', 0, div);
|
|
941
|
-
simulateEvent('mousedown', 0, div);
|
|
942
|
-
|
|
943
|
-
expect(work).equals(3);
|
|
944
|
-
|
|
945
|
-
div.parentNode.removeChild(div);
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
it('Add event handler for several elements', function () {
|
|
949
|
-
let work = '';
|
|
950
|
-
|
|
951
|
-
const editor = getJodit(),
|
|
952
|
-
eventEmmiter = new Jodit.modules.EventsNative(),
|
|
953
|
-
div1 = editor.ed.createElement('button'),
|
|
954
|
-
div2 = editor.ed.createElement('button');
|
|
955
|
-
|
|
956
|
-
editor.ed.body.appendChild(div1);
|
|
957
|
-
editor.ed.body.appendChild(div2);
|
|
958
|
-
|
|
959
|
-
div1.textContent = 'test1';
|
|
960
|
-
div2.textContent = 'test2';
|
|
961
|
-
|
|
962
|
-
eventEmmiter.on([div1, div2], 'click', function () {
|
|
963
|
-
work += this.textContent;
|
|
964
|
-
});
|
|
965
|
-
|
|
966
|
-
eventEmmiter.fire(div1, 'click');
|
|
967
|
-
eventEmmiter.fire(div2, 'click');
|
|
968
|
-
|
|
969
|
-
expect(work).equals('test1test2');
|
|
970
|
-
|
|
971
|
-
div1.parentNode.removeChild(div1);
|
|
972
|
-
div2.parentNode.removeChild(div2);
|
|
973
|
-
});
|
|
974
|
-
|
|
975
|
-
it('Fire trigger', function () {
|
|
976
|
-
let work = 0;
|
|
977
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
978
|
-
div = document.createElement('button');
|
|
979
|
-
|
|
980
|
-
document.body.appendChild(div);
|
|
981
|
-
|
|
982
|
-
eventEmmiter.on(div, 'click', function () {
|
|
983
|
-
work++;
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
eventEmmiter.fire(div, 'click');
|
|
987
|
-
expect(work).equals(1);
|
|
988
|
-
|
|
989
|
-
div.parentNode.removeChild(div);
|
|
990
|
-
});
|
|
991
|
-
|
|
992
|
-
describe('Remove all handlers using event namespace', function () {
|
|
993
|
-
it('Should remove all handlers in this namespace', function () {
|
|
994
|
-
let work = 0;
|
|
995
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
996
|
-
div = document.createElement('button');
|
|
997
|
-
|
|
998
|
-
document.body.appendChild(div);
|
|
999
|
-
|
|
1000
|
-
eventEmmiter.on(div, 'click.test', function () {
|
|
1001
|
-
work++;
|
|
1002
|
-
});
|
|
1003
|
-
|
|
1004
|
-
eventEmmiter.on(div, 'mousedown.test', function () {
|
|
1005
|
-
work++;
|
|
1006
|
-
});
|
|
1007
|
-
|
|
1008
|
-
eventEmmiter.fire(div, 'click');
|
|
1009
|
-
eventEmmiter.fire(div, 'mousedown');
|
|
1010
|
-
eventEmmiter.fire(div, 'click.test');
|
|
1011
|
-
eventEmmiter.fire(div, 'mousedown.test');
|
|
1012
|
-
|
|
1013
|
-
expect(work).equals(4);
|
|
1014
|
-
|
|
1015
|
-
eventEmmiter.off(div, '.test');
|
|
1016
|
-
|
|
1017
|
-
eventEmmiter.fire(div, 'click');
|
|
1018
|
-
eventEmmiter.fire(div, 'mousedown');
|
|
1019
|
-
eventEmmiter.fire(div, 'click.test');
|
|
1020
|
-
eventEmmiter.fire(div, 'mousedown.test');
|
|
1021
|
-
|
|
1022
|
-
expect(work).equals(4);
|
|
1023
|
-
|
|
1024
|
-
div.parentNode.removeChild(div);
|
|
1025
|
-
});
|
|
1026
|
-
});
|
|
1027
|
-
|
|
1028
|
-
it('Proxy event from iframe.window to main.window', function () {
|
|
1029
|
-
let work = 0;
|
|
1030
|
-
|
|
1031
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
1032
|
-
mousedown = function () {
|
|
1033
|
-
work++;
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
window.addEventListener('mousedown', mousedown);
|
|
1037
|
-
|
|
1038
|
-
eventEmmiter.fire(window, 'mousedown');
|
|
1039
|
-
|
|
1040
|
-
expect(work).equals(1);
|
|
1041
|
-
|
|
1042
|
-
window.removeEventListener('mousedown', mousedown);
|
|
1043
|
-
});
|
|
1044
|
-
});
|
|
1045
|
-
|
|
1046
|
-
describe('Check destruct', function () {
|
|
1047
|
-
describe('For window', function () {
|
|
1048
|
-
it('Should remove all handlers', function () {
|
|
1049
|
-
const editor = getJodit();
|
|
1050
|
-
let checker = 0;
|
|
1051
|
-
|
|
1052
|
-
editor.events.on(window, 'updateSome1', function () {
|
|
1053
|
-
checker += 1;
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
editor.events.fire(window, 'updateSome1');
|
|
1057
|
-
|
|
1058
|
-
expect(1).equals(checker);
|
|
1059
|
-
|
|
1060
|
-
simulateEvent('updateSome1', 0, window);
|
|
1061
|
-
|
|
1062
|
-
expect(2).equals(checker);
|
|
1063
|
-
|
|
1064
|
-
editor.destruct();
|
|
1065
|
-
|
|
1066
|
-
simulateEvent('updateSome1', 0, window);
|
|
1067
|
-
simulateEvent('updateSome1', 0, window);
|
|
1068
|
-
simulateEvent('updateSome1', 0, window);
|
|
1069
|
-
|
|
1070
|
-
expect(2).equals(checker);
|
|
1071
|
-
});
|
|
1072
|
-
});
|
|
1073
|
-
|
|
1074
|
-
describe('For document', function () {
|
|
1075
|
-
it('Should remove all handlers', function () {
|
|
1076
|
-
const editor = getJodit();
|
|
1077
|
-
let checker = 0;
|
|
1078
|
-
|
|
1079
|
-
editor.events.on(document, 'updateSome1', function () {
|
|
1080
|
-
checker += 1;
|
|
1081
|
-
});
|
|
1082
|
-
|
|
1083
|
-
editor.events.fire(document, 'updateSome1');
|
|
1084
|
-
|
|
1085
|
-
expect(1).equals(checker);
|
|
1086
|
-
|
|
1087
|
-
simulateEvent('updateSome1', 0, document);
|
|
1088
|
-
|
|
1089
|
-
expect(2).equals(checker);
|
|
1090
|
-
|
|
1091
|
-
editor.destruct();
|
|
1092
|
-
|
|
1093
|
-
simulateEvent('updateSome1', 0, document);
|
|
1094
|
-
simulateEvent('updateSome1', 0, document);
|
|
1095
|
-
simulateEvent('updateSome1', 0, document);
|
|
1096
|
-
|
|
1097
|
-
expect(2).equals(checker);
|
|
1098
|
-
});
|
|
1099
|
-
});
|
|
1100
|
-
|
|
1101
|
-
describe('For body', function () {
|
|
1102
|
-
it('Should remove all handlers', function () {
|
|
1103
|
-
const editor = getJodit();
|
|
1104
|
-
let checker = 0;
|
|
1105
|
-
|
|
1106
|
-
editor.events.on(document.body, 'updateSome1', function () {
|
|
1107
|
-
checker += 1;
|
|
1108
|
-
});
|
|
1109
|
-
|
|
1110
|
-
editor.events.fire(document.body, 'updateSome1');
|
|
1111
|
-
|
|
1112
|
-
expect(1).equals(checker);
|
|
1113
|
-
|
|
1114
|
-
simulateEvent('updateSome1', 0, document.body);
|
|
1115
|
-
|
|
1116
|
-
expect(2).equals(checker);
|
|
1117
|
-
|
|
1118
|
-
editor.destruct();
|
|
1119
|
-
|
|
1120
|
-
simulateEvent('updateSome1', 0, document.body);
|
|
1121
|
-
simulateEvent('updateSome1', 0, document.body);
|
|
1122
|
-
simulateEvent('updateSome1', 0, document.body);
|
|
1123
|
-
|
|
1124
|
-
expect(2).equals(checker);
|
|
1125
|
-
});
|
|
1126
|
-
});
|
|
1127
|
-
});
|
|
1128
|
-
});
|
|
1129
|
-
|
|
1130
|
-
describe('Helpers', function () {
|
|
1131
|
-
describe('dataBind', function () {
|
|
1132
|
-
it('Should save value in object', function () {
|
|
1133
|
-
const obj = {
|
|
1134
|
-
stop: 2
|
|
1135
|
-
};
|
|
1136
|
-
Jodit.modules.Helpers.dataBind(obj, 'test', 1);
|
|
1137
|
-
expect(Object.keys(obj).toString()).equals('stop');
|
|
1138
|
-
expect(Jodit.modules.Helpers.dataBind(obj, 'test')).equals(1);
|
|
1139
|
-
});
|
|
1140
|
-
|
|
1141
|
-
describe('remove value', function () {
|
|
1142
|
-
it('Should save value in object', function () {
|
|
1143
|
-
const obj = {
|
|
1144
|
-
stop: 2
|
|
1145
|
-
};
|
|
1146
|
-
|
|
1147
|
-
Jodit.modules.Helpers.dataBind(obj, 'test', 1);
|
|
1148
|
-
expect(Object.keys(obj).toString()).equals('stop');
|
|
1149
|
-
|
|
1150
|
-
expect(Jodit.modules.Helpers.dataBind(obj, 'test')).equals(
|
|
1151
|
-
1
|
|
1152
|
-
);
|
|
1153
|
-
|
|
1154
|
-
Jodit.modules.Helpers.dataBind(obj, 'test', 2);
|
|
1155
|
-
|
|
1156
|
-
expect(Jodit.modules.Helpers.dataBind(obj, 'test')).equals(
|
|
1157
|
-
2
|
|
1158
|
-
);
|
|
1159
|
-
|
|
1160
|
-
Jodit.modules.Helpers.dataBind(obj, 'test', null);
|
|
1161
|
-
|
|
1162
|
-
expect(
|
|
1163
|
-
Jodit.modules.Helpers.dataBind(obj, 'test')
|
|
1164
|
-
).does.not.equal(2);
|
|
1165
|
-
});
|
|
1166
|
-
});
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
describe('Check case sensitive', function () {
|
|
1171
|
-
it('Should call event listener only when match case', function () {
|
|
1172
|
-
const eventEmmiter = new Jodit.modules.EventsNative(),
|
|
1173
|
-
simpleObject = {};
|
|
1174
|
-
let clicked = '';
|
|
1175
|
-
|
|
1176
|
-
eventEmmiter.on(simpleObject, 'click', function (count) {
|
|
1177
|
-
clicked += count;
|
|
1178
|
-
});
|
|
1179
|
-
|
|
1180
|
-
eventEmmiter.on(simpleObject, 'CLICK', function (count) {
|
|
1181
|
-
clicked += count;
|
|
1182
|
-
});
|
|
1183
|
-
|
|
1184
|
-
eventEmmiter.fire(simpleObject, 'Click', '1');
|
|
1185
|
-
eventEmmiter.fire(simpleObject, 'CLICK', '2');
|
|
1186
|
-
eventEmmiter.fire(simpleObject, 'click', '3');
|
|
1187
|
-
|
|
1188
|
-
expect('23').equals(clicked);
|
|
1189
|
-
});
|
|
1190
|
-
});
|
|
1191
|
-
|
|
1192
|
-
describe('Option events', function () {
|
|
1193
|
-
describe('Set events options', function () {
|
|
1194
|
-
it('Should set these in jodit.events', function () {
|
|
1195
|
-
let counter = [];
|
|
1196
|
-
const editor = getJodit({
|
|
1197
|
-
events: {
|
|
1198
|
-
afterInit: function () {
|
|
1199
|
-
counter.push('afterInit');
|
|
1200
|
-
},
|
|
1201
|
-
onSome: function () {
|
|
1202
|
-
counter.push('onSome');
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
});
|
|
1206
|
-
|
|
1207
|
-
editor.e.fire('onSome');
|
|
1208
|
-
|
|
1209
|
-
expect(counter.join('|')).equals('afterInit|onSome');
|
|
1210
|
-
});
|
|
1211
|
-
|
|
1212
|
-
describe('For several places', function () {
|
|
1213
|
-
it('Should set these in jodit.events', function () {
|
|
1214
|
-
let counter = [];
|
|
1215
|
-
const editor = getJodit({
|
|
1216
|
-
events: {
|
|
1217
|
-
afterInit: function () {
|
|
1218
|
-
counter.push('afterInit');
|
|
1219
|
-
},
|
|
1220
|
-
onSome: function () {
|
|
1221
|
-
counter.push('onSome');
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1225
|
-
|
|
1226
|
-
editor.addPlace(appendTestArea(), {
|
|
1227
|
-
events: {
|
|
1228
|
-
afterAddPlace: function () {
|
|
1229
|
-
counter.push('afterAddPlace');
|
|
1230
|
-
},
|
|
1231
|
-
onSome: function () {
|
|
1232
|
-
counter.push('onSome.place');
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
});
|
|
1236
|
-
|
|
1237
|
-
editor.e.fire('onSome');
|
|
1238
|
-
|
|
1239
|
-
expect(counter.join('|')).equals(
|
|
1240
|
-
'afterInit|afterAddPlace|onSome|onSome.place'
|
|
1241
|
-
);
|
|
1242
|
-
});
|
|
1243
|
-
});
|
|
1244
|
-
});
|
|
1245
|
-
});
|
|
1246
|
-
});
|