Reformat Ace2Editor frame boot scripts.

This commit is contained in:
Chad Weider 2012-09-11 20:59:50 -07:00
parent fa65f889ec
commit 9f5946c942
1 changed files with 47 additions and 18 deletions

View File

@ -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";