zoukankan      html  css  js  c++  java
  • domReady source code, domready源码

    domready源码,domready实现代码,js实现domready的源代码。

    jquery的domready源码,require.js的domready源代码

    .

    [domReady sourceCode]
    https://raw.githubusercontent.com/requirejs/domReady/latest/domReady.js

    /**
     * @license RequireJS domReady 2.0.1 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
     * Available via the MIT or new BSD license.
     * see: http://github.com/requirejs/domReady for details
     */
    /*jslint */
    /*global require: false, define: false, requirejs: false,
      window: false, clearInterval: false, document: false,
      self: false, setInterval: false */
    
    
    define(function () {
        'use strict';
    
        var isTop, testDiv, scrollIntervalId,
            isBrowser = typeof window !== "undefined" && window.document,
            isPageLoaded = !isBrowser,
            doc = isBrowser ? document : null,
            readyCalls = [];
    
        function runCallbacks(callbacks) {
            var i;
            for (i = 0; i < callbacks.length; i += 1) {
                callbacks[i](doc);
            }
        }
    
        function callReady() {
            var callbacks = readyCalls;
    
            if (isPageLoaded) {
                //Call the DOM ready callbacks
                if (callbacks.length) {
                    readyCalls = [];
                    runCallbacks(callbacks);
                }
            }
        }
    
        /**
         * Sets the page as loaded.
         */
        function pageLoaded() {
            if (!isPageLoaded) {
                isPageLoaded = true;
                if (scrollIntervalId) {
                    clearInterval(scrollIntervalId);
                }
    
                callReady();
            }
        }
    
        if (isBrowser) {
            if (document.addEventListener) {
                //Standards. Hooray! Assumption here that if standards based,
                //it knows about DOMContentLoaded.
                document.addEventListener("DOMContentLoaded", pageLoaded, false);
                window.addEventListener("load", pageLoaded, false);
            } else if (window.attachEvent) {
                window.attachEvent("onload", pageLoaded);
    
                testDiv = document.createElement('div');
                try {
                    isTop = window.frameElement === null;
                } catch (e) {}
    
                //DOMContentLoaded approximation that uses a doScroll, as found by
                //Diego Perini: http://javascript.nwbox.com/IEContentLoaded/,
                //but modified by other contributors, including jdalton
                if (testDiv.doScroll && isTop && window.external) {
                    scrollIntervalId = setInterval(function () {
                        try {
                            testDiv.doScroll();
                            pageLoaded();
                        } catch (e) {}
                    }, 30);
                }
            }
    
            //Check if document already complete, and if so, just trigger page load
            //listeners. Latest webkit browsers also use "interactive", and
            //will fire the onDOMContentLoaded before "interactive" but not after
            //entering "interactive" or "complete". More details:
            //http://dev.w3.org/html5/spec/the-end.html#the-end
            //http://stackoverflow.com/questions/3665561/document-readystate-of-interactive-vs-ondomcontentloaded
            //Hmm, this is more complicated on further use, see "firing too early"
            //bug: https://github.com/requirejs/domReady/issues/1
            //so removing the || document.readyState === "interactive" test.
            //There is still a window.onload binding that should get fired if
            //DOMContentLoaded is missed.
            if (document.readyState === "complete") {
                pageLoaded();
            }
        }
    
        /** START OF PUBLIC API **/
    
        /**
         * Registers a callback for DOM ready. If DOM is already ready, the
         * callback is called immediately.
         * @param {Function} callback
         */
        function domReady(callback) {
            if (isPageLoaded) {
                callback(doc);
            } else {
                readyCalls.push(callback);
            }
            return domReady;
        }
    
        domReady.version = '2.0.1';
    
        /**
         * Loader Plugin API method
         */
        domReady.load = function (name, req, onLoad, config) {
            if (config.isBuild) {
                onLoad(null);
            } else {
                domReady(onLoad);
            }
        };
    
        /** END OF PUBLIC API **/
    
        return domReady;
    });

    .

  • 相关阅读:
    【Spark】Spark Streaming 动态更新filter关注的内容
    【Scala】Scala-Option-Null的蹊跷
    java-汉字转化拼音(纯java)
    java-汉字转换拼音-pinyin4j.jar
    mysql-拼接字段concat,concat_ws函数
    sql-将查询字段拼接起来
    sql-insert一条语句执行多条数据插入
    证券挂单时间
    jquery-通过js编写弹出窗口
    html-css控制背景图全屏拉伸不重复显示
  • 原文地址:https://www.cnblogs.com/didi/p/4113381.html
Copyright © 2011-2022 走看看