1 | /*! |
---|
2 | * Ext JS Library 3.4.0 |
---|
3 | * Copyright(c) 2006-2011 Sencha Inc. |
---|
4 | * licensing@sencha.com |
---|
5 | * http://www.sencha.com/license |
---|
6 | */ |
---|
7 | // for old browsers |
---|
8 | window.undefined = window.undefined; |
---|
9 | |
---|
10 | /** |
---|
11 | * @class Ext |
---|
12 | * Ext core utilities and functions. |
---|
13 | * @singleton |
---|
14 | */ |
---|
15 | |
---|
16 | Ext = { |
---|
17 | /** |
---|
18 | * The version of the framework |
---|
19 | * @type String |
---|
20 | */ |
---|
21 | version : '3.4.0', |
---|
22 | versionDetail : { |
---|
23 | major : 3, |
---|
24 | minor : 4, |
---|
25 | patch : 0 |
---|
26 | } |
---|
27 | }; |
---|
28 | |
---|
29 | /** |
---|
30 | * Copies all the properties of config to obj. |
---|
31 | * @param {Object} obj The receiver of the properties |
---|
32 | * @param {Object} config The source of the properties |
---|
33 | * @param {Object} defaults A different object that will also be applied for default values |
---|
34 | * @return {Object} returns obj |
---|
35 | * @member Ext apply |
---|
36 | */ |
---|
37 | Ext.apply = function(o, c, defaults){ |
---|
38 | // no "this" reference for friendly out of scope calls |
---|
39 | if(defaults){ |
---|
40 | Ext.apply(o, defaults); |
---|
41 | } |
---|
42 | if(o && c && typeof c == 'object'){ |
---|
43 | for(var p in c){ |
---|
44 | o[p] = c[p]; |
---|
45 | } |
---|
46 | } |
---|
47 | return o; |
---|
48 | }; |
---|
49 | |
---|
50 | (function(){ |
---|
51 | var idSeed = 0, |
---|
52 | toString = Object.prototype.toString, |
---|
53 | ua = navigator.userAgent.toLowerCase(), |
---|
54 | check = function(r){ |
---|
55 | return r.test(ua); |
---|
56 | }, |
---|
57 | DOC = document, |
---|
58 | docMode = DOC.documentMode, |
---|
59 | isStrict = DOC.compatMode == "CSS1Compat", |
---|
60 | isOpera = check(/opera/), |
---|
61 | isChrome = check(/\bchrome\b/), |
---|
62 | isWebKit = check(/webkit/), |
---|
63 | isSafari = !isChrome && check(/safari/), |
---|
64 | isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2 |
---|
65 | isSafari3 = isSafari && check(/version\/3/), |
---|
66 | isSafari4 = isSafari && check(/version\/4/), |
---|
67 | isIE = !isOpera && check(/msie/), |
---|
68 | isIE7 = isIE && (check(/msie 7/) || docMode == 7), |
---|
69 | isIE8 = isIE && (check(/msie 8/) && docMode != 7), |
---|
70 | isIE9 = isIE && check(/msie 9/), |
---|
71 | isIE6 = isIE && !isIE7 && !isIE8 && !isIE9, |
---|
72 | isGecko = !isWebKit && check(/gecko/), |
---|
73 | isGecko2 = isGecko && check(/rv:1\.8/), |
---|
74 | isGecko3 = isGecko && check(/rv:1\.9/), |
---|
75 | isBorderBox = isIE && !isStrict, |
---|
76 | isWindows = check(/windows|win32/), |
---|
77 | isMac = check(/macintosh|mac os x/), |
---|
78 | isAir = check(/adobeair/), |
---|
79 | isLinux = check(/linux/), |
---|
80 | isSecure = /^https/i.test(window.location.protocol); |
---|
81 | |
---|
82 | // remove css image flicker |
---|
83 | if(isIE6){ |
---|
84 | try{ |
---|
85 | DOC.execCommand("BackgroundImageCache", false, true); |
---|
86 | }catch(e){} |
---|
87 | } |
---|
88 | |
---|
89 | Ext.apply(Ext, { |
---|
90 | /** |
---|
91 | * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent |
---|
92 | * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>). |
---|
93 | * @type String |
---|
94 | */ |
---|
95 | SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank', |
---|
96 | /** |
---|
97 | * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode |
---|
98 | * @type Boolean |
---|
99 | */ |
---|
100 | isStrict : isStrict, |
---|
101 | /** |
---|
102 | * True if the page is running over SSL |
---|
103 | * @type Boolean |
---|
104 | */ |
---|
105 | isSecure : isSecure, |
---|
106 | /** |
---|
107 | * True when the document is fully initialized and ready for action |
---|
108 | * @type Boolean |
---|
109 | */ |
---|
110 | isReady : false, |
---|
111 | |
---|
112 | /** |
---|
113 | * True if the {@link Ext.Fx} Class is available |
---|
114 | * @type Boolean |
---|
115 | * @property enableFx |
---|
116 | */ |
---|
117 | |
---|
118 | /** |
---|
119 | * HIGHLY EXPERIMENTAL |
---|
120 | * True to force css based border-box model override and turning off javascript based adjustments. This is a |
---|
121 | * runtime configuration and must be set before onReady. |
---|
122 | * @type Boolean |
---|
123 | */ |
---|
124 | enableForcedBoxModel : false, |
---|
125 | |
---|
126 | /** |
---|
127 | * True to automatically uncache orphaned Ext.Elements periodically (defaults to true) |
---|
128 | * @type Boolean |
---|
129 | */ |
---|
130 | enableGarbageCollector : true, |
---|
131 | |
---|
132 | /** |
---|
133 | * True to automatically purge event listeners during garbageCollection (defaults to false). |
---|
134 | * @type Boolean |
---|
135 | */ |
---|
136 | enableListenerCollection : false, |
---|
137 | |
---|
138 | /** |
---|
139 | * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed. |
---|
140 | * Currently not optimized for performance. |
---|
141 | * @type Boolean |
---|
142 | */ |
---|
143 | enableNestedListenerRemoval : false, |
---|
144 | |
---|
145 | /** |
---|
146 | * Indicates whether to use native browser parsing for JSON methods. |
---|
147 | * This option is ignored if the browser does not support native JSON methods. |
---|
148 | * <b>Note: Native JSON methods will not work with objects that have functions. |
---|
149 | * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false) |
---|
150 | * @type Boolean |
---|
151 | */ |
---|
152 | USE_NATIVE_JSON : false, |
---|
153 | |
---|
154 | /** |
---|
155 | * Copies all the properties of config to obj if they don't already exist. |
---|
156 | * @param {Object} obj The receiver of the properties |
---|
157 | * @param {Object} config The source of the properties |
---|
158 | * @return {Object} returns obj |
---|
159 | */ |
---|
160 | applyIf : function(o, c){ |
---|
161 | if(o){ |
---|
162 | for(var p in c){ |
---|
163 | if(!Ext.isDefined(o[p])){ |
---|
164 | o[p] = c[p]; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | return o; |
---|
169 | }, |
---|
170 | |
---|
171 | /** |
---|
172 | * Generates unique ids. If the element already has an id, it is unchanged |
---|
173 | * @param {Mixed} el (optional) The element to generate an id for |
---|
174 | * @param {String} prefix (optional) Id prefix (defaults "ext-gen") |
---|
175 | * @return {String} The generated Id. |
---|
176 | */ |
---|
177 | id : function(el, prefix){ |
---|
178 | el = Ext.getDom(el, true) || {}; |
---|
179 | if (!el.id) { |
---|
180 | el.id = (prefix || "ext-gen") + (++idSeed); |
---|
181 | } |
---|
182 | return el.id; |
---|
183 | }, |
---|
184 | |
---|
185 | /** |
---|
186 | * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method |
---|
187 | * also adds the function "override()" to the subclass that can be used to override members of the class.</p> |
---|
188 | * For example, to create a subclass of Ext GridPanel: |
---|
189 | * <pre><code> |
---|
190 | MyGridPanel = Ext.extend(Ext.grid.GridPanel, { |
---|
191 | constructor: function(config) { |
---|
192 | |
---|
193 | // Create configuration for this Grid. |
---|
194 | var store = new Ext.data.Store({...}); |
---|
195 | var colModel = new Ext.grid.ColumnModel({...}); |
---|
196 | |
---|
197 | // Create a new config object containing our computed properties |
---|
198 | // *plus* whatever was in the config parameter. |
---|
199 | config = Ext.apply({ |
---|
200 | store: store, |
---|
201 | colModel: colModel |
---|
202 | }, config); |
---|
203 | |
---|
204 | MyGridPanel.superclass.constructor.call(this, config); |
---|
205 | |
---|
206 | // Your postprocessing here |
---|
207 | }, |
---|
208 | |
---|
209 | yourMethod: function() { |
---|
210 | // etc. |
---|
211 | } |
---|
212 | }); |
---|
213 | </code></pre> |
---|
214 | * |
---|
215 | * <p>This function also supports a 3-argument call in which the subclass's constructor is |
---|
216 | * passed as an argument. In this form, the parameters are as follows:</p> |
---|
217 | * <div class="mdetail-params"><ul> |
---|
218 | * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li> |
---|
219 | * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li> |
---|
220 | * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's |
---|
221 | * prototype, and are therefore shared among all instances of the new class.</div></li> |
---|
222 | * </ul></div> |
---|
223 | * |
---|
224 | * @param {Function} superclass The constructor of class being extended. |
---|
225 | * @param {Object} overrides <p>A literal with members which are copied into the subclass's |
---|
226 | * prototype, and are therefore shared between all instances of the new class.</p> |
---|
227 | * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used |
---|
228 | * to define the constructor of the new class, and is returned. If this property is |
---|
229 | * <i>not</i> specified, a constructor is generated and returned which just calls the |
---|
230 | * superclass's constructor passing on its parameters.</p> |
---|
231 | * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p> |
---|
232 | * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided. |
---|
233 | */ |
---|
234 | extend : function(){ |
---|
235 | // inline overrides |
---|
236 | var io = function(o){ |
---|
237 | for(var m in o){ |
---|
238 | this[m] = o[m]; |
---|
239 | } |
---|
240 | }; |
---|
241 | var oc = Object.prototype.constructor; |
---|
242 | |
---|
243 | return function(sb, sp, overrides){ |
---|
244 | if(typeof sp == 'object'){ |
---|
245 | overrides = sp; |
---|
246 | sp = sb; |
---|
247 | sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);}; |
---|
248 | } |
---|
249 | var F = function(){}, |
---|
250 | sbp, |
---|
251 | spp = sp.prototype; |
---|
252 | |
---|
253 | F.prototype = spp; |
---|
254 | sbp = sb.prototype = new F(); |
---|
255 | sbp.constructor=sb; |
---|
256 | sb.superclass=spp; |
---|
257 | if(spp.constructor == oc){ |
---|
258 | spp.constructor=sp; |
---|
259 | } |
---|
260 | sb.override = function(o){ |
---|
261 | Ext.override(sb, o); |
---|
262 | }; |
---|
263 | sbp.superclass = sbp.supr = (function(){ |
---|
264 | return spp; |
---|
265 | }); |
---|
266 | sbp.override = io; |
---|
267 | Ext.override(sb, overrides); |
---|
268 | sb.extend = function(o){return Ext.extend(sb, o);}; |
---|
269 | return sb; |
---|
270 | }; |
---|
271 | }(), |
---|
272 | |
---|
273 | /** |
---|
274 | * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name. |
---|
275 | * Usage:<pre><code> |
---|
276 | Ext.override(MyClass, { |
---|
277 | newMethod1: function(){ |
---|
278 | // etc. |
---|
279 | }, |
---|
280 | newMethod2: function(foo){ |
---|
281 | // etc. |
---|
282 | } |
---|
283 | }); |
---|
284 | </code></pre> |
---|
285 | * @param {Object} origclass The class to override |
---|
286 | * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal |
---|
287 | * containing one or more methods. |
---|
288 | * @method override |
---|
289 | */ |
---|
290 | override : function(origclass, overrides){ |
---|
291 | if(overrides){ |
---|
292 | var p = origclass.prototype; |
---|
293 | Ext.apply(p, overrides); |
---|
294 | if(Ext.isIE && overrides.hasOwnProperty('toString')){ |
---|
295 | p.toString = overrides.toString; |
---|
296 | } |
---|
297 | } |
---|
298 | }, |
---|
299 | |
---|
300 | /** |
---|
301 | * Creates namespaces to be used for scoping variables and classes so that they are not global. |
---|
302 | * Specifying the last node of a namespace implicitly creates all other nodes. Usage: |
---|
303 | * <pre><code> |
---|
304 | Ext.namespace('Company', 'Company.data'); |
---|
305 | Ext.namespace('Company.data'); // equivalent and preferable to above syntax |
---|
306 | Company.Widget = function() { ... } |
---|
307 | Company.data.CustomStore = function(config) { ... } |
---|
308 | </code></pre> |
---|
309 | * @param {String} namespace1 |
---|
310 | * @param {String} namespace2 |
---|
311 | * @param {String} etc |
---|
312 | * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created) |
---|
313 | * @method namespace |
---|
314 | */ |
---|
315 | namespace : function(){ |
---|
316 | var len1 = arguments.length, |
---|
317 | i = 0, |
---|
318 | len2, |
---|
319 | j, |
---|
320 | main, |
---|
321 | ns, |
---|
322 | sub, |
---|
323 | current; |
---|
324 | |
---|
325 | for(; i < len1; ++i) { |
---|
326 | main = arguments[i]; |
---|
327 | ns = arguments[i].split('.'); |
---|
328 | current = window[ns[0]]; |
---|
329 | if (current === undefined) { |
---|
330 | current = window[ns[0]] = {}; |
---|
331 | } |
---|
332 | sub = ns.slice(1); |
---|
333 | len2 = sub.length; |
---|
334 | for(j = 0; j < len2; ++j) { |
---|
335 | current = current[sub[j]] = current[sub[j]] || {}; |
---|
336 | } |
---|
337 | } |
---|
338 | return current; |
---|
339 | }, |
---|
340 | |
---|
341 | /** |
---|
342 | * Takes an object and converts it to an encoded URL. e.g. Ext.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value. |
---|
343 | * @param {Object} o |
---|
344 | * @param {String} pre (optional) A prefix to add to the url encoded string |
---|
345 | * @return {String} |
---|
346 | */ |
---|
347 | urlEncode : function(o, pre){ |
---|
348 | var empty, |
---|
349 | buf = [], |
---|
350 | e = encodeURIComponent; |
---|
351 | |
---|
352 | Ext.iterate(o, function(key, item){ |
---|
353 | empty = Ext.isEmpty(item); |
---|
354 | Ext.each(empty ? key : item, function(val){ |
---|
355 | buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : ''); |
---|
356 | }); |
---|
357 | }); |
---|
358 | if(!pre){ |
---|
359 | buf.shift(); |
---|
360 | pre = ''; |
---|
361 | } |
---|
362 | return pre + buf.join(''); |
---|
363 | }, |
---|
364 | |
---|
365 | /** |
---|
366 | * Takes an encoded URL and and converts it to an object. Example: <pre><code> |
---|
367 | Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"} |
---|
368 | Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]} |
---|
369 | </code></pre> |
---|
370 | * @param {String} string |
---|
371 | * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false). |
---|
372 | * @return {Object} A literal with members |
---|
373 | */ |
---|
374 | urlDecode : function(string, overwrite){ |
---|
375 | if(Ext.isEmpty(string)){ |
---|
376 | return {}; |
---|
377 | } |
---|
378 | var obj = {}, |
---|
379 | pairs = string.split('&'), |
---|
380 | d = decodeURIComponent, |
---|
381 | name, |
---|
382 | value; |
---|
383 | Ext.each(pairs, function(pair) { |
---|
384 | pair = pair.split('='); |
---|
385 | name = d(pair[0]); |
---|
386 | value = d(pair[1]); |
---|
387 | obj[name] = overwrite || !obj[name] ? value : |
---|
388 | [].concat(obj[name]).concat(value); |
---|
389 | }); |
---|
390 | return obj; |
---|
391 | }, |
---|
392 | |
---|
393 | /** |
---|
394 | * Appends content to the query string of a URL, handling logic for whether to place |
---|
395 | * a question mark or ampersand. |
---|
396 | * @param {String} url The URL to append to. |
---|
397 | * @param {String} s The content to append to the URL. |
---|
398 | * @return (String) The resulting URL |
---|
399 | */ |
---|
400 | urlAppend : function(url, s){ |
---|
401 | if(!Ext.isEmpty(s)){ |
---|
402 | return url + (url.indexOf('?') === -1 ? '?' : '&') + s; |
---|
403 | } |
---|
404 | return url; |
---|
405 | }, |
---|
406 | |
---|
407 | /** |
---|
408 | * Converts any iterable (numeric indices and a length property) into a true array |
---|
409 | * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on. |
---|
410 | * For strings, use this instead: "abc".match(/./g) => [a,b,c]; |
---|
411 | * @param {Iterable} the iterable object to be turned into a true Array. |
---|
412 | * @return (Array) array |
---|
413 | */ |
---|
414 | toArray : function(){ |
---|
415 | return isIE ? |
---|
416 | function(a, i, j, res){ |
---|
417 | res = []; |
---|
418 | for(var x = 0, len = a.length; x < len; x++) { |
---|
419 | res.push(a[x]); |
---|
420 | } |
---|
421 | return res.slice(i || 0, j || res.length); |
---|
422 | } : |
---|
423 | function(a, i, j){ |
---|
424 | return Array.prototype.slice.call(a, i || 0, j || a.length); |
---|
425 | }; |
---|
426 | }(), |
---|
427 | |
---|
428 | isIterable : function(v){ |
---|
429 | //check for array or arguments |
---|
430 | if(Ext.isArray(v) || v.callee){ |
---|
431 | return true; |
---|
432 | } |
---|
433 | //check for node list type |
---|
434 | if(/NodeList|HTMLCollection/.test(toString.call(v))){ |
---|
435 | return true; |
---|
436 | } |
---|
437 | //NodeList has an item and length property |
---|
438 | //IXMLDOMNodeList has nextNode method, needs to be checked first. |
---|
439 | return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length)); |
---|
440 | }, |
---|
441 | |
---|
442 | /** |
---|
443 | * Iterates an array calling the supplied function. |
---|
444 | * @param {Array/NodeList/Mixed} array The array to be iterated. If this |
---|
445 | * argument is not really an array, the supplied function is called once. |
---|
446 | * @param {Function} fn The function to be called with each item. If the |
---|
447 | * supplied function returns false, iteration stops and this method returns |
---|
448 | * the current <code>index</code>. This function is called with |
---|
449 | * the following arguments: |
---|
450 | * <div class="mdetail-params"><ul> |
---|
451 | * <li><code>item</code> : <i>Mixed</i> |
---|
452 | * <div class="sub-desc">The item at the current <code>index</code> |
---|
453 | * in the passed <code>array</code></div></li> |
---|
454 | * <li><code>index</code> : <i>Number</i> |
---|
455 | * <div class="sub-desc">The current index within the array</div></li> |
---|
456 | * <li><code>allItems</code> : <i>Array</i> |
---|
457 | * <div class="sub-desc">The <code>array</code> passed as the first |
---|
458 | * argument to <code>Ext.each</code>.</div></li> |
---|
459 | * </ul></div> |
---|
460 | * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. |
---|
461 | * Defaults to the <code>item</code> at the current <code>index</code> |
---|
462 | * within the passed <code>array</code>. |
---|
463 | * @return See description for the fn parameter. |
---|
464 | */ |
---|
465 | each : function(array, fn, scope){ |
---|
466 | if(Ext.isEmpty(array, true)){ |
---|
467 | return; |
---|
468 | } |
---|
469 | if(!Ext.isIterable(array) || Ext.isPrimitive(array)){ |
---|
470 | array = [array]; |
---|
471 | } |
---|
472 | for(var i = 0, len = array.length; i < len; i++){ |
---|
473 | if(fn.call(scope || array[i], array[i], i, array) === false){ |
---|
474 | return i; |
---|
475 | }; |
---|
476 | } |
---|
477 | }, |
---|
478 | |
---|
479 | /** |
---|
480 | * Iterates either the elements in an array, or each of the properties in an object. |
---|
481 | * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}. |
---|
482 | * @param {Object/Array} object The object or array to be iterated |
---|
483 | * @param {Function} fn The function to be called for each iteration. |
---|
484 | * The iteration will stop if the supplied function returns false, or |
---|
485 | * all array elements / object properties have been covered. The signature |
---|
486 | * varies depending on the type of object being interated: |
---|
487 | * <div class="mdetail-params"><ul> |
---|
488 | * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt> |
---|
489 | * <div class="sub-desc"> |
---|
490 | * When iterating an array, the supplied function is called with each item.</div></li> |
---|
491 | * <li>Objects : <tt>(String key, Object value, Object)</tt> |
---|
492 | * <div class="sub-desc"> |
---|
493 | * When iterating an object, the supplied function is called with each key-value pair in |
---|
494 | * the object, and the iterated object</div></li> |
---|
495 | * </ul></div> |
---|
496 | * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to |
---|
497 | * the <code>object</code> being iterated. |
---|
498 | */ |
---|
499 | iterate : function(obj, fn, scope){ |
---|
500 | if(Ext.isEmpty(obj)){ |
---|
501 | return; |
---|
502 | } |
---|
503 | if(Ext.isIterable(obj)){ |
---|
504 | Ext.each(obj, fn, scope); |
---|
505 | return; |
---|
506 | }else if(typeof obj == 'object'){ |
---|
507 | for(var prop in obj){ |
---|
508 | if(obj.hasOwnProperty(prop)){ |
---|
509 | if(fn.call(scope || obj, prop, obj[prop], obj) === false){ |
---|
510 | return; |
---|
511 | }; |
---|
512 | } |
---|
513 | } |
---|
514 | } |
---|
515 | }, |
---|
516 | |
---|
517 | /** |
---|
518 | * Return the dom node for the passed String (id), dom node, or Ext.Element. |
---|
519 | * Optional 'strict' flag is needed for IE since it can return 'name' and |
---|
520 | * 'id' elements by using getElementById. |
---|
521 | * Here are some examples: |
---|
522 | * <pre><code> |
---|
523 | // gets dom node based on id |
---|
524 | var elDom = Ext.getDom('elId'); |
---|
525 | // gets dom node based on the dom node |
---|
526 | var elDom1 = Ext.getDom(elDom); |
---|
527 | |
---|
528 | // If we don't know if we are working with an |
---|
529 | // Ext.Element or a dom node use Ext.getDom |
---|
530 | function(el){ |
---|
531 | var dom = Ext.getDom(el); |
---|
532 | // do something with the dom node |
---|
533 | } |
---|
534 | * </code></pre> |
---|
535 | * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc) |
---|
536 | * when this method is called to be successful. |
---|
537 | * @param {Mixed} el |
---|
538 | * @return HTMLElement |
---|
539 | */ |
---|
540 | getDom : function(el, strict){ |
---|
541 | if(!el || !DOC){ |
---|
542 | return null; |
---|
543 | } |
---|
544 | if (el.dom){ |
---|
545 | return el.dom; |
---|
546 | } else { |
---|
547 | if (typeof el == 'string') { |
---|
548 | var e = DOC.getElementById(el); |
---|
549 | // IE returns elements with the 'name' and 'id' attribute. |
---|
550 | // we do a strict check to return the element with only the id attribute |
---|
551 | if (e && isIE && strict) { |
---|
552 | if (el == e.getAttribute('id')) { |
---|
553 | return e; |
---|
554 | } else { |
---|
555 | return null; |
---|
556 | } |
---|
557 | } |
---|
558 | return e; |
---|
559 | } else { |
---|
560 | return el; |
---|
561 | } |
---|
562 | } |
---|
563 | }, |
---|
564 | |
---|
565 | /** |
---|
566 | * Returns the current document body as an {@link Ext.Element}. |
---|
567 | * @return Ext.Element The document body |
---|
568 | */ |
---|
569 | getBody : function(){ |
---|
570 | return Ext.get(DOC.body || DOC.documentElement); |
---|
571 | }, |
---|
572 | |
---|
573 | /** |
---|
574 | * Returns the current document body as an {@link Ext.Element}. |
---|
575 | * @return Ext.Element The document body |
---|
576 | */ |
---|
577 | getHead : function() { |
---|
578 | var head; |
---|
579 | |
---|
580 | return function() { |
---|
581 | if (head == undefined) { |
---|
582 | head = Ext.get(DOC.getElementsByTagName("head")[0]); |
---|
583 | } |
---|
584 | |
---|
585 | return head; |
---|
586 | }; |
---|
587 | }(), |
---|
588 | |
---|
589 | /** |
---|
590 | * Removes a DOM node from the document. |
---|
591 | */ |
---|
592 | /** |
---|
593 | * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference. |
---|
594 | * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is |
---|
595 | * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node |
---|
596 | * will be ignored if passed in.</p> |
---|
597 | * @param {HTMLElement} node The node to remove |
---|
598 | */ |
---|
599 | removeNode : isIE && !isIE8 ? function(){ |
---|
600 | var d; |
---|
601 | return function(n){ |
---|
602 | if(n && n.tagName != 'BODY'){ |
---|
603 | (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n); |
---|
604 | d = d || DOC.createElement('div'); |
---|
605 | d.appendChild(n); |
---|
606 | d.innerHTML = ''; |
---|
607 | delete Ext.elCache[n.id]; |
---|
608 | } |
---|
609 | }; |
---|
610 | }() : function(n){ |
---|
611 | if(n && n.parentNode && n.tagName != 'BODY'){ |
---|
612 | (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n); |
---|
613 | n.parentNode.removeChild(n); |
---|
614 | delete Ext.elCache[n.id]; |
---|
615 | } |
---|
616 | }, |
---|
617 | |
---|
618 | /** |
---|
619 | * <p>Returns true if the passed value is empty.</p> |
---|
620 | * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul> |
---|
621 | * <li>null</li> |
---|
622 | * <li>undefined</li> |
---|
623 | * <li>an empty array</li> |
---|
624 | * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li> |
---|
625 | * </ul></div> |
---|
626 | * @param {Mixed} value The value to test |
---|
627 | * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false) |
---|
628 | * @return {Boolean} |
---|
629 | */ |
---|
630 | isEmpty : function(v, allowBlank){ |
---|
631 | return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false); |
---|
632 | }, |
---|
633 | |
---|
634 | /** |
---|
635 | * Returns true if the passed value is a JavaScript array, otherwise false. |
---|
636 | * @param {Mixed} value The value to test |
---|
637 | * @return {Boolean} |
---|
638 | */ |
---|
639 | isArray : function(v){ |
---|
640 | return toString.apply(v) === '[object Array]'; |
---|
641 | }, |
---|
642 | |
---|
643 | /** |
---|
644 | * Returns true if the passed object is a JavaScript date object, otherwise false. |
---|
645 | * @param {Object} object The object to test |
---|
646 | * @return {Boolean} |
---|
647 | */ |
---|
648 | isDate : function(v){ |
---|
649 | return toString.apply(v) === '[object Date]'; |
---|
650 | }, |
---|
651 | |
---|
652 | /** |
---|
653 | * Returns true if the passed value is a JavaScript Object, otherwise false. |
---|
654 | * @param {Mixed} value The value to test |
---|
655 | * @return {Boolean} |
---|
656 | */ |
---|
657 | isObject : function(v){ |
---|
658 | return !!v && Object.prototype.toString.call(v) === '[object Object]'; |
---|
659 | }, |
---|
660 | |
---|
661 | /** |
---|
662 | * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean. |
---|
663 | * @param {Mixed} value The value to test |
---|
664 | * @return {Boolean} |
---|
665 | */ |
---|
666 | isPrimitive : function(v){ |
---|
667 | return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v); |
---|
668 | }, |
---|
669 | |
---|
670 | /** |
---|
671 | * Returns true if the passed value is a JavaScript Function, otherwise false. |
---|
672 | * @param {Mixed} value The value to test |
---|
673 | * @return {Boolean} |
---|
674 | */ |
---|
675 | isFunction : function(v){ |
---|
676 | return toString.apply(v) === '[object Function]'; |
---|
677 | }, |
---|
678 | |
---|
679 | /** |
---|
680 | * Returns true if the passed value is a number. Returns false for non-finite numbers. |
---|
681 | * @param {Mixed} value The value to test |
---|
682 | * @return {Boolean} |
---|
683 | */ |
---|
684 | isNumber : function(v){ |
---|
685 | return typeof v === 'number' && isFinite(v); |
---|
686 | }, |
---|
687 | |
---|
688 | /** |
---|
689 | * Returns true if the passed value is a string. |
---|
690 | * @param {Mixed} value The value to test |
---|
691 | * @return {Boolean} |
---|
692 | */ |
---|
693 | isString : function(v){ |
---|
694 | return typeof v === 'string'; |
---|
695 | }, |
---|
696 | |
---|
697 | /** |
---|
698 | * Returns true if the passed value is a boolean. |
---|
699 | * @param {Mixed} value The value to test |
---|
700 | * @return {Boolean} |
---|
701 | */ |
---|
702 | isBoolean : function(v){ |
---|
703 | return typeof v === 'boolean'; |
---|
704 | }, |
---|
705 | |
---|
706 | /** |
---|
707 | * Returns true if the passed value is an HTMLElement |
---|
708 | * @param {Mixed} value The value to test |
---|
709 | * @return {Boolean} |
---|
710 | */ |
---|
711 | isElement : function(v) { |
---|
712 | return v ? !!v.tagName : false; |
---|
713 | }, |
---|
714 | |
---|
715 | /** |
---|
716 | * Returns true if the passed value is not undefined. |
---|
717 | * @param {Mixed} value The value to test |
---|
718 | * @return {Boolean} |
---|
719 | */ |
---|
720 | isDefined : function(v){ |
---|
721 | return typeof v !== 'undefined'; |
---|
722 | }, |
---|
723 | |
---|
724 | /** |
---|
725 | * True if the detected browser is Opera. |
---|
726 | * @type Boolean |
---|
727 | */ |
---|
728 | isOpera : isOpera, |
---|
729 | /** |
---|
730 | * True if the detected browser uses WebKit. |
---|
731 | * @type Boolean |
---|
732 | */ |
---|
733 | isWebKit : isWebKit, |
---|
734 | /** |
---|
735 | * True if the detected browser is Chrome. |
---|
736 | * @type Boolean |
---|
737 | */ |
---|
738 | isChrome : isChrome, |
---|
739 | /** |
---|
740 | * True if the detected browser is Safari. |
---|
741 | * @type Boolean |
---|
742 | */ |
---|
743 | isSafari : isSafari, |
---|
744 | /** |
---|
745 | * True if the detected browser is Safari 3.x. |
---|
746 | * @type Boolean |
---|
747 | */ |
---|
748 | isSafari3 : isSafari3, |
---|
749 | /** |
---|
750 | * True if the detected browser is Safari 4.x. |
---|
751 | * @type Boolean |
---|
752 | */ |
---|
753 | isSafari4 : isSafari4, |
---|
754 | /** |
---|
755 | * True if the detected browser is Safari 2.x. |
---|
756 | * @type Boolean |
---|
757 | */ |
---|
758 | isSafari2 : isSafari2, |
---|
759 | /** |
---|
760 | * True if the detected browser is Internet Explorer. |
---|
761 | * @type Boolean |
---|
762 | */ |
---|
763 | isIE : isIE, |
---|
764 | /** |
---|
765 | * True if the detected browser is Internet Explorer 6.x. |
---|
766 | * @type Boolean |
---|
767 | */ |
---|
768 | isIE6 : isIE6, |
---|
769 | /** |
---|
770 | * True if the detected browser is Internet Explorer 7.x. |
---|
771 | * @type Boolean |
---|
772 | */ |
---|
773 | isIE7 : isIE7, |
---|
774 | /** |
---|
775 | * True if the detected browser is Internet Explorer 8.x. |
---|
776 | * @type Boolean |
---|
777 | */ |
---|
778 | isIE8 : isIE8, |
---|
779 | /** |
---|
780 | * True if the detected browser is Internet Explorer 9.x. |
---|
781 | * @type Boolean |
---|
782 | */ |
---|
783 | isIE9 : isIE9, |
---|
784 | /** |
---|
785 | * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox). |
---|
786 | * @type Boolean |
---|
787 | */ |
---|
788 | isGecko : isGecko, |
---|
789 | /** |
---|
790 | * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x). |
---|
791 | * @type Boolean |
---|
792 | */ |
---|
793 | isGecko2 : isGecko2, |
---|
794 | /** |
---|
795 | * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x). |
---|
796 | * @type Boolean |
---|
797 | */ |
---|
798 | isGecko3 : isGecko3, |
---|
799 | /** |
---|
800 | * True if the detected browser is Internet Explorer running in non-strict mode. |
---|
801 | * @type Boolean |
---|
802 | */ |
---|
803 | isBorderBox : isBorderBox, |
---|
804 | /** |
---|
805 | * True if the detected platform is Linux. |
---|
806 | * @type Boolean |
---|
807 | */ |
---|
808 | isLinux : isLinux, |
---|
809 | /** |
---|
810 | * True if the detected platform is Windows. |
---|
811 | * @type Boolean |
---|
812 | */ |
---|
813 | isWindows : isWindows, |
---|
814 | /** |
---|
815 | * True if the detected platform is Mac OS. |
---|
816 | * @type Boolean |
---|
817 | */ |
---|
818 | isMac : isMac, |
---|
819 | /** |
---|
820 | * True if the detected platform is Adobe Air. |
---|
821 | * @type Boolean |
---|
822 | */ |
---|
823 | isAir : isAir |
---|
824 | }); |
---|
825 | |
---|
826 | /** |
---|
827 | * Creates namespaces to be used for scoping variables and classes so that they are not global. |
---|
828 | * Specifying the last node of a namespace implicitly creates all other nodes. Usage: |
---|
829 | * <pre><code> |
---|
830 | Ext.namespace('Company', 'Company.data'); |
---|
831 | Ext.namespace('Company.data'); // equivalent and preferable to above syntax |
---|
832 | Company.Widget = function() { ... } |
---|
833 | Company.data.CustomStore = function(config) { ... } |
---|
834 | </code></pre> |
---|
835 | * @param {String} namespace1 |
---|
836 | * @param {String} namespace2 |
---|
837 | * @param {String} etc |
---|
838 | * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created) |
---|
839 | * @method ns |
---|
840 | */ |
---|
841 | Ext.ns = Ext.namespace; |
---|
842 | })(); |
---|
843 | |
---|
844 | Ext.ns('Ext.util', 'Ext.lib', 'Ext.data', 'Ext.supports'); |
---|
845 | |
---|
846 | Ext.elCache = {}; |
---|
847 | |
---|
848 | /** |
---|
849 | * @class Function |
---|
850 | * These functions are available on every Function object (any JavaScript function). |
---|
851 | */ |
---|
852 | Ext.apply(Function.prototype, { |
---|
853 | /** |
---|
854 | * Creates an interceptor function. The passed function is called before the original one. If it returns false, |
---|
855 | * the original one is not called. The resulting function returns the results of the original function. |
---|
856 | * The passed function is called with the parameters of the original function. Example usage: |
---|
857 | * <pre><code> |
---|
858 | var sayHi = function(name){ |
---|
859 | alert('Hi, ' + name); |
---|
860 | } |
---|
861 | |
---|
862 | sayHi('Fred'); // alerts "Hi, Fred" |
---|
863 | |
---|
864 | // create a new function that validates input without |
---|
865 | // directly modifying the original function: |
---|
866 | var sayHiToFriend = sayHi.createInterceptor(function(name){ |
---|
867 | return name == 'Brian'; |
---|
868 | }); |
---|
869 | |
---|
870 | sayHiToFriend('Fred'); // no alert |
---|
871 | sayHiToFriend('Brian'); // alerts "Hi, Brian" |
---|
872 | </code></pre> |
---|
873 | * @param {Function} fcn The function to call before the original |
---|
874 | * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed. |
---|
875 | * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b> |
---|
876 | * @return {Function} The new function |
---|
877 | */ |
---|
878 | createInterceptor : function(fcn, scope){ |
---|
879 | var method = this; |
---|
880 | return !Ext.isFunction(fcn) ? |
---|
881 | this : |
---|
882 | function() { |
---|
883 | var me = this, |
---|
884 | args = arguments; |
---|
885 | fcn.target = me; |
---|
886 | fcn.method = method; |
---|
887 | return (fcn.apply(scope || me || window, args) !== false) ? |
---|
888 | method.apply(me || window, args) : |
---|
889 | null; |
---|
890 | }; |
---|
891 | }, |
---|
892 | |
---|
893 | /** |
---|
894 | * Creates a callback that passes arguments[0], arguments[1], arguments[2], ... |
---|
895 | * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code> |
---|
896 | * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the |
---|
897 | * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always |
---|
898 | * executes in the window scope. |
---|
899 | * <p>This method is required when you want to pass arguments to a callback function. If no arguments |
---|
900 | * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn). |
---|
901 | * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function |
---|
902 | * would simply execute immediately when the code is parsed. Example usage: |
---|
903 | * <pre><code> |
---|
904 | var sayHi = function(name){ |
---|
905 | alert('Hi, ' + name); |
---|
906 | } |
---|
907 | |
---|
908 | // clicking the button alerts "Hi, Fred" |
---|
909 | new Ext.Button({ |
---|
910 | text: 'Say Hi', |
---|
911 | renderTo: Ext.getBody(), |
---|
912 | handler: sayHi.createCallback('Fred') |
---|
913 | }); |
---|
914 | </code></pre> |
---|
915 | * @return {Function} The new function |
---|
916 | */ |
---|
917 | createCallback : function(/*args...*/){ |
---|
918 | // make args available, in function below |
---|
919 | var args = arguments, |
---|
920 | method = this; |
---|
921 | return function() { |
---|
922 | return method.apply(window, args); |
---|
923 | }; |
---|
924 | }, |
---|
925 | |
---|
926 | /** |
---|
927 | * Creates a delegate (callback) that sets the scope to obj. |
---|
928 | * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code> |
---|
929 | * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the |
---|
930 | * callback points to obj. Example usage: |
---|
931 | * <pre><code> |
---|
932 | var sayHi = function(name){ |
---|
933 | // Note this use of "this.text" here. This function expects to |
---|
934 | // execute within a scope that contains a text property. In this |
---|
935 | // example, the "this" variable is pointing to the btn object that |
---|
936 | // was passed in createDelegate below. |
---|
937 | alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.'); |
---|
938 | } |
---|
939 | |
---|
940 | var btn = new Ext.Button({ |
---|
941 | text: 'Say Hi', |
---|
942 | renderTo: Ext.getBody() |
---|
943 | }); |
---|
944 | |
---|
945 | // This callback will execute in the scope of the |
---|
946 | // button instance. Clicking the button alerts |
---|
947 | // "Hi, Fred. You clicked the "Say Hi" button." |
---|
948 | btn.on('click', sayHi.createDelegate(btn, ['Fred'])); |
---|
949 | </code></pre> |
---|
950 | * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed. |
---|
951 | * <b>If omitted, defaults to the browser window.</b> |
---|
952 | * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) |
---|
953 | * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding, |
---|
954 | * if a number the args are inserted at the specified position |
---|
955 | * @return {Function} The new function |
---|
956 | */ |
---|
957 | createDelegate : function(obj, args, appendArgs){ |
---|
958 | var method = this; |
---|
959 | return function() { |
---|
960 | var callArgs = args || arguments; |
---|
961 | if (appendArgs === true){ |
---|
962 | callArgs = Array.prototype.slice.call(arguments, 0); |
---|
963 | callArgs = callArgs.concat(args); |
---|
964 | }else if (Ext.isNumber(appendArgs)){ |
---|
965 | callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first |
---|
966 | var applyArgs = [appendArgs, 0].concat(args); // create method call params |
---|
967 | Array.prototype.splice.apply(callArgs, applyArgs); // splice them in |
---|
968 | } |
---|
969 | return method.apply(obj || window, callArgs); |
---|
970 | }; |
---|
971 | }, |
---|
972 | |
---|
973 | /** |
---|
974 | * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage: |
---|
975 | * <pre><code> |
---|
976 | var sayHi = function(name){ |
---|
977 | alert('Hi, ' + name); |
---|
978 | } |
---|
979 | |
---|
980 | // executes immediately: |
---|
981 | sayHi('Fred'); |
---|
982 | |
---|
983 | // executes after 2 seconds: |
---|
984 | sayHi.defer(2000, this, ['Fred']); |
---|
985 | |
---|
986 | // this syntax is sometimes useful for deferring |
---|
987 | // execution of an anonymous function: |
---|
988 | (function(){ |
---|
989 | alert('Anonymous'); |
---|
990 | }).defer(100); |
---|
991 | </code></pre> |
---|
992 | * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately) |
---|
993 | * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed. |
---|
994 | * <b>If omitted, defaults to the browser window.</b> |
---|
995 | * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) |
---|
996 | * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding, |
---|
997 | * if a number the args are inserted at the specified position |
---|
998 | * @return {Number} The timeout id that can be used with clearTimeout |
---|
999 | */ |
---|
1000 | defer : function(millis, obj, args, appendArgs){ |
---|
1001 | var fn = this.createDelegate(obj, args, appendArgs); |
---|
1002 | if(millis > 0){ |
---|
1003 | return setTimeout(fn, millis); |
---|
1004 | } |
---|
1005 | fn(); |
---|
1006 | return 0; |
---|
1007 | } |
---|
1008 | }); |
---|
1009 | |
---|
1010 | /** |
---|
1011 | * @class String |
---|
1012 | * These functions are available on every String object. |
---|
1013 | */ |
---|
1014 | Ext.applyIf(String, { |
---|
1015 | /** |
---|
1016 | * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each |
---|
1017 | * token must be unique, and must increment in the format {0}, {1}, etc. Example usage: |
---|
1018 | * <pre><code> |
---|
1019 | var cls = 'my-class', text = 'Some text'; |
---|
1020 | var s = String.format('<div class="{0}">{1}</div>', cls, text); |
---|
1021 | // s now contains the string: '<div class="my-class">Some text</div>' |
---|
1022 | * </code></pre> |
---|
1023 | * @param {String} string The tokenized string to be formatted |
---|
1024 | * @param {String} value1 The value to replace token {0} |
---|
1025 | * @param {String} value2 Etc... |
---|
1026 | * @return {String} The formatted string |
---|
1027 | * @static |
---|
1028 | */ |
---|
1029 | format : function(format){ |
---|
1030 | var args = Ext.toArray(arguments, 1); |
---|
1031 | return format.replace(/\{(\d+)\}/g, function(m, i){ |
---|
1032 | return args[i]; |
---|
1033 | }); |
---|
1034 | } |
---|
1035 | }); |
---|
1036 | |
---|
1037 | /** |
---|
1038 | * @class Array |
---|
1039 | */ |
---|
1040 | Ext.applyIf(Array.prototype, { |
---|
1041 | /** |
---|
1042 | * Checks whether or not the specified object exists in the array. |
---|
1043 | * @param {Object} o The object to check for |
---|
1044 | * @param {Number} from (Optional) The index at which to begin the search |
---|
1045 | * @return {Number} The index of o in the array (or -1 if it is not found) |
---|
1046 | */ |
---|
1047 | indexOf : function(o, from){ |
---|
1048 | var len = this.length; |
---|
1049 | from = from || 0; |
---|
1050 | from += (from < 0) ? len : 0; |
---|
1051 | for (; from < len; ++from){ |
---|
1052 | if(this[from] === o){ |
---|
1053 | return from; |
---|
1054 | } |
---|
1055 | } |
---|
1056 | return -1; |
---|
1057 | }, |
---|
1058 | |
---|
1059 | /** |
---|
1060 | * Removes the specified object from the array. If the object is not found nothing happens. |
---|
1061 | * @param {Object} o The object to remove |
---|
1062 | * @return {Array} this array |
---|
1063 | */ |
---|
1064 | remove : function(o){ |
---|
1065 | var index = this.indexOf(o); |
---|
1066 | if(index != -1){ |
---|
1067 | this.splice(index, 1); |
---|
1068 | } |
---|
1069 | return this; |
---|
1070 | } |
---|
1071 | }); |
---|
1072 | /** |
---|
1073 | * @class Ext.util.TaskRunner |
---|
1074 | * Provides the ability to execute one or more arbitrary tasks in a multithreaded |
---|
1075 | * manner. Generally, you can use the singleton {@link Ext.TaskMgr} instead, but |
---|
1076 | * if needed, you can create separate instances of TaskRunner. Any number of |
---|
1077 | * separate tasks can be started at any time and will run independently of each |
---|
1078 | * other. Example usage: |
---|
1079 | * <pre><code> |
---|
1080 | // Start a simple clock task that updates a div once per second |
---|
1081 | var updateClock = function(){ |
---|
1082 | Ext.fly('clock').update(new Date().format('g:i:s A')); |
---|
1083 | } |
---|
1084 | var task = { |
---|
1085 | run: updateClock, |
---|
1086 | interval: 1000 //1 second |
---|
1087 | } |
---|
1088 | var runner = new Ext.util.TaskRunner(); |
---|
1089 | runner.start(task); |
---|
1090 | |
---|
1091 | // equivalent using TaskMgr |
---|
1092 | Ext.TaskMgr.start({ |
---|
1093 | run: updateClock, |
---|
1094 | interval: 1000 |
---|
1095 | }); |
---|
1096 | |
---|
1097 | * </code></pre> |
---|
1098 | * <p>See the {@link #start} method for details about how to configure a task object.</p> |
---|
1099 | * Also see {@link Ext.util.DelayedTask}. |
---|
1100 | * |
---|
1101 | * @constructor |
---|
1102 | * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance |
---|
1103 | * (defaults to 10) |
---|
1104 | */ |
---|
1105 | Ext.util.TaskRunner = function(interval){ |
---|
1106 | interval = interval || 10; |
---|
1107 | var tasks = [], |
---|
1108 | removeQueue = [], |
---|
1109 | id = 0, |
---|
1110 | running = false, |
---|
1111 | |
---|
1112 | // private |
---|
1113 | stopThread = function(){ |
---|
1114 | running = false; |
---|
1115 | clearInterval(id); |
---|
1116 | id = 0; |
---|
1117 | }, |
---|
1118 | |
---|
1119 | // private |
---|
1120 | startThread = function(){ |
---|
1121 | if(!running){ |
---|
1122 | running = true; |
---|
1123 | id = setInterval(runTasks, interval); |
---|
1124 | } |
---|
1125 | }, |
---|
1126 | |
---|
1127 | // private |
---|
1128 | removeTask = function(t){ |
---|
1129 | removeQueue.push(t); |
---|
1130 | if(t.onStop){ |
---|
1131 | t.onStop.apply(t.scope || t); |
---|
1132 | } |
---|
1133 | }, |
---|
1134 | |
---|
1135 | // private |
---|
1136 | runTasks = function(){ |
---|
1137 | var rqLen = removeQueue.length, |
---|
1138 | now = new Date().getTime(); |
---|
1139 | |
---|
1140 | if(rqLen > 0){ |
---|
1141 | for(var i = 0; i < rqLen; i++){ |
---|
1142 | tasks.remove(removeQueue[i]); |
---|
1143 | } |
---|
1144 | removeQueue = []; |
---|
1145 | if(tasks.length < 1){ |
---|
1146 | stopThread(); |
---|
1147 | return; |
---|
1148 | } |
---|
1149 | } |
---|
1150 | for(var i = 0, t, itime, rt, len = tasks.length; i < len; ++i){ |
---|
1151 | t = tasks[i]; |
---|
1152 | itime = now - t.taskRunTime; |
---|
1153 | if(t.interval <= itime){ |
---|
1154 | rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]); |
---|
1155 | t.taskRunTime = now; |
---|
1156 | if(rt === false || t.taskRunCount === t.repeat){ |
---|
1157 | removeTask(t); |
---|
1158 | return; |
---|
1159 | } |
---|
1160 | } |
---|
1161 | if(t.duration && t.duration <= (now - t.taskStartTime)){ |
---|
1162 | removeTask(t); |
---|
1163 | } |
---|
1164 | } |
---|
1165 | }; |
---|
1166 | |
---|
1167 | /** |
---|
1168 | * Starts a new task. |
---|
1169 | * @method start |
---|
1170 | * @param {Object} task <p>A config object that supports the following properties:<ul> |
---|
1171 | * <li><code>run</code> : Function<div class="sub-desc"><p>The function to execute each time the task is invoked. The |
---|
1172 | * function will be called at each interval and passed the <code>args</code> argument if specified, and the |
---|
1173 | * current invocation count if not.</p> |
---|
1174 | * <p>If a particular scope (<code>this</code> reference) is required, be sure to specify it using the <code>scope</code> argument.</p> |
---|
1175 | * <p>Return <code>false</code> from this function to terminate the task.</p></div></li> |
---|
1176 | * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task |
---|
1177 | * should be invoked.</div></li> |
---|
1178 | * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function |
---|
1179 | * specified by <code>run</code>. If not specified, the current invocation count is passed.</div></li> |
---|
1180 | * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the |
---|
1181 | * <code>run</code> function. Defaults to the task config object.</div></li> |
---|
1182 | * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to invoke |
---|
1183 | * the task before stopping automatically (defaults to indefinite).</div></li> |
---|
1184 | * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to invoke the task before |
---|
1185 | * stopping automatically (defaults to indefinite).</div></li> |
---|
1186 | * </ul></p> |
---|
1187 | * <p>Before each invocation, Ext injects the property <code>taskRunCount</code> into the task object so |
---|
1188 | * that calculations based on the repeat count can be performed.</p> |
---|
1189 | * @return {Object} The task |
---|
1190 | */ |
---|
1191 | this.start = function(task){ |
---|
1192 | tasks.push(task); |
---|
1193 | task.taskStartTime = new Date().getTime(); |
---|
1194 | task.taskRunTime = 0; |
---|
1195 | task.taskRunCount = 0; |
---|
1196 | startThread(); |
---|
1197 | return task; |
---|
1198 | }; |
---|
1199 | |
---|
1200 | /** |
---|
1201 | * Stops an existing running task. |
---|
1202 | * @method stop |
---|
1203 | * @param {Object} task The task to stop |
---|
1204 | * @return {Object} The task |
---|
1205 | */ |
---|
1206 | this.stop = function(task){ |
---|
1207 | removeTask(task); |
---|
1208 | return task; |
---|
1209 | }; |
---|
1210 | |
---|
1211 | /** |
---|
1212 | * Stops all tasks that are currently running. |
---|
1213 | * @method stopAll |
---|
1214 | */ |
---|
1215 | this.stopAll = function(){ |
---|
1216 | stopThread(); |
---|
1217 | for(var i = 0, len = tasks.length; i < len; i++){ |
---|
1218 | if(tasks[i].onStop){ |
---|
1219 | tasks[i].onStop(); |
---|
1220 | } |
---|
1221 | } |
---|
1222 | tasks = []; |
---|
1223 | removeQueue = []; |
---|
1224 | }; |
---|
1225 | }; |
---|
1226 | |
---|
1227 | /** |
---|
1228 | * @class Ext.TaskMgr |
---|
1229 | * @extends Ext.util.TaskRunner |
---|
1230 | * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See |
---|
1231 | * {@link Ext.util.TaskRunner} for supported methods and task config properties. |
---|
1232 | * <pre><code> |
---|
1233 | // Start a simple clock task that updates a div once per second |
---|
1234 | var task = { |
---|
1235 | run: function(){ |
---|
1236 | Ext.fly('clock').update(new Date().format('g:i:s A')); |
---|
1237 | }, |
---|
1238 | interval: 1000 //1 second |
---|
1239 | } |
---|
1240 | Ext.TaskMgr.start(task); |
---|
1241 | </code></pre> |
---|
1242 | * <p>See the {@link #start} method for details about how to configure a task object.</p> |
---|
1243 | * @singleton |
---|
1244 | */ |
---|
1245 | Ext.TaskMgr = new Ext.util.TaskRunner();if(typeof jQuery == "undefined"){ |
---|
1246 | throw "Unable to load Ext, jQuery not found."; |
---|
1247 | } |
---|
1248 | |
---|
1249 | (function(){ |
---|
1250 | var libFlyweight; |
---|
1251 | |
---|
1252 | Ext.lib.Dom = { |
---|
1253 | getViewWidth : function(full){ |
---|
1254 | // jQuery doesn't report full window size on document query, so max both |
---|
1255 | return full ? Math.max(jQuery(document).width(),jQuery(window).width()) : jQuery(window).width(); |
---|
1256 | }, |
---|
1257 | |
---|
1258 | getViewHeight : function(full){ |
---|
1259 | // jQuery doesn't report full window size on document query, so max both |
---|
1260 | return full ? Math.max(jQuery(document).height(),jQuery(window).height()) : jQuery(window).height(); |
---|
1261 | }, |
---|
1262 | |
---|
1263 | isAncestor : function(p, c){ |
---|
1264 | var ret = false; |
---|
1265 | |
---|
1266 | p = Ext.getDom(p); |
---|
1267 | c = Ext.getDom(c); |
---|
1268 | if (p && c) { |
---|
1269 | if (p.contains) { |
---|
1270 | return p.contains(c); |
---|
1271 | } else if (p.compareDocumentPosition) { |
---|
1272 | return !!(p.compareDocumentPosition(c) & 16); |
---|
1273 | } else { |
---|
1274 | while (c = c.parentNode) { |
---|
1275 | ret = c == p || ret; |
---|
1276 | } |
---|
1277 | } |
---|
1278 | } |
---|
1279 | return ret; |
---|
1280 | }, |
---|
1281 | |
---|
1282 | getRegion : function(el){ |
---|
1283 | return Ext.lib.Region.getRegion(el); |
---|
1284 | }, |
---|
1285 | |
---|
1286 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
1287 | // Use of jQuery.offset() removed to promote consistent behavior across libs. |
---|
1288 | // JVS 05/23/07 |
---|
1289 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
1290 | |
---|
1291 | getY : function(el){ |
---|
1292 | return this.getXY(el)[1]; |
---|
1293 | }, |
---|
1294 | |
---|
1295 | getX : function(el){ |
---|
1296 | return this.getXY(el)[0]; |
---|
1297 | }, |
---|
1298 | |
---|
1299 | getXY : function(el) { |
---|
1300 | var p, pe, b, scroll, bd = (document.body || document.documentElement); |
---|
1301 | el = Ext.getDom(el); |
---|
1302 | |
---|
1303 | if(el == bd){ |
---|
1304 | return [0, 0]; |
---|
1305 | } |
---|
1306 | |
---|
1307 | if (el.getBoundingClientRect) { |
---|
1308 | b = el.getBoundingClientRect(); |
---|
1309 | scroll = fly(document).getScroll(); |
---|
1310 | return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)]; |
---|
1311 | } |
---|
1312 | var x = 0, y = 0; |
---|
1313 | |
---|
1314 | p = el; |
---|
1315 | |
---|
1316 | var hasAbsolute = fly(el).getStyle("position") == "absolute"; |
---|
1317 | |
---|
1318 | while (p) { |
---|
1319 | |
---|
1320 | x += p.offsetLeft; |
---|
1321 | y += p.offsetTop; |
---|
1322 | |
---|
1323 | if (!hasAbsolute && fly(p).getStyle("position") == "absolute") { |
---|
1324 | hasAbsolute = true; |
---|
1325 | } |
---|
1326 | |
---|
1327 | if (Ext.isGecko) { |
---|
1328 | pe = fly(p); |
---|
1329 | |
---|
1330 | var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0; |
---|
1331 | var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0; |
---|
1332 | |
---|
1333 | |
---|
1334 | x += bl; |
---|
1335 | y += bt; |
---|
1336 | |
---|
1337 | |
---|
1338 | if (p != el && pe.getStyle('overflow') != 'visible') { |
---|
1339 | x += bl; |
---|
1340 | y += bt; |
---|
1341 | } |
---|
1342 | } |
---|
1343 | p = p.offsetParent; |
---|
1344 | } |
---|
1345 | |
---|
1346 | if (Ext.isSafari && hasAbsolute) { |
---|
1347 | x -= bd.offsetLeft; |
---|
1348 | y -= bd.offsetTop; |
---|
1349 | } |
---|
1350 | |
---|
1351 | if (Ext.isGecko && !hasAbsolute) { |
---|
1352 | var dbd = fly(bd); |
---|
1353 | x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0; |
---|
1354 | y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0; |
---|
1355 | } |
---|
1356 | |
---|
1357 | p = el.parentNode; |
---|
1358 | while (p && p != bd) { |
---|
1359 | if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) { |
---|
1360 | x -= p.scrollLeft; |
---|
1361 | y -= p.scrollTop; |
---|
1362 | } |
---|
1363 | p = p.parentNode; |
---|
1364 | } |
---|
1365 | return [x, y]; |
---|
1366 | }, |
---|
1367 | |
---|
1368 | setXY : function(el, xy){ |
---|
1369 | el = Ext.fly(el, '_setXY'); |
---|
1370 | el.position(); |
---|
1371 | var pts = el.translatePoints(xy); |
---|
1372 | if(xy[0] !== false){ |
---|
1373 | el.dom.style.left = pts.left + "px"; |
---|
1374 | } |
---|
1375 | if(xy[1] !== false){ |
---|
1376 | el.dom.style.top = pts.top + "px"; |
---|
1377 | } |
---|
1378 | }, |
---|
1379 | |
---|
1380 | setX : function(el, x){ |
---|
1381 | this.setXY(el, [x, false]); |
---|
1382 | }, |
---|
1383 | |
---|
1384 | setY : function(el, y){ |
---|
1385 | this.setXY(el, [false, y]); |
---|
1386 | } |
---|
1387 | }; |
---|
1388 | |
---|
1389 | // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights |
---|
1390 | function fly(el){ |
---|
1391 | if(!libFlyweight){ |
---|
1392 | libFlyweight = new Ext.Element.Flyweight(); |
---|
1393 | } |
---|
1394 | libFlyweight.dom = el; |
---|
1395 | return libFlyweight; |
---|
1396 | } |
---|
1397 | Ext.lib.Event = { |
---|
1398 | getPageX : function(e){ |
---|
1399 | e = e.browserEvent || e; |
---|
1400 | return e.pageX; |
---|
1401 | }, |
---|
1402 | |
---|
1403 | getPageY : function(e){ |
---|
1404 | e = e.browserEvent || e; |
---|
1405 | return e.pageY; |
---|
1406 | }, |
---|
1407 | |
---|
1408 | getXY : function(e){ |
---|
1409 | e = e.browserEvent || e; |
---|
1410 | return [e.pageX, e.pageY]; |
---|
1411 | }, |
---|
1412 | |
---|
1413 | getTarget : function(e){ |
---|
1414 | return e.target; |
---|
1415 | }, |
---|
1416 | |
---|
1417 | // all Ext events will go through event manager which provides scoping |
---|
1418 | on : function(el, eventName, fn, scope, override){ |
---|
1419 | jQuery(el).bind(eventName, fn); |
---|
1420 | }, |
---|
1421 | |
---|
1422 | un : function(el, eventName, fn){ |
---|
1423 | jQuery(el).unbind(eventName, fn); |
---|
1424 | }, |
---|
1425 | |
---|
1426 | purgeElement : function(el){ |
---|
1427 | jQuery(el).unbind(); |
---|
1428 | }, |
---|
1429 | |
---|
1430 | preventDefault : function(e){ |
---|
1431 | e = e.browserEvent || e; |
---|
1432 | if(e.preventDefault){ |
---|
1433 | e.preventDefault(); |
---|
1434 | }else{ |
---|
1435 | e.returnValue = false; |
---|
1436 | } |
---|
1437 | }, |
---|
1438 | |
---|
1439 | stopPropagation : function(e){ |
---|
1440 | e = e.browserEvent || e; |
---|
1441 | if(e.stopPropagation){ |
---|
1442 | e.stopPropagation(); |
---|
1443 | }else{ |
---|
1444 | e.cancelBubble = true; |
---|
1445 | } |
---|
1446 | }, |
---|
1447 | |
---|
1448 | stopEvent : function(e){ |
---|
1449 | this.preventDefault(e); |
---|
1450 | this.stopPropagation(e); |
---|
1451 | }, |
---|
1452 | |
---|
1453 | onAvailable : function(id, fn, scope){ |
---|
1454 | var start = new Date(); |
---|
1455 | var f = function(){ |
---|
1456 | if(start.getElapsed() > 10000){ |
---|
1457 | clearInterval(iid); |
---|
1458 | } |
---|
1459 | var el = document.getElementById(id); |
---|
1460 | if(el){ |
---|
1461 | clearInterval(iid); |
---|
1462 | fn.call(scope||window, el); |
---|
1463 | } |
---|
1464 | }; |
---|
1465 | var iid = setInterval(f, 50); |
---|
1466 | }, |
---|
1467 | |
---|
1468 | resolveTextNode: Ext.isGecko ? function(node){ |
---|
1469 | if(!node){ |
---|
1470 | return; |
---|
1471 | } |
---|
1472 | var s = HTMLElement.prototype.toString.call(node); |
---|
1473 | if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){ |
---|
1474 | return; |
---|
1475 | } |
---|
1476 | return node.nodeType == 3 ? node.parentNode : node; |
---|
1477 | } : function(node){ |
---|
1478 | return node && node.nodeType == 3 ? node.parentNode : node; |
---|
1479 | }, |
---|
1480 | |
---|
1481 | getRelatedTarget: function(ev) { |
---|
1482 | ev = ev.browserEvent || ev; |
---|
1483 | var t = ev.relatedTarget; |
---|
1484 | if (!t) { |
---|
1485 | if (ev.type == "mouseout") { |
---|
1486 | t = ev.toElement; |
---|
1487 | } else if (ev.type == "mouseover") { |
---|
1488 | t = ev.fromElement; |
---|
1489 | } |
---|
1490 | } |
---|
1491 | |
---|
1492 | return this.resolveTextNode(t); |
---|
1493 | } |
---|
1494 | }; |
---|
1495 | |
---|
1496 | Ext.lib.Ajax = function(){ |
---|
1497 | var createComplete = function(cb){ |
---|
1498 | return function(xhr, status){ |
---|
1499 | if((status == 'error' || status == 'timeout') && cb.failure){ |
---|
1500 | cb.failure.call(cb.scope||window, createResponse(cb, xhr)); |
---|
1501 | }else if(cb.success){ |
---|
1502 | cb.success.call(cb.scope||window, createResponse(cb, xhr)); |
---|
1503 | } |
---|
1504 | }; |
---|
1505 | }; |
---|
1506 | |
---|
1507 | var createResponse = function(cb, xhr){ |
---|
1508 | var headerObj = {}, |
---|
1509 | headerStr, |
---|
1510 | t, |
---|
1511 | s; |
---|
1512 | |
---|
1513 | try { |
---|
1514 | headerStr = xhr.getAllResponseHeaders(); |
---|
1515 | Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){ |
---|
1516 | t = v.indexOf(':'); |
---|
1517 | if(t >= 0){ |
---|
1518 | s = v.substr(0, t).toLowerCase(); |
---|
1519 | if(v.charAt(t + 1) == ' '){ |
---|
1520 | ++t; |
---|
1521 | } |
---|
1522 | headerObj[s] = v.substr(t + 1); |
---|
1523 | } |
---|
1524 | }); |
---|
1525 | } catch(e) {} |
---|
1526 | |
---|
1527 | return { |
---|
1528 | responseText: xhr.responseText, |
---|
1529 | responseXML : xhr.responseXML, |
---|
1530 | argument: cb.argument, |
---|
1531 | status: xhr.status, |
---|
1532 | statusText: xhr.statusText, |
---|
1533 | getResponseHeader : function(header){ |
---|
1534 | return headerObj[header.toLowerCase()]; |
---|
1535 | }, |
---|
1536 | getAllResponseHeaders : function(){ |
---|
1537 | return headerStr; |
---|
1538 | } |
---|
1539 | }; |
---|
1540 | }; |
---|
1541 | return { |
---|
1542 | request : function(method, uri, cb, data, options){ |
---|
1543 | var o = { |
---|
1544 | type: method, |
---|
1545 | url: uri, |
---|
1546 | data: data, |
---|
1547 | timeout: cb.timeout, |
---|
1548 | complete: createComplete(cb) |
---|
1549 | }; |
---|
1550 | |
---|
1551 | if(options){ |
---|
1552 | var hs = options.headers; |
---|
1553 | if(options.xmlData){ |
---|
1554 | o.data = options.xmlData; |
---|
1555 | o.processData = false; |
---|
1556 | o.type = (method ? method : (options.method ? options.method : 'POST')); |
---|
1557 | if (!hs || !hs['Content-Type']){ |
---|
1558 | o.contentType = 'text/xml'; |
---|
1559 | } |
---|
1560 | }else if(options.jsonData){ |
---|
1561 | o.data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData; |
---|
1562 | o.processData = false; |
---|
1563 | o.type = (method ? method : (options.method ? options.method : 'POST')); |
---|
1564 | if (!hs || !hs['Content-Type']){ |
---|
1565 | o.contentType = 'application/json'; |
---|
1566 | } |
---|
1567 | } |
---|
1568 | if(hs){ |
---|
1569 | o.beforeSend = function(xhr){ |
---|
1570 | for (var h in hs) { |
---|
1571 | if (hs.hasOwnProperty(h)) { |
---|
1572 | xhr.setRequestHeader(h, hs[h]); |
---|
1573 | } |
---|
1574 | } |
---|
1575 | }; |
---|
1576 | } |
---|
1577 | } |
---|
1578 | jQuery.ajax(o); |
---|
1579 | }, |
---|
1580 | |
---|
1581 | formRequest : function(form, uri, cb, data, isUpload, sslUri){ |
---|
1582 | jQuery.ajax({ |
---|
1583 | type: Ext.getDom(form).method ||'POST', |
---|
1584 | url: uri, |
---|
1585 | data: jQuery(form).serialize()+(data?'&'+data:''), |
---|
1586 | timeout: cb.timeout, |
---|
1587 | complete: createComplete(cb) |
---|
1588 | }); |
---|
1589 | }, |
---|
1590 | |
---|
1591 | isCallInProgress : function(trans){ |
---|
1592 | return false; |
---|
1593 | }, |
---|
1594 | |
---|
1595 | abort : function(trans){ |
---|
1596 | return false; |
---|
1597 | }, |
---|
1598 | |
---|
1599 | serializeForm : function(form){ |
---|
1600 | return jQuery(form.dom||form).serialize(); |
---|
1601 | } |
---|
1602 | }; |
---|
1603 | }(); |
---|
1604 | |
---|
1605 | Ext.lib.Anim = function(){ |
---|
1606 | var createAnim = function(cb, scope){ |
---|
1607 | var animated = true; |
---|
1608 | return { |
---|
1609 | stop : function(skipToLast){ |
---|
1610 | // do nothing |
---|
1611 | }, |
---|
1612 | |
---|
1613 | isAnimated : function(){ |
---|
1614 | return animated; |
---|
1615 | }, |
---|
1616 | |
---|
1617 | proxyCallback : function(){ |
---|
1618 | animated = false; |
---|
1619 | Ext.callback(cb, scope); |
---|
1620 | } |
---|
1621 | }; |
---|
1622 | }; |
---|
1623 | return { |
---|
1624 | scroll : function(el, args, duration, easing, cb, scope){ |
---|
1625 | // scroll anim not supported so just scroll immediately |
---|
1626 | var anim = createAnim(cb, scope); |
---|
1627 | el = Ext.getDom(el); |
---|
1628 | if(typeof args.scroll.to[0] == 'number'){ |
---|
1629 | el.scrollLeft = args.scroll.to[0]; |
---|
1630 | } |
---|
1631 | if(typeof args.scroll.to[1] == 'number'){ |
---|
1632 | el.scrollTop = args.scroll.to[1]; |
---|
1633 | } |
---|
1634 | anim.proxyCallback(); |
---|
1635 | return anim; |
---|
1636 | }, |
---|
1637 | |
---|
1638 | motion : function(el, args, duration, easing, cb, scope){ |
---|
1639 | return this.run(el, args, duration, easing, cb, scope); |
---|
1640 | }, |
---|
1641 | |
---|
1642 | color : function(el, args, duration, easing, cb, scope){ |
---|
1643 | // color anim not supported, so execute callback immediately |
---|
1644 | var anim = createAnim(cb, scope); |
---|
1645 | anim.proxyCallback(); |
---|
1646 | return anim; |
---|
1647 | }, |
---|
1648 | |
---|
1649 | run : function(el, args, duration, easing, cb, scope, type){ |
---|
1650 | var anim = createAnim(cb, scope), e = Ext.fly(el, '_animrun'); |
---|
1651 | var o = {}; |
---|
1652 | for(var k in args){ |
---|
1653 | switch(k){ // jquery doesn't support, so convert |
---|
1654 | case 'points': |
---|
1655 | var by, pts; |
---|
1656 | e.position(); |
---|
1657 | if(by = args.points.by){ |
---|
1658 | var xy = e.getXY(); |
---|
1659 | pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]); |
---|
1660 | }else{ |
---|
1661 | pts = e.translatePoints(args.points.to); |
---|
1662 | } |
---|
1663 | o.left = pts.left; |
---|
1664 | o.top = pts.top; |
---|
1665 | if(!parseInt(e.getStyle('left'), 10)){ // auto bug |
---|
1666 | e.setLeft(0); |
---|
1667 | } |
---|
1668 | if(!parseInt(e.getStyle('top'), 10)){ |
---|
1669 | e.setTop(0); |
---|
1670 | } |
---|
1671 | if(args.points.from){ |
---|
1672 | e.setXY(args.points.from); |
---|
1673 | } |
---|
1674 | break; |
---|
1675 | case 'width': |
---|
1676 | o.width = args.width.to; |
---|
1677 | if (args.width.from) |
---|
1678 | e.setWidth(args.width.from); |
---|
1679 | break; |
---|
1680 | case 'height': |
---|
1681 | o.height = args.height.to; |
---|
1682 | if (args.height.from) |
---|
1683 | e.setHeight(args.height.from); |
---|
1684 | break; |
---|
1685 | case 'opacity': |
---|
1686 | o.opacity = args.opacity.to; |
---|
1687 | if (args.opacity.from) |
---|
1688 | e.setOpacity(args.opacity.from); |
---|
1689 | break; |
---|
1690 | case 'left': |
---|
1691 | o.left = args.left.to; |
---|
1692 | if (args.left.from) |
---|
1693 | e.setLeft(args.left.from); |
---|
1694 | break; |
---|
1695 | case 'top': |
---|
1696 | o.top = args.top.to; |
---|
1697 | if (args.top.from) |
---|
1698 | e.setTop(args.top.from); |
---|
1699 | break; |
---|
1700 | // jQuery can't handle callback, scope, and xy arguments, so break here |
---|
1701 | case 'callback': |
---|
1702 | case 'scope': |
---|
1703 | case 'xy': |
---|
1704 | break; |
---|
1705 | |
---|
1706 | default: |
---|
1707 | o[k] = args[k].to; |
---|
1708 | if (args[k].from) |
---|
1709 | e.setStyle(k, args[k].from); |
---|
1710 | break; |
---|
1711 | } |
---|
1712 | } |
---|
1713 | // TODO: find out about easing plug in? |
---|
1714 | jQuery(el).animate(o, duration*1000, undefined, anim.proxyCallback); |
---|
1715 | return anim; |
---|
1716 | } |
---|
1717 | }; |
---|
1718 | }(); |
---|
1719 | |
---|
1720 | |
---|
1721 | Ext.lib.Region = function(t, r, b, l) { |
---|
1722 | this.top = t; |
---|
1723 | this[1] = t; |
---|
1724 | this.right = r; |
---|
1725 | this.bottom = b; |
---|
1726 | this.left = l; |
---|
1727 | this[0] = l; |
---|
1728 | }; |
---|
1729 | |
---|
1730 | Ext.lib.Region.prototype = { |
---|
1731 | contains : function(region) { |
---|
1732 | return ( region.left >= this.left && |
---|
1733 | region.right <= this.right && |
---|
1734 | region.top >= this.top && |
---|
1735 | region.bottom <= this.bottom ); |
---|
1736 | |
---|
1737 | }, |
---|
1738 | |
---|
1739 | getArea : function() { |
---|
1740 | return ( (this.bottom - this.top) * (this.right - this.left) ); |
---|
1741 | }, |
---|
1742 | |
---|
1743 | intersect : function(region) { |
---|
1744 | var t = Math.max( this.top, region.top ); |
---|
1745 | var r = Math.min( this.right, region.right ); |
---|
1746 | var b = Math.min( this.bottom, region.bottom ); |
---|
1747 | var l = Math.max( this.left, region.left ); |
---|
1748 | |
---|
1749 | if (b >= t && r >= l) { |
---|
1750 | return new Ext.lib.Region(t, r, b, l); |
---|
1751 | } else { |
---|
1752 | return null; |
---|
1753 | } |
---|
1754 | }, |
---|
1755 | union : function(region) { |
---|
1756 | var t = Math.min( this.top, region.top ); |
---|
1757 | var r = Math.max( this.right, region.right ); |
---|
1758 | var b = Math.max( this.bottom, region.bottom ); |
---|
1759 | var l = Math.min( this.left, region.left ); |
---|
1760 | |
---|
1761 | return new Ext.lib.Region(t, r, b, l); |
---|
1762 | }, |
---|
1763 | |
---|
1764 | constrainTo : function(r) { |
---|
1765 | this.top = this.top.constrain(r.top, r.bottom); |
---|
1766 | this.bottom = this.bottom.constrain(r.top, r.bottom); |
---|
1767 | this.left = this.left.constrain(r.left, r.right); |
---|
1768 | this.right = this.right.constrain(r.left, r.right); |
---|
1769 | return this; |
---|
1770 | }, |
---|
1771 | |
---|
1772 | adjust : function(t, l, b, r){ |
---|
1773 | this.top += t; |
---|
1774 | this.left += l; |
---|
1775 | this.right += r; |
---|
1776 | this.bottom += b; |
---|
1777 | return this; |
---|
1778 | } |
---|
1779 | }; |
---|
1780 | |
---|
1781 | Ext.lib.Region.getRegion = function(el) { |
---|
1782 | var p = Ext.lib.Dom.getXY(el); |
---|
1783 | |
---|
1784 | var t = p[1]; |
---|
1785 | var r = p[0] + el.offsetWidth; |
---|
1786 | var b = p[1] + el.offsetHeight; |
---|
1787 | var l = p[0]; |
---|
1788 | |
---|
1789 | return new Ext.lib.Region(t, r, b, l); |
---|
1790 | }; |
---|
1791 | |
---|
1792 | Ext.lib.Point = function(x, y) { |
---|
1793 | if (Ext.isArray(x)) { |
---|
1794 | y = x[1]; |
---|
1795 | x = x[0]; |
---|
1796 | } |
---|
1797 | this.x = this.right = this.left = this[0] = x; |
---|
1798 | this.y = this.top = this.bottom = this[1] = y; |
---|
1799 | }; |
---|
1800 | |
---|
1801 | Ext.lib.Point.prototype = new Ext.lib.Region(); |
---|
1802 | |
---|
1803 | // prevent IE leaks |
---|
1804 | if(Ext.isIE) { |
---|
1805 | function fnCleanUp() { |
---|
1806 | var p = Function.prototype; |
---|
1807 | delete p.createSequence; |
---|
1808 | delete p.defer; |
---|
1809 | delete p.createDelegate; |
---|
1810 | delete p.createCallback; |
---|
1811 | delete p.createInterceptor; |
---|
1812 | |
---|
1813 | window.detachEvent("onunload", fnCleanUp); |
---|
1814 | } |
---|
1815 | window.attachEvent("onunload", fnCleanUp); |
---|
1816 | } |
---|
1817 | })(); |
---|