| 1 |
"use strict"; |
| 2 |
module.exports = DocumentFragment; |
| 3 |
|
| 4 |
var Node = require('./Node'); |
| 5 |
var NodeList = require('./NodeList'); |
| 6 |
var ContainerNode = require('./ContainerNode'); |
| 7 |
var Element = require('./Element'); |
| 8 |
var select = require('./select'); |
| 9 |
var utils = require('./utils'); |
| 10 |
|
| 11 |
function DocumentFragment(doc) { |
| 12 |
ContainerNode.call(this); |
| 13 |
this.nodeType = Node.DOCUMENT_FRAGMENT_NODE; |
| 14 |
this.ownerDocument = doc; |
| 15 |
} |
| 16 |
|
| 17 |
DocumentFragment.prototype = Object.create(ContainerNode.prototype, { |
| 18 |
nodeName: { value: '#document-fragment' }, |
| 19 |
nodeValue: { |
| 20 |
get: function() { |
| 21 |
return null; |
| 22 |
}, |
| 23 |
set: function() {} |
| 24 |
}, |
| 25 |
|
| 26 |
textContent: Object.getOwnPropertyDescriptor(Element.prototype, 'textContent'), |
| 27 |
|
| 28 |
|
| 29 |
innerText: Object.getOwnPropertyDescriptor(Element.prototype, 'innerText'), |
| 30 |
|
| 31 |
querySelector: { value: function(selector) { |
| 32 |
|
| 33 |
var nodes = this.querySelectorAll(selector); |
| 34 |
return nodes.length ? nodes[0] : null; |
| 35 |
}}, |
| 36 |
querySelectorAll: { value: function(selector) { |
| 37 |
|
| 38 |
var context = Object.create(this); |
| 39 |
|
| 40 |
|
| 41 |
context.isHTML = true; |
| 42 |
context.getElementsByTagName = Element.prototype.getElementsByTagName; |
| 43 |
context.nextElement = |
| 44 |
Object.getOwnPropertyDescriptor(Element.prototype, 'firstElementChild'). |
| 45 |
get; |
| 46 |
|
| 47 |
var nodes = select(selector, context); |
| 48 |
return nodes.item ? nodes : new NodeList(nodes); |
| 49 |
}}, |
| 50 |
|
| 51 |
|
| 52 |
clone: { value: function clone() { |
| 53 |
return new DocumentFragment(this.ownerDocument); |
| 54 |
}}, |
| 55 |
isEqual: { value: function isEqual(n) { |
| 56 |
|
| 57 |
|
| 58 |
return true; |
| 59 |
}}, |
| 60 |
|
| 61 |
|
| 62 |
innerHTML: { |
| 63 |
get: function() { return this.serialize(); }, |
| 64 |
set: utils.nyi |
| 65 |
}, |
| 66 |
outerHTML: { |
| 67 |
get: function() { return this.serialize(); }, |
| 68 |
set: utils.nyi |
| 69 |
}, |
| 70 |
|
| 71 |
}); |