diff --git a/src/static/js/ace.js b/src/static/js/ace.js index e7e4fca8..1561dea5 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -33,6 +33,14 @@ Ace2Editor.registry = { var hooks = require('./pluginfw/hooks'); var _ = require('./underscore'); +function scriptTag(source) { + return ( + '' + ) +} + function Ace2Editor() { var ace2 = Ace2Editor; @@ -226,23 +234,20 @@ function Ace2Editor() throw new Error("Require kernel could not be found."); } - iframeHTML.push('\ -\n\ -'); - iframeHTML.push('<\/script>'); +$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").jQuery; // Expose jQuery #HACK\n\ +require("ep_etherpad-lite/static/js/ace2_inner");\n\ +')); iframeHTML.push(''); @@ -256,8 +261,32 @@ function Ace2Editor() var thisFunctionsName = "ChildAccessibleAce2Editor"; (function () {return this}())[thisFunctionsName] = Ace2Editor; - var outerScript = 'editorId = "' + info.id + '"; editorInfo = parent.' + thisFunctionsName + '.registry[editorId]; ' + 'window.onload = function() ' + '{ window.onload = null; setTimeout' + '(function() ' + '{ var iframe = document.createElement("IFRAME"); iframe.name = "ace_inner";' + 'iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); ' + 'iframe.frameBorder = 0; iframe.allowTransparency = true; ' + // for IE - 'outerdocbody.insertBefore(iframe, outerdocbody.firstChild); ' + 'iframe.ace_outerWin = window; ' + 'readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; ' + 'var doc = iframe.contentWindow.document; doc.open(); var text = (' + JSON.stringify(iframeHTML.join('\n')) + ');doc.write(text); doc.close(); ' + '}, 0); }'; + var outerScript = '\ +editorId = ' + JSON.stringify(info.id) + ';\n\ +editorInfo = parent[' + JSON.stringify(thisFunctionsName) + '].registry[editorId];\n\ +window.onload = function () {\n\ + window.onload = null;\n\ + setTimeout(function () {\n\ + var iframe = document.createElement("IFRAME");\n\ + iframe.name = "ace_inner";\n\ + iframe.scrolling = "no";\n\ + var outerdocbody = document.getElementById("outerdocbody");\n\ + iframe.frameBorder = 0;\n\ + iframe.allowTransparency = true; // for IE\n\ + outerdocbody.insertBefore(iframe, outerdocbody.firstChild);\n\ + iframe.ace_outerWin = window;\n\ + readyFunc = function () {\n\ + editorInfo.onEditorReady();\n\ + readyFunc = null;\n\ + editorInfo = null;\n\ + };\n\ + var doc = iframe.contentWindow.document;\n\ + doc.open();\n\ + var text = (' + JSON.stringify(iframeHTML.join('\n')) + ');\n\ + doc.write(text);\n\ + doc.close();\n\ + }, 0);\n\ +}'; var outerHTML = [doctype, ''] @@ -275,7 +304,7 @@ function Ace2Editor() // bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly // (throbs busy while typing) - outerHTML.push('', '\x3cscript>\n', outerScript.replace(/<\//g, '<\\/'), '\n\x3c/script>', '
x
'); + outerHTML.push('', scriptTag(outerScript), '
x
'); var outerFrame = document.createElement("IFRAME"); outerFrame.name = "ace_outer";