File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,24 @@ export function query (el) {
36
36
* @return {Boolean }
37
37
*/
38
38
39
- export function inDoc ( node ) {
40
- var doc = document . documentElement
39
+ export function inDoc ( node , win ) {
40
+ win = win || window
41
+ var doc = win . document . documentElement
41
42
var parent = node && node . parentNode
42
- return doc === node ||
43
+ var isInDoc = doc === node ||
43
44
doc === parent ||
44
45
! ! ( parent && parent . nodeType === 1 && ( doc . contains ( parent ) ) )
46
+ if ( ! isInDoc ) {
47
+ var frames = win . frames
48
+ if ( frames ) {
49
+ for ( var i = 0 ; i < frames . length ; i ++ ) {
50
+ if ( inDoc ( node , frames [ i ] ) ) {
51
+ return true
52
+ }
53
+ }
54
+ }
55
+ }
56
+ return isInDoc
45
57
}
46
58
47
59
/**
Original file line number Diff line number Diff line change @@ -22,6 +22,18 @@ describe('Util - DOM', function () {
22
22
expect ( _ . inDoc ( target ) ) . toBe ( false )
23
23
} )
24
24
25
+ it ( 'inDoc (iframe)' , function ( done ) {
26
+ var f = document . createElement ( 'iframe' )
27
+ f . onload = function ( ) {
28
+ f . contentWindow . document . body . appendChild ( target )
29
+ expect ( _ . inDoc ( target ) ) . toBe ( true )
30
+ document . body . removeChild ( f )
31
+ done ( )
32
+ }
33
+ document . body . appendChild ( f )
34
+ f . src = "about:blank"
35
+ } )
36
+
25
37
it ( 'getAttr' , function ( ) {
26
38
target . setAttribute ( 'v-test' , 'ok' )
27
39
var val = _ . getAttr ( target , 'v-test' )
You can’t perform that action at this time.
0 commit comments