prototype: Define Node constants conditionally after checking for Node.ELEMENT_NODE presence. Add unit test to check the values of all constants. Closes #7625.

This commit is contained in:
Thomas Fuchs 2007-08-17 11:20:56 +00:00
parent 194fda0b6d
commit aa1a7f5bf0
3 changed files with 45 additions and 19 deletions

View File

@ -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]

View File

@ -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);
}
};
};

View File

@ -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');