📄 element.js
字号:
/** * @event DOMActivate * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */// DOM Mutation events /** * @event DOMSubtreeModified * Where supported. Fires when the subtree is modified. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */ /** * @event DOMNodeInserted * Where supported. Fires when a node has been added as a child of another node. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */ /** * @event DOMNodeRemoved * Where supported. Fires when a descendant node of the element is removed. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */ /** * @event DOMNodeRemovedFromDocument * Where supported. Fires when a node is being removed from a document. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */ /** * @event DOMNodeInsertedIntoDocument * Where supported. Fires when a node is being inserted into a document. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */ /** * @event DOMAttrModified * Where supported. Fires when an attribute has been modified. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */ /** * @event DOMCharacterDataModified * Where supported. Fires when the character data has been modified. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event */ /** * The default unit to append to CSS values where a unit isn't provided (defaults to px). * @type String */ defaultUnit : "px", /** * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child) * @param {String} selector The simple selector to test * @return {Boolean} True if this element matches the selector, else false */ is : function(simpleSelector){ return Ext.DomQuery.is(this.dom, simpleSelector); }, /** * Tries to focus the element. Any exceptions are caught and ignored. * @param {Number} defer (optional) Milliseconds to defer the focus * @return {Ext.Element} this */ focus : function(defer) { var me = this; try{ if(!isNaN(defer)){ me.focus.defer(defer, me); }else{ me.dom.focus(); } }catch(e){} return me; }, /** * Tries to blur the element. Any exceptions are caught and ignored. * @return {Ext.Element} this */ blur : function() { try{ this.dom.blur(); }catch(e){} return this; }, /** * Returns the value of the "value" attribute * @param {Boolean} asNumber true to parse the value as a number * @return {String/Number} */ getValue : function(asNumber){ var val = this.dom.value; return asNumber ? parseInt(val, 10) : val; }, /** * Appends an event handler to this element. The shorthand version {@link #on} is equivalent. * @param {String} eventName The type of event to handle * @param {Function} fn The handler function the event invokes. This function is passed * the following parameters:<ul> * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li> * <li><b>el</b> : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event. * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li> * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li> * </ul> * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed. * <b>If omitted, defaults to this Element.</b>. * @param {Object} options (optional) An object containing handler configuration properties. * This may contain any of the following properties:<ul> * <li><b>scope</b> Object : <div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed. * <b>If omitted, defaults to this Element.</b></div></li> * <li><b>delegate</b> String: <div class="sub-desc">A simple selector to filter the target or look for a descendant of the target. See below for additional details.</div></li> * <li><b>stopEvent</b> Boolean: <div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li> * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li> * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li> * <li><b>normalized</b> Boolean: <div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li> * <li><b>target</b> Ext.Element: <div class="sub-desc">The event will be passed to handler only when it has bubbled up to the specified target element</div></li> * <li><b>delay</b> Number: <div class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</div></li> * <li><b>single</b> Boolean: <div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li> * <li><b>buffer</b> Number: <div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed * by the specified number of milliseconds. If the event fires again within that time, the original * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li> * </ul><br> * <p> * <b>Combining Options</b><br> * In the following examples, the shorthand form {@link #on} is used rather than the more verbose * addListener. The two are equivalent. Using the options argument, it is possible to combine different * types of listeners:<br> * <br> * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;"> * Code:<pre><code>el.on('click', this.onClick, this, { single: true, delay: 100, stopEvent : true, forumId: 4});</code></pre></p> * <p> * <b>Attaching multiple handlers in 1 call</b><br> * The method also allows for a single argument to be passed which is a config object containing properties * which specify multiple handlers.</p> * <p> * Code:<pre><code>el.on({ 'click' : { fn: this.onClick, scope: this, delay: 100 }, 'mouseover' : { fn: this.onMouseOver, scope: this }, 'mouseout' : { fn: this.onMouseOut, scope: this }});</code></pre> * <p> * Or a shorthand syntax:<br> * Code:<pre><code></p>el.on({ 'click' : this.onClick, 'mouseover' : this.onMouseOver, 'mouseout' : this.onMouseOut, scope: this}); * </code></pre></p> * <p><b>delegate</b></p> * <p>This is a configuration option that you can pass along when registering a handler for * an event to assist with event delegation. Event delegation is a technique that is used to * reduce memory consumption and prevent exposure to memory-leaks. By registering an event * for a container element as opposed to each element within a container. By setting this * configuration option to a simple selector, the target element will be filtered to look for * a descendant of the target. * For example:<pre><code>// using this markup:<div id='elId'> <p id='p1'>paragraph one</p> <p id='p2' class='clickable'>paragraph two</p> <p id='p3'>paragraph three</p></div>// utilize event delegation to registering just one handler on the container element: el = Ext.get('elId');el.on( 'click', function(e,t) { // handle click console.info(t.id); // 'p2' }, this, { // filter the target element to be a descendant with the class 'clickable' delegate: '.clickable' }); * </code></pre></p> * @return {Ext.Element} this */ addListener : function(eventName, fn, scope, options){ Ext.EventManager.on(this.dom, eventName, fn, scope || this, options); return this; }, /** * Removes an event handler from this element. The shorthand version {@link #un} is equivalent. * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the * listener, the same scope must be specified here. * Example: * <pre><code>el.removeListener('click', this.handlerFn);// orel.un('click', this.handlerFn);</code></pre> * @param {String} eventName the type of event to remove * @param {Function} fn the method the event invokes * @param {Object} scope (optional) The scope (The <tt>this</tt> reference) of the handler function. Defaults * to this Element. * @return {Ext.Element} this */ removeListener : function(eventName, fn, scope){ Ext.EventManager.removeListener(this.dom, eventName, fn, scope || this); return this; }, /** * Removes all previous added listeners from this element * @return {Ext.Element} this */ removeAllListeners : function(){ Ext.EventManager.removeAll(this.dom); return this; }, /** * @private Test if size has a unit, otherwise appends the default */ addUnits : function(size){ if(size === "" || size == "auto" || size === undefined){ size = size || ''; } else if(!isNaN(size) || !unitPattern.test(size)){ size = size + (this.defaultUnit || 'px'); } return size; }, /** * <p>Updates the <a href="http://developer.mozilla.org/en/DOM/element.innerHTML">innerHTML</a> of this Element * from a specified URL. Note that this is subject to the <a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same Origin Policy</a></p> * <p>Updating innerHTML of an element will <b>not</b> execute embedded <tt><script></tt> elements. This is a browser restriction.</p> * @param {Mixed} options. Either a sring containing the URL from which to load the HTML, or an {@link Ext.Ajax#request} options object specifying * exactly how to request the HTML. * @return {Ext.Element} this */ load : function(url, params, cb){ Ext.Ajax.request(Ext.apply({ params: params, url: url.url || url, callback: cb, el: this, indicatorText: url.indicatorText || '' }, Ext.isObject(url) ? url : {})); return this; }, /** * Tests various css rules/browsers to determine if this element uses a border box * @return {Boolean} */ isBorderBox : function(){ return noBoxAdjust[(this.dom.tagName || "").toLowerCase()] || Ext.isBorderBox; }, /** * Removes this element from the DOM and deletes it from the cache */ remove : function(){ Ext.removeNode(this.dom); delete El.cache[this.dom.id];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -