diff --git a/CHANGELOG b/CHANGELOG index c580428..3806eed 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Define Node constants conditionally after checking for Node.ELEMENT_NODE presence. Add unit test to check the values of all constants. Closes #7625. [Mislav Marohnić] + * Make sure Enumerable#include doesn't do type comparision. [Mislav Marohnić] * Add contextmenu to Event.DOMEvents. [Thomas Fuchs] diff --git a/src/dom.js b/src/dom.js index e6ad889..f99c5d2 100644 --- a/src/dom.js +++ b/src/dom.js @@ -22,23 +22,25 @@ if (Prototype.BrowserFeatures.XPath) { /*--------------------------------------------------------------------------*/ -if (!window.Node) - var Node = { }; - -Object.extend(Node, { - ELEMENT_NODE: 1, - ATTRIBUTE_NODE: 2, - TEXT_NODE: 3, - CDATA_SECTION_NODE: 4, - ENTITY_REFERENCE_NODE: 5, - ENTITY_NODE: 6, - PROCESSING_INSTRUCTION_NODE: 7, - COMMENT_NODE: 8, - DOCUMENT_NODE: 9, - DOCUMENT_TYPE_NODE: 10, - DOCUMENT_FRAGMENT_NODE: 11, - NOTATION_NODE: 12 -}); +if (!window.Node) var Node = { }; + +if (!Node.ELEMENT_NODE) { + // DOM level 2 ECMAScript Language Binding + Object.extend(Node, { + ELEMENT_NODE: 1, + ATTRIBUTE_NODE: 2, + TEXT_NODE: 3, + CDATA_SECTION_NODE: 4, + ENTITY_REFERENCE_NODE: 5, + ENTITY_NODE: 6, + PROCESSING_INSTRUCTION_NODE: 7, + COMMENT_NODE: 8, + DOCUMENT_NODE: 9, + DOCUMENT_TYPE_NODE: 10, + DOCUMENT_FRAGMENT_NODE: 11, + NOTATION_NODE: 12 + }); +} (function() { var element = this.Element; @@ -1211,4 +1213,4 @@ document.viewport = { window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft, window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop); } -}; \ No newline at end of file +}; diff --git a/test/unit/dom.html b/test/unit/dom.html index a800a18..6058d15 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -1498,7 +1498,6 @@ }); }}, - testViewportDimensions: function() {with(this) { window.resizeTo(800, 600); var before = document.viewport.getDimensions(); @@ -1521,6 +1520,29 @@ assertEqual(25, document.viewport.getScrollOffsets().left); window.resizeTo(850, 650); + }}, + + testNodeConstants: function() {with(this) { + assert(window.Node, 'window.Node is unavailable'); + + var constants = $H({ + ELEMENT_NODE: 1, + ATTRIBUTE_NODE: 2, + TEXT_NODE: 3, + CDATA_SECTION_NODE: 4, + ENTITY_REFERENCE_NODE: 5, + ENTITY_NODE: 6, + PROCESSING_INSTRUCTION_NODE: 7, + COMMENT_NODE: 8, + DOCUMENT_NODE: 9, + DOCUMENT_TYPE_NODE: 10, + DOCUMENT_FRAGMENT_NODE: 11, + NOTATION_NODE: 12 + }); + + constants.each(function(pair) { + assertEqual(Node[pair.key], pair.value); + }, this); }} }, 'testlog');