[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();if(typeof YAHOO == "undefined"){ |
---|
| 1246 | throw "Unable to load Ext, core YUI utilities (yahoo, dom, event) not found."; |
---|
| 1247 | } |
---|
| 1248 | |
---|
| 1249 | (function(){ |
---|
| 1250 | var E = YAHOO.util.Event, |
---|
| 1251 | D = YAHOO.util.Dom, |
---|
| 1252 | CN = YAHOO.util.Connect, |
---|
| 1253 | ES = YAHOO.util.Easing, |
---|
| 1254 | A = YAHOO.util.Anim, |
---|
| 1255 | libFlyweight, |
---|
| 1256 | version = YAHOO.env.getVersion('yahoo').version.split('.'), |
---|
| 1257 | mouseEnterSupported = parseInt(version[0], 10) >= 3, |
---|
| 1258 | mouseCache = {}, |
---|
| 1259 | elContains = function(parent, child){ |
---|
| 1260 | if(parent && parent.firstChild){ |
---|
| 1261 | while(child){ |
---|
| 1262 | if(child === parent){ |
---|
| 1263 | return true; |
---|
| 1264 | } |
---|
| 1265 | child = child.parentNode; |
---|
| 1266 | if(child && (child.nodeType != 1)){ |
---|
| 1267 | child = null; |
---|
| 1268 | } |
---|
| 1269 | } |
---|
| 1270 | } |
---|
| 1271 | return false; |
---|
| 1272 | }, checkRelatedTarget = function(e){ |
---|
| 1273 | return !elContains(e.currentTarget, Ext.lib.Event.getRelatedTarget(e)); |
---|
| 1274 | }; |
---|
| 1275 | |
---|
| 1276 | Ext.lib.Dom = { |
---|
| 1277 | getViewWidth : function(full){ |
---|
| 1278 | return full ? D.getDocumentWidth() : D.getViewportWidth(); |
---|
| 1279 | }, |
---|
| 1280 | |
---|
| 1281 | getViewHeight : function(full){ |
---|
| 1282 | return full ? D.getDocumentHeight() : D.getViewportHeight(); |
---|
| 1283 | }, |
---|
| 1284 | |
---|
| 1285 | isAncestor : function(haystack, needle){ |
---|
| 1286 | return D.isAncestor(haystack, needle); |
---|
| 1287 | }, |
---|
| 1288 | |
---|
| 1289 | getRegion : function(el){ |
---|
| 1290 | return D.getRegion(el); |
---|
| 1291 | }, |
---|
| 1292 | |
---|
| 1293 | getY : function(el){ |
---|
| 1294 | return this.getXY(el)[1]; |
---|
| 1295 | }, |
---|
| 1296 | |
---|
| 1297 | getX : function(el){ |
---|
| 1298 | return this.getXY(el)[0]; |
---|
| 1299 | }, |
---|
| 1300 | |
---|
| 1301 | // original version based on YahooUI getXY |
---|
| 1302 | // this version fixes several issues in Safari and FF |
---|
| 1303 | // and boosts performance by removing the batch overhead, repetitive dom lookups and array index calls |
---|
| 1304 | getXY : function(el){ |
---|
| 1305 | var p, pe, b, scroll, bd = (document.body || document.documentElement); |
---|
| 1306 | el = Ext.getDom(el); |
---|
| 1307 | |
---|
| 1308 | if(el == bd){ |
---|
| 1309 | return [0, 0]; |
---|
| 1310 | } |
---|
| 1311 | |
---|
| 1312 | if (el.getBoundingClientRect) { |
---|
| 1313 | b = el.getBoundingClientRect(); |
---|
| 1314 | scroll = fly(document).getScroll(); |
---|
| 1315 | return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)]; |
---|
| 1316 | } |
---|
| 1317 | var x = 0, y = 0; |
---|
| 1318 | |
---|
| 1319 | p = el; |
---|
| 1320 | |
---|
| 1321 | var hasAbsolute = fly(el).getStyle("position") == "absolute"; |
---|
| 1322 | |
---|
| 1323 | while (p) { |
---|
| 1324 | |
---|
| 1325 | x += p.offsetLeft; |
---|
| 1326 | y += p.offsetTop; |
---|
| 1327 | |
---|
| 1328 | if (!hasAbsolute && fly(p).getStyle("position") == "absolute") { |
---|
| 1329 | hasAbsolute = true; |
---|
| 1330 | } |
---|
| 1331 | |
---|
| 1332 | if (Ext.isGecko) { |
---|
| 1333 | pe = fly(p); |
---|
| 1334 | |
---|
| 1335 | var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0; |
---|
| 1336 | var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0; |
---|
| 1337 | |
---|
| 1338 | |
---|
| 1339 | x += bl; |
---|
| 1340 | y += bt; |
---|
| 1341 | |
---|
| 1342 | |
---|
| 1343 | if (p != el && pe.getStyle('overflow') != 'visible') { |
---|
| 1344 | x += bl; |
---|
| 1345 | y += bt; |
---|
| 1346 | } |
---|
| 1347 | } |
---|
| 1348 | p = p.offsetParent; |
---|
| 1349 | } |
---|
| 1350 | |
---|
| 1351 | if (Ext.isSafari && hasAbsolute) { |
---|
| 1352 | x -= bd.offsetLeft; |
---|
| 1353 | y -= bd.offsetTop; |
---|
| 1354 | } |
---|
| 1355 | |
---|
| 1356 | if (Ext.isGecko && !hasAbsolute) { |
---|
| 1357 | var dbd = fly(bd); |
---|
| 1358 | x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0; |
---|
| 1359 | y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0; |
---|
| 1360 | } |
---|
| 1361 | |
---|
| 1362 | p = el.parentNode; |
---|
| 1363 | while (p && p != bd) { |
---|
| 1364 | if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) { |
---|
| 1365 | x -= p.scrollLeft; |
---|
| 1366 | y -= p.scrollTop; |
---|
| 1367 | } |
---|
| 1368 | p = p.parentNode; |
---|
| 1369 | } |
---|
| 1370 | return [x, y]; |
---|
| 1371 | }, |
---|
| 1372 | |
---|
| 1373 | setXY : function(el, xy){ |
---|
| 1374 | el = Ext.fly(el, '_setXY'); |
---|
| 1375 | el.position(); |
---|
| 1376 | var pts = el.translatePoints(xy); |
---|
| 1377 | if(xy[0] !== false){ |
---|
| 1378 | el.dom.style.left = pts.left + "px"; |
---|
| 1379 | } |
---|
| 1380 | if(xy[1] !== false){ |
---|
| 1381 | el.dom.style.top = pts.top + "px"; |
---|
| 1382 | } |
---|
| 1383 | }, |
---|
| 1384 | |
---|
| 1385 | setX : function(el, x){ |
---|
| 1386 | this.setXY(el, [x, false]); |
---|
| 1387 | }, |
---|
| 1388 | |
---|
| 1389 | setY : function(el, y){ |
---|
| 1390 | this.setXY(el, [false, y]); |
---|
| 1391 | } |
---|
| 1392 | }; |
---|
| 1393 | |
---|
| 1394 | Ext.lib.Event = { |
---|
| 1395 | getPageX : function(e){ |
---|
| 1396 | return E.getPageX(e.browserEvent || e); |
---|
| 1397 | }, |
---|
| 1398 | |
---|
| 1399 | getPageY : function(e){ |
---|
| 1400 | return E.getPageY(e.browserEvent || e); |
---|
| 1401 | }, |
---|
| 1402 | |
---|
| 1403 | getXY : function(e){ |
---|
| 1404 | return E.getXY(e.browserEvent || e); |
---|
| 1405 | }, |
---|
| 1406 | |
---|
| 1407 | getTarget : function(e){ |
---|
| 1408 | return E.getTarget(e.browserEvent || e); |
---|
| 1409 | }, |
---|
| 1410 | |
---|
| 1411 | getRelatedTarget : function(e){ |
---|
| 1412 | return E.getRelatedTarget(e.browserEvent || e); |
---|
| 1413 | }, |
---|
| 1414 | |
---|
| 1415 | on : function(el, eventName, fn, scope, override){ |
---|
| 1416 | if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){ |
---|
| 1417 | var item = mouseCache[el.id] || (mouseCache[el.id] = {}); |
---|
| 1418 | item[eventName] = fn; |
---|
| 1419 | fn = fn.createInterceptor(checkRelatedTarget); |
---|
| 1420 | eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout'; |
---|
| 1421 | } |
---|
| 1422 | E.on(el, eventName, fn, scope, override); |
---|
| 1423 | }, |
---|
| 1424 | |
---|
| 1425 | un : function(el, eventName, fn){ |
---|
| 1426 | if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){ |
---|
| 1427 | var item = mouseCache[el.id], |
---|
| 1428 | ev = item && item[eventName]; |
---|
| 1429 | |
---|
| 1430 | if(ev){ |
---|
| 1431 | fn = ev.fn; |
---|
| 1432 | delete item[eventName]; |
---|
| 1433 | eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout'; |
---|
| 1434 | } |
---|
| 1435 | } |
---|
| 1436 | E.removeListener(el, eventName, fn);; |
---|
| 1437 | }, |
---|
| 1438 | |
---|
| 1439 | purgeElement : function(el){ |
---|
| 1440 | E.purgeElement(el); |
---|
| 1441 | }, |
---|
| 1442 | |
---|
| 1443 | preventDefault : function(e){ |
---|
| 1444 | E.preventDefault(e.browserEvent || e); |
---|
| 1445 | }, |
---|
| 1446 | |
---|
| 1447 | stopPropagation : function(e){ |
---|
| 1448 | E.stopPropagation(e.browserEvent || e); |
---|
| 1449 | }, |
---|
| 1450 | |
---|
| 1451 | stopEvent : function(e){ |
---|
| 1452 | E.stopEvent(e.browserEvent || e); |
---|
| 1453 | }, |
---|
| 1454 | |
---|
| 1455 | onAvailable : function(el, fn, scope, override){ |
---|
| 1456 | return E.onAvailable(el, fn, scope, override); |
---|
| 1457 | } |
---|
| 1458 | }; |
---|
| 1459 | |
---|
| 1460 | Ext.lib.Ajax = { |
---|
| 1461 | request : function(method, uri, cb, data, options){ |
---|
| 1462 | if(options){ |
---|
| 1463 | var hs = options.headers; |
---|
| 1464 | if(hs){ |
---|
| 1465 | for(var h in hs){ |
---|
| 1466 | if(hs.hasOwnProperty(h)){ |
---|
| 1467 | CN.initHeader(h, hs[h], false); |
---|
| 1468 | } |
---|
| 1469 | } |
---|
| 1470 | } |
---|
| 1471 | if(options.xmlData){ |
---|
| 1472 | if (!hs || !hs['Content-Type']){ |
---|
| 1473 | CN.initHeader('Content-Type', 'text/xml', false); |
---|
| 1474 | } |
---|
| 1475 | method = (method ? method : (options.method ? options.method : 'POST')); |
---|
| 1476 | data = options.xmlData; |
---|
| 1477 | }else if(options.jsonData){ |
---|
| 1478 | if (!hs || !hs['Content-Type']){ |
---|
| 1479 | CN.initHeader('Content-Type', 'application/json', false); |
---|
| 1480 | } |
---|
| 1481 | method = (method ? method : (options.method ? options.method : 'POST')); |
---|
| 1482 | data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData; |
---|
| 1483 | } |
---|
| 1484 | } |
---|
| 1485 | return CN.asyncRequest(method, uri, cb, data); |
---|
| 1486 | }, |
---|
| 1487 | |
---|
| 1488 | formRequest : function(form, uri, cb, data, isUpload, sslUri){ |
---|
| 1489 | CN.setForm(form, isUpload, sslUri); |
---|
| 1490 | return CN.asyncRequest(Ext.getDom(form).method ||'POST', uri, cb, data); |
---|
| 1491 | }, |
---|
| 1492 | |
---|
| 1493 | isCallInProgress : function(trans){ |
---|
| 1494 | return CN.isCallInProgress(trans); |
---|
| 1495 | }, |
---|
| 1496 | |
---|
| 1497 | abort : function(trans){ |
---|
| 1498 | return CN.abort(trans); |
---|
| 1499 | }, |
---|
| 1500 | |
---|
| 1501 | serializeForm : function(form){ |
---|
| 1502 | var d = CN.setForm(form.dom || form); |
---|
| 1503 | CN.resetFormState(); |
---|
| 1504 | return d; |
---|
| 1505 | } |
---|
| 1506 | }; |
---|
| 1507 | |
---|
| 1508 | Ext.lib.Region = YAHOO.util.Region; |
---|
| 1509 | Ext.lib.Point = YAHOO.util.Point; |
---|
| 1510 | |
---|
| 1511 | |
---|
| 1512 | Ext.lib.Anim = { |
---|
| 1513 | scroll : function(el, args, duration, easing, cb, scope){ |
---|
| 1514 | this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll); |
---|
| 1515 | }, |
---|
| 1516 | |
---|
| 1517 | motion : function(el, args, duration, easing, cb, scope){ |
---|
| 1518 | this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion); |
---|
| 1519 | }, |
---|
| 1520 | |
---|
| 1521 | color : function(el, args, duration, easing, cb, scope){ |
---|
| 1522 | this.run(el, args, duration, easing, cb, scope, YAHOO.util.ColorAnim); |
---|
| 1523 | }, |
---|
| 1524 | |
---|
| 1525 | run : function(el, args, duration, easing, cb, scope, type){ |
---|
| 1526 | type = type || YAHOO.util.Anim; |
---|
| 1527 | if(typeof easing == "string"){ |
---|
| 1528 | easing = YAHOO.util.Easing[easing]; |
---|
| 1529 | } |
---|
| 1530 | var anim = new type(el, args, duration, easing); |
---|
| 1531 | anim.animateX(function(){ |
---|
| 1532 | Ext.callback(cb, scope); |
---|
| 1533 | }); |
---|
| 1534 | return anim; |
---|
| 1535 | } |
---|
| 1536 | }; |
---|
| 1537 | |
---|
| 1538 | // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights |
---|
| 1539 | function fly(el){ |
---|
| 1540 | if(!libFlyweight){ |
---|
| 1541 | libFlyweight = new Ext.Element.Flyweight(); |
---|
| 1542 | } |
---|
| 1543 | libFlyweight.dom = el; |
---|
| 1544 | return libFlyweight; |
---|
| 1545 | } |
---|
| 1546 | |
---|
| 1547 | // prevent IE leaks |
---|
| 1548 | if(Ext.isIE) { |
---|
| 1549 | function fnCleanUp() { |
---|
| 1550 | var p = Function.prototype; |
---|
| 1551 | delete p.createSequence; |
---|
| 1552 | delete p.defer; |
---|
| 1553 | delete p.createDelegate; |
---|
| 1554 | delete p.createCallback; |
---|
| 1555 | delete p.createInterceptor; |
---|
| 1556 | |
---|
| 1557 | window.detachEvent("onunload", fnCleanUp); |
---|
| 1558 | } |
---|
| 1559 | window.attachEvent("onunload", fnCleanUp); |
---|
| 1560 | } |
---|
| 1561 | // various overrides |
---|
| 1562 | |
---|
| 1563 | // add ability for callbacks with animations |
---|
| 1564 | if(YAHOO.util.Anim){ |
---|
| 1565 | YAHOO.util.Anim.prototype.animateX = function(callback, scope){ |
---|
| 1566 | var f = function(){ |
---|
| 1567 | this.onComplete.unsubscribe(f); |
---|
| 1568 | if(typeof callback == "function"){ |
---|
| 1569 | callback.call(scope || this, this); |
---|
| 1570 | } |
---|
| 1571 | }; |
---|
| 1572 | this.onComplete.subscribe(f, this, true); |
---|
| 1573 | this.animate(); |
---|
| 1574 | }; |
---|
| 1575 | } |
---|
| 1576 | |
---|
| 1577 | if(YAHOO.util.DragDrop && Ext.dd.DragDrop){ |
---|
| 1578 | YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding; |
---|
| 1579 | YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo; |
---|
| 1580 | } |
---|
| 1581 | |
---|
| 1582 | YAHOO.util.Dom.getXY = function(el) { |
---|
| 1583 | var f = function(el) { |
---|
| 1584 | return Ext.lib.Dom.getXY(el); |
---|
| 1585 | }; |
---|
| 1586 | return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true); |
---|
| 1587 | }; |
---|
| 1588 | |
---|
| 1589 | |
---|
| 1590 | // workaround for Safari anim duration speed problems |
---|
| 1591 | if(YAHOO.util.AnimMgr){ |
---|
| 1592 | YAHOO.util.AnimMgr.fps = 1000; |
---|
| 1593 | } |
---|
| 1594 | |
---|
| 1595 | YAHOO.util.Region.prototype.adjust = function(t, l, b, r){ |
---|
| 1596 | this.top += t; |
---|
| 1597 | this.left += l; |
---|
| 1598 | this.right += r; |
---|
| 1599 | this.bottom += b; |
---|
| 1600 | return this; |
---|
| 1601 | }; |
---|
| 1602 | |
---|
| 1603 | YAHOO.util.Region.prototype.constrainTo = function(r) { |
---|
| 1604 | this.top = this.top.constrain(r.top, r.bottom); |
---|
| 1605 | this.bottom = this.bottom.constrain(r.top, r.bottom); |
---|
| 1606 | this.left = this.left.constrain(r.left, r.right); |
---|
| 1607 | this.right = this.right.constrain(r.left, r.right); |
---|
| 1608 | return this; |
---|
| 1609 | }; |
---|
| 1610 | |
---|
| 1611 | |
---|
| 1612 | })(); |
---|