Hooks.js
1.4 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
/**
* Hooks.js
*
* Released under LGPL License.
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* Internal class for overriding formatting.
*
* @private
* @class tinymce.fmt.Hooks
*/
define("tinymce/fmt/Hooks", [
"tinymce/util/Arr",
"tinymce/dom/NodeType",
"tinymce/dom/DomQuery"
], function(Arr, NodeType, $) {
var postProcessHooks = [], filter = Arr.filter, each = Arr.each;
function addPostProcessHook(name, hook) {
var hooks = postProcessHooks[name];
if (!hooks) {
postProcessHooks[name] = hooks = [];
}
postProcessHooks[name].push(hook);
}
function postProcess(name, editor) {
each(postProcessHooks[name], function(hook) {
hook(editor);
});
}
addPostProcessHook("pre", function(editor) {
var rng = editor.selection.getRng(), isPre, blocks;
function hasPreSibling(pre) {
return isPre(pre.previousSibling) && Arr.indexOf(blocks, pre.previousSibling) != -1;
}
function joinPre(pre1, pre2) {
$(pre2).remove();
$(pre1).append('<br><br>').append(pre2.childNodes);
}
isPre = NodeType.matchNodeNames('pre');
if (!rng.collapsed) {
blocks = editor.selection.getSelectedBlocks();
each(filter(filter(blocks, isPre), hasPreSibling), function(pre) {
joinPre(pre.previousSibling, pre);
});
}
});
return {
postProcess: postProcess
};
});