From 7821b989fe46184d5ddcef4ad64c999764e53935 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Mon, 4 Feb 2008 23:22:18 +0000 Subject: [PATCH] prototype: Avoid breaking Element.prototype in browsers which support it. Closes #11004. --- CHANGELOG | 2 ++ src/dom.js | 1 + test/unit/dom.html | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 1b67198..0c30302 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Avoid breaking Element.prototype in browsers which support it. Closes #11004. [cfis, Tobie Langel] + * Prevent Element#cumulativeOffset, Element#getOffsetParent, Element#positionedOffset, Element#viewportOffset and Element#clonePosition from throwing an error in IE when called on a parent-less element. Closes #9416, #10192, #10248. [ronstoney, psiborg, kangax] * Prevent Enumerable#eachSlice from entering into an endless loop if passed an argument smaller than 1. Closes #10665. [kangax, Tobie Langel] diff --git a/src/dom.js b/src/dom.js index d790b0e..936b408 100644 --- a/src/dom.js +++ b/src/dom.js @@ -57,6 +57,7 @@ if (!Node.ELEMENT_NODE) { return Element.writeAttribute(cache[tagName].cloneNode(false), attributes); }; Object.extend(this.Element, element || { }); + if (element) this.Element.prototype = element.prototype; }).call(window); Element.cache = { }; diff --git a/test/unit/dom.html b/test/unit/dom.html index 0a7f629..9875226 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -4,6 +4,9 @@ Prototype Unit test file + @@ -1443,6 +1446,11 @@ assertEqual('my_input_field', $(document.body.lastChild).name); if (Prototype.Browser.IE) assertMatch(/name=["']?my_input_field["']?/, $('my_input_field').outerHTML); + + if (originalElement && Prototype.BrowserFeatures.ElementExtensions) { + Element.prototype.fooBar = Prototype.emptyFunction + assertRespondsTo('fooBar', new Element('div')); + } }}, testElementGetHeight: function() {with(this) {