From b023eb1fe5f0a2c7299b7956a225f99a44f521c5 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Thu, 17 May 2012 11:10:09 -0700 Subject: [PATCH] Move IE-style domline creation into the domline file. --- src/static/js/ace2_inner.js | 64 +---------------------------------- src/static/js/domline.js | 66 +++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 07580faa5..d0396635e 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -2800,69 +2800,7 @@ function Ace2Inner(){ function doCreateDomLine(nonEmpty) { - if (browser.msie && (!nonEmpty)) - { - var result = { - node: null, - appendSpan: noop, - prepareForAdd: noop, - notifyAdded: noop, - clearSpans: noop, - finishUpdate: noop, - lineMarker: 0 - }; - - var lineElem = doc.createElement("div"); - result.node = lineElem; - - result.notifyAdded = function() - { - // magic -- settng an empty div's innerHTML to the empty string - // keeps it from collapsing. Apparently innerHTML must be set *after* - // adding the node to the DOM. - // Such a div is what IE 6 creates naturally when you make a blank line - // in a document of divs. However, when copy-and-pasted the div will - // contain a space, so we note its emptiness with a property. - lineElem.innerHTML = " "; // Frist we set a value that isnt blank - // a primitive-valued property survives copy-and-paste - setAssoc(lineElem, "shouldBeEmpty", true); - // an object property doesn't - setAssoc(lineElem, "unpasted", {}); - lineElem.innerHTML = ""; // Then we make it blank.. New line and no space = Awesome :) - }; - var lineClass = 'ace-line'; - result.appendSpan = function(txt, cls) - { - if ((!txt) && cls) - { - // gain a whole-line style (currently to show insertion point in CSS) - lineClass = domline.addToLineClass(lineClass, cls); - } - // otherwise, ignore appendSpan, this is an empty line - }; - result.clearSpans = function() - { - lineClass = ''; // non-null to cause update - }; - - var writeClass = function() - { - if (lineClass !== null) lineElem.className = lineClass; - }; - - result.prepareForAdd = writeClass; - result.finishUpdate = writeClass; - result.getInnerHTML = function() - { - return ""; - }; - - return result; - } - else - { - return domline.createDomLine(nonEmpty, doesWrap, browser, doc); - } + return domline.createDomLine(nonEmpty, doesWrap, browser, doc); } function textify(str) diff --git a/src/static/js/domline.js b/src/static/js/domline.js index d57b25b56..8b09db2f8 100644 --- a/src/static/js/domline.js +++ b/src/static/js/domline.js @@ -249,9 +249,71 @@ DOMLine.prototype = {}; }).call(DOMLine.prototype); -domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) +function SpecialIEDOMLine(nonEmpty, doesWrap, browser, document) { + this.node = null; + this.lineMarker = 0; + this.node = document.createElement("div") + + this.lineClass = 'ace-line'; + + // Apparently overridden at the instance level sometimes... + this.notifyAdded = function () {this._notifyAdded()}; + this.finishUpdate = function () {this._finishUpdate()};; +} +SpecialIEDOMLine.prototype = {}; +(function () { + this._notifyAdded = function () { + // magic -- settng an empty div's innerHTML to the empty string + // keeps it from collapsing. Apparently innerHTML must be set *after* + // adding the node to the DOM. + // Such a div is what IE 6 creates naturally when you make a blank line + // in a document of divs. However, when copy-and-pasted the div will + // contain a space, so we note its emptiness with a property. + this.node.innerHTML = " "; // Frist we set a value that isnt blank + // a primitive-valued property survives copy-and-paste + Ace2Common.setAssoc(lineElem, "shouldBeEmpty", true); + // an object property doesn't + Ace2Common.setAssoc(lineElem, "unpasted", {}); + this.node.innerHTML = ""; // Then we make it blank.. New line and no space = Awesome :) + } + + this.appendSpan = function (txt, cls) { + if ((!txt) && cls) { + // gain a whole-line style (currently to show insertion point in CSS) + this.lineClass = domline.addToLineClass(lineClass, cls); + } + // otherwise, ignore appendSpan, this is an empty line + } + + this.clearSpans = function () { + this.lineClass = ''; // non-null to cause update + } + + this._writeClass = function () { + if (this.lineClass !== null) { + this.node.className = this.lineClass; + } + } + + this.prepareForAdd = function () { + return this._writeClass; + } + this._finishUpdate = function () { + return this._writeClass; + } + this.getInnerHTML = function () { + return ""; + } +}).call(SpecialIEDOMLine.prototype); + +function createDomLine(nonEmpty, doesWrap, browser, document) { - return new DOMLine(nonEmpty, doesWrap, optBrowser, optDocument); + if (browser.msie && (!nonEmpty)) { + // TODO: Why is this necessary? + return new SpecialIEDOMLine(nonEmpty, doesWrap, browser, document); + } else { + return new DOMLine(nonEmpty, doesWrap, browser, document); + } }; domline.processSpaces = function(s, doesWrap)