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) {
3636 * @return {Boolean }
3737 */
3838
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
4142 var parent = node && node . parentNode
42- return doc === node ||
43+ var isInDoc = doc === node ||
4344 doc === parent ||
4445 ! ! ( 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
4557}
4658
4759/**
Original file line number Diff line number Diff line change @@ -22,6 +22,18 @@ describe('Util - DOM', function () {
2222 expect ( _ . inDoc ( target ) ) . toBe ( false )
2323 } )
2424
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+
2537 it ( 'getAttr' , function ( ) {
2638 target . setAttribute ( 'v-test' , 'ok' )
2739 var val = _ . getAttr ( target , 'v-test' )
You can’t perform that action at this time.
0 commit comments