3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
15 * @class Ext.Element
\r
17 Ext.Element.addMethods({
\r
18 <div id="method-Ext.Element-swallowEvent"></div>/**
\r
19 * Stops the specified event(s) from bubbling and optionally prevents the default action
\r
20 * @param {String/Array} eventName an event / array of events to stop from bubbling
\r
21 * @param {Boolean} preventDefault (optional) true to prevent the default action too
\r
22 * @return {Ext.Element} this
\r
24 swallowEvent : function(eventName, preventDefault){
\r
27 e.stopPropagation();
\r
32 if(Ext.isArray(eventName)){
\r
33 Ext.each(eventName, function(e) {
\r
38 me.on(eventName, fn);
\r
42 <div id="method-Ext.Element-relayEvent"></div>/**
\r
43 * Create an event handler on this element such that when the event fires and is handled by this element,
\r
44 * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
\r
45 * @param {String} eventName The type of event to relay
\r
46 * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
\r
47 * for firing the relayed event
\r
49 relayEvent : function(eventName, observable){
\r
50 this.on(eventName, function(e){
\r
51 observable.fireEvent(eventName, e);
\r
55 <div id="method-Ext.Element-clean"></div>/**
\r
56 * Removes worthless text nodes
\r
57 * @param {Boolean} forceReclean (optional) By default the element
\r
58 * keeps track if it has been cleaned already so
\r
59 * you can call this over and over. However, if you update the element and
\r
60 * need to force a reclean, you can pass true.
\r
62 clean : function(forceReclean){
\r
65 n = dom.firstChild,
\r
68 if(Ext.Element.data(dom, 'isCleaned') && forceReclean !== true){
\r
73 var nx = n.nextSibling;
\r
74 if(n.nodeType == 3 && !/\S/.test(n.nodeValue)){
\r
81 Ext.Element.data(dom, 'isCleaned', true);
\r
85 <div id="method-Ext.Element-load"></div>/**
\r
86 * Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object
\r
87 * parameter as {@link Ext.Updater#update}
\r
88 * @return {Ext.Element} this
\r
91 var um = this.getUpdater();
\r
92 um.update.apply(um, arguments);
\r
96 <div id="method-Ext.Element-getUpdater"></div>/**
\r
97 * Gets this element's {@link Ext.Updater Updater}
\r
98 * @return {Ext.Updater} The Updater
\r
100 getUpdater : function(){
\r
101 return this.updateManager || (this.updateManager = new Ext.Updater(this));
\r
104 <div id="method-Ext.Element-update"></div>/**
\r
105 * Update the innerHTML of this element, optionally searching for and processing scripts
\r
106 * @param {String} html The new HTML
\r
107 * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
\r
108 * @param {Function} callback (optional) For async script loading you can be notified when the update completes
\r
109 * @return {Ext.Element} this
\r
111 update : function(html, loadScripts, callback){
\r
114 if(loadScripts !== true){
\r
115 this.dom.innerHTML = html;
\r
116 if(Ext.isFunction(callback)){
\r
125 html += '<span id="' + id + '"></span>';
\r
127 Ext.lib.Event.onAvailable(id, function(){
\r
128 var DOC = document,
\r
129 hd = DOC.getElementsByTagName("head")[0],
\r
130 re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
\r
131 srcRe = /\ssrc=([\'\"])(.*?)\1/i,
\r
132 typeRe = /\stype=([\'\"])(.*?)\1/i,
\r
140 while((match = re.exec(html))){
\r
142 srcMatch = attrs ? attrs.match(srcRe) : false;
\r
143 if(srcMatch && srcMatch[2]){
\r
144 s = DOC.createElement("script");
\r
145 s.src = srcMatch[2];
\r
146 typeMatch = attrs.match(typeRe);
\r
147 if(typeMatch && typeMatch[2]){
\r
148 s.type = typeMatch[2];
\r
151 }else if(match[2] && match[2].length > 0){
\r
152 if(window.execScript) {
\r
153 window.execScript(match[2]);
\r
155 window.eval(match[2]);
\r
159 el = DOC.getElementById(id);
\r
160 if(el){Ext.removeNode(el);}
\r
161 if(Ext.isFunction(callback)){
\r
165 dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
\r
169 <div id="method-Ext.Element-createProxy"></div>/**
\r
170 * Creates a proxy element of this element
\r
171 * @param {String/Object} config The class name of the proxy element or a DomHelper config object
\r
172 * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
\r
173 * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
\r
174 * @return {Ext.Element} The new proxy element
\r
176 createProxy : function(config, renderTo, matchBox){
\r
177 config = Ext.isObject(config) ? config : {tag : "div", cls: config};
\r
180 proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
\r
181 Ext.DomHelper.insertBefore(me.dom, config, true);
\r
183 if(matchBox && me.setBox && me.getBox){ // check to make sure Element.position.js is loaded
\r
184 proxy.setBox(me.getBox());
\r
190 Ext.Element.prototype.getUpdateManager = Ext.Element.prototype.getUpdater;
\r
193 Ext.Element.uncache = function(el){
\r
194 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
\r
196 delete Ext.Element.cache[a[i].id || a[i]];
\r