⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 get-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 2 页
字号:
     */    var _queue = function(type, url, opts) {        var id = "q" + (qidx++);        opts = opts || {};        if (qidx % YAHOO.util.Get.PURGE_THRESH === 0) {            _autoPurge();        }        queues[id] = lang.merge(opts, {            tId: id,            type: type,            url: url,            finished: false,            aborted: false,            nodes: []        });        var q = queues[id];        q.win = q.win || window;        q.scope = q.scope || q.win;        q.autopurge = ("autopurge" in q) ? q.autopurge :                       (type === "script") ? true : false;        lang.later(0, q, _next, id);        return {            tId: id        };    };    /**     * Detects when a node has been loaded.  In the case of     * script nodes, this does not guarantee that contained     * script is ready to use.     * @method _track     * @param type {string} the type of node to track     * @param n {HTMLElement} the node to track     * @param id {string} the id of the request     * @param url {string} the url that is being loaded     * @param win {Window} the targeted window     * @param qlength the number of remaining items in the queue,     * including this one     * @param trackfn {Function} function to execute when finished     * the default is _next     * @private     */    var _track = function(type, n, id, url, win, qlength, trackfn) {        var f = trackfn || _next;        // IE supports the readystatechange event for script and css nodes        if (ua.ie) {            n.onreadystatechange = function() {                var rs = this.readyState;                if ("loaded" === rs || "complete" === rs) {                    YAHOO.log(id + " onload " + url, "info", "Get");                    n.onreadystatechange = null;                    f(id, url);                }            };        // webkit prior to 3.x is problemmatic        } else if (ua.webkit) {            if (type === "script") {                // Safari 3.x supports the load event for script nodes (DOM2)                if (ua.webkit >= 420) {                    n.addEventListener("load", function() {                        YAHOO.log(id + " DOM2 onload " + url, "info", "Get");                        f(id, url);                    });                // Nothing can be done with Safari < 3.x except to pause and hope                // for the best, particularly after last script is inserted. The                // scripts will always execute in the order they arrive, not                // necessarily the order in which they were inserted.  To support                // script nodes with complete reliability in these browsers, script                // nodes either need to invoke a function in the window once they                // are loaded or the implementer needs to provide a well-known                // property that the utility can poll for.                } else {                    // Poll for the existence of the named variable, if it                    // was supplied.                    var q = queues[id];                    if (q.varName) {                        var freq=YAHOO.util.Get.POLL_FREQ;                        YAHOO.log("Polling for " + q.varName[0]);                        q.maxattempts = YAHOO.util.Get.TIMEOUT/freq;                        q.attempts = 0;                        q._cache = q.varName[0].split(".");                        q.timer = lang.later(freq, q, function(o) {                            var a=this._cache, l=a.length, w=this.win, i;                            for (i=0; i<l; i=i+1) {                                w = w[a[i]];                                if (!w) {                                    // if we have exausted our attempts, give up                                    this.attempts++;                                    if (this.attempts++ > this.maxattempts) {                                        var msg = "Over retry limit, giving up";                                        q.timer.cancel();                                        _fail(id, msg);                                    } else {                                        YAHOO.log(a[i] + " failed, retrying");                                    }                                    return;                                }                            }                                                        YAHOO.log("Safari poll complete");                            q.timer.cancel();                            f(id, url);                        }, null, true);                    } else {                        lang.later(YAHOO.util.Get.POLL_FREQ, null, f, [id, url]);                    }                }            }         // FireFox and Opera support onload (but not DOM2 in FF) handlers for        // script nodes.  Opera, but not FF, supports the onload event for link        // nodes.        } else {             n.onload = function() {                YAHOO.log(id + " onload " + url, "info", "Get");                f(id, url);            };        }    };    return {        /**         * The default poll freqency in ms, when needed         * @property POLL_FREQ         * @static         * @type int         * @default 10         */        POLL_FREQ: 10,        /**         * The number of request required before an automatic purge.         * property PURGE_THRESH         * @static         * @type int         * @default 20         */        PURGE_THRESH: 20,        /**         * The length time to poll for varName when loading a script in         * Safari 2.x before the transaction fails.         * property TIMEOUT         * @static         * @type int         * @default 2000         */        TIMEOUT: 2000,                /**         * Called by the the helper for detecting script load in Safari         * @method _finalize         * @param id {string} the transaction id         * @private         */        _finalize: function(id) {            YAHOO.log(id + " finalized ", "info", "Get");            lang.later(0, null, _finish, id);        },        /**         * Abort a transaction         * @method abort         * @param {string|object} either the tId or the object returned from         * script() or css()         */        abort: function(o) {            var id = (lang.isString(o)) ? o : o.tId;            var q = queues[id];            if (q) {                YAHOO.log("Aborting " + id, "info", "Get");                q.aborted = true;            }        },         /**         * Fetches and inserts one or more script nodes into the head         * of the current document or the document in a specified window.         *         * @method script         * @static         * @param url {string|string[]} the url or urls to the script(s)         * @param opts {object} Options:          * <dl>         * <dt>onSuccess</dt>         * <dd>         * callback to execute when the script(s) are finished loading         * The callback receives an object back with the following         * data:         * <dl>         * <dt>win</dt>         * <dd>the window the script(s) were inserted into</dd>         * <dt>data</dt>         * <dd>the data object passed in when the request was made</dd>         * <dt>nodes</dt>         * <dd>An array containing references to the nodes that were         * inserted</dd>         * <dt>purge</dt>         * <dd>A function that, when executed, will remove the nodes         * that were inserted</dd>         * <dt>         * </dl>         * </dd>         * <dt>onFailure</dt>         * <dd>         * callback to execute when the script load operation fails         * The callback receives an object back with the following         * data:         * <dl>         * <dt>win</dt>         * <dd>the window the script(s) were inserted into</dd>         * <dt>data</dt>         * <dd>the data object passed in when the request was made</dd>         * <dt>nodes</dt>         * <dd>An array containing references to the nodes that were         * inserted successfully</dd>         * <dt>purge</dt>         * <dd>A function that, when executed, will remove any nodes         * that were inserted</dd>         * <dt>         * </dl>         * </dd>         * <dt>onTimeout</dt>         * <dd>         * callback to execute when a timeout occurs.         * The callback receives an object back with the following         * data:         * <dl>         * <dt>win</dt>         * <dd>the window the script(s) were inserted into</dd>         * <dt>data</dt>         * <dd>the data object passed in when the request was made</dd>         * <dt>nodes</dt>         * <dd>An array containing references to the nodes that were         * inserted</dd>         * <dt>purge</dt>         * <dd>A function that, when executed, will remove the nodes         * that were inserted</dd>         * <dt>         * </dl>         * </dd>         * <dt>scope</dt>         * <dd>the execution context for the callbacks</dd>         * <dt>win</dt>         * <dd>a window other than the one the utility occupies</dd>         * <dt>autopurge</dt>         * <dd>         * setting to true will let the utilities cleanup routine purge          * the script once loaded         * </dd>         * <dt>data</dt>         * <dd>         * data that is supplied to the callback when the script(s) are         * loaded.         * </dd>         * <dt>varName</dt>         * <dd>         * variable that should be available when a script is finished         * loading.  Used to help Safari 2.x and below with script load          * detection.  The type of this property should match what was         * passed into the url parameter: if loading a single url, a         * string can be supplied.  If loading multiple scripts, you         * must supply an array that contains the variable name for         * each script.         * </dd>         * <dt>insertBefore</dt>         * <dd>node or node id that will become the new node's nextSibling</dd>         * </dl>         * <dt>charset</dt>         * <dd>Node charset, default utf-8</dd>         * <dt>timeout</dt>         * <dd>Number of milliseconds to wait before aborting and firing the timeout event</dd>         * <pre>         * // assumes yahoo, dom, and event are already on the page         * &nbsp;&nbsp;YAHOO.util.Get.script(         * &nbsp;&nbsp;["http://yui.yahooapis.com/2.3.1/build/dragdrop/dragdrop-min.js",         * &nbsp;&nbsp;&nbsp;"http://yui.yahooapis.com/2.3.1/build/animation/animation-min.js"], &#123;         * &nbsp;&nbsp;&nbsp;&nbsp;onSuccess: function(o) &#123;         * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;YAHOO.log(o.data); // foo         * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new YAHOO.util.DDProxy("dd1"); // also new o.reference("dd1"); would work         * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.log("won't cause error because YAHOO is the scope");         * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.log(o.nodes.length === 2) // true         * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// o.purge(); // optionally remove the script nodes immediately         * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,         * &nbsp;&nbsp;&nbsp;&nbsp;onFailure: function(o) &#123;         * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;YAHOO.log("transaction failed");         * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,         * &nbsp;&nbsp;&nbsp;&nbsp;data: "foo",         * &nbsp;&nbsp;&nbsp;&nbsp;timeout: 10000, // 10 second timeout         * &nbsp;&nbsp;&nbsp;&nbsp;scope: YAHOO,         * &nbsp;&nbsp;&nbsp;&nbsp;// win: otherframe // target another window/frame         * &nbsp;&nbsp;&nbsp;&nbsp;autopurge: true // allow the utility to choose when to remove the nodes         * &nbsp;&nbsp;&#125;);         * </pre>         * @return {tId: string} an object containing info about the transaction         */        script: function(url, opts) { return _queue("script", url, opts); },        /**         * Fetches and inserts one or more css link nodes into the          * head of the current document or the document in a specified         * window.         * @method css         * @static         * @param url {string} the url or urls to the css file(s)         * @param opts Options:          * <dl>         * <dt>onSuccess</dt>         * <dd>         * callback to execute when the css file(s) are finished loading         * The callback receives an object back with the following         * data:         * <dl>win</dl>         * <dd>the window the link nodes(s) were inserted into</dd>         * <dt>data</dt>         * <dd>the data object passed in when the request was made</dd>         * <dt>nodes</dt>         * <dd>An array containing references to the nodes that were         * inserted</dd>         * <dt>purge</dt>         * <dd>A function that, when executed, will remove the nodes         * that were inserted</dd>         * <dt>         * </dl>         * </dd>         * <dt>scope</dt>         * <dd>the execution context for the callbacks</dd>         * <dt>win</dt>         * <dd>a window other than the one the utility occupies</dd>         * <dt>data</dt>         * <dd>         * data that is supplied to the callbacks when the nodes(s) are         * loaded.         * </dd>         * <dt>insertBefore</dt>         * <dd>node or node id that will become the new node's nextSibling</dd>         * <dt>charset</dt>         * <dd>Node charset, default utf-8</dd>         * </dl>         * <pre>         *      YAHOO.util.Get.css("http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css");         * </pre>         * <pre>         *      YAHOO.util.Get.css(["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",         *                          "http://yui.yahooapis.com/2.3.1/build/logger/assets/skins/sam/logger.css"]);         * </pre>         * @return {tId: string} an object containing info about the transaction         */        css: function(url, opts) {            return _queue("css", url, opts);         }    };}();YAHOO.register("get", YAHOO.util.Get, {version: "2.6.0", build: "1321"});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -