@@ -2,6 +2,8 @@ var config = require('../config')
2
2
3
3
/**
4
4
* 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.
5
7
*
6
8
* @param {Node } node
7
9
* @return {Boolean }
@@ -12,7 +14,13 @@ var doc =
12
14
document . documentElement
13
15
14
16
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
+ ) ) ;
16
24
}
17
25
18
26
/**
@@ -35,7 +43,7 @@ exports.attr = function (node, attr) {
35
43
* Insert el before target
36
44
*
37
45
* @param {Element } el
38
- * @param {Element } target
46
+ * @param {Element } target
39
47
*/
40
48
41
49
exports . before = function ( el , target ) {
@@ -46,7 +54,7 @@ exports.before = function (el, target) {
46
54
* Insert el after target
47
55
*
48
56
* @param {Element } el
49
- * @param {Element } target
57
+ * @param {Element } target
50
58
*/
51
59
52
60
exports . after = function ( el , target ) {
@@ -71,7 +79,7 @@ exports.remove = function (el) {
71
79
* Prepend el to target
72
80
*
73
81
* @param {Element } el
74
- * @param {Element } target
82
+ * @param {Element } target
75
83
*/
76
84
77
85
exports . prepend = function ( el , target ) {
@@ -194,4 +202,4 @@ exports.extractContent = function (el) {
194
202
}
195
203
}
196
204
return rawContent
197
- }
205
+ }
0 commit comments