Skip to content

Commit

Permalink
fixed DocumentFragment problem spotted in PR 26
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Jan 29, 2016
1 parent c8cc366 commit 11c0275
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DOM4
Many thanks to [cdnjs](http://www.cdnjs.com) for hosting this script. Following an example on how to include it.
```html
<script
src="//cdnjs.cloudflare.com/ajax/libs/dom4/1.5.2/dom4.js"
src="//cdnjs.cloudflare.com/ajax/libs/dom4/1.7.0/dom4.js"
>/* DOM4 */</script>
```

Expand Down
2 changes: 1 addition & 1 deletion build/dom4.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions build/dom4.max.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ THE SOFTWARE.
}
return !!force;
},
DocumentFragment = window.DocumentFragment,
DocumentFragmentPrototype = window.DocumentFragment && DocumentFragment.prototype,
Node = window.Node,
NodePrototype = (Node || Element).prototype,
CharacterData = window.CharacterData || Node,
Expand Down Expand Up @@ -267,22 +267,34 @@ THE SOFTWARE.
};
}
// see https://github.com/WebReflection/dom4/issues/18
if (/before|after|replace|remove/.test(property)) {
if (/^(?:before|after|replace|replaceWith|remove)$/.test(property)) {
if (CharacterData && !(property in CharacterDataPrototype)) {
CharacterDataPrototype[property] = properties[i - 1];
}
if (DocumentType && !(property in DocumentTypePrototype)) {
DocumentTypePrototype[property] = properties[i - 1];
}
}
// see https://github.com/WebReflection/dom4/pull/26
if (/^(?:append|prepend)$/.test(property)) {
if (DocumentFragmentPrototype) {
if (!(property in DocumentFragmentPrototype)) {
DocumentFragmentPrototype[property] = properties[i - 1];
}
} else {
try {
createDocumentFragment().constructor.prototype[property] = properties[i - 1];
} catch(o_O) {}
}
}
}

// bring query and queryAll to the document too
addQueryAndAll(document);

// brings query and queryAll to fragments as well
if (DocumentFragment) {
addQueryAndAll(DocumentFragment.prototype);
if (DocumentFragmentPrototype) {
addQueryAndAll(DocumentFragmentPrototype);
} else {
try {
addQueryAndAll(createDocumentFragment().constructor.prototype);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dom4",
"title": "DOM4",
"description": "a fully tested and covered polyfill for new DOM Level 4 entries",
"version": "1.6.0",
"version": "1.7.0",
"main": "build/dom4.max.js",
"homepage": "https://github.com/WebReflection/dom4",
"author": {
Expand Down
20 changes: 16 additions & 4 deletions src/dom4.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}
return !!force;
},
DocumentFragment = window.DocumentFragment,
DocumentFragmentPrototype = window.DocumentFragment && DocumentFragment.prototype,
Node = window.Node,
NodePrototype = (Node || Element).prototype,
CharacterData = window.CharacterData || Node,
Expand Down Expand Up @@ -245,22 +245,34 @@
};
}
// see https://github.com/WebReflection/dom4/issues/18
if (/before|after|replace|remove/.test(property)) {
if (/^(?:before|after|replace|replaceWith|remove)$/.test(property)) {
if (CharacterData && !(property in CharacterDataPrototype)) {
CharacterDataPrototype[property] = properties[i - 1];
}
if (DocumentType && !(property in DocumentTypePrototype)) {
DocumentTypePrototype[property] = properties[i - 1];
}
}
// see https://github.com/WebReflection/dom4/pull/26
if (/^(?:append|prepend)$/.test(property)) {
if (DocumentFragmentPrototype) {
if (!(property in DocumentFragmentPrototype)) {
DocumentFragmentPrototype[property] = properties[i - 1];
}
} else {
try {
createDocumentFragment().constructor.prototype[property] = properties[i - 1];
} catch(o_O) {}
}
}
}

// bring query and queryAll to the document too
addQueryAndAll(document);

// brings query and queryAll to fragments as well
if (DocumentFragment) {
addQueryAndAll(DocumentFragment.prototype);
if (DocumentFragmentPrototype) {
addQueryAndAll(DocumentFragmentPrototype);
} else {
try {
addQueryAndAll(createDocumentFragment().constructor.prototype);
Expand Down
7 changes: 7 additions & 0 deletions test/dom4.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ wru.test([
wru.assert('can fail aware', !document.body.contains(document));
wru.assert('can work', document.contains(document.body));
}
}, {
name: 'DocumentFragment implements ParentNode interface',
test: function () {
var df = document.createDocumentFragment();
wru.assert('it has an append method', typeof df.append === 'function');
wru.assert('it has an prepend method', typeof df.prepend === 'function');
}
}
].concat(
typeof ShadowRoot === 'function' ?
Expand Down

0 comments on commit 11c0275

Please sign in to comment.