1 |
efrain |
1 |
/**
|
|
|
2 |
* TinyMCE version 6.8.3 (2024-02-08)
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
(function () {
|
|
|
6 |
'use strict';
|
|
|
7 |
|
|
|
8 |
var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
|
|
9 |
|
|
|
10 |
var global = tinymce.util.Tools.resolve('tinymce.Env');
|
|
|
11 |
|
|
|
12 |
const option = name => editor => editor.options.get(name);
|
|
|
13 |
const register$2 = editor => {
|
|
|
14 |
const registerOption = editor.options.register;
|
|
|
15 |
registerOption('pagebreak_separator', {
|
|
|
16 |
processor: 'string',
|
|
|
17 |
default: '<!-- pagebreak -->'
|
|
|
18 |
});
|
|
|
19 |
registerOption('pagebreak_split_block', {
|
|
|
20 |
processor: 'boolean',
|
|
|
21 |
default: false
|
|
|
22 |
});
|
|
|
23 |
};
|
|
|
24 |
const getSeparatorHtml = option('pagebreak_separator');
|
|
|
25 |
const shouldSplitBlock = option('pagebreak_split_block');
|
|
|
26 |
|
|
|
27 |
const pageBreakClass = 'mce-pagebreak';
|
|
|
28 |
const getPlaceholderHtml = shouldSplitBlock => {
|
|
|
29 |
const html = `<img src="${ global.transparentSrc }" class="${ pageBreakClass }" data-mce-resize="false" data-mce-placeholder />`;
|
|
|
30 |
return shouldSplitBlock ? `<p>${ html }</p>` : html;
|
|
|
31 |
};
|
|
|
32 |
const setup$1 = editor => {
|
|
|
33 |
const separatorHtml = getSeparatorHtml(editor);
|
|
|
34 |
const shouldSplitBlock$1 = () => shouldSplitBlock(editor);
|
|
|
35 |
const pageBreakSeparatorRegExp = new RegExp(separatorHtml.replace(/[\?\.\*\[\]\(\)\{\}\+\^\$\:]/g, a => {
|
|
|
36 |
return '\\' + a;
|
|
|
37 |
}), 'gi');
|
|
|
38 |
editor.on('BeforeSetContent', e => {
|
|
|
39 |
e.content = e.content.replace(pageBreakSeparatorRegExp, getPlaceholderHtml(shouldSplitBlock$1()));
|
|
|
40 |
});
|
|
|
41 |
editor.on('PreInit', () => {
|
|
|
42 |
editor.serializer.addNodeFilter('img', nodes => {
|
|
|
43 |
let i = nodes.length, node, className;
|
|
|
44 |
while (i--) {
|
|
|
45 |
node = nodes[i];
|
|
|
46 |
className = node.attr('class');
|
|
|
47 |
if (className && className.indexOf(pageBreakClass) !== -1) {
|
|
|
48 |
const parentNode = node.parent;
|
|
|
49 |
if (parentNode && editor.schema.getBlockElements()[parentNode.name] && shouldSplitBlock$1()) {
|
|
|
50 |
parentNode.type = 3;
|
|
|
51 |
parentNode.value = separatorHtml;
|
|
|
52 |
parentNode.raw = true;
|
|
|
53 |
node.remove();
|
|
|
54 |
continue;
|
|
|
55 |
}
|
|
|
56 |
node.type = 3;
|
|
|
57 |
node.value = separatorHtml;
|
|
|
58 |
node.raw = true;
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
});
|
|
|
62 |
});
|
|
|
63 |
};
|
|
|
64 |
|
|
|
65 |
const register$1 = editor => {
|
|
|
66 |
editor.addCommand('mcePageBreak', () => {
|
|
|
67 |
editor.insertContent(getPlaceholderHtml(shouldSplitBlock(editor)));
|
|
|
68 |
});
|
|
|
69 |
};
|
|
|
70 |
|
|
|
71 |
const setup = editor => {
|
|
|
72 |
editor.on('ResolveName', e => {
|
|
|
73 |
if (e.target.nodeName === 'IMG' && editor.dom.hasClass(e.target, pageBreakClass)) {
|
|
|
74 |
e.name = 'pagebreak';
|
|
|
75 |
}
|
|
|
76 |
});
|
|
|
77 |
};
|
|
|
78 |
|
|
|
79 |
const onSetupEditable = editor => api => {
|
|
|
80 |
const nodeChanged = () => {
|
|
|
81 |
api.setEnabled(editor.selection.isEditable());
|
|
|
82 |
};
|
|
|
83 |
editor.on('NodeChange', nodeChanged);
|
|
|
84 |
nodeChanged();
|
|
|
85 |
return () => {
|
|
|
86 |
editor.off('NodeChange', nodeChanged);
|
|
|
87 |
};
|
|
|
88 |
};
|
|
|
89 |
const register = editor => {
|
|
|
90 |
const onAction = () => editor.execCommand('mcePageBreak');
|
|
|
91 |
editor.ui.registry.addButton('pagebreak', {
|
|
|
92 |
icon: 'page-break',
|
|
|
93 |
tooltip: 'Page break',
|
|
|
94 |
onAction,
|
|
|
95 |
onSetup: onSetupEditable(editor)
|
|
|
96 |
});
|
|
|
97 |
editor.ui.registry.addMenuItem('pagebreak', {
|
|
|
98 |
text: 'Page break',
|
|
|
99 |
icon: 'page-break',
|
|
|
100 |
onAction,
|
|
|
101 |
onSetup: onSetupEditable(editor)
|
|
|
102 |
});
|
|
|
103 |
};
|
|
|
104 |
|
|
|
105 |
var Plugin = () => {
|
|
|
106 |
global$1.add('pagebreak', editor => {
|
|
|
107 |
register$2(editor);
|
|
|
108 |
register$1(editor);
|
|
|
109 |
register(editor);
|
|
|
110 |
setup$1(editor);
|
|
|
111 |
setup(editor);
|
|
|
112 |
});
|
|
|
113 |
};
|
|
|
114 |
|
|
|
115 |
Plugin();
|
|
|
116 |
|
|
|
117 |
})();
|