3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.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) {
26 if (Ext.isArray(eventName)) {
27 Ext.each(eventName, function(e) {
37 * Create an event handler on this element such that when the event fires and is handled by this element,
38 * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
39 * @param {String} eventName The type of event to relay
40 * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
41 * for firing the relayed event
43 relayEvent : function(eventName, observable) {
44 this.on(eventName, function(e) {
45 observable.fireEvent(eventName, e);
50 * Removes worthless text nodes
51 * @param {Boolean} forceReclean (optional) By default the element
52 * keeps track if it has been cleaned already so
53 * you can call this over and over. However, if you update the element and
54 * need to force a reclean, you can pass true.
56 clean : function(forceReclean) {
62 if (Ext.Element.data(dom, 'isCleaned') && forceReclean !== true) {
67 var nx = n.nextSibling;
68 if (n.nodeType == 3 && !(/\S/.test(n.nodeValue))) {
76 Ext.Element.data(dom, 'isCleaned', true);
81 * Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object
82 * parameter as {@link Ext.Updater#update}
83 * @return {Ext.Element} this
86 var updateManager = this.getUpdater();
87 updateManager.update.apply(updateManager, arguments);
93 * Gets this element's {@link Ext.Updater Updater}
94 * @return {Ext.Updater} The Updater
96 getUpdater : function() {
97 return this.updateManager || (this.updateManager = new Ext.Updater(this));
101 * Update the innerHTML of this element, optionally searching for and processing scripts
102 * @param {String} html The new HTML
103 * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
104 * @param {Function} callback (optional) For async script loading you can be notified when the update completes
105 * @return {Ext.Element} this
107 update : function(html, loadScripts, callback) {
113 if (loadScripts !== true) {
114 this.dom.innerHTML = html;
115 if (typeof callback == 'function') {
124 html += '<span id="' + id + '"></span>';
126 Ext.lib.Event.onAvailable(id, function() {
128 hd = DOC.getElementsByTagName("head")[0],
129 re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
130 srcRe = /\ssrc=([\'\"])(.*?)\1/i,
131 typeRe = /\stype=([\'\"])(.*?)\1/i,
139 while ((match = re.exec(html))) {
141 srcMatch = attrs ? attrs.match(srcRe) : false;
142 if (srcMatch && srcMatch[2]) {
143 s = DOC.createElement("script");
145 typeMatch = attrs.match(typeRe);
146 if (typeMatch && typeMatch[2]) {
147 s.type = typeMatch[2];
150 } else if (match[2] && match[2].length > 0) {
151 if (window.execScript) {
152 window.execScript(match[2]);
154 window.eval(match[2]);
159 el = DOC.getElementById(id);
164 if (typeof callback == 'function') {
168 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
172 // inherit docs, overridden so we can add removeAnchor
173 removeAllListeners : function() {
175 Ext.EventManager.removeAll(this.dom);
180 * Creates a proxy element of this element
181 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
182 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
183 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
184 * @return {Ext.Element} The new proxy element
186 createProxy : function(config, renderTo, matchBox) {
187 config = (typeof config == 'object') ? config : {tag : "div", cls: config};
190 proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
191 Ext.DomHelper.insertBefore(me.dom, config, true);
193 if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
194 proxy.setBox(me.getBox());
200 Ext.Element.prototype.getUpdateManager = Ext.Element.prototype.getUpdater;