MCPcopy Index your code
hub / github.com/tinymce/tinymce / add

Function add

modules/tinymce/src/core/main/ts/api/EditorManager.ts:524–561  ·  view source on GitHub ↗

* Adds an editor instance to the editor collection. This will also set it as the active editor. * * @method add * @param {tinymce.Editor} editor Editor instance to add to the collection. * @return {tinymce.Editor} The same instance that got passed in.

(editor)

Source from the content-addressed store, hash-verified

522 * @return {tinymce.Editor} The same instance that got passed in.
523 */
524 add(editor) {
525 const self: EditorManager = this;
526
527 // Prevent existing editors from being added again this could happen
528 // if a user calls createEditor then render or add multiple times.
529 const existingEditor = self.get(editor.id);
530 if (existingEditor === editor) {
531 return editor;
532 }
533
534 if (existingEditor === null) {
535 editors.push(editor);
536 }
537
538 toggleGlobalEvents(true);
539
540 // Doesn't call setActive method since we don't want
541 // to fire a bunch of activate/deactivate calls while initializing
542 self.activeEditor = editor;
543
544 self.dispatch('AddEditor', { editor });
545
546 if (!beforeUnloadDelegate) {
547 beforeUnloadDelegate = (e) => {
548 const event = self.dispatch('BeforeUnload');
549 if (event.returnValue) {
550 // browsers are all a little bit special about this: https://developer.mozilla.org/en-US/docs/Web/API/BeforeUnloadEvent
551 e.preventDefault();
552 e.returnValue = event.returnValue;
553 return event.returnValue;
554 }
555 };
556
557 window.addEventListener('beforeunload', beforeUnloadDelegate);
558 }
559
560 return editor;
561 },
562
563 /**
564 * Creates an editor instance and adds it to the EditorManager collection.

Callers

nothing calls this directly

Calls 3

toggleGlobalEventsFunction · 0.85
getMethod · 0.65
dispatchMethod · 0.65

Tested by

no test coverage detected