博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
domReady source code, domready源码
阅读量:5110 次
发布时间:2019-06-13

本文共 4135 字,大约阅读时间需要 13 分钟。

 

 

 

 

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;});

 

.

 

转载于:https://www.cnblogs.com/didi/p/4113381.html

你可能感兴趣的文章
洛谷 P2024 [NOI2001]食物链 (并查集)
查看>>
CSS Sticky Footer实现
查看>>
python之路_socketserver模块
查看>>
一款我用了好多年的多线程FTP软件
查看>>
GreenDao数据库的简单使用
查看>>
Starting cloudera-scm-server: * Couldn't start cloudera-scm-server的解决办法(图文详解)
查看>>
Hadoop的ChainMapper和ChainReducer使用案例(链式处理)(四)
查看>>
linux 强制删除yum安装的php7.2
查看>>
uiautomator_python使用汇总
查看>>
tomcat cluster session同步时保存map数据遇到的问题
查看>>
Javascript备忘录-枚举一个对象的所有属
查看>>
Asp.net MVC DefaultModelBinder分析
查看>>
KVM安装
查看>>
w3cschool -css
查看>>
《Entity Framework 6 Recipes》中文翻译系列 (10) -----第二章 实体数据建模基础之两实体间Is-a和Has-a关系建模、嵌入值映射 (转)...
查看>>
又是毕业季I
查看>>
涛涛的Party
查看>>
SQL Server 触发器
查看>>
Silverlight 5 系列学习之一
查看>>
最值栈
查看>>