PageRenderTime 73ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/googleappengine/news/war/ext2/source/core/Ext.js

https://github.com/fffej/ClojureProjects
JavaScript | 1060 lines | 873 code | 23 blank | 164 comment | 61 complexity | f36a2aab53b1c1380abd20a53b702754 MD5 | raw file
  1. /*
  2. * Ext JS Library 2.2.1
  3. * Copyright(c) 2006-2009, Ext JS, LLC.
  4. * licensing@extjs.com
  5. *
  6. * http://extjs.com/license
  7. */
  8. Ext = {version: '2.2.1'};
  9. // for old browsers
  10. window["undefined"] = window["undefined"];
  11. /**
  12. * @class Ext
  13. * Ext core utilities and functions.
  14. * @singleton
  15. */
  16. /**
  17. * Copies all the properties of config to obj.
  18. * @param {Object} obj The receiver of the properties
  19. * @param {Object} config The source of the properties
  20. * @param {Object} defaults A different object that will also be applied for default values
  21. * @return {Object} returns obj
  22. * @member Ext apply
  23. */
  24. Ext.apply = function(o, c, defaults){
  25. if(defaults){
  26. // no "this" reference for friendly out of scope calls
  27. Ext.apply(o, defaults);
  28. }
  29. if(o && c && typeof c == 'object'){
  30. for(var p in c){
  31. o[p] = c[p];
  32. }
  33. }
  34. return o;
  35. };
  36. (function(){
  37. var idSeed = 0;
  38. var ua = navigator.userAgent.toLowerCase();
  39. var isStrict = document.compatMode == "CSS1Compat",
  40. isOpera = ua.indexOf("opera") > -1,
  41. isChrome = ua.indexOf("chrome") > -1,
  42. isSafari = !isChrome && (/webkit|khtml/).test(ua),
  43. isSafari3 = isSafari && ua.indexOf('webkit/5') != -1,
  44. isIE = !isOpera && ua.indexOf("msie") > -1,
  45. isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
  46. isIE8 = !isOpera && ua.indexOf("msie 8") > -1,
  47. isGecko = !isSafari && !isChrome && ua.indexOf("gecko") > -1,
  48. isGecko3 = isGecko && ua.indexOf("rv:1.9") > -1,
  49. isBorderBox = isIE && !isStrict,
  50. isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
  51. isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
  52. isAir = (ua.indexOf("adobeair") != -1),
  53. isLinux = (ua.indexOf("linux") != -1),
  54. isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
  55. // remove css image flicker
  56. if(isIE && !isIE7){
  57. try{
  58. document.execCommand("BackgroundImageCache", false, true);
  59. }catch(e){}
  60. }
  61. Ext.apply(Ext, {
  62. /**
  63. * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
  64. * @type Boolean
  65. */
  66. isStrict : isStrict,
  67. /**
  68. * True if the page is running over SSL
  69. * @type Boolean
  70. */
  71. isSecure : isSecure,
  72. /**
  73. * True when the document is fully initialized and ready for action
  74. * @type Boolean
  75. */
  76. isReady : false,
  77. /**
  78. * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
  79. * @type Boolean
  80. */
  81. enableGarbageCollector : true,
  82. /**
  83. * True to automatically purge event listeners after uncaching an element (defaults to false).
  84. * Note: this only happens if enableGarbageCollector is true.
  85. * @type Boolean
  86. */
  87. enableListenerCollection:false,
  88. /**
  89. * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
  90. * the IE insecure content warning (defaults to javascript:false).
  91. * @type String
  92. */
  93. SSL_SECURE_URL : "javascript:false",
  94. /**
  95. * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images. (Defaults to
  96. * "http://extjs.com/s.gif" and you should change this to a URL on your server).
  97. * @type String
  98. */
  99. BLANK_IMAGE_URL : "http:/"+"/extjs.com/s.gif",
  100. /**
  101. * A reusable empty function
  102. * @property
  103. * @type Function
  104. */
  105. emptyFn : function(){},
  106. /**
  107. * Copies all the properties of config to obj if they don't already exist.
  108. * @param {Object} obj The receiver of the properties
  109. * @param {Object} config The source of the properties
  110. * @return {Object} returns obj
  111. */
  112. applyIf : function(o, c){
  113. if(o && c){
  114. for(var p in c){
  115. if(typeof o[p] == "undefined"){ o[p] = c[p]; }
  116. }
  117. }
  118. return o;
  119. },
  120. /**
  121. * Applies event listeners to elements by selectors when the document is ready.
  122. * The event name is specified with an @ suffix.
  123. <pre><code>
  124. Ext.addBehaviors({
  125. // add a listener for click on all anchors in element with id foo
  126. '#foo a@click' : function(e, t){
  127. // do something
  128. },
  129. // add the same listener to multiple selectors (separated by comma BEFORE the @)
  130. '#foo a, #bar span.some-class@mouseover' : function(){
  131. // do something
  132. }
  133. });
  134. </code></pre>
  135. * @param {Object} obj The list of behaviors to apply
  136. */
  137. addBehaviors : function(o){
  138. if(!Ext.isReady){
  139. Ext.onReady(function(){
  140. Ext.addBehaviors(o);
  141. });
  142. return;
  143. }
  144. var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times
  145. for(var b in o){
  146. var parts = b.split('@');
  147. if(parts[1]){ // for Object prototype breakers
  148. var s = parts[0];
  149. if(!cache[s]){
  150. cache[s] = Ext.select(s);
  151. }
  152. cache[s].on(parts[1], o[b]);
  153. }
  154. }
  155. cache = null;
  156. },
  157. /**
  158. * Generates unique ids. If the element already has an id, it is unchanged
  159. * @param {Mixed} el (optional) The element to generate an id for
  160. * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
  161. * @return {String} The generated Id.
  162. */
  163. id : function(el, prefix){
  164. prefix = prefix || "ext-gen";
  165. el = Ext.getDom(el);
  166. var id = prefix + (++idSeed);
  167. return el ? (el.id ? el.id : (el.id = id)) : id;
  168. },
  169. /**
  170. * Extends one class with another class and optionally overrides members with the passed literal. This class
  171. * also adds the function "override()" to the class that can be used to override
  172. * members on an instance.
  173. * * <p>
  174. * This function also supports a 2-argument call in which the subclass's constructor is
  175. * not passed as an argument. In this form, the parameters are as follows:</p><p>
  176. * <div class="mdetail-params"><ul>
  177. * <li><code>superclass</code>
  178. * <div class="sub-desc">The class being extended</div></li>
  179. * <li><code>overrides</code>
  180. * <div class="sub-desc">A literal with members which are copied into the subclass's
  181. * prototype, and are therefore shared among all instances of the new class.<p>
  182. * This may contain a special member named <tt><b>constructor</b></tt>. This is used
  183. * to define the constructor of the new class, and is returned. If this property is
  184. * <i>not</i> specified, a constructor is generated and returned which just calls the
  185. * superclass's constructor passing on its parameters.</p></div></li>
  186. * </ul></div></p><p>
  187. * For example, to create a subclass of the Ext GridPanel:
  188. * <pre><code>
  189. MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
  190. constructor: function(config) {
  191. // Your preprocessing here
  192. MyGridPanel.superclass.constructor.apply(this, arguments);
  193. // Your postprocessing here
  194. },
  195. yourMethod: function() {
  196. // etc.
  197. }
  198. });
  199. </code></pre>
  200. * </p>
  201. * @param {Function} subclass The class inheriting the functionality
  202. * @param {Function} superclass The class being extended
  203. * @param {Object} overrides (optional) A literal with members which are copied into the subclass's
  204. * prototype, and are therefore shared between all instances of the new class.
  205. * @return {Function} The subclass constructor.
  206. * @method extend
  207. */
  208. extend : function(){
  209. // inline overrides
  210. var io = function(o){
  211. for(var m in o){
  212. this[m] = o[m];
  213. }
  214. };
  215. var oc = Object.prototype.constructor;
  216. return function(sb, sp, overrides){
  217. if(typeof sp == 'object'){
  218. overrides = sp;
  219. sp = sb;
  220. sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
  221. }
  222. var F = function(){}, sbp, spp = sp.prototype;
  223. F.prototype = spp;
  224. sbp = sb.prototype = new F();
  225. sbp.constructor=sb;
  226. sb.superclass=spp;
  227. if(spp.constructor == oc){
  228. spp.constructor=sp;
  229. }
  230. sb.override = function(o){
  231. Ext.override(sb, o);
  232. };
  233. sbp.override = io;
  234. Ext.override(sb, overrides);
  235. sb.extend = function(o){Ext.extend(sb, o);};
  236. return sb;
  237. };
  238. }(),
  239. /**
  240. * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
  241. * Usage:<pre><code>
  242. Ext.override(MyClass, {
  243. newMethod1: function(){
  244. // etc.
  245. },
  246. newMethod2: function(foo){
  247. // etc.
  248. }
  249. });
  250. </code></pre>
  251. * @param {Object} origclass The class to override
  252. * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
  253. * containing one or more methods.
  254. * @method override
  255. */
  256. override : function(origclass, overrides){
  257. if(overrides){
  258. var p = origclass.prototype;
  259. for(var method in overrides){
  260. p[method] = overrides[method];
  261. }
  262. if(Ext.isIE && overrides.toString != origclass.toString){
  263. p.toString = overrides.toString;
  264. }
  265. }
  266. },
  267. /**
  268. * Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
  269. * <pre><code>
  270. Ext.namespace('Company', 'Company.data');
  271. Company.Widget = function() { ... }
  272. Company.data.CustomStore = function(config) { ... }
  273. </code></pre>
  274. * @param {String} namespace1
  275. * @param {String} namespace2
  276. * @param {String} etc
  277. * @method namespace
  278. */
  279. namespace : function(){
  280. var a=arguments, o=null, i, j, d, rt;
  281. for (i=0; i<a.length; ++i) {
  282. d=a[i].split(".");
  283. rt = d[0];
  284. eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
  285. for (j=1; j<d.length; ++j) {
  286. o[d[j]]=o[d[j]] || {};
  287. o=o[d[j]];
  288. }
  289. }
  290. },
  291. /**
  292. * 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.
  293. * @param {Object} o
  294. * @return {String}
  295. */
  296. urlEncode : function(o){
  297. if(!o){
  298. return "";
  299. }
  300. var buf = [];
  301. for(var key in o){
  302. var ov = o[key], k = encodeURIComponent(key);
  303. var type = typeof ov;
  304. if(type == 'undefined'){
  305. buf.push(k, "=&");
  306. }else if(type != "function" && type != "object"){
  307. buf.push(k, "=", encodeURIComponent(ov), "&");
  308. }else if(Ext.isDate(ov)){
  309. var s = Ext.encode(ov).replace(/"/g, '');
  310. buf.push(k, "=", s, "&");
  311. }else if(Ext.isArray(ov)){
  312. if (ov.length) {
  313. for(var i = 0, len = ov.length; i < len; i++) {
  314. buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
  315. }
  316. } else {
  317. buf.push(k, "=&");
  318. }
  319. }
  320. }
  321. buf.pop();
  322. return buf.join("");
  323. },
  324. /**
  325. * Takes an encoded URL and and converts it to an object. e.g. Ext.urlDecode("foo=1&bar=2"); would return {foo: "1", bar: "2"}
  326. * or Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); would return {foo: "1", bar: ["2", "3", "4"]}.
  327. * @param {String} string
  328. * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
  329. * @return {Object} A literal with members
  330. */
  331. urlDecode : function(string, overwrite){
  332. if(!string || !string.length){
  333. return {};
  334. }
  335. var obj = {};
  336. var pairs = string.split('&');
  337. var pair, name, value;
  338. for(var i = 0, len = pairs.length; i < len; i++){
  339. pair = pairs[i].split('=');
  340. name = decodeURIComponent(pair[0]);
  341. value = decodeURIComponent(pair[1]);
  342. if(overwrite !== true){
  343. if(typeof obj[name] == "undefined"){
  344. obj[name] = value;
  345. }else if(typeof obj[name] == "string"){
  346. obj[name] = [obj[name]];
  347. obj[name].push(value);
  348. }else{
  349. obj[name].push(value);
  350. }
  351. }else{
  352. obj[name] = value;
  353. }
  354. }
  355. return obj;
  356. },
  357. /**
  358. * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
  359. * passed array is not really an array, your function is called once with it.
  360. * The supplied function is called with (Object item, Number index, Array allItems).
  361. * @param {Array/NodeList/Mixed} array
  362. * @param {Function} fn
  363. * @param {Object} scope
  364. */
  365. each : function(array, fn, scope){
  366. if(typeof array.length == "undefined" || typeof array == "string"){
  367. array = [array];
  368. }
  369. for(var i = 0, len = array.length; i < len; i++){
  370. if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
  371. }
  372. },
  373. // deprecated
  374. combine : function(){
  375. var as = arguments, l = as.length, r = [];
  376. for(var i = 0; i < l; i++){
  377. var a = as[i];
  378. if(Ext.isArray(a)){
  379. r = r.concat(a);
  380. }else if(a.length !== undefined && !a.substr){
  381. r = r.concat(Array.prototype.slice.call(a, 0));
  382. }else{
  383. r.push(a);
  384. }
  385. }
  386. return r;
  387. },
  388. /**
  389. * Escapes the passed string for use in a regular expression
  390. * @param {String} str
  391. * @return {String}
  392. */
  393. escapeRe : function(s) {
  394. return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
  395. },
  396. // internal
  397. callback : function(cb, scope, args, delay){
  398. if(typeof cb == "function"){
  399. if(delay){
  400. cb.defer(delay, scope, args || []);
  401. }else{
  402. cb.apply(scope, args || []);
  403. }
  404. }
  405. },
  406. /**
  407. * Return the dom node for the passed string (id), dom node, or Ext.Element
  408. * @param {Mixed} el
  409. * @return HTMLElement
  410. */
  411. getDom : function(el){
  412. if(!el || !document){
  413. return null;
  414. }
  415. return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
  416. },
  417. /**
  418. * Returns the current HTML document object as an {@link Ext.Element}.
  419. * @return Ext.Element The document
  420. */
  421. getDoc : function(){
  422. return Ext.get(document);
  423. },
  424. /**
  425. * Returns the current document body as an {@link Ext.Element}.
  426. * @return Ext.Element The document body
  427. */
  428. getBody : function(){
  429. return Ext.get(document.body || document.documentElement);
  430. },
  431. /**
  432. * Shorthand for {@link Ext.ComponentMgr#get}
  433. * @param {String} id
  434. * @return Ext.Component
  435. */
  436. getCmp : function(id){
  437. return Ext.ComponentMgr.get(id);
  438. },
  439. /**
  440. * Utility method for validating that a value is numeric, returning the specified default value if it is not.
  441. * @param {Mixed} value Should be a number, but any type will be handled appropriately
  442. * @param {Number} defaultValue The value to return if the original value is non-numeric
  443. * @return {Number} Value, if numeric, else defaultValue
  444. */
  445. num : function(v, defaultValue){
  446. if(typeof v != 'number' || isNaN(v)){
  447. return defaultValue;
  448. }
  449. return v;
  450. },
  451. /**
  452. * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
  453. * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
  454. * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
  455. * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
  456. * passed into this function in a single call as separate arguments.
  457. * @param {Mixed} arg1 An {@link Ext.Element} or {@link Ext.Component} to destroy
  458. * @param {Mixed} arg2 (optional)
  459. * @param {Mixed} etc... (optional)
  460. */
  461. destroy : function(){
  462. for(var i = 0, a = arguments, len = a.length; i < len; i++) {
  463. var as = a[i];
  464. if(as){
  465. if(typeof as.destroy == 'function'){
  466. as.destroy();
  467. }
  468. else if(as.dom){
  469. as.removeAllListeners();
  470. as.remove();
  471. }
  472. }
  473. }
  474. },
  475. /**
  476. * Removes a DOM node from the document. The body node will be ignored if passed in.
  477. * @param {HTMLElement} node The node to remove
  478. */
  479. removeNode : isIE ? function(){
  480. var d;
  481. return function(n){
  482. if(n && n.tagName != 'BODY'){
  483. d = d || document.createElement('div');
  484. d.appendChild(n);
  485. d.innerHTML = '';
  486. }
  487. }
  488. }() : function(n){
  489. if(n && n.parentNode && n.tagName != 'BODY'){
  490. n.parentNode.removeChild(n);
  491. }
  492. },
  493. // inpired by a similar function in mootools library
  494. /**
  495. * Returns the type of object that is passed in. If the object passed in is null or undefined it
  496. * return false otherwise it returns one of the following values:<ul>
  497. * <li><b>string</b>: If the object passed is a string</li>
  498. * <li><b>number</b>: If the object passed is a number</li>
  499. * <li><b>boolean</b>: If the object passed is a boolean value</li>
  500. * <li><b>date</b>: If the object passed is a Date object</li>
  501. * <li><b>function</b>: If the object passed is a function reference</li>
  502. * <li><b>object</b>: If the object passed is an object</li>
  503. * <li><b>array</b>: If the object passed is an array</li>
  504. * <li><b>regexp</b>: If the object passed is a regular expression</li>
  505. * <li><b>element</b>: If the object passed is a DOM Element</li>
  506. * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
  507. * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
  508. * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
  509. * @param {Mixed} object
  510. * @return {String}
  511. */
  512. type : function(o){
  513. if(o === undefined || o === null){
  514. return false;
  515. }
  516. if(o.htmlElement){
  517. return 'element';
  518. }
  519. var t = typeof o;
  520. if(t == 'object' && o.nodeName) {
  521. switch(o.nodeType) {
  522. case 1: return 'element';
  523. case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
  524. }
  525. }
  526. if(t == 'object' || t == 'function') {
  527. switch(o.constructor) {
  528. case Array: return 'array';
  529. case RegExp: return 'regexp';
  530. case Date: return 'date';
  531. }
  532. if(typeof o.length == 'number' && typeof o.item == 'function') {
  533. return 'nodelist';
  534. }
  535. }
  536. return t;
  537. },
  538. /**
  539. * Returns true if the passed value is null, undefined or an empty string.
  540. * @param {Mixed} value The value to test
  541. * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
  542. * @return {Boolean}
  543. */
  544. isEmpty : function(v, allowBlank){
  545. return v === null || v === undefined || (!allowBlank ? v === '' : false);
  546. },
  547. /**
  548. * Utility method for validating that a value is non-empty (i.e. i) not null, ii) not undefined, and iii) not an empty string),
  549. * returning the specified default value if it is.
  550. * @param {Mixed} value The value to test
  551. * @param {Mixed} defaultValue The value to return if the original value is empty
  552. * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
  553. * @return {Mixed} value, if non-empty, else defaultValue
  554. */
  555. value : function(v, defaultValue, allowBlank){
  556. return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
  557. },
  558. /**
  559. * Returns true if the passed object is a JavaScript array, otherwise false.
  560. * @param {Object} The object to test
  561. * @return {Boolean}
  562. */
  563. isArray : function(v){
  564. return v && typeof v.length == 'number' && typeof v.splice == 'function';
  565. },
  566. /**
  567. * Returns true if the passed object is a JavaScript date object, otherwise false.
  568. * @param {Object} The object to test
  569. * @return {Boolean}
  570. */
  571. isDate : function(v){
  572. return v && typeof v.getFullYear == 'function';
  573. },
  574. /**
  575. * True if the detected browser is Opera.
  576. * @type Boolean
  577. */
  578. isOpera : isOpera,
  579. /**
  580. * True if the detected browser is Chrome.
  581. * @type Boolean
  582. */
  583. isChrome : isChrome,
  584. /**
  585. * True if the detected browser is Safari.
  586. * @type Boolean
  587. */
  588. isSafari : isSafari,
  589. /**
  590. * True if the detected browser is Safari 3.x.
  591. * @type Boolean
  592. */
  593. isSafari3 : isSafari3,
  594. /**
  595. * True if the detected browser is Safari 2.x.
  596. * @type Boolean
  597. */
  598. isSafari2 : isSafari && !isSafari3,
  599. /**
  600. * True if the detected browser is Internet Explorer.
  601. * @type Boolean
  602. */
  603. isIE : isIE,
  604. /**
  605. * True if the detected browser is Internet Explorer 6.x.
  606. * @type Boolean
  607. */
  608. isIE6 : isIE && !isIE7 && !isIE8,
  609. /**
  610. * True if the detected browser is Internet Explorer 7.x.
  611. * @type Boolean
  612. */
  613. isIE7 : isIE7,
  614. /**
  615. * True if the detected browser is Internet Explorer 8.x.
  616. * @type Boolean
  617. */
  618. isIE8 : isIE8,
  619. /**
  620. * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
  621. * @type Boolean
  622. */
  623. isGecko : isGecko,
  624. /**
  625. * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
  626. * @type Boolean
  627. */
  628. isGecko2 : isGecko && !isGecko3,
  629. /**
  630. * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
  631. * @type Boolean
  632. */
  633. isGecko3 : isGecko3,
  634. /**
  635. * True if the detected browser is Internet Explorer running in non-strict mode.
  636. * @type Boolean
  637. */
  638. isBorderBox : isBorderBox,
  639. /**
  640. * True if the detected platform is Linux.
  641. * @type Boolean
  642. */
  643. isLinux : isLinux,
  644. /**
  645. * True if the detected platform is Windows.
  646. * @type Boolean
  647. */
  648. isWindows : isWindows,
  649. /**
  650. * True if the detected platform is Mac OS.
  651. * @type Boolean
  652. */
  653. isMac : isMac,
  654. /**
  655. * True if the detected platform is Adobe Air.
  656. * @type Boolean
  657. */
  658. isAir : isAir,
  659. /**
  660. * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
  661. * you may want to set this to true.
  662. * @type Boolean
  663. */
  664. useShims : ((isIE && !isIE7) || (isMac && isGecko && !isGecko3))
  665. });
  666. // in intellij using keyword "namespace" causes parsing errors
  667. Ext.ns = Ext.namespace;
  668. })();
  669. Ext.ns("Ext", "Ext.util", "Ext.grid", "Ext.dd", "Ext.tree", "Ext.data",
  670. "Ext.form", "Ext.menu", "Ext.state", "Ext.lib", "Ext.layout", "Ext.app", "Ext.ux");
  671. /**
  672. * @class Function
  673. * These functions are available on every Function object (any JavaScript function).
  674. */
  675. Ext.apply(Function.prototype, {
  676. /**
  677. * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
  678. * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
  679. * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
  680. * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
  681. * executes in the window scope.
  682. * <p>This method is required when you want to pass arguments to a callback function. If no arguments
  683. * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
  684. * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
  685. * would simply execute immediately when the code is parsed. Example usage:
  686. * <pre><code>
  687. var sayHi = function(name){
  688. alert('Hi, ' + name);
  689. }
  690. // clicking the button alerts "Hi, Fred"
  691. new Ext.Button({
  692. text: 'Say Hi',
  693. renderTo: Ext.getBody(),
  694. handler: sayHi.createCallback('Fred')
  695. });
  696. </code></pre>
  697. * @return {Function} The new function
  698. */
  699. createCallback : function(/*args...*/){
  700. // make args available, in function below
  701. var args = arguments;
  702. var method = this;
  703. return function() {
  704. return method.apply(window, args);
  705. };
  706. },
  707. /**
  708. * Creates a delegate (callback) that sets the scope to obj.
  709. * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
  710. * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
  711. * callback points to obj. Example usage:
  712. * <pre><code>
  713. var sayHi = function(name){
  714. // Note this use of "this.text" here. This function expects to
  715. // execute within a scope that contains a text property. In this
  716. // example, the "this" variable is pointing to the btn object that
  717. // was passed in createDelegate below.
  718. alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
  719. }
  720. var btn = new Ext.Button({
  721. text: 'Say Hi',
  722. renderTo: Ext.getBody()
  723. });
  724. // This callback will execute in the scope of the
  725. // button instance. Clicking the button alerts
  726. // "Hi, Fred. You clicked the "Say Hi" button."
  727. btn.on('click', sayHi.createDelegate(btn, ['Fred']));
  728. </code></pre>
  729. * @param {Object} obj (optional) The object for which the scope is set
  730. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  731. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  732. * if a number the args are inserted at the specified position
  733. * @return {Function} The new function
  734. */
  735. createDelegate : function(obj, args, appendArgs){
  736. var method = this;
  737. return function() {
  738. var callArgs = args || arguments;
  739. if(appendArgs === true){
  740. callArgs = Array.prototype.slice.call(arguments, 0);
  741. callArgs = callArgs.concat(args);
  742. }else if(typeof appendArgs == "number"){
  743. callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
  744. var applyArgs = [appendArgs, 0].concat(args); // create method call params
  745. Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
  746. }
  747. return method.apply(obj || window, callArgs);
  748. };
  749. },
  750. /**
  751. * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
  752. * <pre><code>
  753. var sayHi = function(name){
  754. alert('Hi, ' + name);
  755. }
  756. // executes immediately:
  757. sayHi('Fred');
  758. // executes after 2 seconds:
  759. sayHi.defer(2000, this, ['Fred']);
  760. // this syntax is sometimes useful for deferring
  761. // execution of an anonymous function:
  762. (function(){
  763. alert('Anonymous');
  764. }).defer(100);
  765. </code></pre>
  766. * @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)
  767. * @param {Object} obj (optional) The object for which the scope is set
  768. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  769. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  770. * if a number the args are inserted at the specified position
  771. * @return {Number} The timeout id that can be used with clearTimeout
  772. */
  773. defer : function(millis, obj, args, appendArgs){
  774. var fn = this.createDelegate(obj, args, appendArgs);
  775. if(millis){
  776. return setTimeout(fn, millis);
  777. }
  778. fn();
  779. return 0;
  780. },
  781. /**
  782. * Create a combined function call sequence of the original function + the passed function.
  783. * The resulting function returns the results of the original function.
  784. * The passed fcn is called with the parameters of the original function. Example usage:
  785. * <pre><code>
  786. var sayHi = function(name){
  787. alert('Hi, ' + name);
  788. }
  789. sayHi('Fred'); // alerts "Hi, Fred"
  790. var sayGoodbye = sayHi.createSequence(function(name){
  791. alert('Bye, ' + name);
  792. });
  793. sayGoodbye('Fred'); // both alerts show
  794. </code></pre>
  795. * @param {Function} fcn The function to sequence
  796. * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
  797. * @return {Function} The new function
  798. */
  799. createSequence : function(fcn, scope){
  800. if(typeof fcn != "function"){
  801. return this;
  802. }
  803. var method = this;
  804. return function() {
  805. var retval = method.apply(this || window, arguments);
  806. fcn.apply(scope || this || window, arguments);
  807. return retval;
  808. };
  809. },
  810. /**
  811. * Creates an interceptor function. The passed fcn is called before the original one. If it returns false,
  812. * the original one is not called. The resulting function returns the results of the original function.
  813. * The passed fcn is called with the parameters of the original function. Example usage:
  814. * <pre><code>
  815. var sayHi = function(name){
  816. alert('Hi, ' + name);
  817. }
  818. sayHi('Fred'); // alerts "Hi, Fred"
  819. // create a new function that validates input without
  820. // directly modifying the original function:
  821. var sayHiToFriend = sayHi.createInterceptor(function(name){
  822. return name == 'Brian';
  823. });
  824. sayHiToFriend('Fred'); // no alert
  825. sayHiToFriend('Brian'); // alerts "Hi, Brian"
  826. </code></pre>
  827. * @param {Function} fcn The function to call before the original
  828. * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
  829. * @return {Function} The new function
  830. */
  831. createInterceptor : function(fcn, scope){
  832. if(typeof fcn != "function"){
  833. return this;
  834. }
  835. var method = this;
  836. return function() {
  837. fcn.target = this;
  838. fcn.method = method;
  839. if(fcn.apply(scope || this || window, arguments) === false){
  840. return;
  841. }
  842. return method.apply(this || window, arguments);
  843. };
  844. }
  845. });
  846. /**
  847. * @class String
  848. * These functions are available as static methods on the JavaScript String object.
  849. */
  850. Ext.applyIf(String, {
  851. /**
  852. * Escapes the passed string for ' and \
  853. * @param {String} string The string to escape
  854. * @return {String} The escaped string
  855. * @static
  856. */
  857. escape : function(string) {
  858. return string.replace(/('|\\)/g, "\\$1");
  859. },
  860. /**
  861. * Pads the left side of a string with a specified character. This is especially useful
  862. * for normalizing number and date strings. Example usage:
  863. * <pre><code>
  864. var s = String.leftPad('123', 5, '0');
  865. // s now contains the string: '00123'
  866. </code></pre>
  867. * @param {String} string The original string
  868. * @param {Number} size The total length of the output string
  869. * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
  870. * @return {String} The padded string
  871. * @static
  872. */
  873. leftPad : function (val, size, ch) {
  874. var result = new String(val);
  875. if(!ch) {
  876. ch = " ";
  877. }
  878. while (result.length < size) {
  879. result = ch + result;
  880. }
  881. return result.toString();
  882. },
  883. /**
  884. * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
  885. * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
  886. * <pre><code>
  887. var cls = 'my-class', text = 'Some text';
  888. var s = String.format('&lt;div class="{0}">{1}&lt;/div>', cls, text);
  889. // s now contains the string: '&lt;div class="my-class">Some text&lt;/div>'
  890. </code></pre>
  891. * @param {String} string The tokenized string to be formatted
  892. * @param {String} value1 The value to replace token {0}
  893. * @param {String} value2 Etc...
  894. * @return {String} The formatted string
  895. * @static
  896. */
  897. format : function(format){
  898. var args = Array.prototype.slice.call(arguments, 1);
  899. return format.replace(/\{(\d+)\}/g, function(m, i){
  900. return args[i];
  901. });
  902. }
  903. });
  904. /**
  905. * Utility function that allows you to easily switch a string between two alternating values. The passed value
  906. * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
  907. * they are already different, the first value passed in is returned. Note that this method returns the new value
  908. * but does not change the current string.
  909. * <pre><code>
  910. // alternate sort directions
  911. sort = sort.toggle('ASC', 'DESC');
  912. // instead of conditional logic:
  913. sort = (sort == 'ASC' ? 'DESC' : 'ASC');
  914. </code></pre>
  915. * @param {String} value The value to compare to the current string
  916. * @param {String} other The new value to use if the string already equals the first value passed in
  917. * @return {String} The new value
  918. */
  919. String.prototype.toggle = function(value, other){
  920. return this == value ? other : value;
  921. };
  922. /**
  923. * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
  924. * <pre><code>
  925. var s = ' foo bar ';
  926. alert('-' + s + '-'); //alerts "- foo bar -"
  927. alert('-' + s.trim() + '-'); //alerts "-foo bar-"
  928. </code></pre>
  929. * @return {String} The trimmed string
  930. */
  931. String.prototype.trim = function(){
  932. var re = /^\s+|\s+$/g;
  933. return function(){ return this.replace(re, ""); };
  934. }();
  935. /**
  936. * @class Number
  937. */
  938. Ext.applyIf(Number.prototype, {
  939. /**
  940. * Checks whether or not the current number is within a desired range. If the number is already within the
  941. * range it is returned, otherwise the min or max value is returned depending on which side of the range is
  942. * exceeded. Note that this method returns the constrained value but does not change the current number.
  943. * @param {Number} min The minimum number in the range
  944. * @param {Number} max The maximum number in the range
  945. * @return {Number} The constrained value if outside the range, otherwise the current value
  946. */
  947. constrain : function(min, max){
  948. return Math.min(Math.max(this, min), max);
  949. }
  950. });
  951. /**
  952. * @class Array
  953. */
  954. Ext.applyIf(Array.prototype, {
  955. /**
  956. * Checks whether or not the specified object exists in the array.
  957. * @param {Object} o The object to check for
  958. * @return {Number} The index of o in the array (or -1 if it is not found)
  959. */
  960. indexOf : function(o){
  961. for (var i = 0, len = this.length; i < len; i++){
  962. if(this[i] == o) return i;
  963. }
  964. return -1;
  965. },
  966. /**
  967. * Removes the specified object from the array. If the object is not found nothing happens.
  968. * @param {Object} o The object to remove
  969. * @return {Array} this array
  970. */
  971. remove : function(o){
  972. var index = this.indexOf(o);
  973. if(index != -1){
  974. this.splice(index, 1);
  975. }
  976. return this;
  977. }
  978. });
  979. /**
  980. Returns the number of milliseconds between this date and date
  981. @param {Date} date (optional) Defaults to now
  982. @return {Number} The diff in milliseconds
  983. @member Date getElapsed
  984. */
  985. Date.prototype.getElapsed = function(date) {
  986. return Math.abs((date || new Date()).getTime()-this.getTime());
  987. };