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

📄 event.js

📁 一个使用yui-ext库
💻 JS
📖 第 1 页 / 共 5 页
字号:
                                scope = l[EU.ADJ_SCOPE];                            }                        }                        l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ] );                        unloadListeners[i] = null;                        l=null;                        scope=null;                    }                }                unloadListeners = null;                if (listeners && listeners.length > 0) {                    j = listeners.length;                    while (j) {                        index = j-1;                        l = listeners[index];                        if (l) {                            EU.removeListener(l[EU.EL], l[EU.TYPE],                                     l[EU.FN], index);                        }                         j = j - 1;                    }                    l=null;                    EU.clearCache();                }                for (i=0,len=legacyEvents.length; i<len; ++i) {                    // dereference the element                    //delete legacyEvents[i][0];                    legacyEvents[i][0] = null;                    // delete the array item                    //delete legacyEvents[i];                    legacyEvents[i] = null;                }                legacyEvents = null;                EU._simpleRemove(window, "unload", EU._unload);            },            /**             * Returns scrollLeft             * @method _getScrollLeft             * @static             * @private             */            _getScrollLeft: function() {                return this._getScroll()[1];            },            /**             * Returns scrollTop             * @method _getScrollTop             * @static             * @private             */            _getScrollTop: function() {                return this._getScroll()[0];            },            /**             * Returns the scrollTop and scrollLeft.  Used to calculate the              * pageX and pageY in Internet Explorer             * @method _getScroll             * @static             * @private             */            _getScroll: function() {                var dd = document.documentElement, db = document.body;                if (dd && (dd.scrollTop || dd.scrollLeft)) {                    return [dd.scrollTop, dd.scrollLeft];                } else if (db) {                    return [db.scrollTop, db.scrollLeft];                } else {                    return [0, 0];                }            },                        /**             * Used by old versions of CustomEvent, restored for backwards             * compatibility             * @method regCE             * @private             */            regCE: function() {                // does nothing            },            /**             * Adds a DOM event directly without the caching, cleanup, scope adj, etc             *             * @method _simpleAdd             * @param {HTMLElement} el      the element to bind the handler to             * @param {string}      sType   the type of event handler             * @param {function}    fn      the callback to invoke             * @param {boolen}      capture capture or bubble phase             * @static             * @private             */            _simpleAdd: function () {                if (window.addEventListener) {                    return function(el, sType, fn, capture) {                        el.addEventListener(sType, fn, (capture));                    };                } else if (window.attachEvent) {                    return function(el, sType, fn, capture) {                        el.attachEvent("on" + sType, fn);                    };                } else {                    return function(){};                }            }(),            /**             * Basic remove listener             *             * @method _simpleRemove             * @param {HTMLElement} el      the element to bind the handler to             * @param {string}      sType   the type of event handler             * @param {function}    fn      the callback to invoke             * @param {boolen}      capture capture or bubble phase             * @static             * @private             */            _simpleRemove: function() {                if (window.removeEventListener) {                    return function (el, sType, fn, capture) {                        el.removeEventListener(sType, fn, (capture));                    };                } else if (window.detachEvent) {                    return function (el, sType, fn) {                        el.detachEvent("on" + sType, fn);                    };                } else {                    return function(){};                }            }()        };    }();    (function() {        var EU = YAHOO.util.Event;        /**         * YAHOO.util.Event.on is an alias for addListener         * @method on         * @see addListener         * @static         */        EU.on = EU.addListener;        // YAHOO.mix(EU, YAHOO.util.EventProvider.prototype);        // EU.createEvent("DOMContentReady");        // EU.subscribe("DOMContentReady", EU._load);        if (document && document.body) {            EU._load();        } else {            // EU._simpleAdd(document, "DOMContentLoaded", EU._load);            EU._simpleAdd(window, "load", EU._load);        }        EU._simpleAdd(window, "unload", EU._unload);        EU._tryPreloadAttach();    })();}/** * The CustomEvent class lets you define events for your application * that can be subscribed to by one or more independent component. * * @param {String}  type The type of event, which is passed to the callback *                  when the event fires * @param {Object}  oScope The context the event will fire from.  "this" will *                  refer to this object in the callback.  Default value:  *                  the window object.  The listener can override this. * @param {boolean} silent pass true to prevent the event from writing to *                  the debugsystem * @param {int}     signature the signature that the custom event subscriber *                  will receive. YAHOO.util.CustomEvent.LIST or  *                  YAHOO.util.CustomEvent.FLAT.  The default is *                  YAHOO.util.CustomEvent.LIST. * @namespace YAHOO.util * @class CustomEvent * @constructor */YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {    /**     * The type of event, returned to subscribers when the event fires     * @property type     * @type string     */    this.type = type;    /**     * The scope the the event will fire from by default.  Defaults to the window      * obj     * @property scope     * @type object     */    this.scope = oScope || window;    /**     * By default all custom events are logged in the debug build, set silent     * to true to disable debug outpu for this event.     * @property silent     * @type boolean     */    this.silent = silent;    /**     * Custom events support two styles of arguments provided to the event     * subscribers.       * <ul>     * <li>YAHOO.util.CustomEvent.LIST:      *   <ul>     *   <li>param1: event name</li>     *   <li>param2: array of arguments sent to fire</li>     *   <li>param3: <optional> a custom object supplied by the subscriber</li>     *   </ul>     * </li>     * <li>YAHOO.util.CustomEvent.FLAT     *   <ul>     *   <li>param1: the first argument passed to fire.  If you need to     *           pass multiple parameters, use and array or object literal</li>     *   <li>param2: <optional> a custom object supplied by the subscriber</li>     *   </ul>     * </li>     * </ul>     *   @property signature     *   @type int     */    this.signature = signature || YAHOO.util.CustomEvent.LIST;    /**     * The subscribers to this event     * @property subscribers     * @type Subscriber[]     */    this.subscribers = [];    if (!this.silent) {    }    var onsubscribeType = "_YUICEOnSubscribe";    // Only add subscribe events for events that are not generated by     // CustomEvent    if (type !== onsubscribeType) {        /**         * Custom events provide a custom event that fires whenever there is         * a new subscriber to the event.  This provides an opportunity to         * handle the case where there is a non-repeating event that has         * already fired has a new subscriber.           *         * @event subscribeEvent         * @type YAHOO.util.CustomEvent         * @param {Function} fn The function to execute         * @param {Object}   obj An object to be passed along when the event          *                       fires         * @param {boolean|Object}  override If true, the obj passed in becomes          *                                   the execution scope of the listener.         *                                   if an object, that object becomes the         *                                   the execution scope.         */        this.subscribeEvent =                 new YAHOO.util.CustomEvent(onsubscribeType, this, true);    } };/** * Subscriber listener sigature constant.  The LIST type returns three * parameters: the event type, the array of args passed to fire, and * the optional custom object * @property YAHOO.util.CustomEvent.LIST * @static * @type int */YAHOO.util.CustomEvent.LIST = 0;/** * Subscriber listener sigature constant.  The FLAT type returns two * parameters: the first argument passed to fire and the optional  * custom object * @property YAHOO.util.CustomEvent.FLAT * @static * @type int */YAHOO.util.CustomEvent.FLAT = 1;YAHOO.util.CustomEvent.prototype = {    /**     * Subscribes the caller to this event     * @method subscribe     * @param {Function} fn        The function to execute     * @param {Object}   obj       An object to be passed along when the event      *                             fires     * @param {boolean|Object}  override If true, the obj passed in becomes      *                                   the execution scope of the listener.     *                                   if an object, that object becomes the     *                                   the execution scope.     */    subscribe: function(fn, obj, override) {        if (this.subscribeEvent) {            this.subscribeEvent.fire(fn, obj, override);        }        this.subscribers.push( new YAHOO.util.Subscriber(fn, obj, override) );    },    /**     * Unsubscribes subscribers.     * @method unsubscribe     * @param {Function} fn  The subscribed function to remove, if not supplied     *                       all will be removed     * @param {Object}   obj  The custom object passed to subscribe.  This is     *                        optional, but if supplied will be used to     *                        disambiguate multiple listeners that are the same     *                        (e.g., you subscribe many object using a function     *                        that lives on the prototype)     * @return {boolean} True if the subscriber was found and detached.     */    unsubscribe: function(fn, obj) {        if (!fn) {            return this.unsubscribeAll();        }        var found = false;        for (var i=0, len=this.subscribers.length; i<len; ++i) {            var s = this.subscribers[i];            if (s && s.contains(fn, obj)) {                this._delete(i);                found = true;            }        }        return found;    },    /**     * Notifies the subscribers.  The callback functions will be executed     * from the scope specified when the event was created, and with the      * following parameters:     *   <ul>     *   <li>The type of event</li>     *   <li>All of the arguments fire() was executed with as an array</li>     *   <li>The custom object (if any) that was passed into the subscribe()      *       method</li>     *   </ul>     * @method fire      * @param {Object*} arguments an arbitrary set of parameters to pass to      *                            the handler.     * @return {boolean} false if one of the subscribers returned false,      *                   true otherwise     */    fire: function() {        var len=this.subscribers.length;        if (!len && this.silent) {            return true;        }        var args=[], ret=true, i;        for (i=0; i<arguments.length; ++i) {            args.push(arguments[i]);        }        var argslength = args.length;

⌨️ 快捷键说明

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