Changeset 1158
- Timestamp:
- 10/09/06 11:55:56 (2 years ago)
- Files:
-
- mochikit/branches/selector/MochiKit/MockDOM.js (modified) (3 diffs)
- mochikit/branches/selector/MochiKit/Selector.js (modified) (4 diffs)
- mochikit/branches/selector/tests/test_MochiKit-Selector.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mochikit/branches/selector/MochiKit/MockDOM.js
r1144 r1158 38 38 39 39 /** @id MochiKit.MockDOM.MockElement */ 40 MochiKit.MockDOM.MockElement = function (name, data ) {40 MochiKit.MockDOM.MockElement = function (name, data, ownerDocument) { 41 41 this.tagName = this.nodeName = name.toUpperCase(); 42 if (typeof(data) == "string") { 42 this.ownerDocument = ownerDocument || null; 43 if (name == "DOCUMENT") { 44 this.nodeType = 9; 45 this.childNodes = []; 46 } else if (typeof(data) == "string") { 43 47 this.nodeValue = data; 44 48 this.nodeType = 3; … … 59 63 /** @id MochiKit.MockDOM.MockElement.prototype.createElement */ 60 64 createElement: function (tagName) { 61 return new MochiKit.MockDOM.MockElement(tagName );65 return new MochiKit.MockDOM.MockElement(tagName, null, this.nodeType == 9 ? this : this.ownerDocument); 62 66 }, 63 67 /** @id MochiKit.MockDOM.MockElement.prototype.createTextNode */ … … 80 84 toString: function () { 81 85 return "MockElement(" + this.tagName + ")"; 86 }, 87 /** @id MochiKit.MockDOM.MockElement.prototype.getElementsByTagName */ 88 getElementsByTagName: function (tagName) { 89 var foundElements = []; 90 MochiKit.Base.nodeWalk(this, function(node){ 91 if (tagName == '*' || tagName == node.tagName) { 92 foundElements.push(node); 93 return node.childNodes; 94 } 95 }); 96 return foundElements; 82 97 } 83 98 }; mochikit/branches/selector/MochiKit/Selector.js
r1157 r1158 127 127 switch (pseudoClass) { 128 128 case 'root': 129 conditions.push('element === document.documentElement'); break;129 conditions.push('element.nodeType == 9 || element === element.ownerDocument.documentElement'); break; 130 130 case 'nth-child': 131 131 case 'nth-last-child': … … 285 285 } 286 286 287 if (element = $(this.params.id)) {287 if (element = MochiKit.DOM.getElement(this.params.id)) { 288 288 if (this.match(element)) { 289 289 if (!scope || inScope(element, scope)) { … … 302 302 303 303 if (axis == "") { 304 scope = (scope || document).getElementsByTagName(this.params.tagName || '*');304 scope = (scope || currentDocument()).getElementsByTagName(this.params.tagName || '*'); 305 305 } else if (axis == ">") { 306 306 if (!scope) { … … 371 371 372 372 function $$() { 373 return MochiKit.Selector.findChildElements( document, arguments);374 } 375 373 return MochiKit.Selector.findChildElements(currentDocument(), arguments); 374 } 375 mochikit/branches/selector/tests/test_MochiKit-Selector.html
r1156 r1158 223 223 is( results[i], expected[i+4], "'a[href$=outsidep] ~ *' selector" + ' (' + i + ')'); 224 224 } 225 226 expected = [document.documentElement]; 227 results = $$(':root'); 228 for (var i=0; i < results.length; i ++) { 229 is( results[i], expected[i], "':root' selector" + ' (' + i + ')'); 230 } 231 232 var doc = MochiKit.MockDOM.createDocument(); 233 appendChildNodes(doc.body, A({"href": "http://www.example.com/insideAnotherDocument"}, "Inside a document")); 234 withDocument(doc, function(){ 235 is( $$(":root")[0], doc, ":root on a different document" ); 236 is( $$("a")[0], doc.body.firstChild, "a inside a different document" ); 237 }); 225 238 226 239 ok( true, "test suite finished!");
