3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
10 Ext.Element.addMethods({
\r
12 * Stops the specified event(s) from bubbling and optionally prevents the default action
\r
13 * @param {String/Array} eventName an event / array of events to stop from bubbling
\r
14 * @param {Boolean} preventDefault (optional) true to prevent the default action too
\r
15 * @return {Ext.Element} this
\r
17 swallowEvent : function(eventName, preventDefault){
\r
20 e.stopPropagation();
\r
25 if(Ext.isArray(eventName)){
\r
26 Ext.each(eventName, function(e) {
\r
31 me.on(eventName, fn);
\r
36 * Create an event handler on this element such that when the event fires and is handled by this element,
\r
37 * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
\r
38 * @param {String} eventName The type of event to relay
\r
39 * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
\r
40 * for firing the relayed event
\r
42 relayEvent : function(eventName, observable){
\r
43 this.on(eventName, function(e){
\r
44 observable.fireEvent(eventName, e);
\r
49 * Removes worthless text nodes
\r
50 * @param {Boolean} forceReclean (optional) By default the element
\r
51 * keeps track if it has been cleaned already so
\r
52 * you can call this over and over. However, if you update the element and
\r
53 * need to force a reclean, you can pass true.
\r
55 clean : function(forceReclean){
\r
58 n = dom.firstChild,
\r
61 if(Ext.Element.data(dom, 'isCleaned') && forceReclean !== true){
\r
66 var nx = n.nextSibling;
\r
67 if(n.nodeType == 3 && !/\S/.test(n.nodeValue)){
\r
74 Ext.Element.data(dom, 'isCleaned', true);
\r
79 * Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object
\r
80 * parameter as {@link Ext.Updater#update}
\r
81 * @return {Ext.Element} this
\r
84 var um = this.getUpdater();
\r
85 um.update.apply(um, arguments);
\r
90 * Gets this element's {@link Ext.Updater Updater}
\r
91 * @return {Ext.Updater} The Updater
\r
93 getUpdater : function(){
\r
94 return this.updateManager || (this.updateManager = new Ext.Updater(this));
\r
98 * Update the innerHTML of this element, optionally searching for and processing scripts
\r
99 * @param {String} html The new HTML
\r
100 * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
\r
101 * @param {Function} callback (optional) For async script loading you can be notified when the update completes
\r
102 * @return {Ext.Element} this
\r
104 update : function(html, loadScripts, callback){
\r
107 if(loadScripts !== true){
\r
108 this.dom.innerHTML = html;
\r
109 if(Ext.isFunction(callback)){
\r
118 html += '<span id="' + id + '"></span>';
\r
120 Ext.lib.Event.onAvailable(id, function(){
\r
121 var DOC = document,
\r
122 hd = DOC.getElementsByTagName("head")[0],
\r
123 re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
\r
124 srcRe = /\ssrc=([\'\"])(.*?)\1/i,
\r
125 typeRe = /\stype=([\'\"])(.*?)\1/i,
\r
133 while((match = re.exec(html))){
\r
135 srcMatch = attrs ? attrs.match(srcRe) : false;
\r
136 if(srcMatch && srcMatch[2]){
\r
137 s = DOC.createElement("script");
\r
138 s.src = srcMatch[2];
\r
139 typeMatch = attrs.match(typeRe);
\r
140 if(typeMatch && typeMatch[2]){
\r
141 s.type = typeMatch[2];
\r
144 }else if(match[2] && match[2].length > 0){
\r
145 if(window.execScript) {
\r
146 window.execScript(match[2]);
\r
148 window.eval(match[2]);
\r
152 el = DOC.getElementById(id);
\r
153 if(el){Ext.removeNode(el);}
\r
154 if(Ext.isFunction(callback)){
\r
158 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
\r
163 * Creates a proxy element of this element
\r
164 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
\r
165 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
\r
166 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
\r
167 * @return {Ext.Element} The new proxy element
\r
169 createProxy : function(config, renderTo, matchBox){
\r
170 config = Ext.isObject(config) ? config : {tag : "div", cls: config};
\r
173 proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
\r
174 Ext.DomHelper.insertBefore(me.dom, config, true);
\r
176 if(matchBox && me.setBox && me.getBox){ // check to make sure Element.position.js is loaded
\r
177 proxy.setBox(me.getBox());
\r
183 Ext.Element.prototype.getUpdateManager = Ext.Element.prototype.getUpdater;
\r
186 Ext.Element.uncache = function(el){
\r
187 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
\r
189 delete Ext.Element.cache[a[i].id || a[i]];
\r