diff options
author | Chad Weider <cweider@oofn.net> | 2012-09-11 20:59:50 -0700 |
---|---|---|
committer | Chad Weider <cweider@oofn.net> | 2012-09-21 22:09:55 -0700 |
commit | 9f5946c9426346d371cb84f53a6005a7f853175b (patch) | |
tree | 4bb0eb5e44ade881e5574ad0ba8a15370fa32331 /src/static/js/ace.js | |
parent | fa65f889ec8174b2b723fcc45b7d391780b9cd52 (diff) | |
download | etherpad-lite-9f5946c9426346d371cb84f53a6005a7f853175b.zip |
Reformat Ace2Editor frame boot scripts.
Diffstat (limited to 'src/static/js/ace.js')
-rw-r--r-- | src/static/js/ace.js | 65 |
1 files changed, 47 insertions, 18 deletions
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 ( + '<script type="text/javascript">\n' + + source.replace(/<\//g, '<\\/') + + '</script>' + ) +} + function Ace2Editor() { var ace2 = Ace2Editor; @@ -226,23 +234,20 @@ function Ace2Editor() throw new Error("Require kernel could not be found."); } - iframeHTML.push('\ -<script type="text/javascript">\n\ -' + Ace2Editor.EMBEDED[KERNEL_SOURCE] + '\n\ - require.setRootURI("../javascripts/src");\n\ - require.setLibraryURI("../javascripts/lib");\n\ - require.setGlobalKeyPath("require");\n\ + iframeHTML.push(scriptTag( +Ace2Editor.EMBEDED[KERNEL_SOURCE] + '\n\ +require.setRootURI("../javascripts/src");\n\ +require.setLibraryURI("../javascripts/lib");\n\ +require.setGlobalKeyPath("require");\n\ \n\ - var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");\n\ - var plugins = require("ep_etherpad-lite/static/js/pluginfw/client_plugins");\n\ - hooks.plugins = plugins;\n\ - plugins.adoptPluginsFromAncestorsOf(window);\n\ +var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");\n\ +var plugins = require("ep_etherpad-lite/static/js/pluginfw/client_plugins");\n\ +hooks.plugins = plugins;\n\ +plugins.adoptPluginsFromAncestorsOf(window);\n\ \n\ - $ = jQuery = require("ep_etherpad-lite/static/js/rjquery").jQuery; // Expose jQuery #HACK\n\ - require("ep_etherpad-lite/static/js/ace2_inner");\n\ -</script>\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('<style type="text/css" title="dynamicsyntax"></style>'); @@ -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, '<html><head>'] @@ -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('<link rel="stylesheet" type="text/css" href="data:text/css,"/>', '\x3cscript>\n', outerScript.replace(/<\//g, '<\\/'), '\n\x3c/script>', '</head><body id="outerdocbody"><div id="sidediv"><!-- --></div><div id="linemetricsdiv">x</div><div id="overlaysdiv"><!-- --></div></body></html>'); + outerHTML.push('<link rel="stylesheet" type="text/css" href="data:text/css,"/>', scriptTag(outerScript), '</head><body id="outerdocbody"><div id="sidediv"><!-- --></div><div id="linemetricsdiv">x</div><div id="overlaysdiv"><!-- --></div></body></html>'); var outerFrame = document.createElement("IFRAME"); outerFrame.name = "ace_outer"; |