all files / dom/ready/ compact.js

100% Statements 32/32
94.74% Branches 18/19
100% Functions 6/6
100% Lines 32/32
13 statements, 2 functions, 11 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                         
import { avalon, window, document, root, inBrowser } from '../../seed/core'
 
var readyList = []
 
export function fireReady(fn) {
    avalon.isReady = true
    while (fn = readyList.shift()) {
        fn(avalon)
    }
}
 
avalon.ready = function (fn) {
    readyList.push(fn)
    if (avalon.isReady) {
        fireReady()
    }
}
 
avalon.ready(function () {
   avalon.scan && avalon.scan(document.body)
})
 
/* istanbul ignore next */
function bootstrap() {
    function doScrollCheck() {
        try { //IE下通过doScrollCheck检测DOM树是否建完
            root.doScroll('left')
            fireReady()
        } catch (e) {
            setTimeout(doScrollCheck)
        }
    }
    Iif (document.readyState === 'complete') {
        setTimeout(fireReady) //如果在domReady之外加载
    } else Eif (document.addEventListener) {
        document.addEventListener('DOMContentLoaded', fireReady,false)
    } else if (document.attachEvent) {
        //必须传入三个参数,否则在firefox4-26中报错
        //caught exception: [Exception... "Not enough arguments"  nsresult: "0x
        document.attachEvent('onreadystatechange', function () {
            if (document.readyState === 'complete') {
                fireReady()
            }
        })
        try {
            var isTop = window.frameElement === null
        } catch (e) {
        }
        if (root.doScroll && isTop && window.external) {//fix IE iframe BUG
            doScrollCheck()
        }
    }
 
    avalon.bind(window, 'load', fireReady)
}
Eif (inBrowser) {
    bootstrap()
}