| 1 |
efrain |
1 |
/**
|
| 1441 |
ariadna |
2 |
* TinyMCE version 7.7.1 (2025-03-05)
|
| 1 |
efrain |
3 |
*/
|
|
|
4 |
|
|
|
5 |
(function () {
|
|
|
6 |
'use strict';
|
|
|
7 |
|
|
|
8 |
var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
|
|
9 |
|
|
|
10 |
const isSimpleType = type => value => typeof value === type;
|
|
|
11 |
const isFunction = isSimpleType('function');
|
|
|
12 |
|
|
|
13 |
var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
|
|
|
14 |
|
|
|
15 |
var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
|
|
|
16 |
|
|
|
17 |
const option = name => editor => editor.options.get(name);
|
|
|
18 |
const register$2 = editor => {
|
|
|
19 |
const registerOption = editor.options.register;
|
|
|
20 |
registerOption('save_enablewhendirty', {
|
|
|
21 |
processor: 'boolean',
|
|
|
22 |
default: true
|
|
|
23 |
});
|
|
|
24 |
registerOption('save_onsavecallback', { processor: 'function' });
|
|
|
25 |
registerOption('save_oncancelcallback', { processor: 'function' });
|
|
|
26 |
};
|
|
|
27 |
const enableWhenDirty = option('save_enablewhendirty');
|
|
|
28 |
const getOnSaveCallback = option('save_onsavecallback');
|
|
|
29 |
const getOnCancelCallback = option('save_oncancelcallback');
|
|
|
30 |
|
|
|
31 |
const displayErrorMessage = (editor, message) => {
|
|
|
32 |
editor.notificationManager.open({
|
|
|
33 |
text: message,
|
|
|
34 |
type: 'error'
|
|
|
35 |
});
|
|
|
36 |
};
|
|
|
37 |
const save = editor => {
|
|
|
38 |
const formObj = global$1.DOM.getParent(editor.id, 'form');
|
|
|
39 |
if (enableWhenDirty(editor) && !editor.isDirty()) {
|
|
|
40 |
return;
|
|
|
41 |
}
|
|
|
42 |
editor.save();
|
|
|
43 |
const onSaveCallback = getOnSaveCallback(editor);
|
|
|
44 |
if (isFunction(onSaveCallback)) {
|
|
|
45 |
onSaveCallback.call(editor, editor);
|
|
|
46 |
editor.nodeChanged();
|
|
|
47 |
return;
|
|
|
48 |
}
|
|
|
49 |
if (formObj) {
|
|
|
50 |
editor.setDirty(false);
|
|
|
51 |
if (!formObj.onsubmit || formObj.onsubmit()) {
|
|
|
52 |
if (typeof formObj.submit === 'function') {
|
|
|
53 |
formObj.submit();
|
|
|
54 |
} else {
|
|
|
55 |
displayErrorMessage(editor, 'Error: Form submit field collision.');
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
editor.nodeChanged();
|
|
|
59 |
} else {
|
|
|
60 |
displayErrorMessage(editor, 'Error: No form element found.');
|
|
|
61 |
}
|
|
|
62 |
};
|
|
|
63 |
const cancel = editor => {
|
|
|
64 |
const h = global.trim(editor.startContent);
|
|
|
65 |
const onCancelCallback = getOnCancelCallback(editor);
|
|
|
66 |
if (isFunction(onCancelCallback)) {
|
|
|
67 |
onCancelCallback.call(editor, editor);
|
|
|
68 |
return;
|
|
|
69 |
}
|
|
|
70 |
editor.resetContent(h);
|
|
|
71 |
};
|
|
|
72 |
|
|
|
73 |
const register$1 = editor => {
|
|
|
74 |
editor.addCommand('mceSave', () => {
|
|
|
75 |
save(editor);
|
|
|
76 |
});
|
|
|
77 |
editor.addCommand('mceCancel', () => {
|
|
|
78 |
cancel(editor);
|
|
|
79 |
});
|
|
|
80 |
};
|
|
|
81 |
|
|
|
82 |
const stateToggle = editor => api => {
|
|
|
83 |
const handler = () => {
|
|
|
84 |
api.setEnabled(!enableWhenDirty(editor) || editor.isDirty());
|
|
|
85 |
};
|
|
|
86 |
handler();
|
|
|
87 |
editor.on('NodeChange dirty', handler);
|
|
|
88 |
return () => editor.off('NodeChange dirty', handler);
|
|
|
89 |
};
|
|
|
90 |
const register = editor => {
|
|
|
91 |
editor.ui.registry.addButton('save', {
|
|
|
92 |
icon: 'save',
|
|
|
93 |
tooltip: 'Save',
|
|
|
94 |
enabled: false,
|
|
|
95 |
onAction: () => editor.execCommand('mceSave'),
|
| 1441 |
ariadna |
96 |
onSetup: stateToggle(editor),
|
|
|
97 |
shortcut: 'Meta+S'
|
| 1 |
efrain |
98 |
});
|
|
|
99 |
editor.ui.registry.addButton('cancel', {
|
|
|
100 |
icon: 'cancel',
|
|
|
101 |
tooltip: 'Cancel',
|
|
|
102 |
enabled: false,
|
|
|
103 |
onAction: () => editor.execCommand('mceCancel'),
|
|
|
104 |
onSetup: stateToggle(editor)
|
|
|
105 |
});
|
|
|
106 |
editor.addShortcut('Meta+S', '', 'mceSave');
|
|
|
107 |
};
|
|
|
108 |
|
|
|
109 |
var Plugin = () => {
|
|
|
110 |
global$2.add('save', editor => {
|
|
|
111 |
register$2(editor);
|
|
|
112 |
register(editor);
|
|
|
113 |
register$1(editor);
|
|
|
114 |
});
|
|
|
115 |
};
|
|
|
116 |
|
|
|
117 |
Plugin();
|
|
|
118 |
|
|
|
119 |
})();
|