10000 change inDoc function to work properly in phantom.js · pooq/vue@405e959 · GitHub
[go: up one dir, main page]

Skip to content

Commit 405e959

Browse files
committed
change inDoc function to work properly in phantom.js
1 parent a06cd65 commit 405e959

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/util/dom.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var config = require('../config')
22

33
/**
44
* Check if a node is in the document.
5+
* Note: document.documentElement.contains should work here but doesn't seem to
6+
* work properly in phantom.js making unit testing difficult.
57
*
68
* @param {Node} node
79
* @return {Boolean}
@@ -12,7 +14,13 @@ var doc =
1214
document.documentElement
1315

1416
exports.inDoc = function (node) {
15-
return doc && doc.contains(node)
17+
var adown = doc.nodeType === 9 ? doc.documentElement : doc
18+
var bup = node && node.parentNode
19+
return doc === bup || !!( bup && bup.nodeType === 1 && (
20+
adown.contains
21+
? adown.contains( bup )
22+
: doc.compareDocumentPosition && doc.compareDocumentPosition( bup ) & 16
23+
));
1624
}
1725

1826
/**
@@ -35,7 +43,7 @@ exports.attr = function (node, attr) {
3543
* Insert el before target
3644
*
3745
* @param {Element} el
38-
* @param {Element} target
46+
* @param {Element} target
3947
*/
4048

4149
exports.before = function (el, target) {
@@ -46,7 +54,7 @@ exports.before = function (el, target) {
4654
* Insert el after target
4755
*
4856
* @param {Element} el
49-
* @param {Element} target
57+
* @param {Element} target
5058
*/
5159

5260
exports.after = function (el, target) {
@@ -71,7 +79,7 @@ exports.remove = function (el) {
7179
* Prepend el to target
7280
*
7381
* @param {Element} el
74-
* @param {Element} target
82+
* @param {Element} target
7583
*/
7684

7785
exports.prepend = function (el, target) {
@@ -194,4 +202,4 @@ exports.extractContent = function (el) {
194202
}
195203
}
196204
return rawContent
197-
}
205+
}

0 commit comments

Comments
 (0)
0