diff --git a/src/static/js/ace.js b/src/static/js/ace.js index af402dd2e..dde1134db 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -184,10 +184,10 @@ const Ace2Editor = function () { outerDocument.documentElement.classList.add('inner-editor', 'outerdoc', ...skinVariants); addStyleTagsFor(outerDocument, includedCSS); - const style = outerDocument.createElement('style'); - style.type = 'text/css'; - style.title = 'dynamicsyntax'; - outerDocument.head.appendChild(style); + const styleO = outerDocument.createElement('style'); + styleO.type = 'text/css'; + styleO.title = 'dynamicsyntax'; + outerDocument.head.appendChild(styleO); const link = outerDocument.createElement('link'); link.rel = 'stylesheet'; @@ -196,69 +196,65 @@ const Ace2Editor = function () { outerDocument.head.appendChild(link); outerWindow.editorInfo = Ace2Editor.registry[info.id]; - outerWindow.onload = () => { - outerWindow.onload = null; - const window = outerWindow; - const document = outerDocument; - setTimeout(() => { - const iframe = document.createElement('iframe'); - iframe.name = 'ace_inner'; - iframe.title = 'pad'; - iframe.scrolling = 'no'; - iframe.frameBorder = 0; - iframe.allowTransparency = true; // for IE - iframe.ace_outerWin = window; - document.body.insertBefore(iframe, document.body.firstChild); - window.readyFunc = () => { - delete window.readyFunc; - window.editorInfo.onEditorReady(); - delete window.editorInfo; - }; - const innerWindow = iframe.contentWindow; - const innerDocument = innerWindow.document; - innerDocument.documentElement.classList.add('inner-editor', ...skinVariants); - addStyleTagsFor(innerDocument, includedCSS); + const iframe = outerDocument.createElement('iframe'); + iframe.name = 'ace_inner'; + iframe.title = 'pad'; + iframe.scrolling = 'no'; + iframe.frameBorder = 0; + iframe.allowTransparency = true; // for IE + iframe.ace_outerWin = outerWindow; + const innerOnloadHandler = () => { + const require = window[1].frames[0].require; + if(!require) { + setTimeout(innerOnloadHandler, 10); + } else { + require.setRootURI('../javascripts/src'); + require.setLibraryURI('../javascripts/lib'); + require.setGlobalKeyPath('require'); - const script = innerDocument.createElement('script'); - script.type = 'text/javascript'; - script.src = `../static/js/require-kernel.js?v=${clientVars.randomVersionString}`; - innerDocument.head.appendChild(script); + const plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins'); + plugins.adoptPluginsFromAncestorsOf(window); - innerWindow.onload = () => { - innerWindow.onload = null; - const window = innerWindow; - const require = window.require; - require.setRootURI('../javascripts/src'); - require.setLibraryURI('../javascripts/lib'); - require.setGlobalKeyPath('require'); + const jQuery = require('ep_etherpad-lite/static/js/rjquery').jQuery; + window[1].frames[0].$ = jQuery; + const Ace2Inner = require('ep_etherpad-lite/static/js/ace2_inner'); - window.plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins'); - window.plugins.adoptPluginsFromAncestorsOf(window); - - window.$ = window.jQuery = require('ep_etherpad-lite/static/js/rjquery').jQuery; - window.Ace2Inner = require('ep_etherpad-lite/static/js/ace2_inner'); - - window.plugins.ensure(() => window.Ace2Inner.init()); - }; - - const style = innerDocument.createElement('style'); - style.type = 'text/css'; - style.title = 'dynamicsyntax'; - innerDocument.head.appendChild(style); - - const headLines = []; - hooks.callAll('aceInitInnerdocbodyHead', {iframeHTML: headLines}); - const tmp = innerDocument.createElement('div'); - tmp.innerHTML = headLines.join('\n'); - while (tmp.firstChild) innerDocument.head.appendChild(tmp.firstChild); - - innerDocument.body.id = 'innerdocbody'; - innerDocument.body.classList.add('innerdocbody'); - innerDocument.body.setAttribute('role', 'application'); - innerDocument.body.setAttribute('spellcheck', 'false'); - innerDocument.body.appendChild(innerDocument.createTextNode('\u00A0')); //   - }, 0); + plugins.ensure(() => Ace2Inner.init()); + } }; + iframe.addEventListener('load', innerOnloadHandler); + outerDocument.body.insertBefore(iframe, outerDocument.body.firstChild); + outerWindow.readyFunc = () => { + delete outerWindow.readyFunc; + outerWindow.editorInfo.onEditorReady(); + delete outerWindow.editorInfo; + }; + const innerWindow = iframe.contentWindow; + const innerDocument = innerWindow.document; + innerDocument.documentElement.classList.add('inner-editor', ...skinVariants); + addStyleTagsFor(innerDocument, includedCSS); + + const script = innerDocument.createElement('script'); + script.type = 'text/javascript'; + script.src = `../static/js/require-kernel.js?v=${clientVars.randomVersionString}`; + innerDocument.head.appendChild(script); + + const styleI = innerDocument.createElement('style'); + styleI.type = 'text/css'; + styleI.title = 'dynamicsyntax'; + innerDocument.head.appendChild(styleI); + + const headLines = []; + hooks.callAll('aceInitInnerdocbodyHead', {iframeHTML: headLines}); + const tmp = innerDocument.createElement('div'); + tmp.innerHTML = headLines.join('\n'); + while (tmp.firstChild) innerDocument.head.appendChild(tmp.firstChild); + + innerDocument.body.id = 'innerdocbody'; + innerDocument.body.classList.add('innerdocbody'); + innerDocument.body.setAttribute('role', 'application'); + innerDocument.body.setAttribute('spellcheck', 'false'); + innerDocument.body.appendChild(innerDocument.createTextNode('\u00A0')); //   outerDocument.body.id = 'outerdocbody'; outerDocument.body.classList.add('outerdocbody', ...pluginUtils.clientPluginNames());