@wiris/mathtype-tinymce6 8.9.1 → 8.9.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/README.md +96 -95
- package/editor_plugin.src.js +183 -123
- package/global.js +11 -11
- package/package.json +2 -2
- package/plugin.min.js +1 -1
- package/project.json +4 -12
- package/webpack.config.js +99 -95
package/editor_plugin.src.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import IntegrationModel from
|
|
2
|
-
import Configuration from
|
|
3
|
-
import Parser from
|
|
4
|
-
import Util from
|
|
5
|
-
import Listeners from
|
|
6
|
-
import StringManager from
|
|
1
|
+
import IntegrationModel from "@wiris/mathtype-html-integration-devkit/src/integrationmodel";
|
|
2
|
+
import Configuration from "@wiris/mathtype-html-integration-devkit/src/configuration";
|
|
3
|
+
import Parser from "@wiris/mathtype-html-integration-devkit/src/parser";
|
|
4
|
+
import Util from "@wiris/mathtype-html-integration-devkit/src/util";
|
|
5
|
+
import Listeners from "@wiris/mathtype-html-integration-devkit/src/listeners";
|
|
6
|
+
import StringManager from "@wiris/mathtype-html-integration-devkit/src/stringmanager";
|
|
7
7
|
|
|
8
|
-
import packageInfo from
|
|
8
|
+
import packageInfo from "./package.json";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* TinyMCE integration class. This class extends IntegrationModel class.
|
|
@@ -38,13 +38,14 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
38
38
|
*/
|
|
39
39
|
getPath() {
|
|
40
40
|
if (this.isMoodle) {
|
|
41
|
-
const search =
|
|
41
|
+
const search = "lib/editor/tinymce";
|
|
42
42
|
const pos = tinymce.baseURL.indexOf(search);
|
|
43
43
|
const baseURL = tinymce.baseURL.substr(0, pos + search.length);
|
|
44
44
|
return `${baseURL}/plugins/tiny_mce_wiris/tinymce/`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
}
|
|
46
|
+
if (this.isExternal) {
|
|
47
|
+
const externalUrl = this.editorObject.options.get("external_plugins").tiny_mce_wiris;
|
|
48
|
+
return externalUrl.substring(0, externalUrl.lastIndexOf("/") + 1);
|
|
48
49
|
}
|
|
49
50
|
return `${tinymce.baseURL}/plugins/tiny_mce_wiris/`;
|
|
50
51
|
}
|
|
@@ -66,14 +67,14 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
66
67
|
const editorSettings = this.editorObject;
|
|
67
68
|
// Try to get editorParameters.language, fail silently otherwise
|
|
68
69
|
try {
|
|
69
|
-
return editorSettings.options.get(
|
|
70
|
+
return editorSettings.options.get("mathTypeParameters").editorParameters.language;
|
|
70
71
|
} catch (e) {}
|
|
71
72
|
// Get the deprecated wirisformulaeditorlang
|
|
72
|
-
if (editorSettings.options.get(
|
|
73
|
-
console.warn(
|
|
74
|
-
return editorSettings.options.get(
|
|
73
|
+
if (editorSettings.options.get("wirisformulaeditorlang")) {
|
|
74
|
+
console.warn("Deprecated property wirisformulaeditorlang. Use mathTypeParameters on instead.");
|
|
75
|
+
return editorSettings.options.get("wirisformulaeditorlang");
|
|
75
76
|
}
|
|
76
|
-
const langParam = this.editorObject.options.get(
|
|
77
|
+
const langParam = this.editorObject.options.get("language");
|
|
77
78
|
return langParam || super.getLanguage();
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -86,15 +87,19 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
86
87
|
super.callbackFunction();
|
|
87
88
|
|
|
88
89
|
// Avoid to change class of image formulas.
|
|
89
|
-
const imageClassName = Configuration.get(
|
|
90
|
+
const imageClassName = Configuration.get("imageClassName");
|
|
90
91
|
if (this.isIframe) {
|
|
91
92
|
// Attaching observers to wiris images.
|
|
92
|
-
if (typeof Parser.observer !==
|
|
93
|
-
Array.prototype.forEach.call(
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
if (typeof Parser.observer !== "undefined") {
|
|
94
|
+
Array.prototype.forEach.call(
|
|
95
|
+
this.target.contentDocument.getElementsByClassName(imageClassName),
|
|
96
|
+
(wirisImages) => {
|
|
97
|
+
Parser.observer.observe(wirisImages);
|
|
98
|
+
},
|
|
99
|
+
);
|
|
96
100
|
}
|
|
97
|
-
} else {
|
|
101
|
+
} else {
|
|
102
|
+
// Inline.
|
|
98
103
|
// Attaching observers to wiris images.
|
|
99
104
|
Array.prototype.forEach.call(document.getElementsByClassName(imageClassName), (wirisImages) => {
|
|
100
105
|
Parser.observer.observe(wirisImages);
|
|
@@ -103,9 +108,9 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
103
108
|
|
|
104
109
|
// When a formula is updated TinyMCE 'Change' event must be fired.
|
|
105
110
|
// See https://www.tiny.cloud/docs/advanced/events/#change for further information.
|
|
106
|
-
const listener = Listeners.newListener(
|
|
107
|
-
if (typeof this.editorObject.fire !==
|
|
108
|
-
this.editorObject.fire(
|
|
111
|
+
const listener = Listeners.newListener("onAfterFormulaInsertion", () => {
|
|
112
|
+
if (typeof this.editorObject.fire !== "undefined") {
|
|
113
|
+
this.editorObject.fire("Change");
|
|
109
114
|
}
|
|
110
115
|
});
|
|
111
116
|
this.getCore().addListener(listener);
|
|
@@ -114,11 +119,11 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
114
119
|
// Avoid filter formulas with performance enabled.
|
|
115
120
|
dataImgFiltered[this.editorObject.id] = this.editorObject.images_dataimg_filter;
|
|
116
121
|
this.editorObject.images_dataimg_filter = (img) => {
|
|
117
|
-
if (img.hasAttribute(
|
|
118
|
-
return img.hasAttribute(
|
|
122
|
+
if (img.hasAttribute("class") && img.getAttribute("class").indexOf(Configuration.get("imageClassName")) !== -1) {
|
|
123
|
+
return img.hasAttribute("internal-blob");
|
|
119
124
|
}
|
|
120
125
|
// If the client put an image data filter, run. Otherwise default behaviour (put blob).
|
|
121
|
-
if (typeof dataImgFiltered[this.editorObject.id] !==
|
|
126
|
+
if (typeof dataImgFiltered[this.editorObject.id] !== "undefined") {
|
|
122
127
|
return dataImgFiltered[this.editorObject.id](img);
|
|
123
128
|
}
|
|
124
129
|
return true;
|
|
@@ -130,8 +135,11 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
130
135
|
* @param {string} mathml - MathML to generate the formula and can be caught with the event.
|
|
131
136
|
*/
|
|
132
137
|
updateFormula(mathml) {
|
|
133
|
-
if (typeof this.editorObject.fire !==
|
|
134
|
-
this.editorObject.fire(
|
|
138
|
+
if (typeof this.editorObject.fire !== "undefined") {
|
|
139
|
+
this.editorObject.fire("ExecCommand", {
|
|
140
|
+
command: "updateFormula",
|
|
141
|
+
value: mathml,
|
|
142
|
+
});
|
|
135
143
|
}
|
|
136
144
|
super.updateFormula(mathml);
|
|
137
145
|
}
|
|
@@ -154,22 +162,22 @@ export class TinyMceIntegration extends IntegrationModel {
|
|
|
154
162
|
* @param {string} editor - Editor instance.
|
|
155
163
|
* @param {string} pluginName - TinyMCE 6 plugin name.
|
|
156
164
|
*/
|
|
157
|
-
registerMoodleOption
|
|
165
|
+
registerMoodleOption(editor, pluginName) {
|
|
158
166
|
const registerOption = editor.options.register;
|
|
159
167
|
|
|
160
168
|
registerOption(`${pluginName}:filterEnabled`, {
|
|
161
|
-
processor:
|
|
162
|
-
|
|
169
|
+
processor: "boolean",
|
|
170
|
+
default: false,
|
|
163
171
|
});
|
|
164
172
|
|
|
165
173
|
registerOption(`${pluginName}:editorEnabled`, {
|
|
166
|
-
processor:
|
|
167
|
-
|
|
174
|
+
processor: "boolean",
|
|
175
|
+
default: false,
|
|
168
176
|
});
|
|
169
177
|
|
|
170
178
|
registerOption(`${pluginName}:chemistryEnabled`, {
|
|
171
|
-
processor:
|
|
172
|
-
|
|
179
|
+
processor: "boolean",
|
|
180
|
+
default: false,
|
|
173
181
|
});
|
|
174
182
|
}
|
|
175
183
|
}
|
|
@@ -193,23 +201,24 @@ export const currentInstance = null;
|
|
|
193
201
|
with the TinyMCE instance and using the `external_plugins` option.
|
|
194
202
|
*/
|
|
195
203
|
(function () {
|
|
196
|
-
const isMoodle = !!(
|
|
197
|
-
const pluginName = isMoodle ?
|
|
204
|
+
const isMoodle = !!(typeof M === "object" && M !== null); // eslint-disable-line no-undef;
|
|
205
|
+
const pluginName = isMoodle ? "tiny_wiris/plugin" : "tiny_mce_wiris";
|
|
198
206
|
|
|
199
|
-
tinymce.PluginManager.add(pluginName, (editor, url) => ({
|
|
207
|
+
tinymce.PluginManager.add(pluginName, (editor, url) => ({
|
|
208
|
+
// eslint-disable-line no-unused-vars
|
|
200
209
|
init(editor) {
|
|
201
210
|
const callbackMethodArguments = {};
|
|
202
211
|
|
|
203
212
|
/**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
* Integration model properties
|
|
214
|
+
* @type {Object}
|
|
215
|
+
* @property {Object} target - Integration DOM target.
|
|
216
|
+
* @property {String} configurationService - Configuration integration service.
|
|
217
|
+
* @property {String} version - Plugin version.
|
|
218
|
+
* @property {String} scriptName - Integration script name.
|
|
219
|
+
* @property {Object} environment - Integration environment properties.
|
|
220
|
+
* @property {String} editor - Editor name.
|
|
221
|
+
*/
|
|
213
222
|
const integrationModelProperties = {};
|
|
214
223
|
integrationModelProperties.serviceProviderProperties = {
|
|
215
224
|
URI: process.env.SERVICE_PROVIDER_URI,
|
|
@@ -219,30 +228,37 @@ export const currentInstance = null;
|
|
|
219
228
|
integrationModelProperties.isMoodle = isMoodle; // eslint-disable-line no-undef
|
|
220
229
|
if (integrationModelProperties.isMoodle) {
|
|
221
230
|
// eslint-disable-next-line no-undef
|
|
222
|
-
integrationModelProperties.configurationService =
|
|
231
|
+
integrationModelProperties.configurationService =
|
|
232
|
+
M.cfg.wwwroot + "/filter/wiris/integration/configurationjs.php"; // eslint-disable-line prefer-template
|
|
223
233
|
}
|
|
224
|
-
if (typeof
|
|
225
|
-
integrationModelProperties.configurationService = Util.concatenateUrl(
|
|
226
|
-
|
|
227
|
-
|
|
234
|
+
if (typeof editor.options.get("wiriscontextpath") !== "undefined") {
|
|
235
|
+
integrationModelProperties.configurationService = Util.concatenateUrl(
|
|
236
|
+
editor.options.get("wiriscontextpath"),
|
|
237
|
+
integrationModelProperties.configurationService,
|
|
238
|
+
);
|
|
239
|
+
`${editor.options.get("wiriscontextpath")}/${integrationModelProperties.configurationService}`; // eslint-disable-line no-unused-expressions
|
|
240
|
+
console.warn(
|
|
241
|
+
"Deprecated property wiriscontextpath. Use mathTypeParameters instead.",
|
|
242
|
+
editor.opts.wiriscontextpath,
|
|
243
|
+
);
|
|
228
244
|
}
|
|
229
245
|
|
|
230
246
|
// Overriding MathType integration parameters.
|
|
231
247
|
|
|
232
248
|
// Register our custom parameters inside TinyMCE's options
|
|
233
|
-
editor.options.register(
|
|
234
|
-
processor:
|
|
249
|
+
editor.options.register("mathTypeParameters", {
|
|
250
|
+
processor: "object",
|
|
235
251
|
default: {},
|
|
236
252
|
});
|
|
237
253
|
|
|
238
|
-
if (editor.options.isRegistered(
|
|
239
|
-
integrationModelProperties.integrationParameters = editor.options.get(
|
|
254
|
+
if (editor.options.isRegistered("mathTypeParameters")) {
|
|
255
|
+
integrationModelProperties.integrationParameters = editor.options.get("mathTypeParameters");
|
|
240
256
|
}
|
|
241
257
|
|
|
242
|
-
integrationModelProperties.scriptName =
|
|
258
|
+
integrationModelProperties.scriptName = "plugin.min.js";
|
|
243
259
|
integrationModelProperties.environment = {};
|
|
244
260
|
|
|
245
|
-
integrationModelProperties.environment.editor =
|
|
261
|
+
integrationModelProperties.environment.editor = "TinyMCE 6.x";
|
|
246
262
|
integrationModelProperties.environment.editorVersion = `${tinymce.majorVersion}.${tinymce.minorVersion}`;
|
|
247
263
|
|
|
248
264
|
integrationModelProperties.callbackMethodArguments = callbackMethodArguments;
|
|
@@ -252,27 +268,31 @@ export const currentInstance = null;
|
|
|
252
268
|
// However, as TinyMCE is not initialized at this point the HTML target is not created.
|
|
253
269
|
// Here we create the target as null and onInit object the target is updated.
|
|
254
270
|
integrationModelProperties.target = null;
|
|
255
|
-
const isExternalPlugin =
|
|
271
|
+
const isExternalPlugin =
|
|
272
|
+
typeof editor.options.get("external_plugins") !== "undefined" &&
|
|
273
|
+
"tiny_mce_wiris" in editor.options.get("external_plugins");
|
|
256
274
|
integrationModelProperties.isExternal = isExternalPlugin;
|
|
257
|
-
integrationModelProperties.rtl =
|
|
275
|
+
integrationModelProperties.rtl = editor.options.get("directionality") === "rtl";
|
|
258
276
|
|
|
259
277
|
// Set Moodle configurations for Telemetry purposes.
|
|
260
278
|
const registerOption = editor.options.register;
|
|
261
279
|
registerOption(`${pluginName}:moodleCourseCategory`, {
|
|
262
|
-
processor:
|
|
263
|
-
|
|
280
|
+
processor: "integer",
|
|
281
|
+
default: undefined,
|
|
264
282
|
});
|
|
265
283
|
registerOption(`${pluginName}:moodleCourseName`, {
|
|
266
|
-
processor:
|
|
267
|
-
|
|
284
|
+
processor: "string",
|
|
285
|
+
default: undefined,
|
|
268
286
|
});
|
|
269
287
|
registerOption(`${pluginName}:moodleVersion`, {
|
|
270
|
-
processor:
|
|
271
|
-
|
|
288
|
+
processor: "integer",
|
|
289
|
+
default: undefined,
|
|
272
290
|
});
|
|
273
291
|
|
|
274
292
|
integrationModelProperties.environment.moodleVersion = editor.options.get(`${pluginName}:moodleVersion`);
|
|
275
|
-
integrationModelProperties.environment.moodleCourseCategory = editor.options.get(
|
|
293
|
+
integrationModelProperties.environment.moodleCourseCategory = editor.options.get(
|
|
294
|
+
`${pluginName}:moodleCourseCategory`,
|
|
295
|
+
);
|
|
276
296
|
integrationModelProperties.environment.moodleCourseName = editor.options.get(`${pluginName}:moodleCourseName`);
|
|
277
297
|
|
|
278
298
|
// GenericIntegration instance.
|
|
@@ -286,7 +306,8 @@ export const currentInstance = null;
|
|
|
286
306
|
tinyMceIntegrationInstance.registerMoodleOption(editor, pluginName);
|
|
287
307
|
}
|
|
288
308
|
|
|
289
|
-
const onInit = function (editor) {
|
|
309
|
+
const onInit = function (editor) {
|
|
310
|
+
// eslint-disable-line no-shadow
|
|
290
311
|
const integrationInstance = WirisPlugin.instances[tinyMceIntegrationInstance.editorObject.id];
|
|
291
312
|
if (!editor.inline) {
|
|
292
313
|
integrationInstance.setTarget(editor.getContentAreaContainer().firstChild);
|
|
@@ -294,28 +315,43 @@ export const currentInstance = null;
|
|
|
294
315
|
integrationInstance.setTarget(editor.getElement());
|
|
295
316
|
}
|
|
296
317
|
integrationInstance.setEditorObject(editor);
|
|
297
|
-
integrationInstance.listeners.fire(
|
|
298
|
-
if (editor.options.isRegistered(
|
|
299
|
-
Configuration.update(
|
|
318
|
+
integrationInstance.listeners.fire("onTargetReady", {});
|
|
319
|
+
if (editor.options.isRegistered("mathTypeParameters")) {
|
|
320
|
+
Configuration.update("editorParameters", editor.options.get("mathTypeParameters"));
|
|
300
321
|
}
|
|
301
322
|
|
|
302
323
|
// Prevent TinyMCE attributes insertion.
|
|
303
324
|
// TinyMCE insert attributes only when a new node is inserted.
|
|
304
325
|
// For this reason, the mutation observer only acts on addedNodes.
|
|
305
|
-
const mutationInstance = new MutationObserver(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
326
|
+
const mutationInstance = new MutationObserver(
|
|
327
|
+
function (editor, mutations) {
|
|
328
|
+
// eslint-disable-line no-shadow
|
|
329
|
+
Array.prototype.forEach.call(
|
|
330
|
+
mutations,
|
|
331
|
+
function (editor, mutation) {
|
|
332
|
+
// eslint-disable-line no-shadow
|
|
333
|
+
Array.prototype.forEach.call(
|
|
334
|
+
mutation.addedNodes,
|
|
335
|
+
function (editor, node) {
|
|
336
|
+
// eslint-disable-line no-shadow
|
|
337
|
+
if (node.nodeType === 1) {
|
|
338
|
+
// Act only in our own formulas.
|
|
339
|
+
Array.prototype.forEach.call(
|
|
340
|
+
node.querySelectorAll(`.${WirisPlugin.Configuration.get("imageClassName")}`),
|
|
341
|
+
((editor, image) => {
|
|
342
|
+
// eslint-disable-line no-shadow
|
|
343
|
+
// This only is executed due to init parse.
|
|
344
|
+
image.removeAttribute("data-mce-src");
|
|
345
|
+
image.removeAttribute("data-mce-style");
|
|
346
|
+
}).bind(this, editor),
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
}.bind(this, editor),
|
|
350
|
+
);
|
|
351
|
+
}.bind(this, editor),
|
|
352
|
+
);
|
|
353
|
+
}.bind(this, editor),
|
|
354
|
+
);
|
|
319
355
|
mutationInstance.observe(editor.getBody(), {
|
|
320
356
|
attributes: true,
|
|
321
357
|
childList: true,
|
|
@@ -326,7 +362,7 @@ export const currentInstance = null;
|
|
|
326
362
|
const content = editor.getContent();
|
|
327
363
|
// We set content in html because other tiny plugins need data-mce
|
|
328
364
|
// and this is not possible with raw format.
|
|
329
|
-
editor.setContent(Parser.initParse(content, editor.options.get(
|
|
365
|
+
editor.setContent(Parser.initParse(content, editor.options.get("language")), { format: "html" });
|
|
330
366
|
// This clean undoQueue for prevent onChange and Dirty state.
|
|
331
367
|
editor.undoManager.clear();
|
|
332
368
|
// Init parsing OK. If a setContent method is called
|
|
@@ -336,62 +372,76 @@ export const currentInstance = null;
|
|
|
336
372
|
WirisPlugin.instances[editor.id].initParsed = true;
|
|
337
373
|
};
|
|
338
374
|
|
|
339
|
-
|
|
375
|
+
// Change the destroy behavior to also destroy the MathType instance.
|
|
376
|
+
const destroy = editor.destroy;
|
|
377
|
+
|
|
378
|
+
editor.destroy = function () {
|
|
379
|
+
WirisPlugin.instances[editor.id].listeners.fire("onDestroy", {});
|
|
380
|
+
|
|
381
|
+
// Destroy the Mathtype instance.
|
|
382
|
+
WirisPlugin.instances[editor.id].destroy();
|
|
383
|
+
destroy.call(editor);
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
if ("onInit" in editor) {
|
|
340
387
|
editor.onInit.add(onInit);
|
|
341
388
|
} else {
|
|
342
|
-
editor.on(
|
|
389
|
+
editor.on("init", () => {
|
|
343
390
|
onInit(editor);
|
|
344
391
|
});
|
|
345
392
|
}
|
|
346
393
|
|
|
347
|
-
if (
|
|
348
|
-
editor.onActivate.add((editor) => {
|
|
394
|
+
if ("onActivate" in editor) {
|
|
395
|
+
editor.onActivate.add((editor) => {
|
|
396
|
+
// eslint-disable-line no-unused-vars, no-shadow
|
|
349
397
|
WirisPlugin.currentInstance = WirisPlugin.instances[tinymce.activeEditor.id];
|
|
350
398
|
});
|
|
351
399
|
} else {
|
|
352
|
-
editor.on(
|
|
400
|
+
editor.on("focus", (event) => {
|
|
401
|
+
// eslint-disable-line no-unused-vars, no-shadow
|
|
353
402
|
WirisPlugin.currentInstance = WirisPlugin.instances[tinymce.activeEditor.id];
|
|
354
403
|
});
|
|
355
404
|
}
|
|
356
405
|
|
|
357
|
-
const onSave = function (editor, params) {
|
|
406
|
+
const onSave = function (editor, params) {
|
|
407
|
+
// eslint-disable-line no-shadow
|
|
358
408
|
if (integrationModelProperties.isMoodle) {
|
|
359
|
-
params.content = Parser.endParseSaveMode(params.content, editor.getParam(
|
|
409
|
+
params.content = Parser.endParseSaveMode(params.content, editor.getParam("language"));
|
|
360
410
|
} else {
|
|
361
|
-
params.content = Parser.endParse(params.content, editor.getParam(
|
|
411
|
+
params.content = Parser.endParse(params.content, editor.getParam("language"));
|
|
362
412
|
}
|
|
363
413
|
};
|
|
364
414
|
|
|
365
|
-
if (
|
|
415
|
+
if ("onSaveContent" in editor) {
|
|
366
416
|
editor.onSaveContent.add(onSave);
|
|
367
417
|
} else {
|
|
368
|
-
editor.on(
|
|
418
|
+
editor.on("saveContent", (params) => {
|
|
369
419
|
onSave(editor, params);
|
|
370
420
|
});
|
|
371
421
|
}
|
|
372
422
|
|
|
373
|
-
if (
|
|
423
|
+
if ("onGetContent" in editor) {
|
|
374
424
|
editor.onGetContent.add(onSave);
|
|
375
425
|
} else {
|
|
376
|
-
editor.on(
|
|
426
|
+
editor.on("getContent", (params) => {
|
|
377
427
|
onSave(editor, params);
|
|
378
428
|
});
|
|
379
429
|
}
|
|
380
430
|
|
|
381
|
-
if (
|
|
431
|
+
if ("onBeforeSetContent" in editor) {
|
|
382
432
|
editor.onBeforeSetContent.add((e, params) => {
|
|
383
433
|
if (integrationModelProperties.isMoodle) {
|
|
384
|
-
params.content = Parser.initParseSaveMode(params.content, editor.getParam(
|
|
434
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam("language"));
|
|
385
435
|
} else if (WirisPlugin.instances[editor.id].initParsed) {
|
|
386
|
-
params.content = Parser.initParseSaveMode(params.content, editor.getParam(
|
|
436
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam("language"));
|
|
387
437
|
}
|
|
388
438
|
});
|
|
389
439
|
} else {
|
|
390
|
-
editor.on(
|
|
440
|
+
editor.on("beforeSetContent", (params) => {
|
|
391
441
|
if (integrationModelProperties.isMoodle) {
|
|
392
|
-
params.content = Parser.initParseSaveMode(params.content, editor.getParam(
|
|
442
|
+
params.content = Parser.initParseSaveMode(params.content, editor.getParam("language"));
|
|
393
443
|
} else if (WirisPlugin.instances[editor.id].initParsed) {
|
|
394
|
-
params.content = Parser.initParse(params.content, editor.getParam(
|
|
444
|
+
params.content = Parser.initParse(params.content, editor.getParam("language"));
|
|
395
445
|
}
|
|
396
446
|
});
|
|
397
447
|
}
|
|
@@ -404,34 +454,44 @@ export const currentInstance = null;
|
|
|
404
454
|
}
|
|
405
455
|
|
|
406
456
|
const commonEditor = editor.ui.registry;
|
|
407
|
-
const mathTypeIcon =
|
|
408
|
-
const chemTypeIcon =
|
|
409
|
-
const mathTypeIconSvg =
|
|
410
|
-
|
|
457
|
+
const mathTypeIcon = "mathtypeicon";
|
|
458
|
+
const chemTypeIcon = "chemtypeicon";
|
|
459
|
+
const mathTypeIconSvg =
|
|
460
|
+
'<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"viewBox="0 0 300 261.7" style="enable-background:new 0 0 300 261.7;" xml:space="preserve"><g id=icon-wirisformula stroke="none" stroke-width="1" fill-rule="evenodd"><g><path class="st1" d="M90.2,257.7c-11.4,0-21.9-6.4-27-16.7l-60-119.9c-7.5-14.9-1.4-33.1,13.5-40.5c14.9-7.5,33.1-1.4,40.5,13.5l27.3,54.7L121.1,39c5.3-15.8,22.4-24.4,38.2-19.1c15.8,5.3,24.4,22.4,19.1,38.2l-59.6,179c-3.9,11.6-14.3,19.7-26.5,20.6C91.6,257.7,90.9,257.7,90.2,257.7"/></g></g><g><g><path class="st2" d="M300,32.8c0-16.4-13.4-29.7-29.9-29.7c-2.9,0-7.2,0.8-7.2,0.8c-37.9,9.1-71.3,14-112,14c-0.3,0-0.6,0-1,0c-16.5,0-29.9,13.3-29.9,29.7c0,16.4,13.4,29.7,29.9,29.7l0,0c45.3,0,83.1-5.3,125.3-15.3h0C289.3,59.5,300,47.4,300,32.8"/></g></g></svg>'; // eslint-disable-line max-len
|
|
461
|
+
const chemTypeIconSvg =
|
|
462
|
+
'<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"viewBox="0 0 40.3 49.5" style="enable-background:new 0 0 40.3 49.5;" xml:space="preserve"><g id=icon-wirisformula stroke="none" stroke-width="1" fill-rule="evenodd"><g><path class="st1" d="M39.2,12.1c0-1.9-1.1-3.6-2.7-4.4L24.5,0.9l0,0c-0.7-0.4-1.5-0.6-2.4-0.6c-0.9,0-1.7,0.2-2.4,0.6l0,0L2.3,10.8 l0,0C0.9,11.7,0,13.2,0,14.9h0v19.6h0c0,1.7,0.9,3.3,2.3,4.1l0,0l17.4,9.9l0,0c0.7,0.4,1.5,0.6,2.4,0.6c0.9,0,1.7-0.2,2.4-0.6l0,0 l12.2-6.9h0c1.5-0.8,2.6-2.5,2.6-4.3c0-2.7-2.2-4.9-4.9-4.9c-0.9,0-1.8,0.3-2.5,0.7l0,0l-9.7,5.6l-12.3-7V17.8l12.3-7l9.9,5.7l0,0 c0.7,0.4,1.5,0.6,2.4,0.6C37,17,39.2,14.8,39.2,12.1"/></g></g></svg>';
|
|
411
463
|
|
|
412
464
|
commonEditor.addIcon(mathTypeIcon, mathTypeIconSvg);
|
|
413
465
|
commonEditor.addIcon(chemTypeIcon, chemTypeIconSvg);
|
|
414
466
|
|
|
415
467
|
// Get editor language code
|
|
416
|
-
let lang_code = editor.options.get(
|
|
417
|
-
lang_code =
|
|
468
|
+
let lang_code = editor.options.get("language");
|
|
469
|
+
lang_code = lang_code.split("-")[0].split("_")[0];
|
|
418
470
|
|
|
419
471
|
// Check If MathType/ChemType are enabled on Moodle
|
|
420
|
-
const editorEnabled =
|
|
421
|
-
|
|
472
|
+
const editorEnabled =
|
|
473
|
+
!isMoodle ||
|
|
474
|
+
(isMoodle &&
|
|
475
|
+
editor.options.get(`${pluginName}:editorEnabled`) &&
|
|
476
|
+
editor.options.get(`${pluginName}:filterEnabled`));
|
|
477
|
+
const chemEnabled =
|
|
478
|
+
!isMoodle ||
|
|
479
|
+
(isMoodle &&
|
|
480
|
+
editor.options.get(`${pluginName}:chemistryEnabled`) &&
|
|
481
|
+
editor.options.get(`${pluginName}:filterEnabled`));
|
|
422
482
|
|
|
423
483
|
if (editorEnabled) {
|
|
424
484
|
// The next two blocks create menu items to give the possibility
|
|
425
485
|
// of add MathType in the menubar.
|
|
426
|
-
commonEditor.addMenuItem(
|
|
427
|
-
text:
|
|
486
|
+
commonEditor.addMenuItem("tiny_mce_wiris_formulaEditor", {
|
|
487
|
+
text: "MathType",
|
|
428
488
|
icon: mathTypeIcon,
|
|
429
489
|
onAction: openFormulaEditorFunction,
|
|
430
490
|
});
|
|
431
491
|
|
|
432
492
|
// MathType button.
|
|
433
|
-
commonEditor.addButton(
|
|
434
|
-
tooltip: StringManager.get(
|
|
493
|
+
commonEditor.addButton("tiny_mce_wiris_formulaEditor", {
|
|
494
|
+
tooltip: StringManager.get("insert_math", lang_code),
|
|
435
495
|
image: `${WirisPlugin.instances[editor.id].getIconsPath()}formula.png`,
|
|
436
496
|
onAction: openFormulaEditorFunction,
|
|
437
497
|
icon: mathTypeIcon,
|
|
@@ -465,7 +525,7 @@ export const currentInstance = null;
|
|
|
465
525
|
}
|
|
466
526
|
editor.addCommand(cmd, commandFunction);
|
|
467
527
|
commonEditor.addButton(`tiny_mce_wiris_formulaEditor${customEditors.editors[customEditor].name}`, {
|
|
468
|
-
tooltip: StringManager.get(
|
|
528
|
+
tooltip: StringManager.get("insert_chem", lang_code),
|
|
469
529
|
onAction: commandFunction,
|
|
470
530
|
image: WirisPlugin.instances[editor.id].getIconsPath() + customEditors.editors[customEditor].icon,
|
|
471
531
|
icon: chemTypeIcon, // At the moment only chemTypeIcon because of the provisional solution for TinyMCE6.
|
|
@@ -478,11 +538,11 @@ export const currentInstance = null;
|
|
|
478
538
|
// All versions.
|
|
479
539
|
getMetadata() {
|
|
480
540
|
return {
|
|
481
|
-
longname:
|
|
482
|
-
name:
|
|
483
|
-
url:
|
|
541
|
+
longname: "tiny_mce_wiris",
|
|
542
|
+
name: "Maths for More",
|
|
543
|
+
url: "http://www.wiris.com",
|
|
484
544
|
version: packageInfo.version,
|
|
485
545
|
};
|
|
486
546
|
},
|
|
487
547
|
}));
|
|
488
|
-
}()
|
|
548
|
+
})();
|
package/global.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import Core from
|
|
2
|
-
import Parser from
|
|
3
|
-
import Util from
|
|
4
|
-
import Image from
|
|
5
|
-
import Configuration from
|
|
6
|
-
import Listeners from
|
|
7
|
-
import IntegrationModel from
|
|
8
|
-
import Latex from
|
|
9
|
-
import
|
|
10
|
-
import Test from
|
|
11
|
-
import { TinyMceIntegration, currentInstance, instances } from
|
|
1
|
+
import Core from "@wiris/mathtype-html-integration-devkit/src/core.src";
|
|
2
|
+
import Parser from "@wiris/mathtype-html-integration-devkit/src/parser";
|
|
3
|
+
import Util from "@wiris/mathtype-html-integration-devkit/src/util";
|
|
4
|
+
import Image from "@wiris/mathtype-html-integration-devkit/src/image";
|
|
5
|
+
import Configuration from "@wiris/mathtype-html-integration-devkit/src/configuration";
|
|
6
|
+
import Listeners from "@wiris/mathtype-html-integration-devkit/src/listeners";
|
|
7
|
+
import IntegrationModel from "@wiris/mathtype-html-integration-devkit/src/integrationmodel";
|
|
8
|
+
import Latex from "@wiris/mathtype-html-integration-devkit/src/latex";
|
|
9
|
+
import "@wiris/mathtype-html-integration-devkit/src/backwardslib";
|
|
10
|
+
import Test from "@wiris/mathtype-html-integration-devkit/src/test";
|
|
11
|
+
import { TinyMceIntegration, currentInstance, instances } from "./editor_plugin.src";
|
|
12
12
|
|
|
13
13
|
// Expose WirisPlugin variable to the window.
|
|
14
14
|
window.WirisPlugin = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wiris/mathtype-tinymce6",
|
|
3
|
-
"version": "8.9.
|
|
3
|
+
"version": "8.9.2",
|
|
4
4
|
"description": "MathType Web for TinyMCE6 editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chem",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepack": "yarn && npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@wiris/mathtype-html-integration-devkit": "1.17.
|
|
35
|
+
"@wiris/mathtype-html-integration-devkit": "1.17.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "^7.24.4",
|