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