Element-more_wev8.js
6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*!
* Ext JS Library 3.0.0
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
/**
* @class Ext.Element
*/
Ext.Element.addMethods({
/**
* Stops the specified event(s) from bubbling and optionally prevents the default action
* @param {String/Array} eventName an event / array of events to stop from bubbling
* @param {Boolean} preventDefault (optional) true to prevent the default action too
* @return {Ext.Element} this
*/
swallowEvent : function(eventName, preventDefault){
var me = this;
function fn(e){
e.stopPropagation();
if(preventDefault){
e.preventDefault();
}
}
if(Ext.isArray(eventName)){
Ext.each(eventName, function(e) {
me.on(e, fn);
});
return me;
}
me.on(eventName, fn);
return me;
},
/**
* Create an event handler on this element such that when the event fires and is handled by this element,
* it will be relayed to another object (i.e., fired again as if it originated from that object instead).
* @param {String} eventName The type of event to relay
* @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
* for firing the relayed event
*/
relayEvent : function(eventName, observable){
this.on(eventName, function(e){
observable.fireEvent(eventName, e);
});
},
/**
* Removes worthless text nodes
* @param {Boolean} forceReclean (optional) By default the element
* keeps track if it has been cleaned already so
* you can call this over and over. However, if you update the element and
* need to force a reclean, you can pass true.
*/
clean : function(forceReclean){
var me = this,
dom = me.dom,
n = dom.firstChild,
ni = -1;
if(Ext.Element.data(dom, 'isCleaned') && forceReclean !== true){
return me;
}
while(n){
var nx = n.nextSibling;
if(n.nodeType == 3 && !/\S/.test(n.nodeValue)){
dom.removeChild(n);
}else{
n.nodeIndex = ++ni;
}
n = nx;
}
Ext.Element.data(dom, 'isCleaned', true);
return me;
},
/**
* Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object
* parameter as {@link Ext.Updater#update}
* @return {Ext.Element} this
*/
load : function(){
var um = this.getUpdater();
um.update.apply(um, arguments);
return this;
},
/**
* Gets this element's {@link Ext.Updater Updater}
* @return {Ext.Updater} The Updater
*/
getUpdater : function(){
return this.updateManager || (this.updateManager = new Ext.Updater(this));
},
/**
* Update the innerHTML of this element, optionally searching for and processing scripts
* @param {String} html The new HTML
* @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
* @param {Function} callback (optional) For async script loading you can be notified when the update completes
* @return {Ext.Element} this
*/
update : function(html, loadScripts, callback){
html = html || "";
if(loadScripts !== true){
this.dom.innerHTML = html;
if(Ext.isFunction(callback)){
callback();
}
return this;
}
var id = Ext.id(),
dom = this.dom;
html += '<span id="' + id + '"></span>';
Ext.lib.Event.onAvailable(id, function(){
var DOC = document,
hd = DOC.getElementsByTagName("head")[0],
re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
srcRe = /\ssrc=([\'\"])(.*?)\1/i,
typeRe = /\stype=([\'\"])(.*?)\1/i,
match,
attrs,
srcMatch,
typeMatch,
el,
s;
while((match = re.exec(html))){
attrs = match[1];
srcMatch = attrs ? attrs.match(srcRe) : false;
if(srcMatch && srcMatch[2]){
s = DOC.createElement("script");
s.src = srcMatch[2];
typeMatch = attrs.match(typeRe);
if(typeMatch && typeMatch[2]){
s.type = typeMatch[2];
}
hd.appendChild(s);
}else if(match[2] && match[2].length > 0){
if(window.execScript) {
window.execScript(match[2]);
} else {
window.eval(match[2]);
}
}
}
el = DOC.getElementById(id);
if(el){Ext.removeNode(el);}
if(Ext.isFunction(callback)){
callback();
}
});
dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
return this;
},
/**
* Creates a proxy element of this element
* @param {String/Object} config The class name of the proxy element or a DomHelper config object
* @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
* @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
* @return {Ext.Element} The new proxy element
*/
createProxy : function(config, renderTo, matchBox){
config = Ext.isObject(config) ? config : {tag : "div", cls: config};
var me = this,
proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
Ext.DomHelper.insertBefore(me.dom, config, true);
if(matchBox && me.setBox && me.getBox){ // check to make sure Element.position_wev8.js is loaded
proxy.setBox(me.getBox());
}
return proxy;
}
});
Ext.Element.prototype.getUpdateManager = Ext.Element.prototype.getUpdater;
// private
Ext.Element.uncache = function(el){
for(var i = 0, a = arguments, len = a.length; i < len; i++) {
if(a[i]){
delete Ext.Element.cache[a[i].id || a[i]];
}
}
};