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

📄 eventmanager.js

📁 Ext JS是一个创建丰富互联网应用程序的跨浏览器的JavaScrip库。它包含:高效率
💻 JS
📖 第 1 页 / 共 2 页
字号:
     * @param {Object} scope (optional) The scope in which to execute the handler     * function (the handler function's "this" context)     * @param {Object} options (optional) An object containing standard {@link #addListener} options     * @member Ext.EventManager     * @method on     */    pub.on = pub.addListener;    /**     * Removes an event handler from an element.  Shorthand for {@link #removeListener}.     * @param {String/HTMLElement} el The id or html element from which to remove the event     * @param {String} eventName The type of event     * @param {Function} fn The handler function to remove     * @return {Boolean} True if a listener was actually removed, else false     * @member Ext.EventManager     * @method un     */    pub.un = pub.removeListener;    pub.stoppedMouseDownEvent = new Ext.util.Event();    return pub;}();/**  * Fires when the document is ready (before onload and before images are loaded).  Shorthand of {@link Ext.EventManager#onDocumentReady}.  * @param {Function} fn The method the event invokes  * @param {Object} scope An object that becomes the scope of the handler  * @param {boolean} options (optional) An object containing standard {@link #addListener} options  * @member Ext  * @method onReady */Ext.onReady = Ext.EventManager.onDocumentReady;//Initialize doc classes(function(){        var initExtCss = function(){        // find the body element        var bd = document.body || document.getElementsByTagName('body')[0];        if(!bd){ return false; }        var cls = [' ',                Ext.isIE ? "ext-ie " + (Ext.isIE6 ? 'ext-ie6' : (Ext.isIE7 ? 'ext-ie7' : 'ext-ie8'))                : Ext.isGecko ? "ext-gecko " + (Ext.isGecko2 ? 'ext-gecko2' : 'ext-gecko3')                : Ext.isOpera ? "ext-opera"                : Ext.isWebKit ? "ext-webkit"                : Ext.isSafari ? "ext-safari"                : Ext.isChrome ? "ext-chrome" : ""];        if(Ext.isMac){            cls.push("ext-mac");        }        if(Ext.isLinux){            cls.push("ext-linux");        }        if(Ext.isBorderBox){            cls.push('ext-border-box');        }        if(Ext.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"            var p = bd.parentNode;            if(p){                p.className += ' ext-strict';            }        }        bd.className += cls.join(' ');        return true;    }    if(!initExtCss()){        Ext.onReady(initExtCss);    }})();/** * @class Ext.EventObject * Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject  * wraps the browser's native event-object normalizing cross-browser differences, * such as which mouse button is clicked, keys pressed, mechanisms to stop * event-propagation along with a method to prevent default actions from taking place. * <p>For example:</p> * <pre><code>function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject    e.preventDefault();    var target = e.getTarget(); // same as t (the target HTMLElement)    ...}var myDiv = {@link Ext#get Ext.get}("myDiv");  // get reference to an {@link Ext.Element}myDiv.on(         // 'on' is shorthand for addListener    "click",      // perform an action on click of myDiv    handleClick   // reference to the action handler);  // other methods to do the same:Ext.EventManager.on("myDiv", 'click', handleClick);Ext.EventManager.addListener("myDiv", 'click', handleClick); </code></pre> * @singleton */Ext.EventObject = function(){    var E = Ext.lib.Event,    	// safari keypress events for special keys return bad keycodes    	safariKeys = {	        3 : 13, // enter	        63234 : 37, // left	        63235 : 39, // right	        63232 : 38, // up	        63233 : 40, // down	        63276 : 33, // page up	        63277 : 34, // page down	        63272 : 46, // delete	        63273 : 36, // home	        63275 : 35  // end    	},    	// normalize button clicks    	btnMap = Ext.isIE ? {1:0,4:1,2:2} :                (Ext.isWebKit ? {1:0,2:1,3:2} : {0:0,1:1,2:2});    Ext.EventObjectImpl = function(e){        if(e){            this.setEvent(e.browserEvent || e);        }    };    Ext.EventObjectImpl.prototype = {           /** @private */        setEvent : function(e){	        var me = this;            if(e == me || (e && e.browserEvent)){ // already wrapped                return e;            }            me.browserEvent = e;            if(e){                // normalize buttons                me.button = e.button ? btnMap[e.button] : (e.which ? e.which - 1 : -1);                if(e.type == 'click' && me.button == -1){                    me.button = 0;                }                me.type = e.type;                me.shiftKey = e.shiftKey;                // mac metaKey behaves like ctrlKey                me.ctrlKey = e.ctrlKey || e.metaKey;                me.altKey = e.altKey;                // in getKey these will be normalized for the mac                me.keyCode = e.keyCode;                me.charCode = e.charCode;                // cache the target for the delayed and or buffered events                me.target = E.getTarget(e);                // same for XY                me.xy = E.getXY(e);            }else{                me.button = -1;                me.shiftKey = false;                me.ctrlKey = false;                me.altKey = false;                me.keyCode = 0;                me.charCode = 0;                me.target = null;                me.xy = [0, 0];            }            return me;        },        /**         * Stop the event (preventDefault and stopPropagation)         */        stopEvent : function(){	        var me = this;            if(me.browserEvent){                if(me.browserEvent.type == 'mousedown'){                    Ext.EventManager.stoppedMouseDownEvent.fire(me);                }                E.stopEvent(me.browserEvent);            }        },        /**         * Prevents the browsers default handling of the event.         */        preventDefault : function(){            if(this.browserEvent){                E.preventDefault(this.browserEvent);            }        },                /**         * Cancels bubbling of the event.         */        stopPropagation : function(){	        var me = this;            if(me.browserEvent){                if(me.browserEvent.type == 'mousedown'){                    Ext.EventManager.stoppedMouseDownEvent.fire(me);                }                E.stopPropagation(me.browserEvent);            }        },        /**         * Gets the character code for the event.         * @return {Number}         */        getCharCode : function(){            return this.charCode || this.keyCode;        },        /**         * Returns a normalized keyCode for the event.         * @return {Number} The key code         */        getKey : function(){            return this.normalizeKey(this.keyCode || this.charCode)        },				// private		normalizeKey: function(k){			return Ext.isSafari ? (safariKeys[k] || k) : k; 		},        /**         * Gets the x coordinate of the event.         * @return {Number}         */        getPageX : function(){            return this.xy[0];        },        /**         * Gets the y coordinate of the event.         * @return {Number}         */        getPageY : function(){            return this.xy[1];        },//         /**//          * Gets the time of the event.//          * @return {Number}//          *///         getTime : function(){//             if(this.browserEvent){//                 return E.getTime(this.browserEvent);//             }//             return null;//         },        /**         * Gets the page coordinates of the event.         * @return {Array} The xy values like [x, y]         */        getXY : function(){            return this.xy;        },        /**         * Gets the target for the event.         * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target         * @param {Number/Mixed} maxDepth (optional) The max depth to                search as a number or element (defaults to 10 || document.body)         * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node         * @return {HTMLelement}         */        getTarget : function(selector, maxDepth, returnEl){            return selector ? Ext.fly(this.target).findParent(selector, maxDepth, returnEl) : (returnEl ? Ext.get(this.target) : this.target);        },        /**         * Gets the related target.         * @return {HTMLElement}         */        getRelatedTarget : function(){            return this.browserEvent ? E.getRelatedTarget(this.browserEvent) : null;        },        /**         * Normalizes mouse wheel delta across browsers         * @return {Number} The delta         */        getWheelDelta : function(){            var e = this.browserEvent;            var delta = 0;            if(e.wheelDelta){ /* IE/Opera. */                delta = e.wheelDelta/120;            }else if(e.detail){ /* Mozilla case. */                delta = -e.detail/3;            }            return delta;        },				/**		* Returns true if the target of this event is a child of el.  Unless the allowEl parameter is set, it will return false if if the target is el.		* Example usage:<pre><code>		// Handle click on any child of an element		Ext.getBody().on('click', function(e){			if(e.within('some-el')){				alert('Clicked on a child of some-el!');			}		});				// Handle click directly on an element, ignoring clicks on child nodes		Ext.getBody().on('click', function(e,t){			if((t.id == 'some-el') && !e.within(t, true)){				alert('Clicked directly on some-el!');			}		});		</code></pre>		 * @param {Mixed} el The id, DOM element or Ext.Element to check		 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target		 * @param {Boolean} allowEl {optional} true to also check if the passed element is the target or related target		 * @return {Boolean}		 */		within : function(el, related, allowEl){			var t = this[related ? "getRelatedTarget" : "getTarget"]();			return t && ((allowEl ? (t == Ext.getDom(el)) : false) || Ext.fly(el).contains(t));		}	 };    return new Ext.EventObjectImpl();}();

⌨️ 快捷键说明

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