From 0759ee67dd15c58e732e93ed5b0a459dea63bd79 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 14:55:43 +0200 Subject: [PATCH 1/6] Use element.ownerDocument instead of document. --- lib/ace/layer/text.js | 6 +++--- lib/ace/scrollbar.js | 2 +- lib/ace/virtual_renderer.js | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 89b684bf..4e17e221 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -121,8 +121,8 @@ var Text = function(parentEl) { // Note: characterWidth can be a float! measureNode.innerHTML = lang.stringRepeat("Xy", n); - if (document.body) { - document.body.appendChild(measureNode); + if (this.element.ownerDocument.body) { + this.element.ownerDocument.body.appendChild(measureNode); } else { var container = this.element.parentNode; while (!dom.hasCssClass(container, "ace_editor")) @@ -257,7 +257,7 @@ var Text = function(parentEl) { }; this.$renderLinesFragment = function(config, firstRow, lastRow) { - var fragment = document.createDocumentFragment(), + var fragment = this.element.ownerDocument.createDocumentFragment(), row = firstRow, fold = this.session.getNextFold(row), foldStart = fold ?fold.start.row :Infinity; diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index ad6c3b1a..ea63edec 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -56,7 +56,7 @@ var ScrollBar = function(parent) { // of 0px // in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar // make element a little bit wider to retain scrollbar when page is zoomed - this.width = dom.scrollbarWidth(); + this.width = dom.scrollbarWidth(parent.ownerDocument); this.element.style.width = (this.width || 15) + 5 + "px"; event.addListener(this.element, "scroll", this.onScroll.bind(this)); diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index dfa0fb56..130121d4 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -135,7 +135,10 @@ var VirtualRenderer = function(container, theme) { height : 1 }; - this.$loop = new RenderLoop(this.$renderChanges.bind(this)); + this.$loop = new RenderLoop( + this.$renderChanges.bind(this), + this.container.ownerDocument.defaultView + ); this.$loop.schedule(this.CHANGE_FULL); this.setPadding(4); From 738e7c1a0be14a6a8afaed9faf254a80de672e34 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 14:56:15 +0200 Subject: [PATCH 2/6] Use zeroTimeout bounded to the window. --- lib/ace/renderloop.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/ace/renderloop.js b/lib/ace/renderloop.js index afe998c3..67c82185 100644 --- a/lib/ace/renderloop.js +++ b/lib/ace/renderloop.js @@ -20,6 +20,7 @@ * * Contributor(s): * Fabian Jakobs + * Irakli Gozalishvili (http://jeditoolkit.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -39,10 +40,11 @@ define(function(require, exports, module) { var event = require("pilot/event"); -var RenderLoop = function(onRender) { +var RenderLoop = function(onRender, window) { this.onRender = onRender; this.pending = false; this.changes = 0; + this.setTimeoutZero = this.setTimeoutZero.bind(window); }; (function() { @@ -70,31 +72,31 @@ var RenderLoop = function(onRender) { window.msRequestAnimationFrame; if (this.setTimeoutZero) { - - this.setTimeoutZero = this.setTimeoutZero.bind(window) + this.setTimeoutZero = this.setTimeoutZero; } else if (window.postMessage) { - this.messageName = "zero-timeout-message"; + this.setTimeoutZero = (function(messageName, attached, listener) { + return function setTimeoutZero(callback) { + // Set up listener if not listening already. + if (!attached) { + event.addListener(this, "message", function(e) { + if (listener && e.data == messageName) { + event.stopPropagation(e); + listener(); + } + }); + attached = true; + } - this.setTimeoutZero = function(callback) { - if (!this.attached) { - var _self = this; - event.addListener(window, "message", function(e) { - if (_self.callback && e.data == _self.messageName) { - event.stopPropagation(e); - _self.callback(); - } - }); - this.attached = true; - } - this.callback = callback; - window.postMessage(this.messageName, "*"); - } + listener = callback; + this.postMessage(messageName, "*"); + }; + })("zero-timeout-message", false, null); } else { this.setTimeoutZero = function(callback) { - setTimeout(callback, 0); + this.setTimeout(callback, 0); } } From e5aa00fec93bc3099c953ed816ff6b8a1f792cbc Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 17:55:30 +0200 Subject: [PATCH 3/6] Updating all themes to new format. --- lib/ace/layer/text.js | 1 + lib/ace/scrollbar.js | 1 + lib/ace/theme/clouds.js | 11 +++-------- lib/ace/theme/clouds_midnight.js | 11 +++-------- lib/ace/theme/cobalt.js | 11 +++-------- lib/ace/theme/crimson_editor.js | 8 ++------ lib/ace/theme/dawn.js | 10 +++------- lib/ace/theme/eclipse.js | 8 ++------ lib/ace/theme/idle_fingers.js | 10 +++------- lib/ace/theme/kr_theme.js | 10 +++------- lib/ace/theme/merbivore.js | 10 +++------- lib/ace/theme/merbivore_soft.js | 10 +++------- lib/ace/theme/mono_industrial.js | 10 +++------- lib/ace/theme/monokai.js | 10 +++------- lib/ace/theme/pastel_on_dark.js | 8 ++------ lib/ace/theme/solarized_dark.js | 10 +++------- lib/ace/theme/solarized_light.js | 10 +++------- lib/ace/theme/textmate.js | 8 ++------ lib/ace/theme/twilight.js | 11 +++-------- lib/ace/theme/vibrant_ink.js | 10 +++------- 20 files changed, 52 insertions(+), 126 deletions(-) diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 4e17e221..6944dca3 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -23,6 +23,7 @@ * Fabian Jakobs * Julian Viereck * Mihai Sucan + * Irakli Gozalishvili (http://jeditoolkit.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index ea63edec..e38795e3 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -20,6 +20,7 @@ * * Contributor(s): * Fabian Jakobs + * Irakli Gozalishvili (http://jeditoolkit.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or diff --git a/lib/ace/theme/clouds.js b/lib/ace/theme/clouds.js index 9db45260..b3484bf6 100644 --- a/lib/ace/theme/clouds.js +++ b/lib/ace/theme/clouds.js @@ -37,9 +37,8 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-clouds .ace_editor {\ +exports.cssClass = "ace-clouds"; +exports.cssText = ".ace-clouds .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -252,8 +251,4 @@ define(function(require, exports, module) { \ }"; - // import CSS once - dom.importCssString(cssText); - - exports.cssClass = "ace-clouds"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/clouds_midnight.js b/lib/ace/theme/clouds_midnight.js index adc8663f..14c4d8e7 100644 --- a/lib/ace/theme/clouds_midnight.js +++ b/lib/ace/theme/clouds_midnight.js @@ -37,9 +37,8 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-clouds-midnight .ace_editor {\ +exports.cssClass = "ace-clouds-midnight"; +exports.cssText = ".ace-clouds-midnight .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -253,8 +252,4 @@ background-color:#E92E2E;\ \ }"; - // import CSS once - dom.importCssString(cssText); - - exports.cssClass = "ace-clouds-midnight"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/cobalt.js b/lib/ace/theme/cobalt.js index c8009106..95da2d2e 100644 --- a/lib/ace/theme/cobalt.js +++ b/lib/ace/theme/cobalt.js @@ -37,9 +37,8 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-cobalt .ace_editor {\ +exports.cssClass = "ace-cobalt"; +exports.cssText = ".ace-cobalt .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -255,8 +254,4 @@ background-color:#001221;\ \ }"; - // import CSS once - dom.importCssString(cssText); - - exports.cssClass = "ace-cobalt"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/crimson_editor.js b/lib/ace/theme/crimson_editor.js index 54ea8d97..52a11c1e 100644 --- a/lib/ace/theme/crimson_editor.js +++ b/lib/ace/theme/crimson_editor.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-crimson-editor .ace_editor {\ +exports.cssText = ".ace-crimson-editor .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -195,8 +193,6 @@ define(function(require, exports, module) { color: rgb(192, 0, 192);\ }"; - // Import CSS once. - dom.importCssString(cssText); +exports.cssClass = "ace-crimson-editor"; - exports.cssClass = "ace-crimson-editor"; }); diff --git a/lib/ace/theme/dawn.js b/lib/ace/theme/dawn.js index d2fce4da..9a6e8a17 100644 --- a/lib/ace/theme/dawn.js +++ b/lib/ace/theme/dawn.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-dawn .ace_editor {\ +exports.cssText = ".ace-dawn .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -258,8 +256,6 @@ color:#5A525F;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-dawn"; - exports.cssClass = "ace-dawn"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/eclipse.js b/lib/ace/theme/eclipse.js index 82836e32..e7d63601 100644 --- a/lib/ace/theme/eclipse.js +++ b/lib/ace/theme/eclipse.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-eclipse .ace_editor {\ +exports.cssText = ".ace-eclipse .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -143,8 +141,6 @@ define(function(require, exports, module) { background: rgb(232, 242, 254);\ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-eclipse"; - exports.cssClass = "ace-eclipse"; }); diff --git a/lib/ace/theme/idle_fingers.js b/lib/ace/theme/idle_fingers.js index 8702f16b..f1d5d4fb 100644 --- a/lib/ace/theme/idle_fingers.js +++ b/lib/ace/theme/idle_fingers.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-idle-fingers .ace_editor {\ +exports.cssText = ".ace-idle-fingers .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -255,8 +253,6 @@ color:#BC9458;\ background-color:#FFF980; \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-idle-fingers"; - exports.cssClass = "ace-idle-fingers"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/kr_theme.js b/lib/ace/theme/kr_theme.js index 176941ab..88b54cc6 100644 --- a/lib/ace/theme/kr_theme.js +++ b/lib/ace/theme/kr_theme.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-kr-theme .ace_editor {\ +exports.cssText = ".ace-kr-theme .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -254,8 +252,6 @@ color:#706D5B;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-kr-theme"; - exports.cssClass = "ace-kr-theme"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/merbivore.js b/lib/ace/theme/merbivore.js index 5ba36c97..00c2290d 100644 --- a/lib/ace/theme/merbivore.js +++ b/lib/ace/theme/merbivore.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-merbivore .ace_editor {\ +exports.cssText = ".ace-merbivore .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -246,8 +244,6 @@ background-color:#990000;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-merbivore"; - exports.cssClass = "ace-merbivore"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/merbivore_soft.js b/lib/ace/theme/merbivore_soft.js index a16e1751..dd82e044 100644 --- a/lib/ace/theme/merbivore_soft.js +++ b/lib/ace/theme/merbivore_soft.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-merbivore-soft .ace_editor {\ +exports.cssText = ".ace-merbivore-soft .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -246,8 +244,6 @@ background-color:#FE3838;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-merbivore-soft"; - exports.cssClass = "ace-merbivore-soft"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/mono_industrial.js b/lib/ace/theme/mono_industrial.js index ecc5b59c..596344ee 100644 --- a/lib/ace/theme/mono_industrial.js +++ b/lib/ace/theme/mono_industrial.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-mono-industrial .ace_editor {\ +exports.cssText = ".ace-mono-industrial .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -254,8 +252,6 @@ background-color:#151C19;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-mono-industrial"; - exports.cssClass = "ace-mono-industrial"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/monokai.js b/lib/ace/theme/monokai.js index 12ae43bd..ad8a325f 100644 --- a/lib/ace/theme/monokai.js +++ b/lib/ace/theme/monokai.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-monokai .ace_editor {\ +exports.cssText = ".ace-monokai .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -254,8 +252,6 @@ background-color:#AE81FF;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-monokai"; - exports.cssClass = "ace-monokai"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/pastel_on_dark.js b/lib/ace/theme/pastel_on_dark.js index 51b33fdb..78e74b5a 100644 --- a/lib/ace/theme/pastel_on_dark.js +++ b/lib/ace/theme/pastel_on_dark.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-pastel-on-dark .ace_editor {\ +exports.cssText = ".ace-pastel-on-dark .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -195,8 +193,6 @@ color:#D2A8A1;\ color:#494949;\ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-pastel-on-dark"; - exports.cssClass = "ace-pastel-on-dark"; }); diff --git a/lib/ace/theme/solarized_dark.js b/lib/ace/theme/solarized_dark.js index 63b957a4..2e66818d 100644 --- a/lib/ace/theme/solarized_dark.js +++ b/lib/ace/theme/solarized_dark.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-solarized-dark .ace_editor {\ +exports.cssText = ".ace-solarized-dark .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -253,8 +251,6 @@ color:#657B83;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-solarized-dark"; - exports.cssClass = "ace-solarized-dark"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/solarized_light.js b/lib/ace/theme/solarized_light.js index 3362d4a9..a3b63348 100644 --- a/lib/ace/theme/solarized_light.js +++ b/lib/ace/theme/solarized_light.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-solarized-light .ace_editor {\ +exports.cssText = ".ace-solarized-light .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -252,8 +250,6 @@ define(function(require, exports, module) { \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-solarized-light"; - exports.cssClass = "ace-solarized-light"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/textmate.js b/lib/ace/theme/textmate.js index 71f6f109..66df6924 100644 --- a/lib/ace/theme/textmate.js +++ b/lib/ace/theme/textmate.js @@ -37,9 +37,9 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - var cssText = ".ace-tm .ace_editor {\ +exports.cssClass = "ace-tm"; +exports.cssText = ".ace-tm .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -206,8 +206,4 @@ define(function(require, exports, module) { color: rgb(255, 0, 0)\ }"; - // import CSS once - dom.importCssString(cssText); - - exports.cssClass = "ace-tm"; }); diff --git a/lib/ace/theme/twilight.js b/lib/ace/theme/twilight.js index 9f535311..04c15ebb 100644 --- a/lib/ace/theme/twilight.js +++ b/lib/ace/theme/twilight.js @@ -37,9 +37,8 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-twilight .ace_editor {\ +exports.cssClass = "ace-twilight"; +exports.cssText = ".ace-twilight .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -256,8 +255,4 @@ color:#5F5A60;\ \ }"; - // import CSS once - dom.importCssString(cssText); - - exports.cssClass = "ace-twilight"; -}); \ No newline at end of file +}); diff --git a/lib/ace/theme/vibrant_ink.js b/lib/ace/theme/vibrant_ink.js index 4045dff1..292a11ad 100644 --- a/lib/ace/theme/vibrant_ink.js +++ b/lib/ace/theme/vibrant_ink.js @@ -37,9 +37,7 @@ define(function(require, exports, module) { - var dom = require("pilot/dom"); - - var cssText = ".ace-vibrant-ink .ace_editor {\ +exports.cssText = ".ace-vibrant-ink .ace_editor {\ border: 2px solid rgb(159, 159, 159);\ }\ \ @@ -255,8 +253,6 @@ color:#99CC99;\ \ }"; - // import CSS once - dom.importCssString(cssText); +exports.cssClass = "ace-vibrant-ink"; - exports.cssClass = "ace-vibrant-ink"; -}); \ No newline at end of file +}); From 190ed05eae70656d665e99e05cd2db0ece244ae9 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 9 Sep 2011 17:56:18 +0200 Subject: [PATCH 4/6] Update `importCssString` so that it can work with remote DOM documents. --- lib/ace/virtual_renderer.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 130121d4..35332bd8 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -53,11 +53,11 @@ var RenderLoop = require("ace/renderloop").RenderLoop; var EventEmitter = require("pilot/event_emitter").EventEmitter; var editorCss = require("ace/requirejs/text!ace/css/editor.css"); -// import CSS once -dom.importCssString(editorCss); - var VirtualRenderer = function(container, theme) { this.container = container; + + // Imports CSS once per DOM document ('ace_editor' serves as an identifier). + dom.importCssString(editorCss, "ace_editor", container.ownerDocument); dom.addCssClass(this.container, "ace_editor"); this.setTheme(theme); @@ -803,6 +803,12 @@ var VirtualRenderer = function(container, theme) { } function afterLoad(theme) { + dom.importCssString( + theme.cssText, + theme.cssClass, + _self.container.ownerDocument + ); + if (_self.$theme) dom.removeCssClass(_self.container, _self.$theme); From 55e4f7e803c08226cf143075debf8f9da7f3ad0a Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 12 Oct 2011 14:12:27 +0000 Subject: [PATCH 5/6] pilot --- support/pilot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/pilot b/support/pilot index 48ddaa84..05f9e1d5 160000 --- a/support/pilot +++ b/support/pilot @@ -1 +1 @@ -Subproject commit 48ddaa841476ddf9210ccbb2b310952db8212084 +Subproject commit 05f9e1d5ec1fbbc18daf7077e5fcbf56ae797f80 From 5774aa14dc1c03fad97e5db086382819d5329b5c Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 12 Oct 2011 16:22:07 +0200 Subject: [PATCH 6/6] pilot --- support/pilot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/pilot b/support/pilot index 05f9e1d5..c720ab56 160000 --- a/support/pilot +++ b/support/pilot @@ -1 +1 @@ -Subproject commit 05f9e1d5ec1fbbc18daf7077e5fcbf56ae797f80 +Subproject commit c720ab56a80ba8cc10d0c86a9c4f1fa9cfc83b1b