From fa65f889ec8174b2b723fcc45b7d391780b9cd52 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 11 Sep 2012 20:52:48 -0700 Subject: [PATCH 1/3] Consolidate Ace2Editor frame's boot script. --- src/static/js/ace.js | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/static/js/ace.js b/src/static/js/ace.js index db62deb4..e7e4fca8 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -24,6 +24,8 @@ // requires: plugins // requires: undefined +var KERNEL_SOURCE = '../static/js/require-kernel.js'; + Ace2Editor.registry = { nextId: 1 }; @@ -155,24 +157,6 @@ function Ace2Editor() return {embeded: embededFiles, remote: remoteFiles}; } - function pushRequireScriptTo(buffer) { - var KERNEL_SOURCE = '../static/js/require-kernel.js'; - var KERNEL_BOOT = '\ -require.setRootURI("../javascripts/src");\n\ -require.setLibraryURI("../javascripts/lib");\n\ -require.setGlobalKeyPath("require");\n\ -'; - if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) { - buffer.push('\ +\n\ + $ = jQuery = require("ep_etherpad-lite/static/js/rjquery").jQuery; // Expose jQuery #HACK\n\ + require("ep_etherpad-lite/static/js/ace2_inner");\n\ +\n\ '); - - iframeHTML.push('' + ) +} + 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"; From 622819ba930b5d4685c053eefaac77c1776fe0b0 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Wed, 12 Sep 2012 00:04:15 -0700 Subject: [PATCH 3/3] Make intialization of Ace2Inner analogous to other page controllers. --- src/static/js/ace.js | 6 ++- src/static/js/ace2_inner.js | 94 +++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 47 deletions(-) diff --git a/src/static/js/ace.js b/src/static/js/ace.js index 1561dea5..e50f75c7 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -246,7 +246,11 @@ 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\ +var Ace2Inner = require("ep_etherpad-lite/static/js/ace2_inner");\n\ +\n\ +plugins.ensure(function () {\n\ + Ace2Inner.init();\n\ +});\n\ ')); iframeHTML.push(''); diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 962eda2a..652a3d25 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -19,7 +19,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -var editor, _, $, jQuery, plugins, Ace2Common; +var _, $, jQuery, plugins, Ace2Common; Ace2Common = require('./ace2_common'); @@ -5430,62 +5430,64 @@ function Ace2Inner(){ return documentAttributeManager.setAttributesOnRange.apply(documentAttributeManager, arguments); }; - $(document).ready(function(){ - doc = document; // defined as a var in scope outside - inCallStack("setup", function() - { - var body = doc.getElementById("innerdocbody"); - root = body; // defined as a var in scope outside - if (browser.mozilla) $(root).addClass("mozilla"); - if (browser.safari) $(root).addClass("safari"); - if (browser.msie) $(root).addClass("msie"); - if (browser.msie) + this.init = function () { + $(document).ready(function(){ + doc = document; // defined as a var in scope outside + inCallStack("setup", function() { - // cache CSS background images - try + var body = doc.getElementById("innerdocbody"); + root = body; // defined as a var in scope outside + if (browser.mozilla) $(root).addClass("mozilla"); + if (browser.safari) $(root).addClass("safari"); + if (browser.msie) $(root).addClass("msie"); + if (browser.msie) { - doc.execCommand("BackgroundImageCache", false, true); + // cache CSS background images + try + { + doc.execCommand("BackgroundImageCache", false, true); + } + catch (e) + { /* throws an error in some IE 6 but not others! */ + } } - catch (e) - { /* throws an error in some IE 6 but not others! */ - } - } - setClassPresence(root, "authorColors", true); - setClassPresence(root, "doesWrap", doesWrap); + setClassPresence(root, "authorColors", true); + setClassPresence(root, "doesWrap", doesWrap); - initDynamicCSS(); + initDynamicCSS(); - enforceEditability(); + enforceEditability(); - // set up dom and rep - while (root.firstChild) root.removeChild(root.firstChild); - var oneEntry = createDomLineEntry(""); - doRepLineSplice(0, rep.lines.length(), [oneEntry]); - insertDomLines(null, [oneEntry.domInfo], null); - rep.alines = Changeset.splitAttributionLines( - Changeset.makeAttribution("\n"), "\n"); + // set up dom and rep + while (root.firstChild) root.removeChild(root.firstChild); + var oneEntry = createDomLineEntry(""); + doRepLineSplice(0, rep.lines.length(), [oneEntry]); + insertDomLines(null, [oneEntry.domInfo], null); + rep.alines = Changeset.splitAttributionLines( + Changeset.makeAttribution("\n"), "\n"); - bindTheEventHandlers(); + bindTheEventHandlers(); - }); + }); - hooks.callAll('aceInitialized', { - editorInfo: editorInfo, - rep: rep, - documentAttributeManager: documentAttributeManager - }); + hooks.callAll('aceInitialized', { + editorInfo: editorInfo, + rep: rep, + documentAttributeManager: documentAttributeManager + }); - scheduler.setTimeout(function() - { - parent.readyFunc(); // defined in code that sets up the inner iframe - }, 0); + scheduler.setTimeout(function() + { + parent.readyFunc(); // defined in code that sets up the inner iframe + }, 0); - isSetUp = true; - }); + isSetUp = true; + }); + } } -// Ensure that plugins are loaded before initializing the editor -plugins.ensure(function () { - var editor = new Ace2Inner(); -}); +exports.init = function () { + var editor = new Ace2Inner() + editor.init(); +};