[76] | 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();(function(){ |
---|
| 1246 | var libFlyweight; |
---|
| 1247 | |
---|
| 1248 | function fly(el) { |
---|
| 1249 | if (!libFlyweight) { |
---|
| 1250 | libFlyweight = new Ext.Element.Flyweight(); |
---|
| 1251 | } |
---|
| 1252 | libFlyweight.dom = el; |
---|
| 1253 | return libFlyweight; |
---|
| 1254 | } |
---|
| 1255 | |
---|
| 1256 | (function(){ |
---|
| 1257 | var doc = document, |
---|
| 1258 | isCSS1 = doc.compatMode == "CSS1Compat", |
---|
| 1259 | MAX = Math.max, |
---|
| 1260 | ROUND = Math.round, |
---|
| 1261 | PARSEINT = parseInt; |
---|
| 1262 | |
---|
| 1263 | Ext.lib.Dom = { |
---|
| 1264 | isAncestor : function(p, c) { |
---|
| 1265 | var ret = false; |
---|
| 1266 | |
---|
| 1267 | p = Ext.getDom(p); |
---|
| 1268 | c = Ext.getDom(c); |
---|
| 1269 | if (p && c) { |
---|
| 1270 | if (p.contains) { |
---|
| 1271 | return p.contains(c); |
---|
| 1272 | } else if (p.compareDocumentPosition) { |
---|
| 1273 | return !!(p.compareDocumentPosition(c) & 16); |
---|
| 1274 | } else { |
---|
| 1275 | while (c = c.parentNode) { |
---|
| 1276 | ret = c == p || ret; |
---|
| 1277 | } |
---|
| 1278 | } |
---|
| 1279 | } |
---|
| 1280 | return ret; |
---|
| 1281 | }, |
---|
| 1282 | |
---|
| 1283 | getViewWidth : function(full) { |
---|
| 1284 | return full ? this.getDocumentWidth() : this.getViewportWidth(); |
---|
| 1285 | }, |
---|
| 1286 | |
---|
| 1287 | getViewHeight : function(full) { |
---|
| 1288 | return full ? this.getDocumentHeight() : this.getViewportHeight(); |
---|
| 1289 | }, |
---|
| 1290 | |
---|
| 1291 | getDocumentHeight: function() { |
---|
| 1292 | return MAX(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, this.getViewportHeight()); |
---|
| 1293 | }, |
---|
| 1294 | |
---|
| 1295 | getDocumentWidth: function() { |
---|
| 1296 | return MAX(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, this.getViewportWidth()); |
---|
| 1297 | }, |
---|
| 1298 | |
---|
| 1299 | getViewportHeight: function(){ |
---|
| 1300 | return Ext.isIE ? |
---|
| 1301 | (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) : |
---|
| 1302 | self.innerHeight; |
---|
| 1303 | }, |
---|
| 1304 | |
---|
| 1305 | getViewportWidth : function() { |
---|
| 1306 | return !Ext.isStrict && !Ext.isOpera ? doc.body.clientWidth : |
---|
| 1307 | Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth; |
---|
| 1308 | }, |
---|
| 1309 | |
---|
| 1310 | getY : function(el) { |
---|
| 1311 | return this.getXY(el)[1]; |
---|
| 1312 | }, |
---|
| 1313 | |
---|
| 1314 | getX : function(el) { |
---|
| 1315 | return this.getXY(el)[0]; |
---|
| 1316 | }, |
---|
| 1317 | |
---|
| 1318 | getXY : function(el) { |
---|
| 1319 | var p, |
---|
| 1320 | pe, |
---|
| 1321 | b, |
---|
| 1322 | bt, |
---|
| 1323 | bl, |
---|
| 1324 | dbd, |
---|
| 1325 | x = 0, |
---|
| 1326 | y = 0, |
---|
| 1327 | scroll, |
---|
| 1328 | hasAbsolute, |
---|
| 1329 | bd = (doc.body || doc.documentElement), |
---|
| 1330 | ret = [0,0]; |
---|
| 1331 | |
---|
| 1332 | el = Ext.getDom(el); |
---|
| 1333 | |
---|
| 1334 | if(el != bd){ |
---|
| 1335 | if (el.getBoundingClientRect) { |
---|
| 1336 | b = el.getBoundingClientRect(); |
---|
| 1337 | scroll = fly(document).getScroll(); |
---|
| 1338 | ret = [ROUND(b.left + scroll.left), ROUND(b.top + scroll.top)]; |
---|
| 1339 | } else { |
---|
| 1340 | p = el; |
---|
| 1341 | hasAbsolute = fly(el).isStyle("position", "absolute"); |
---|
| 1342 | |
---|
| 1343 | while (p) { |
---|
| 1344 | pe = fly(p); |
---|
| 1345 | x += p.offsetLeft; |
---|
| 1346 | y += p.offsetTop; |
---|
| 1347 | |
---|
| 1348 | hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute"); |
---|
| 1349 | |
---|
| 1350 | if (Ext.isGecko) { |
---|
| 1351 | y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0; |
---|
| 1352 | x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0; |
---|
| 1353 | |
---|
| 1354 | if (p != el && !pe.isStyle('overflow','visible')) { |
---|
| 1355 | x += bl; |
---|
| 1356 | y += bt; |
---|
| 1357 | } |
---|
| 1358 | } |
---|
| 1359 | p = p.offsetParent; |
---|
| 1360 | } |
---|
| 1361 | |
---|
| 1362 | if (Ext.isSafari && hasAbsolute) { |
---|
| 1363 | x -= bd.offsetLeft; |
---|
| 1364 | y -= bd.offsetTop; |
---|
| 1365 | } |
---|
| 1366 | |
---|
| 1367 | if (Ext.isGecko && !hasAbsolute) { |
---|
| 1368 | dbd = fly(bd); |
---|
| 1369 | x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0; |
---|
| 1370 | y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0; |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | p = el.parentNode; |
---|
| 1374 | while (p && p != bd) { |
---|
| 1375 | if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) { |
---|
| 1376 | x -= p.scrollLeft; |
---|
| 1377 | y -= p.scrollTop; |
---|
| 1378 | } |
---|
| 1379 | p = p.parentNode; |
---|
| 1380 | } |
---|
| 1381 | ret = [x,y]; |
---|
| 1382 | } |
---|
| 1383 | } |
---|
| 1384 | return ret; |
---|
| 1385 | }, |
---|
| 1386 | |
---|
| 1387 | setXY : function(el, xy) { |
---|
| 1388 | (el = Ext.fly(el, '_setXY')).position(); |
---|
| 1389 | |
---|
| 1390 | var pts = el.translatePoints(xy), |
---|
| 1391 | style = el.dom.style, |
---|
| 1392 | pos; |
---|
| 1393 | |
---|
| 1394 | for (pos in pts) { |
---|
| 1395 | if (!isNaN(pts[pos])) { |
---|
| 1396 | style[pos] = pts[pos] + "px"; |
---|
| 1397 | } |
---|
| 1398 | } |
---|
| 1399 | }, |
---|
| 1400 | |
---|
| 1401 | setX : function(el, x) { |
---|
| 1402 | this.setXY(el, [x, false]); |
---|
| 1403 | }, |
---|
| 1404 | |
---|
| 1405 | setY : function(el, y) { |
---|
| 1406 | this.setXY(el, [false, y]); |
---|
| 1407 | } |
---|
| 1408 | }; |
---|
| 1409 | })();Ext.lib.Event = function() { |
---|
| 1410 | var loadComplete = false, |
---|
| 1411 | unloadListeners = {}, |
---|
| 1412 | retryCount = 0, |
---|
| 1413 | onAvailStack = [], |
---|
| 1414 | _interval, |
---|
| 1415 | locked = false, |
---|
| 1416 | win = window, |
---|
| 1417 | doc = document, |
---|
| 1418 | |
---|
| 1419 | // constants |
---|
| 1420 | POLL_RETRYS = 200, |
---|
| 1421 | POLL_INTERVAL = 20, |
---|
| 1422 | TYPE = 0, |
---|
| 1423 | FN = 1, |
---|
| 1424 | OBJ = 2, |
---|
| 1425 | ADJ_SCOPE = 3, |
---|
| 1426 | SCROLLLEFT = 'scrollLeft', |
---|
| 1427 | SCROLLTOP = 'scrollTop', |
---|
| 1428 | UNLOAD = 'unload', |
---|
| 1429 | MOUSEOVER = 'mouseover', |
---|
| 1430 | MOUSEOUT = 'mouseout', |
---|
| 1431 | // private |
---|
| 1432 | doAdd = function() { |
---|
| 1433 | var ret; |
---|
| 1434 | if (win.addEventListener) { |
---|
| 1435 | ret = function(el, eventName, fn, capture) { |
---|
| 1436 | if (eventName == 'mouseenter') { |
---|
| 1437 | fn = fn.createInterceptor(checkRelatedTarget); |
---|
| 1438 | el.addEventListener(MOUSEOVER, fn, (capture)); |
---|
| 1439 | } else if (eventName == 'mouseleave') { |
---|
| 1440 | fn = fn.createInterceptor(checkRelatedTarget); |
---|
| 1441 | el.addEventListener(MOUSEOUT, fn, (capture)); |
---|
| 1442 | } else { |
---|
| 1443 | el.addEventListener(eventName, fn, (capture)); |
---|
| 1444 | } |
---|
| 1445 | return fn; |
---|
| 1446 | }; |
---|
| 1447 | } else if (win.attachEvent) { |
---|
| 1448 | ret = function(el, eventName, fn, capture) { |
---|
| 1449 | el.attachEvent("on" + eventName, fn); |
---|
| 1450 | return fn; |
---|
| 1451 | }; |
---|
| 1452 | } else { |
---|
| 1453 | ret = function(){}; |
---|
| 1454 | } |
---|
| 1455 | return ret; |
---|
| 1456 | }(), |
---|
| 1457 | // private |
---|
| 1458 | doRemove = function(){ |
---|
| 1459 | var ret; |
---|
| 1460 | if (win.removeEventListener) { |
---|
| 1461 | ret = function (el, eventName, fn, capture) { |
---|
| 1462 | if (eventName == 'mouseenter') { |
---|
| 1463 | eventName = MOUSEOVER; |
---|
| 1464 | } else if (eventName == 'mouseleave') { |
---|
| 1465 | eventName = MOUSEOUT; |
---|
| 1466 | } |
---|
| 1467 | el.removeEventListener(eventName, fn, (capture)); |
---|
| 1468 | }; |
---|
| 1469 | } else if (win.detachEvent) { |
---|
| 1470 | ret = function (el, eventName, fn) { |
---|
| 1471 | el.detachEvent("on" + eventName, fn); |
---|
| 1472 | }; |
---|
| 1473 | } else { |
---|
| 1474 | ret = function(){}; |
---|
| 1475 | } |
---|
| 1476 | return ret; |
---|
| 1477 | }(); |
---|
| 1478 | |
---|
| 1479 | function checkRelatedTarget(e) { |
---|
| 1480 | return !elContains(e.currentTarget, pub.getRelatedTarget(e)); |
---|
| 1481 | } |
---|
| 1482 | |
---|
| 1483 | function elContains(parent, child) { |
---|
| 1484 | if(parent && parent.firstChild){ |
---|
| 1485 | while(child) { |
---|
| 1486 | if(child === parent) { |
---|
| 1487 | return true; |
---|
| 1488 | } |
---|
| 1489 | child = child.parentNode; |
---|
| 1490 | if(child && (child.nodeType != 1)) { |
---|
| 1491 | child = null; |
---|
| 1492 | } |
---|
| 1493 | } |
---|
| 1494 | } |
---|
| 1495 | return false; |
---|
| 1496 | } |
---|
| 1497 | |
---|
| 1498 | // private |
---|
| 1499 | function _tryPreloadAttach() { |
---|
| 1500 | var ret = false, |
---|
| 1501 | notAvail = [], |
---|
| 1502 | element, i, v, override, |
---|
| 1503 | tryAgain = !loadComplete || (retryCount > 0); |
---|
| 1504 | |
---|
| 1505 | if(!locked){ |
---|
| 1506 | locked = true; |
---|
| 1507 | |
---|
| 1508 | for(i = 0; i < onAvailStack.length; ++i){ |
---|
| 1509 | v = onAvailStack[i]; |
---|
| 1510 | if(v && (element = doc.getElementById(v.id))){ |
---|
| 1511 | if(!v.checkReady || loadComplete || element.nextSibling || (doc && doc.body)) { |
---|
| 1512 | override = v.override; |
---|
| 1513 | element = override ? (override === true ? v.obj : override) : element; |
---|
| 1514 | v.fn.call(element, v.obj); |
---|
| 1515 | onAvailStack.remove(v); |
---|
| 1516 | --i; |
---|
| 1517 | }else{ |
---|
| 1518 | notAvail.push(v); |
---|
| 1519 | } |
---|
| 1520 | } |
---|
| 1521 | } |
---|
| 1522 | |
---|
| 1523 | retryCount = (notAvail.length === 0) ? 0 : retryCount - 1; |
---|
| 1524 | |
---|
| 1525 | if (tryAgain) { |
---|
| 1526 | startInterval(); |
---|
| 1527 | } else { |
---|
| 1528 | clearInterval(_interval); |
---|
| 1529 | _interval = null; |
---|
| 1530 | } |
---|
| 1531 | ret = !(locked = false); |
---|
| 1532 | } |
---|
| 1533 | return ret; |
---|
| 1534 | } |
---|
| 1535 | |
---|
| 1536 | // private |
---|
| 1537 | function startInterval() { |
---|
| 1538 | if(!_interval){ |
---|
| 1539 | var callback = function() { |
---|
| 1540 | _tryPreloadAttach(); |
---|
| 1541 | }; |
---|
| 1542 | _interval = setInterval(callback, POLL_INTERVAL); |
---|
| 1543 | } |
---|
| 1544 | } |
---|
| 1545 | |
---|
| 1546 | // private |
---|
| 1547 | function getScroll() { |
---|
| 1548 | var dd = doc.documentElement, |
---|
| 1549 | db = doc.body; |
---|
| 1550 | if(dd && (dd[SCROLLTOP] || dd[SCROLLLEFT])){ |
---|
| 1551 | return [dd[SCROLLLEFT], dd[SCROLLTOP]]; |
---|
| 1552 | }else if(db){ |
---|
| 1553 | return [db[SCROLLLEFT], db[SCROLLTOP]]; |
---|
| 1554 | }else{ |
---|
| 1555 | return [0, 0]; |
---|
| 1556 | } |
---|
| 1557 | } |
---|
| 1558 | |
---|
| 1559 | // private |
---|
| 1560 | function getPageCoord (ev, xy) { |
---|
| 1561 | ev = ev.browserEvent || ev; |
---|
| 1562 | var coord = ev['page' + xy]; |
---|
| 1563 | if (!coord && coord !== 0) { |
---|
| 1564 | coord = ev['client' + xy] || 0; |
---|
| 1565 | |
---|
| 1566 | if (Ext.isIE) { |
---|
| 1567 | coord += getScroll()[xy == "X" ? 0 : 1]; |
---|
| 1568 | } |
---|
| 1569 | } |
---|
| 1570 | |
---|
| 1571 | return coord; |
---|
| 1572 | } |
---|
| 1573 | |
---|
| 1574 | var pub = { |
---|
| 1575 | extAdapter: true, |
---|
| 1576 | onAvailable : function(p_id, p_fn, p_obj, p_override) { |
---|
| 1577 | onAvailStack.push({ |
---|
| 1578 | id: p_id, |
---|
| 1579 | fn: p_fn, |
---|
| 1580 | obj: p_obj, |
---|
| 1581 | override: p_override, |
---|
| 1582 | checkReady: false }); |
---|
| 1583 | |
---|
| 1584 | retryCount = POLL_RETRYS; |
---|
| 1585 | startInterval(); |
---|
| 1586 | }, |
---|
| 1587 | |
---|
| 1588 | // This function should ALWAYS be called from Ext.EventManager |
---|
| 1589 | addListener: function(el, eventName, fn) { |
---|
| 1590 | el = Ext.getDom(el); |
---|
| 1591 | if (el && fn) { |
---|
| 1592 | if (eventName == UNLOAD) { |
---|
| 1593 | if (unloadListeners[el.id] === undefined) { |
---|
| 1594 | unloadListeners[el.id] = []; |
---|
| 1595 | } |
---|
| 1596 | unloadListeners[el.id].push([eventName, fn]); |
---|
| 1597 | return fn; |
---|
| 1598 | } |
---|
| 1599 | return doAdd(el, eventName, fn, false); |
---|
| 1600 | } |
---|
| 1601 | return false; |
---|
| 1602 | }, |
---|
| 1603 | |
---|
| 1604 | // This function should ALWAYS be called from Ext.EventManager |
---|
| 1605 | removeListener: function(el, eventName, fn) { |
---|
| 1606 | el = Ext.getDom(el); |
---|
| 1607 | var i, len, li, lis; |
---|
| 1608 | if (el && fn) { |
---|
| 1609 | if(eventName == UNLOAD){ |
---|
| 1610 | if((lis = unloadListeners[el.id]) !== undefined){ |
---|
| 1611 | for(i = 0, len = lis.length; i < len; i++){ |
---|
| 1612 | if((li = lis[i]) && li[TYPE] == eventName && li[FN] == fn){ |
---|
| 1613 | unloadListeners[el.id].splice(i, 1); |
---|
| 1614 | } |
---|
| 1615 | } |
---|
| 1616 | } |
---|
| 1617 | return; |
---|
| 1618 | } |
---|
| 1619 | doRemove(el, eventName, fn, false); |
---|
| 1620 | } |
---|
| 1621 | }, |
---|
| 1622 | |
---|
| 1623 | getTarget : function(ev) { |
---|
| 1624 | ev = ev.browserEvent || ev; |
---|
| 1625 | return this.resolveTextNode(ev.target || ev.srcElement); |
---|
| 1626 | }, |
---|
| 1627 | |
---|
| 1628 | resolveTextNode : Ext.isGecko ? function(node){ |
---|
| 1629 | if(!node){ |
---|
| 1630 | return; |
---|
| 1631 | } |
---|
| 1632 | // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197 |
---|
| 1633 | var s = HTMLElement.prototype.toString.call(node); |
---|
| 1634 | if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){ |
---|
| 1635 | return; |
---|
| 1636 | } |
---|
| 1637 | return node.nodeType == 3 ? node.parentNode : node; |
---|
| 1638 | } : function(node){ |
---|
| 1639 | return node && node.nodeType == 3 ? node.parentNode : node; |
---|
| 1640 | }, |
---|
| 1641 | |
---|
| 1642 | getRelatedTarget : function(ev) { |
---|
| 1643 | ev = ev.browserEvent || ev; |
---|
| 1644 | return this.resolveTextNode(ev.relatedTarget || |
---|
| 1645 | (/(mouseout|mouseleave)/.test(ev.type) ? ev.toElement : |
---|
| 1646 | /(mouseover|mouseenter)/.test(ev.type) ? ev.fromElement : null)); |
---|
| 1647 | }, |
---|
| 1648 | |
---|
| 1649 | getPageX : function(ev) { |
---|
| 1650 | return getPageCoord(ev, "X"); |
---|
| 1651 | }, |
---|
| 1652 | |
---|
| 1653 | getPageY : function(ev) { |
---|
| 1654 | return getPageCoord(ev, "Y"); |
---|
| 1655 | }, |
---|
| 1656 | |
---|
| 1657 | |
---|
| 1658 | getXY : function(ev) { |
---|
| 1659 | return [this.getPageX(ev), this.getPageY(ev)]; |
---|
| 1660 | }, |
---|
| 1661 | |
---|
| 1662 | stopEvent : function(ev) { |
---|
| 1663 | this.stopPropagation(ev); |
---|
| 1664 | this.preventDefault(ev); |
---|
| 1665 | }, |
---|
| 1666 | |
---|
| 1667 | stopPropagation : function(ev) { |
---|
| 1668 | ev = ev.browserEvent || ev; |
---|
| 1669 | if (ev.stopPropagation) { |
---|
| 1670 | ev.stopPropagation(); |
---|
| 1671 | } else { |
---|
| 1672 | ev.cancelBubble = true; |
---|
| 1673 | } |
---|
| 1674 | }, |
---|
| 1675 | |
---|
| 1676 | preventDefault : function(ev) { |
---|
| 1677 | ev = ev.browserEvent || ev; |
---|
| 1678 | if (ev.preventDefault) { |
---|
| 1679 | ev.preventDefault(); |
---|
| 1680 | } else { |
---|
| 1681 | if (ev.keyCode) { |
---|
| 1682 | ev.keyCode = 0; |
---|
| 1683 | } |
---|
| 1684 | ev.returnValue = false; |
---|
| 1685 | } |
---|
| 1686 | }, |
---|
| 1687 | |
---|
| 1688 | getEvent : function(e) { |
---|
| 1689 | e = e || win.event; |
---|
| 1690 | if (!e) { |
---|
| 1691 | var c = this.getEvent.caller; |
---|
| 1692 | while (c) { |
---|
| 1693 | e = c.arguments[0]; |
---|
| 1694 | if (e && Event == e.constructor) { |
---|
| 1695 | break; |
---|
| 1696 | } |
---|
| 1697 | c = c.caller; |
---|
| 1698 | } |
---|
| 1699 | } |
---|
| 1700 | return e; |
---|
| 1701 | }, |
---|
| 1702 | |
---|
| 1703 | getCharCode : function(ev) { |
---|
| 1704 | ev = ev.browserEvent || ev; |
---|
| 1705 | return ev.charCode || ev.keyCode || 0; |
---|
| 1706 | }, |
---|
| 1707 | |
---|
| 1708 | //clearCache: function() {}, |
---|
| 1709 | // deprecated, call from EventManager |
---|
| 1710 | getListeners : function(el, eventName) { |
---|
| 1711 | Ext.EventManager.getListeners(el, eventName); |
---|
| 1712 | }, |
---|
| 1713 | |
---|
| 1714 | // deprecated, call from EventManager |
---|
| 1715 | purgeElement : function(el, recurse, eventName) { |
---|
| 1716 | Ext.EventManager.purgeElement(el, recurse, eventName); |
---|
| 1717 | }, |
---|
| 1718 | |
---|
| 1719 | _load : function(e) { |
---|
| 1720 | loadComplete = true; |
---|
| 1721 | |
---|
| 1722 | if (Ext.isIE && e !== true) { |
---|
| 1723 | // IE8 complains that _load is null or not an object |
---|
| 1724 | // so lets remove self via arguments.callee |
---|
| 1725 | doRemove(win, "load", arguments.callee); |
---|
| 1726 | } |
---|
| 1727 | }, |
---|
| 1728 | |
---|
| 1729 | _unload : function(e) { |
---|
| 1730 | var EU = Ext.lib.Event, |
---|
| 1731 | i, v, ul, id, len, scope; |
---|
| 1732 | |
---|
| 1733 | for (id in unloadListeners) { |
---|
| 1734 | ul = unloadListeners[id]; |
---|
| 1735 | for (i = 0, len = ul.length; i < len; i++) { |
---|
| 1736 | v = ul[i]; |
---|
| 1737 | if (v) { |
---|
| 1738 | try{ |
---|
| 1739 | scope = v[ADJ_SCOPE] ? (v[ADJ_SCOPE] === true ? v[OBJ] : v[ADJ_SCOPE]) : win; |
---|
| 1740 | v[FN].call(scope, EU.getEvent(e), v[OBJ]); |
---|
| 1741 | }catch(ex){} |
---|
| 1742 | } |
---|
| 1743 | } |
---|
| 1744 | }; |
---|
| 1745 | |
---|
| 1746 | Ext.EventManager._unload(); |
---|
| 1747 | |
---|
| 1748 | doRemove(win, UNLOAD, EU._unload); |
---|
| 1749 | } |
---|
| 1750 | }; |
---|
| 1751 | |
---|
| 1752 | // Initialize stuff. |
---|
| 1753 | pub.on = pub.addListener; |
---|
| 1754 | pub.un = pub.removeListener; |
---|
| 1755 | if (doc && doc.body) { |
---|
| 1756 | pub._load(true); |
---|
| 1757 | } else { |
---|
| 1758 | doAdd(win, "load", pub._load); |
---|
| 1759 | } |
---|
| 1760 | doAdd(win, UNLOAD, pub._unload); |
---|
| 1761 | _tryPreloadAttach(); |
---|
| 1762 | |
---|
| 1763 | return pub; |
---|
| 1764 | }(); |
---|
| 1765 | /* |
---|
| 1766 | * Portions of this file are based on pieces of Yahoo User Interface Library |
---|
| 1767 | * Copyright (c) 2007, Yahoo! Inc. All rights reserved. |
---|
| 1768 | * YUI licensed under the BSD License: |
---|
| 1769 | * http://developer.yahoo.net/yui/license.txt |
---|
| 1770 | */ |
---|
| 1771 | Ext.lib.Ajax = function() { |
---|
| 1772 | var activeX = ['Msxml2.XMLHTTP.6.0', |
---|
| 1773 | 'Msxml2.XMLHTTP.3.0', |
---|
| 1774 | 'Msxml2.XMLHTTP'], |
---|
| 1775 | CONTENTTYPE = 'Content-Type'; |
---|
| 1776 | |
---|
| 1777 | // private |
---|
| 1778 | function setHeader(o) { |
---|
| 1779 | var conn = o.conn, |
---|
| 1780 | prop, |
---|
| 1781 | headers = {}; |
---|
| 1782 | |
---|
| 1783 | function setTheHeaders(conn, headers){ |
---|
| 1784 | for (prop in headers) { |
---|
| 1785 | if (headers.hasOwnProperty(prop)) { |
---|
| 1786 | conn.setRequestHeader(prop, headers[prop]); |
---|
| 1787 | } |
---|
| 1788 | } |
---|
| 1789 | } |
---|
| 1790 | |
---|
| 1791 | Ext.apply(headers, pub.headers, pub.defaultHeaders); |
---|
| 1792 | setTheHeaders(conn, headers); |
---|
| 1793 | delete pub.headers; |
---|
| 1794 | } |
---|
| 1795 | |
---|
| 1796 | // private |
---|
| 1797 | function createExceptionObject(tId, callbackArg, isAbort, isTimeout) { |
---|
| 1798 | return { |
---|
| 1799 | tId : tId, |
---|
| 1800 | status : isAbort ? -1 : 0, |
---|
| 1801 | statusText : isAbort ? 'transaction aborted' : 'communication failure', |
---|
| 1802 | isAbort: isAbort, |
---|
| 1803 | isTimeout: isTimeout, |
---|
| 1804 | argument : callbackArg |
---|
| 1805 | }; |
---|
| 1806 | } |
---|
| 1807 | |
---|
| 1808 | // private |
---|
| 1809 | function initHeader(label, value) { |
---|
| 1810 | (pub.headers = pub.headers || {})[label] = value; |
---|
| 1811 | } |
---|
| 1812 | |
---|
| 1813 | // private |
---|
| 1814 | function createResponseObject(o, callbackArg) { |
---|
| 1815 | var headerObj = {}, |
---|
| 1816 | headerStr, |
---|
| 1817 | conn = o.conn, |
---|
| 1818 | t, |
---|
| 1819 | s, |
---|
| 1820 | // see: https://prototype.lighthouseapp.com/projects/8886/tickets/129-ie-mangles-http-response-status-code-204-to-1223 |
---|
| 1821 | isBrokenStatus = conn.status == 1223; |
---|
| 1822 | |
---|
| 1823 | try { |
---|
| 1824 | headerStr = o.conn.getAllResponseHeaders(); |
---|
| 1825 | Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){ |
---|
| 1826 | t = v.indexOf(':'); |
---|
| 1827 | if(t >= 0){ |
---|
| 1828 | s = v.substr(0, t).toLowerCase(); |
---|
| 1829 | if(v.charAt(t + 1) == ' '){ |
---|
| 1830 | ++t; |
---|
| 1831 | } |
---|
| 1832 | headerObj[s] = v.substr(t + 1); |
---|
| 1833 | } |
---|
| 1834 | }); |
---|
| 1835 | } catch(e) {} |
---|
| 1836 | |
---|
| 1837 | return { |
---|
| 1838 | tId : o.tId, |
---|
| 1839 | // Normalize the status and statusText when IE returns 1223, see the above link. |
---|
| 1840 | status : isBrokenStatus ? 204 : conn.status, |
---|
| 1841 | statusText : isBrokenStatus ? 'No Content' : conn.statusText, |
---|
| 1842 | getResponseHeader : function(header){return headerObj[header.toLowerCase()];}, |
---|
| 1843 | getAllResponseHeaders : function(){return headerStr;}, |
---|
| 1844 | responseText : conn.responseText, |
---|
| 1845 | responseXML : conn.responseXML, |
---|
| 1846 | argument : callbackArg |
---|
| 1847 | }; |
---|
| 1848 | } |
---|
| 1849 | |
---|
| 1850 | // private |
---|
| 1851 | function releaseObject(o) { |
---|
| 1852 | if (o.tId) { |
---|
| 1853 | pub.conn[o.tId] = null; |
---|
| 1854 | } |
---|
| 1855 | o.conn = null; |
---|
| 1856 | o = null; |
---|
| 1857 | } |
---|
| 1858 | |
---|
| 1859 | // private |
---|
| 1860 | function handleTransactionResponse(o, callback, isAbort, isTimeout) { |
---|
| 1861 | if (!callback) { |
---|
| 1862 | releaseObject(o); |
---|
| 1863 | return; |
---|
| 1864 | } |
---|
| 1865 | |
---|
| 1866 | var httpStatus, responseObject; |
---|
| 1867 | |
---|
| 1868 | try { |
---|
| 1869 | if (o.conn.status !== undefined && o.conn.status != 0) { |
---|
| 1870 | httpStatus = o.conn.status; |
---|
| 1871 | } |
---|
| 1872 | else { |
---|
| 1873 | httpStatus = 13030; |
---|
| 1874 | } |
---|
| 1875 | } |
---|
| 1876 | catch(e) { |
---|
| 1877 | httpStatus = 13030; |
---|
| 1878 | } |
---|
| 1879 | |
---|
| 1880 | if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) { |
---|
| 1881 | responseObject = createResponseObject(o, callback.argument); |
---|
| 1882 | if (callback.success) { |
---|
| 1883 | if (!callback.scope) { |
---|
| 1884 | callback.success(responseObject); |
---|
| 1885 | } |
---|
| 1886 | else { |
---|
| 1887 | callback.success.apply(callback.scope, [responseObject]); |
---|
| 1888 | } |
---|
| 1889 | } |
---|
| 1890 | } |
---|
| 1891 | else { |
---|
| 1892 | switch (httpStatus) { |
---|
| 1893 | case 12002: |
---|
| 1894 | case 12029: |
---|
| 1895 | case 12030: |
---|
| 1896 | case 12031: |
---|
| 1897 | case 12152: |
---|
| 1898 | case 13030: |
---|
| 1899 | responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout); |
---|
| 1900 | if (callback.failure) { |
---|
| 1901 | if (!callback.scope) { |
---|
| 1902 | callback.failure(responseObject); |
---|
| 1903 | } |
---|
| 1904 | else { |
---|
| 1905 | callback.failure.apply(callback.scope, [responseObject]); |
---|
| 1906 | } |
---|
| 1907 | } |
---|
| 1908 | break; |
---|
| 1909 | default: |
---|
| 1910 | responseObject = createResponseObject(o, callback.argument); |
---|
| 1911 | if (callback.failure) { |
---|
| 1912 | if (!callback.scope) { |
---|
| 1913 | callback.failure(responseObject); |
---|
| 1914 | } |
---|
| 1915 | else { |
---|
| 1916 | callback.failure.apply(callback.scope, [responseObject]); |
---|
| 1917 | } |
---|
| 1918 | } |
---|
| 1919 | } |
---|
| 1920 | } |
---|
| 1921 | |
---|
| 1922 | releaseObject(o); |
---|
| 1923 | responseObject = null; |
---|
| 1924 | } |
---|
| 1925 | |
---|
| 1926 | function checkResponse(o, callback, conn, tId, poll, cbTimeout){ |
---|
| 1927 | if (conn && conn.readyState == 4) { |
---|
| 1928 | clearInterval(poll[tId]); |
---|
| 1929 | poll[tId] = null; |
---|
| 1930 | |
---|
| 1931 | if (cbTimeout) { |
---|
| 1932 | clearTimeout(pub.timeout[tId]); |
---|
| 1933 | pub.timeout[tId] = null; |
---|
| 1934 | } |
---|
| 1935 | handleTransactionResponse(o, callback); |
---|
| 1936 | } |
---|
| 1937 | } |
---|
| 1938 | |
---|
| 1939 | function checkTimeout(o, callback){ |
---|
| 1940 | pub.abort(o, callback, true); |
---|
| 1941 | } |
---|
| 1942 | |
---|
| 1943 | |
---|
| 1944 | // private |
---|
| 1945 | function handleReadyState(o, callback){ |
---|
| 1946 | callback = callback || {}; |
---|
| 1947 | var conn = o.conn, |
---|
| 1948 | tId = o.tId, |
---|
| 1949 | poll = pub.poll, |
---|
| 1950 | cbTimeout = callback.timeout || null; |
---|
| 1951 | |
---|
| 1952 | if (cbTimeout) { |
---|
| 1953 | pub.conn[tId] = conn; |
---|
| 1954 | pub.timeout[tId] = setTimeout(checkTimeout.createCallback(o, callback), cbTimeout); |
---|
| 1955 | } |
---|
| 1956 | poll[tId] = setInterval(checkResponse.createCallback(o, callback, conn, tId, poll, cbTimeout), pub.pollInterval); |
---|
| 1957 | } |
---|
| 1958 | |
---|
| 1959 | // private |
---|
| 1960 | function asyncRequest(method, uri, callback, postData) { |
---|
| 1961 | var o = getConnectionObject() || null; |
---|
| 1962 | |
---|
| 1963 | if (o) { |
---|
| 1964 | o.conn.open(method, uri, true); |
---|
| 1965 | |
---|
| 1966 | if (pub.useDefaultXhrHeader) { |
---|
| 1967 | initHeader('X-Requested-With', pub.defaultXhrHeader); |
---|
| 1968 | } |
---|
| 1969 | |
---|
| 1970 | if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){ |
---|
| 1971 | initHeader(CONTENTTYPE, pub.defaultPostHeader); |
---|
| 1972 | } |
---|
| 1973 | |
---|
| 1974 | if (pub.defaultHeaders || pub.headers) { |
---|
| 1975 | setHeader(o); |
---|
| 1976 | } |
---|
| 1977 | |
---|
| 1978 | handleReadyState(o, callback); |
---|
| 1979 | o.conn.send(postData || null); |
---|
| 1980 | } |
---|
| 1981 | return o; |
---|
| 1982 | } |
---|
| 1983 | |
---|
| 1984 | // private |
---|
| 1985 | function getConnectionObject() { |
---|
| 1986 | var o; |
---|
| 1987 | |
---|
| 1988 | try { |
---|
| 1989 | if (o = createXhrObject(pub.transactionId)) { |
---|
| 1990 | pub.transactionId++; |
---|
| 1991 | } |
---|
| 1992 | } catch(e) { |
---|
| 1993 | } finally { |
---|
| 1994 | return o; |
---|
| 1995 | } |
---|
| 1996 | } |
---|
| 1997 | |
---|
| 1998 | // private |
---|
| 1999 | function createXhrObject(transactionId) { |
---|
| 2000 | var http; |
---|
| 2001 | |
---|
| 2002 | try { |
---|
| 2003 | http = new XMLHttpRequest(); |
---|
| 2004 | } catch(e) { |
---|
| 2005 | for (var i = Ext.isIE6 ? 1 : 0; i < activeX.length; ++i) { |
---|
| 2006 | try { |
---|
| 2007 | http = new ActiveXObject(activeX[i]); |
---|
| 2008 | break; |
---|
| 2009 | } catch(e) {} |
---|
| 2010 | } |
---|
| 2011 | } finally { |
---|
| 2012 | return {conn : http, tId : transactionId}; |
---|
| 2013 | } |
---|
| 2014 | } |
---|
| 2015 | |
---|
| 2016 | var pub = { |
---|
| 2017 | request : function(method, uri, cb, data, options) { |
---|
| 2018 | if(options){ |
---|
| 2019 | var me = this, |
---|
| 2020 | xmlData = options.xmlData, |
---|
| 2021 | jsonData = options.jsonData, |
---|
| 2022 | hs; |
---|
| 2023 | |
---|
| 2024 | Ext.applyIf(me, options); |
---|
| 2025 | |
---|
| 2026 | if(xmlData || jsonData){ |
---|
| 2027 | hs = me.headers; |
---|
| 2028 | if(!hs || !hs[CONTENTTYPE]){ |
---|
| 2029 | initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json'); |
---|
| 2030 | } |
---|
| 2031 | data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData); |
---|
| 2032 | } |
---|
| 2033 | } |
---|
| 2034 | return asyncRequest(method || options.method || "POST", uri, cb, data); |
---|
| 2035 | }, |
---|
| 2036 | |
---|
| 2037 | serializeForm : function(form) { |
---|
| 2038 | var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements, |
---|
| 2039 | hasSubmit = false, |
---|
| 2040 | encoder = encodeURIComponent, |
---|
| 2041 | name, |
---|
| 2042 | data = '', |
---|
| 2043 | type, |
---|
| 2044 | hasValue; |
---|
| 2045 | |
---|
| 2046 | Ext.each(fElements, function(element){ |
---|
| 2047 | name = element.name; |
---|
| 2048 | type = element.type; |
---|
| 2049 | |
---|
| 2050 | if (!element.disabled && name) { |
---|
| 2051 | if (/select-(one|multiple)/i.test(type)) { |
---|
| 2052 | Ext.each(element.options, function(opt){ |
---|
| 2053 | if (opt.selected) { |
---|
| 2054 | hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified; |
---|
| 2055 | data += String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text)); |
---|
| 2056 | } |
---|
| 2057 | }); |
---|
| 2058 | } else if (!(/file|undefined|reset|button/i.test(type))) { |
---|
| 2059 | if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) { |
---|
| 2060 | data += encoder(name) + '=' + encoder(element.value) + '&'; |
---|
| 2061 | hasSubmit = /submit/i.test(type); |
---|
| 2062 | } |
---|
| 2063 | } |
---|
| 2064 | } |
---|
| 2065 | }); |
---|
| 2066 | return data.substr(0, data.length - 1); |
---|
| 2067 | }, |
---|
| 2068 | |
---|
| 2069 | useDefaultHeader : true, |
---|
| 2070 | defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8', |
---|
| 2071 | useDefaultXhrHeader : true, |
---|
| 2072 | defaultXhrHeader : 'XMLHttpRequest', |
---|
| 2073 | poll : {}, |
---|
| 2074 | timeout : {}, |
---|
| 2075 | conn: {}, |
---|
| 2076 | pollInterval : 50, |
---|
| 2077 | transactionId : 0, |
---|
| 2078 | |
---|
| 2079 | // This is never called - Is it worth exposing this? |
---|
| 2080 | // setProgId : function(id) { |
---|
| 2081 | // activeX.unshift(id); |
---|
| 2082 | // }, |
---|
| 2083 | |
---|
| 2084 | // This is never called - Is it worth exposing this? |
---|
| 2085 | // setDefaultPostHeader : function(b) { |
---|
| 2086 | // this.useDefaultHeader = b; |
---|
| 2087 | // }, |
---|
| 2088 | |
---|
| 2089 | // This is never called - Is it worth exposing this? |
---|
| 2090 | // setDefaultXhrHeader : function(b) { |
---|
| 2091 | // this.useDefaultXhrHeader = b; |
---|
| 2092 | // }, |
---|
| 2093 | |
---|
| 2094 | // This is never called - Is it worth exposing this? |
---|
| 2095 | // setPollingInterval : function(i) { |
---|
| 2096 | // if (typeof i == 'number' && isFinite(i)) { |
---|
| 2097 | // this.pollInterval = i; |
---|
| 2098 | // } |
---|
| 2099 | // }, |
---|
| 2100 | |
---|
| 2101 | // This is never called - Is it worth exposing this? |
---|
| 2102 | // resetDefaultHeaders : function() { |
---|
| 2103 | // this.defaultHeaders = null; |
---|
| 2104 | // }, |
---|
| 2105 | |
---|
| 2106 | abort : function(o, callback, isTimeout) { |
---|
| 2107 | var me = this, |
---|
| 2108 | tId = o.tId, |
---|
| 2109 | isAbort = false; |
---|
| 2110 | |
---|
| 2111 | if (me.isCallInProgress(o)) { |
---|
| 2112 | o.conn.abort(); |
---|
| 2113 | clearInterval(me.poll[tId]); |
---|
| 2114 | me.poll[tId] = null; |
---|
| 2115 | clearTimeout(pub.timeout[tId]); |
---|
| 2116 | me.timeout[tId] = null; |
---|
| 2117 | |
---|
| 2118 | handleTransactionResponse(o, callback, (isAbort = true), isTimeout); |
---|
| 2119 | } |
---|
| 2120 | return isAbort; |
---|
| 2121 | }, |
---|
| 2122 | |
---|
| 2123 | isCallInProgress : function(o) { |
---|
| 2124 | // if there is a connection and readyState is not 0 or 4 |
---|
| 2125 | return o.conn && !{0:true,4:true}[o.conn.readyState]; |
---|
| 2126 | } |
---|
| 2127 | }; |
---|
| 2128 | return pub; |
---|
| 2129 | }();(function(){ |
---|
| 2130 | var EXTLIB = Ext.lib, |
---|
| 2131 | noNegatives = /width|height|opacity|padding/i, |
---|
| 2132 | offsetAttribute = /^((width|height)|(top|left))$/, |
---|
| 2133 | defaultUnit = /width|height|top$|bottom$|left$|right$/i, |
---|
| 2134 | offsetUnit = /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i, |
---|
| 2135 | isset = function(v){ |
---|
| 2136 | return typeof v !== 'undefined'; |
---|
| 2137 | }, |
---|
| 2138 | now = function(){ |
---|
| 2139 | return new Date(); |
---|
| 2140 | }; |
---|
| 2141 | |
---|
| 2142 | EXTLIB.Anim = { |
---|
| 2143 | motion : function(el, args, duration, easing, cb, scope) { |
---|
| 2144 | return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion); |
---|
| 2145 | }, |
---|
| 2146 | |
---|
| 2147 | run : function(el, args, duration, easing, cb, scope, type) { |
---|
| 2148 | type = type || Ext.lib.AnimBase; |
---|
| 2149 | if (typeof easing == "string") { |
---|
| 2150 | easing = Ext.lib.Easing[easing]; |
---|
| 2151 | } |
---|
| 2152 | var anim = new type(el, args, duration, easing); |
---|
| 2153 | anim.animateX(function() { |
---|
| 2154 | if(Ext.isFunction(cb)){ |
---|
| 2155 | cb.call(scope); |
---|
| 2156 | } |
---|
| 2157 | }); |
---|
| 2158 | return anim; |
---|
| 2159 | } |
---|
| 2160 | }; |
---|
| 2161 | |
---|
| 2162 | EXTLIB.AnimBase = function(el, attributes, duration, method) { |
---|
| 2163 | if (el) { |
---|
| 2164 | this.init(el, attributes, duration, method); |
---|
| 2165 | } |
---|
| 2166 | }; |
---|
| 2167 | |
---|
| 2168 | EXTLIB.AnimBase.prototype = { |
---|
| 2169 | doMethod: function(attr, start, end) { |
---|
| 2170 | var me = this; |
---|
| 2171 | return me.method(me.curFrame, start, end - start, me.totalFrames); |
---|
| 2172 | }, |
---|
| 2173 | |
---|
| 2174 | |
---|
| 2175 | setAttr: function(attr, val, unit) { |
---|
| 2176 | if (noNegatives.test(attr) && val < 0) { |
---|
| 2177 | val = 0; |
---|
| 2178 | } |
---|
| 2179 | Ext.fly(this.el, '_anim').setStyle(attr, val + unit); |
---|
| 2180 | }, |
---|
| 2181 | |
---|
| 2182 | |
---|
| 2183 | getAttr: function(attr) { |
---|
| 2184 | var el = Ext.fly(this.el), |
---|
| 2185 | val = el.getStyle(attr), |
---|
| 2186 | a = offsetAttribute.exec(attr) || []; |
---|
| 2187 | |
---|
| 2188 | if (val !== 'auto' && !offsetUnit.test(val)) { |
---|
| 2189 | return parseFloat(val); |
---|
| 2190 | } |
---|
| 2191 | |
---|
| 2192 | return (!!(a[2]) || (el.getStyle('position') == 'absolute' && !!(a[3]))) ? el.dom['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)] : 0; |
---|
| 2193 | }, |
---|
| 2194 | |
---|
| 2195 | |
---|
| 2196 | getDefaultUnit: function(attr) { |
---|
| 2197 | return defaultUnit.test(attr) ? 'px' : ''; |
---|
| 2198 | }, |
---|
| 2199 | |
---|
| 2200 | animateX : function(callback, scope) { |
---|
| 2201 | var me = this, |
---|
| 2202 | f = function() { |
---|
| 2203 | me.onComplete.removeListener(f); |
---|
| 2204 | if (Ext.isFunction(callback)) { |
---|
| 2205 | callback.call(scope || me, me); |
---|
| 2206 | } |
---|
| 2207 | }; |
---|
| 2208 | me.onComplete.addListener(f, me); |
---|
| 2209 | me.animate(); |
---|
| 2210 | }, |
---|
| 2211 | |
---|
| 2212 | |
---|
| 2213 | setRunAttr: function(attr) { |
---|
| 2214 | var me = this, |
---|
| 2215 | a = this.attributes[attr], |
---|
| 2216 | to = a.to, |
---|
| 2217 | by = a.by, |
---|
| 2218 | from = a.from, |
---|
| 2219 | unit = a.unit, |
---|
| 2220 | ra = (this.runAttrs[attr] = {}), |
---|
| 2221 | end; |
---|
| 2222 | |
---|
| 2223 | if (!isset(to) && !isset(by)){ |
---|
| 2224 | return false; |
---|
| 2225 | } |
---|
| 2226 | |
---|
| 2227 | var start = isset(from) ? from : me.getAttr(attr); |
---|
| 2228 | if (isset(to)) { |
---|
| 2229 | end = to; |
---|
| 2230 | }else if(isset(by)) { |
---|
| 2231 | if (Ext.isArray(start)){ |
---|
| 2232 | end = []; |
---|
| 2233 | for(var i=0,len=start.length; i<len; i++) { |
---|
| 2234 | end[i] = start[i] + by[i]; |
---|
| 2235 | } |
---|
| 2236 | }else{ |
---|
| 2237 | end = start + by; |
---|
| 2238 | } |
---|
| 2239 | } |
---|
| 2240 | |
---|
| 2241 | Ext.apply(ra, { |
---|
| 2242 | start: start, |
---|
| 2243 | end: end, |
---|
| 2244 | unit: isset(unit) ? unit : me.getDefaultUnit(attr) |
---|
| 2245 | }); |
---|
| 2246 | }, |
---|
| 2247 | |
---|
| 2248 | |
---|
| 2249 | init: function(el, attributes, duration, method) { |
---|
| 2250 | var me = this, |
---|
| 2251 | actualFrames = 0, |
---|
| 2252 | mgr = EXTLIB.AnimMgr; |
---|
| 2253 | |
---|
| 2254 | Ext.apply(me, { |
---|
| 2255 | isAnimated: false, |
---|
| 2256 | startTime: null, |
---|
| 2257 | el: Ext.getDom(el), |
---|
| 2258 | attributes: attributes || {}, |
---|
| 2259 | duration: duration || 1, |
---|
| 2260 | method: method || EXTLIB.Easing.easeNone, |
---|
| 2261 | useSec: true, |
---|
| 2262 | curFrame: 0, |
---|
| 2263 | totalFrames: mgr.fps, |
---|
| 2264 | runAttrs: {}, |
---|
| 2265 | animate: function(){ |
---|
| 2266 | var me = this, |
---|
| 2267 | d = me.duration; |
---|
| 2268 | |
---|
| 2269 | if(me.isAnimated){ |
---|
| 2270 | return false; |
---|
| 2271 | } |
---|
| 2272 | |
---|
| 2273 | me.curFrame = 0; |
---|
| 2274 | me.totalFrames = me.useSec ? Math.ceil(mgr.fps * d) : d; |
---|
| 2275 | mgr.registerElement(me); |
---|
| 2276 | }, |
---|
| 2277 | |
---|
| 2278 | stop: function(finish){ |
---|
| 2279 | var me = this; |
---|
| 2280 | |
---|
| 2281 | if(finish){ |
---|
| 2282 | me.curFrame = me.totalFrames; |
---|
| 2283 | me._onTween.fire(); |
---|
| 2284 | } |
---|
| 2285 | mgr.stop(me); |
---|
| 2286 | } |
---|
| 2287 | }); |
---|
| 2288 | |
---|
| 2289 | var onStart = function(){ |
---|
| 2290 | var me = this, |
---|
| 2291 | attr; |
---|
| 2292 | |
---|
| 2293 | me.onStart.fire(); |
---|
| 2294 | me.runAttrs = {}; |
---|
| 2295 | for(attr in this.attributes){ |
---|
| 2296 | this.setRunAttr(attr); |
---|
| 2297 | } |
---|
| 2298 | |
---|
| 2299 | me.isAnimated = true; |
---|
| 2300 | me.startTime = now(); |
---|
| 2301 | actualFrames = 0; |
---|
| 2302 | }; |
---|
| 2303 | |
---|
| 2304 | |
---|
| 2305 | var onTween = function(){ |
---|
| 2306 | var me = this; |
---|
| 2307 | |
---|
| 2308 | me.onTween.fire({ |
---|
| 2309 | duration: now() - me.startTime, |
---|
| 2310 | curFrame: me.curFrame |
---|
| 2311 | }); |
---|
| 2312 | |
---|
| 2313 | var ra = me.runAttrs; |
---|
| 2314 | for (var attr in ra) { |
---|
| 2315 | this.setAttr(attr, me.doMethod(attr, ra[attr].start, ra[attr].end), ra[attr].unit); |
---|
| 2316 | } |
---|
| 2317 | |
---|
| 2318 | ++actualFrames; |
---|
| 2319 | }; |
---|
| 2320 | |
---|
| 2321 | var onComplete = function() { |
---|
| 2322 | var me = this, |
---|
| 2323 | actual = (now() - me.startTime) / 1000, |
---|
| 2324 | data = { |
---|
| 2325 | duration: actual, |
---|
| 2326 | frames: actualFrames, |
---|
| 2327 | fps: actualFrames / actual |
---|
| 2328 | }; |
---|
| 2329 | |
---|
| 2330 | me.isAnimated = false; |
---|
| 2331 | actualFrames = 0; |
---|
| 2332 | me.onComplete.fire(data); |
---|
| 2333 | }; |
---|
| 2334 | |
---|
| 2335 | me.onStart = new Ext.util.Event(me); |
---|
| 2336 | me.onTween = new Ext.util.Event(me); |
---|
| 2337 | me.onComplete = new Ext.util.Event(me); |
---|
| 2338 | (me._onStart = new Ext.util.Event(me)).addListener(onStart); |
---|
| 2339 | (me._onTween = new Ext.util.Event(me)).addListener(onTween); |
---|
| 2340 | (me._onComplete = new Ext.util.Event(me)).addListener(onComplete); |
---|
| 2341 | } |
---|
| 2342 | }; |
---|
| 2343 | |
---|
| 2344 | |
---|
| 2345 | Ext.lib.AnimMgr = new function() { |
---|
| 2346 | var me = this, |
---|
| 2347 | thread = null, |
---|
| 2348 | queue = [], |
---|
| 2349 | tweenCount = 0; |
---|
| 2350 | |
---|
| 2351 | |
---|
| 2352 | Ext.apply(me, { |
---|
| 2353 | fps: 1000, |
---|
| 2354 | delay: 1, |
---|
| 2355 | registerElement: function(tween){ |
---|
| 2356 | queue.push(tween); |
---|
| 2357 | ++tweenCount; |
---|
| 2358 | tween._onStart.fire(); |
---|
| 2359 | me.start(); |
---|
| 2360 | }, |
---|
| 2361 | |
---|
| 2362 | unRegister: function(tween, index){ |
---|
| 2363 | tween._onComplete.fire(); |
---|
| 2364 | index = index || getIndex(tween); |
---|
| 2365 | if (index != -1) { |
---|
| 2366 | queue.splice(index, 1); |
---|
| 2367 | } |
---|
| 2368 | |
---|
| 2369 | if (--tweenCount <= 0) { |
---|
| 2370 | me.stop(); |
---|
| 2371 | } |
---|
| 2372 | }, |
---|
| 2373 | |
---|
| 2374 | start: function(){ |
---|
| 2375 | if(thread === null){ |
---|
| 2376 | thread = setInterval(me.run, me.delay); |
---|
| 2377 | } |
---|
| 2378 | }, |
---|
| 2379 | |
---|
| 2380 | stop: function(tween){ |
---|
| 2381 | if(!tween){ |
---|
| 2382 | clearInterval(thread); |
---|
| 2383 | for(var i = 0, len = queue.length; i < len; ++i){ |
---|
| 2384 | if(queue[0].isAnimated){ |
---|
| 2385 | me.unRegister(queue[0], 0); |
---|
| 2386 | } |
---|
| 2387 | } |
---|
| 2388 | |
---|
| 2389 | queue = []; |
---|
| 2390 | thread = null; |
---|
| 2391 | tweenCount = 0; |
---|
| 2392 | }else{ |
---|
| 2393 | me.unRegister(tween); |
---|
| 2394 | } |
---|
| 2395 | }, |
---|
| 2396 | |
---|
| 2397 | run: function(){ |
---|
| 2398 | var tf, i, len, tween; |
---|
| 2399 | for(i = 0, len = queue.length; i<len; i++) { |
---|
| 2400 | tween = queue[i]; |
---|
| 2401 | if(tween && tween.isAnimated){ |
---|
| 2402 | tf = tween.totalFrames; |
---|
| 2403 | if(tween.curFrame < tf || tf === null){ |
---|
| 2404 | ++tween.curFrame; |
---|
| 2405 | if(tween.useSec){ |
---|
| 2406 | correctFrame(tween); |
---|
| 2407 | } |
---|
| 2408 | tween._onTween.fire(); |
---|
| 2409 | }else{ |
---|
| 2410 | me.stop(tween); |
---|
| 2411 | } |
---|
| 2412 | } |
---|
| 2413 | } |
---|
| 2414 | } |
---|
| 2415 | }); |
---|
| 2416 | |
---|
| 2417 | var getIndex = function(anim) { |
---|
| 2418 | var i, len; |
---|
| 2419 | for(i = 0, len = queue.length; i<len; i++) { |
---|
| 2420 | if(queue[i] === anim) { |
---|
| 2421 | return i; |
---|
| 2422 | } |
---|
| 2423 | } |
---|
| 2424 | return -1; |
---|
| 2425 | }; |
---|
| 2426 | |
---|
| 2427 | var correctFrame = function(tween) { |
---|
| 2428 | var frames = tween.totalFrames, |
---|
| 2429 | frame = tween.curFrame, |
---|
| 2430 | duration = tween.duration, |
---|
| 2431 | expected = (frame * duration * 1000 / frames), |
---|
| 2432 | elapsed = (now() - tween.startTime), |
---|
| 2433 | tweak = 0; |
---|
| 2434 | |
---|
| 2435 | if(elapsed < duration * 1000){ |
---|
| 2436 | tweak = Math.round((elapsed / expected - 1) * frame); |
---|
| 2437 | }else{ |
---|
| 2438 | tweak = frames - (frame + 1); |
---|
| 2439 | } |
---|
| 2440 | if(tweak > 0 && isFinite(tweak)){ |
---|
| 2441 | if(tween.curFrame + tweak >= frames){ |
---|
| 2442 | tweak = frames - (frame + 1); |
---|
| 2443 | } |
---|
| 2444 | tween.curFrame += tweak; |
---|
| 2445 | } |
---|
| 2446 | }; |
---|
| 2447 | }; |
---|
| 2448 | |
---|
| 2449 | EXTLIB.Bezier = new function() { |
---|
| 2450 | |
---|
| 2451 | this.getPosition = function(points, t) { |
---|
| 2452 | var n = points.length, |
---|
| 2453 | tmp = [], |
---|
| 2454 | c = 1 - t, |
---|
| 2455 | i, |
---|
| 2456 | j; |
---|
| 2457 | |
---|
| 2458 | for (i = 0; i < n; ++i) { |
---|
| 2459 | tmp[i] = [points[i][0], points[i][1]]; |
---|
| 2460 | } |
---|
| 2461 | |
---|
| 2462 | for (j = 1; j < n; ++j) { |
---|
| 2463 | for (i = 0; i < n - j; ++i) { |
---|
| 2464 | tmp[i][0] = c * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; |
---|
| 2465 | tmp[i][1] = c * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; |
---|
| 2466 | } |
---|
| 2467 | } |
---|
| 2468 | |
---|
| 2469 | return [ tmp[0][0], tmp[0][1] ]; |
---|
| 2470 | |
---|
| 2471 | }; |
---|
| 2472 | }; |
---|
| 2473 | |
---|
| 2474 | |
---|
| 2475 | EXTLIB.Easing = { |
---|
| 2476 | easeNone: function (t, b, c, d) { |
---|
| 2477 | return c * t / d + b; |
---|
| 2478 | }, |
---|
| 2479 | |
---|
| 2480 | |
---|
| 2481 | easeIn: function (t, b, c, d) { |
---|
| 2482 | return c * (t /= d) * t + b; |
---|
| 2483 | }, |
---|
| 2484 | |
---|
| 2485 | |
---|
| 2486 | easeOut: function (t, b, c, d) { |
---|
| 2487 | return -c * (t /= d) * (t - 2) + b; |
---|
| 2488 | } |
---|
| 2489 | }; |
---|
| 2490 | |
---|
| 2491 | (function() { |
---|
| 2492 | EXTLIB.Motion = function(el, attributes, duration, method) { |
---|
| 2493 | if (el) { |
---|
| 2494 | EXTLIB.Motion.superclass.constructor.call(this, el, attributes, duration, method); |
---|
| 2495 | } |
---|
| 2496 | }; |
---|
| 2497 | |
---|
| 2498 | Ext.extend(EXTLIB.Motion, Ext.lib.AnimBase); |
---|
| 2499 | |
---|
| 2500 | var superclass = EXTLIB.Motion.superclass, |
---|
| 2501 | pointsRe = /^points$/i; |
---|
| 2502 | |
---|
| 2503 | Ext.apply(EXTLIB.Motion.prototype, { |
---|
| 2504 | setAttr: function(attr, val, unit){ |
---|
| 2505 | var me = this, |
---|
| 2506 | setAttr = superclass.setAttr; |
---|
| 2507 | |
---|
| 2508 | if (pointsRe.test(attr)) { |
---|
| 2509 | unit = unit || 'px'; |
---|
| 2510 | setAttr.call(me, 'left', val[0], unit); |
---|
| 2511 | setAttr.call(me, 'top', val[1], unit); |
---|
| 2512 | } else { |
---|
| 2513 | setAttr.call(me, attr, val, unit); |
---|
| 2514 | } |
---|
| 2515 | }, |
---|
| 2516 | |
---|
| 2517 | getAttr: function(attr){ |
---|
| 2518 | var me = this, |
---|
| 2519 | getAttr = superclass.getAttr; |
---|
| 2520 | |
---|
| 2521 | return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr); |
---|
| 2522 | }, |
---|
| 2523 | |
---|
| 2524 | doMethod: function(attr, start, end){ |
---|
| 2525 | var me = this; |
---|
| 2526 | |
---|
| 2527 | return pointsRe.test(attr) |
---|
| 2528 | ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100) |
---|
| 2529 | : superclass.doMethod.call(me, attr, start, end); |
---|
| 2530 | }, |
---|
| 2531 | |
---|
| 2532 | setRunAttr: function(attr){ |
---|
| 2533 | if(pointsRe.test(attr)){ |
---|
| 2534 | |
---|
| 2535 | var me = this, |
---|
| 2536 | el = this.el, |
---|
| 2537 | points = this.attributes.points, |
---|
| 2538 | control = points.control || [], |
---|
| 2539 | from = points.from, |
---|
| 2540 | to = points.to, |
---|
| 2541 | by = points.by, |
---|
| 2542 | DOM = EXTLIB.Dom, |
---|
| 2543 | start, |
---|
| 2544 | i, |
---|
| 2545 | end, |
---|
| 2546 | len, |
---|
| 2547 | ra; |
---|
| 2548 | |
---|
| 2549 | |
---|
| 2550 | if(control.length > 0 && !Ext.isArray(control[0])){ |
---|
| 2551 | control = [control]; |
---|
| 2552 | }else{ |
---|
| 2553 | /* |
---|
| 2554 | var tmp = []; |
---|
| 2555 | for (i = 0,len = control.length; i < len; ++i) { |
---|
| 2556 | tmp[i] = control[i]; |
---|
| 2557 | } |
---|
| 2558 | control = tmp; |
---|
| 2559 | */ |
---|
| 2560 | } |
---|
| 2561 | |
---|
| 2562 | Ext.fly(el, '_anim').position(); |
---|
| 2563 | DOM.setXY(el, isset(from) ? from : DOM.getXY(el)); |
---|
| 2564 | start = me.getAttr('points'); |
---|
| 2565 | |
---|
| 2566 | |
---|
| 2567 | if(isset(to)){ |
---|
| 2568 | end = translateValues.call(me, to, start); |
---|
| 2569 | for (i = 0,len = control.length; i < len; ++i) { |
---|
| 2570 | control[i] = translateValues.call(me, control[i], start); |
---|
| 2571 | } |
---|
| 2572 | } else if (isset(by)) { |
---|
| 2573 | end = [start[0] + by[0], start[1] + by[1]]; |
---|
| 2574 | |
---|
| 2575 | for (i = 0,len = control.length; i < len; ++i) { |
---|
| 2576 | control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ]; |
---|
| 2577 | } |
---|
| 2578 | } |
---|
| 2579 | |
---|
| 2580 | ra = this.runAttrs[attr] = [start]; |
---|
| 2581 | if (control.length > 0) { |
---|
| 2582 | ra = ra.concat(control); |
---|
| 2583 | } |
---|
| 2584 | |
---|
| 2585 | ra[ra.length] = end; |
---|
| 2586 | }else{ |
---|
| 2587 | superclass.setRunAttr.call(this, attr); |
---|
| 2588 | } |
---|
| 2589 | } |
---|
| 2590 | }); |
---|
| 2591 | |
---|
| 2592 | var translateValues = function(val, start) { |
---|
| 2593 | var pageXY = EXTLIB.Dom.getXY(this.el); |
---|
| 2594 | return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]]; |
---|
| 2595 | }; |
---|
| 2596 | })(); |
---|
| 2597 | })();// Easing functions |
---|
| 2598 | (function(){ |
---|
| 2599 | // shortcuts to aid compression |
---|
| 2600 | var abs = Math.abs, |
---|
| 2601 | pi = Math.PI, |
---|
| 2602 | asin = Math.asin, |
---|
| 2603 | pow = Math.pow, |
---|
| 2604 | sin = Math.sin, |
---|
| 2605 | EXTLIB = Ext.lib; |
---|
| 2606 | |
---|
| 2607 | Ext.apply(EXTLIB.Easing, { |
---|
| 2608 | |
---|
| 2609 | easeBoth: function (t, b, c, d) { |
---|
| 2610 | return ((t /= d / 2) < 1) ? c / 2 * t * t + b : -c / 2 * ((--t) * (t - 2) - 1) + b; |
---|
| 2611 | }, |
---|
| 2612 | |
---|
| 2613 | easeInStrong: function (t, b, c, d) { |
---|
| 2614 | return c * (t /= d) * t * t * t + b; |
---|
| 2615 | }, |
---|
| 2616 | |
---|
| 2617 | easeOutStrong: function (t, b, c, d) { |
---|
| 2618 | return -c * ((t = t / d - 1) * t * t * t - 1) + b; |
---|
| 2619 | }, |
---|
| 2620 | |
---|
| 2621 | easeBothStrong: function (t, b, c, d) { |
---|
| 2622 | return ((t /= d / 2) < 1) ? c / 2 * t * t * t * t + b : -c / 2 * ((t -= 2) * t * t * t - 2) + b; |
---|
| 2623 | }, |
---|
| 2624 | |
---|
| 2625 | elasticIn: function (t, b, c, d, a, p) { |
---|
| 2626 | if (t == 0 || (t /= d) == 1) { |
---|
| 2627 | return t == 0 ? b : b + c; |
---|
| 2628 | } |
---|
| 2629 | p = p || (d * .3); |
---|
| 2630 | |
---|
| 2631 | var s; |
---|
| 2632 | if (a >= abs(c)) { |
---|
| 2633 | s = p / (2 * pi) * asin(c / a); |
---|
| 2634 | } else { |
---|
| 2635 | a = c; |
---|
| 2636 | s = p / 4; |
---|
| 2637 | } |
---|
| 2638 | |
---|
| 2639 | return -(a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b; |
---|
| 2640 | |
---|
| 2641 | }, |
---|
| 2642 | |
---|
| 2643 | elasticOut: function (t, b, c, d, a, p) { |
---|
| 2644 | if (t == 0 || (t /= d) == 1) { |
---|
| 2645 | return t == 0 ? b : b + c; |
---|
| 2646 | } |
---|
| 2647 | p = p || (d * .3); |
---|
| 2648 | |
---|
| 2649 | var s; |
---|
| 2650 | if (a >= abs(c)) { |
---|
| 2651 | s = p / (2 * pi) * asin(c / a); |
---|
| 2652 | } else { |
---|
| 2653 | a = c; |
---|
| 2654 | s = p / 4; |
---|
| 2655 | } |
---|
| 2656 | |
---|
| 2657 | return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b; |
---|
| 2658 | }, |
---|
| 2659 | |
---|
| 2660 | elasticBoth: function (t, b, c, d, a, p) { |
---|
| 2661 | if (t == 0 || (t /= d / 2) == 2) { |
---|
| 2662 | return t == 0 ? b : b + c; |
---|
| 2663 | } |
---|
| 2664 | |
---|
| 2665 | p = p || (d * (.3 * 1.5)); |
---|
| 2666 | |
---|
| 2667 | var s; |
---|
| 2668 | if (a >= abs(c)) { |
---|
| 2669 | s = p / (2 * pi) * asin(c / a); |
---|
| 2670 | } else { |
---|
| 2671 | a = c; |
---|
| 2672 | s = p / 4; |
---|
| 2673 | } |
---|
| 2674 | |
---|
| 2675 | return t < 1 ? |
---|
| 2676 | -.5 * (a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b : |
---|
| 2677 | a * pow(2, -10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p) * .5 + c + b; |
---|
| 2678 | }, |
---|
| 2679 | |
---|
| 2680 | backIn: function (t, b, c, d, s) { |
---|
| 2681 | s = s || 1.70158; |
---|
| 2682 | return c * (t /= d) * t * ((s + 1) * t - s) + b; |
---|
| 2683 | }, |
---|
| 2684 | |
---|
| 2685 | |
---|
| 2686 | backOut: function (t, b, c, d, s) { |
---|
| 2687 | if (!s) { |
---|
| 2688 | s = 1.70158; |
---|
| 2689 | } |
---|
| 2690 | return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; |
---|
| 2691 | }, |
---|
| 2692 | |
---|
| 2693 | |
---|
| 2694 | backBoth: function (t, b, c, d, s) { |
---|
| 2695 | s = s || 1.70158; |
---|
| 2696 | |
---|
| 2697 | return ((t /= d / 2 ) < 1) ? |
---|
| 2698 | c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b : |
---|
| 2699 | c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; |
---|
| 2700 | }, |
---|
| 2701 | |
---|
| 2702 | |
---|
| 2703 | bounceIn: function (t, b, c, d) { |
---|
| 2704 | return c - EXTLIB.Easing.bounceOut(d - t, 0, c, d) + b; |
---|
| 2705 | }, |
---|
| 2706 | |
---|
| 2707 | |
---|
| 2708 | bounceOut: function (t, b, c, d) { |
---|
| 2709 | if ((t /= d) < (1 / 2.75)) { |
---|
| 2710 | return c * (7.5625 * t * t) + b; |
---|
| 2711 | } else if (t < (2 / 2.75)) { |
---|
| 2712 | return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; |
---|
| 2713 | } else if (t < (2.5 / 2.75)) { |
---|
| 2714 | return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; |
---|
| 2715 | } |
---|
| 2716 | return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; |
---|
| 2717 | }, |
---|
| 2718 | |
---|
| 2719 | |
---|
| 2720 | bounceBoth: function (t, b, c, d) { |
---|
| 2721 | return (t < d / 2) ? |
---|
| 2722 | EXTLIB.Easing.bounceIn(t * 2, 0, c, d) * .5 + b : |
---|
| 2723 | EXTLIB.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b; |
---|
| 2724 | } |
---|
| 2725 | }); |
---|
| 2726 | })(); |
---|
| 2727 | |
---|
| 2728 | (function() { |
---|
| 2729 | var EXTLIB = Ext.lib; |
---|
| 2730 | // Color Animation |
---|
| 2731 | EXTLIB.Anim.color = function(el, args, duration, easing, cb, scope) { |
---|
| 2732 | return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.ColorAnim); |
---|
| 2733 | }; |
---|
| 2734 | |
---|
| 2735 | EXTLIB.ColorAnim = function(el, attributes, duration, method) { |
---|
| 2736 | EXTLIB.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method); |
---|
| 2737 | }; |
---|
| 2738 | |
---|
| 2739 | Ext.extend(EXTLIB.ColorAnim, EXTLIB.AnimBase); |
---|
| 2740 | |
---|
| 2741 | var superclass = EXTLIB.ColorAnim.superclass, |
---|
| 2742 | colorRE = /color$/i, |
---|
| 2743 | transparentRE = /^transparent|rgba\(0, 0, 0, 0\)$/, |
---|
| 2744 | rgbRE = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i, |
---|
| 2745 | hexRE= /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i, |
---|
| 2746 | hex3RE = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i, |
---|
| 2747 | isset = function(v){ |
---|
| 2748 | return typeof v !== 'undefined'; |
---|
| 2749 | }; |
---|
| 2750 | |
---|
| 2751 | // private |
---|
| 2752 | function parseColor(s) { |
---|
| 2753 | var pi = parseInt, |
---|
| 2754 | base, |
---|
| 2755 | out = null, |
---|
| 2756 | c; |
---|
| 2757 | |
---|
| 2758 | if (s.length == 3) { |
---|
| 2759 | return s; |
---|
| 2760 | } |
---|
| 2761 | |
---|
| 2762 | Ext.each([hexRE, rgbRE, hex3RE], function(re, idx){ |
---|
| 2763 | base = (idx % 2 == 0) ? 16 : 10; |
---|
| 2764 | c = re.exec(s); |
---|
| 2765 | if(c && c.length == 4){ |
---|
| 2766 | out = [pi(c[1], base), pi(c[2], base), pi(c[3], base)]; |
---|
| 2767 | return false; |
---|
| 2768 | } |
---|
| 2769 | }); |
---|
| 2770 | return out; |
---|
| 2771 | } |
---|
| 2772 | |
---|
| 2773 | Ext.apply(EXTLIB.ColorAnim.prototype, { |
---|
| 2774 | getAttr : function(attr) { |
---|
| 2775 | var me = this, |
---|
| 2776 | el = me.el, |
---|
| 2777 | val; |
---|
| 2778 | if(colorRE.test(attr)){ |
---|
| 2779 | while(el && transparentRE.test(val = Ext.fly(el).getStyle(attr))){ |
---|
| 2780 | el = el.parentNode; |
---|
| 2781 | val = "fff"; |
---|
| 2782 | } |
---|
| 2783 | }else{ |
---|
| 2784 | val = superclass.getAttr.call(me, attr); |
---|
| 2785 | } |
---|
| 2786 | return val; |
---|
| 2787 | }, |
---|
| 2788 | |
---|
| 2789 | doMethod : function(attr, start, end) { |
---|
| 2790 | var me = this, |
---|
| 2791 | val, |
---|
| 2792 | floor = Math.floor, |
---|
| 2793 | i, |
---|
| 2794 | len, |
---|
| 2795 | v; |
---|
| 2796 | |
---|
| 2797 | if(colorRE.test(attr)){ |
---|
| 2798 | val = []; |
---|
| 2799 | end = end || []; |
---|
| 2800 | |
---|
| 2801 | for(i = 0, len = start.length; i < len; i++) { |
---|
| 2802 | v = start[i]; |
---|
| 2803 | val[i] = superclass.doMethod.call(me, attr, v, end[i]); |
---|
| 2804 | } |
---|
| 2805 | val = 'rgb(' + floor(val[0]) + ',' + floor(val[1]) + ',' + floor(val[2]) + ')'; |
---|
| 2806 | }else{ |
---|
| 2807 | val = superclass.doMethod.call(me, attr, start, end); |
---|
| 2808 | } |
---|
| 2809 | return val; |
---|
| 2810 | }, |
---|
| 2811 | |
---|
| 2812 | setRunAttr : function(attr) { |
---|
| 2813 | var me = this, |
---|
| 2814 | a = me.attributes[attr], |
---|
| 2815 | to = a.to, |
---|
| 2816 | by = a.by, |
---|
| 2817 | ra; |
---|
| 2818 | |
---|
| 2819 | superclass.setRunAttr.call(me, attr); |
---|
| 2820 | ra = me.runAttrs[attr]; |
---|
| 2821 | if(colorRE.test(attr)){ |
---|
| 2822 | var start = parseColor(ra.start), |
---|
| 2823 | end = parseColor(ra.end); |
---|
| 2824 | |
---|
| 2825 | if(!isset(to) && isset(by)){ |
---|
| 2826 | end = parseColor(by); |
---|
| 2827 | for(var i=0,len=start.length; i<len; i++) { |
---|
| 2828 | end[i] = start[i] + end[i]; |
---|
| 2829 | } |
---|
| 2830 | } |
---|
| 2831 | ra.start = start; |
---|
| 2832 | ra.end = end; |
---|
| 2833 | } |
---|
| 2834 | } |
---|
| 2835 | }); |
---|
| 2836 | })(); |
---|
| 2837 | |
---|
| 2838 | |
---|
| 2839 | (function() { |
---|
| 2840 | // Scroll Animation |
---|
| 2841 | var EXTLIB = Ext.lib; |
---|
| 2842 | EXTLIB.Anim.scroll = function(el, args, duration, easing, cb, scope) { |
---|
| 2843 | return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.Scroll); |
---|
| 2844 | }; |
---|
| 2845 | |
---|
| 2846 | EXTLIB.Scroll = function(el, attributes, duration, method) { |
---|
| 2847 | if(el){ |
---|
| 2848 | EXTLIB.Scroll.superclass.constructor.call(this, el, attributes, duration, method); |
---|
| 2849 | } |
---|
| 2850 | }; |
---|
| 2851 | |
---|
| 2852 | Ext.extend(EXTLIB.Scroll, EXTLIB.ColorAnim); |
---|
| 2853 | |
---|
| 2854 | var superclass = EXTLIB.Scroll.superclass, |
---|
| 2855 | SCROLL = 'scroll'; |
---|
| 2856 | |
---|
| 2857 | Ext.apply(EXTLIB.Scroll.prototype, { |
---|
| 2858 | |
---|
| 2859 | doMethod : function(attr, start, end) { |
---|
| 2860 | var val, |
---|
| 2861 | me = this, |
---|
| 2862 | curFrame = me.curFrame, |
---|
| 2863 | totalFrames = me.totalFrames; |
---|
| 2864 | |
---|
| 2865 | if(attr == SCROLL){ |
---|
| 2866 | val = [me.method(curFrame, start[0], end[0] - start[0], totalFrames), |
---|
| 2867 | me.method(curFrame, start[1], end[1] - start[1], totalFrames)]; |
---|
| 2868 | }else{ |
---|
| 2869 | val = superclass.doMethod.call(me, attr, start, end); |
---|
| 2870 | } |
---|
| 2871 | return val; |
---|
| 2872 | }, |
---|
| 2873 | |
---|
| 2874 | getAttr : function(attr) { |
---|
| 2875 | var me = this; |
---|
| 2876 | |
---|
| 2877 | if (attr == SCROLL) { |
---|
| 2878 | return [me.el.scrollLeft, me.el.scrollTop]; |
---|
| 2879 | }else{ |
---|
| 2880 | return superclass.getAttr.call(me, attr); |
---|
| 2881 | } |
---|
| 2882 | }, |
---|
| 2883 | |
---|
| 2884 | setAttr : function(attr, val, unit) { |
---|
| 2885 | var me = this; |
---|
| 2886 | |
---|
| 2887 | if(attr == SCROLL){ |
---|
| 2888 | me.el.scrollLeft = val[0]; |
---|
| 2889 | me.el.scrollTop = val[1]; |
---|
| 2890 | }else{ |
---|
| 2891 | superclass.setAttr.call(me, attr, val, unit); |
---|
| 2892 | } |
---|
| 2893 | } |
---|
| 2894 | }); |
---|
| 2895 | })(); |
---|
| 2896 | if (Ext.isIE) { |
---|
| 2897 | function fnCleanUp() { |
---|
| 2898 | var p = Function.prototype; |
---|
| 2899 | delete p.createSequence; |
---|
| 2900 | delete p.defer; |
---|
| 2901 | delete p.createDelegate; |
---|
| 2902 | delete p.createCallback; |
---|
| 2903 | delete p.createInterceptor; |
---|
| 2904 | |
---|
| 2905 | window.detachEvent("onunload", fnCleanUp); |
---|
| 2906 | } |
---|
| 2907 | window.attachEvent("onunload", fnCleanUp); |
---|
| 2908 | } |
---|
| 2909 | })(); |
---|