Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14466 lines
536 KiB

  1. /*!
  2. * Ext JS Library 3.2.0
  3. * Copyright(c) 2006-2010 Ext JS, Inc.
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /**
  8. * @class Ext.DomHelper
  9. * <p>The DomHelper class provides a layer of abstraction from DOM and transparently supports creating
  10. * elements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates
  11. * from your DOM building code.</p>
  12. *
  13. * <p><b><u>DomHelper element specification object</u></b></p>
  14. * <p>A specification object is used when creating elements. Attributes of this object
  15. * are assumed to be element attributes, except for 4 special attributes:
  16. * <div class="mdetail-params"><ul>
  17. * <li><b><tt>tag</tt></b> : <div class="sub-desc">The tag name of the element</div></li>
  18. * <li><b><tt>children</tt></b> : or <tt>cn</tt><div class="sub-desc">An array of the
  19. * same kind of element definition objects to be created and appended. These can be nested
  20. * as deep as you want.</div></li>
  21. * <li><b><tt>cls</tt></b> : <div class="sub-desc">The class attribute of the element.
  22. * This will end up being either the "class" attribute on a HTML fragment or className
  23. * for a DOM node, depending on whether DomHelper is using fragments or DOM.</div></li>
  24. * <li><b><tt>html</tt></b> : <div class="sub-desc">The innerHTML for the element</div></li>
  25. * </ul></div></p>
  26. *
  27. * <p><b><u>Insertion methods</u></b></p>
  28. * <p>Commonly used insertion methods:
  29. * <div class="mdetail-params"><ul>
  30. * <li><b><tt>{@link #append}</tt></b> : <div class="sub-desc"></div></li>
  31. * <li><b><tt>{@link #insertBefore}</tt></b> : <div class="sub-desc"></div></li>
  32. * <li><b><tt>{@link #insertAfter}</tt></b> : <div class="sub-desc"></div></li>
  33. * <li><b><tt>{@link #overwrite}</tt></b> : <div class="sub-desc"></div></li>
  34. * <li><b><tt>{@link #createTemplate}</tt></b> : <div class="sub-desc"></div></li>
  35. * <li><b><tt>{@link #insertHtml}</tt></b> : <div class="sub-desc"></div></li>
  36. * </ul></div></p>
  37. *
  38. * <p><b><u>Example</u></b></p>
  39. * <p>This is an example, where an unordered list with 3 children items is appended to an existing
  40. * element with id <tt>'my-div'</tt>:<br>
  41. <pre><code>
  42. var dh = Ext.DomHelper; // create shorthand alias
  43. // specification object
  44. var spec = {
  45. id: 'my-ul',
  46. tag: 'ul',
  47. cls: 'my-list',
  48. // append children after creating
  49. children: [ // may also specify 'cn' instead of 'children'
  50. {tag: 'li', id: 'item0', html: 'List Item 0'},
  51. {tag: 'li', id: 'item1', html: 'List Item 1'},
  52. {tag: 'li', id: 'item2', html: 'List Item 2'}
  53. ]
  54. };
  55. var list = dh.append(
  56. 'my-div', // the context element 'my-div' can either be the id or the actual node
  57. spec // the specification object
  58. );
  59. </code></pre></p>
  60. * <p>Element creation specification parameters in this class may also be passed as an Array of
  61. * specification objects. This can be used to insert multiple sibling nodes into an existing
  62. * container very efficiently. For example, to add more list items to the example above:<pre><code>
  63. dh.append('my-ul', [
  64. {tag: 'li', id: 'item3', html: 'List Item 3'},
  65. {tag: 'li', id: 'item4', html: 'List Item 4'}
  66. ]);
  67. * </code></pre></p>
  68. *
  69. * <p><b><u>Templating</u></b></p>
  70. * <p>The real power is in the built-in templating. Instead of creating or appending any elements,
  71. * <tt>{@link #createTemplate}</tt> returns a Template object which can be used over and over to
  72. * insert new elements. Revisiting the example above, we could utilize templating this time:
  73. * <pre><code>
  74. // create the node
  75. var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});
  76. // get template
  77. var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});
  78. for(var i = 0; i < 5, i++){
  79. tpl.append(list, [i]); // use template to append to the actual node
  80. }
  81. * </code></pre></p>
  82. * <p>An example using a template:<pre><code>
  83. var html = '<a id="{0}" href="{1}" class="nav">{2}</a>';
  84. var tpl = new Ext.DomHelper.createTemplate(html);
  85. tpl.append('blog-roll', ['link1', 'http://www.jackslocum.com/', "Jack&#39;s Site"]);
  86. tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin&#39;s Site"]);
  87. * </code></pre></p>
  88. *
  89. * <p>The same example using named parameters:<pre><code>
  90. var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  91. var tpl = new Ext.DomHelper.createTemplate(html);
  92. tpl.append('blog-roll', {
  93. id: 'link1',
  94. url: 'http://www.jackslocum.com/',
  95. text: "Jack&#39;s Site"
  96. });
  97. tpl.append('blog-roll', {
  98. id: 'link2',
  99. url: 'http://www.dustindiaz.com/',
  100. text: "Dustin&#39;s Site"
  101. });
  102. * </code></pre></p>
  103. *
  104. * <p><b><u>Compiling Templates</u></b></p>
  105. * <p>Templates are applied using regular expressions. The performance is great, but if
  106. * you are adding a bunch of DOM elements using the same template, you can increase
  107. * performance even further by {@link Ext.Template#compile "compiling"} the template.
  108. * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and
  109. * broken up at the different variable points and a dynamic function is created and eval'ed.
  110. * The generated function performs string concatenation of these parts and the passed
  111. * variables instead of using regular expressions.
  112. * <pre><code>
  113. var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  114. var tpl = new Ext.DomHelper.createTemplate(html);
  115. tpl.compile();
  116. //... use template like normal
  117. * </code></pre></p>
  118. *
  119. * <p><b><u>Performance Boost</u></b></p>
  120. * <p>DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead
  121. * of DOM can significantly boost performance.</p>
  122. * <p>Element creation specification parameters may also be strings. If {@link #useDom} is <tt>false</tt>,
  123. * then the string is used as innerHTML. If {@link #useDom} is <tt>true</tt>, a string specification
  124. * results in the creation of a text node. Usage:</p>
  125. * <pre><code>
  126. Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance
  127. * </code></pre>
  128. * @singleton
  129. */
  130. Ext.DomHelper = function(){
  131. var tempTableEl = null,
  132. emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,
  133. tableRe = /^table|tbody|tr|td$/i,
  134. pub,
  135. // kill repeat to save bytes
  136. afterbegin = 'afterbegin',
  137. afterend = 'afterend',
  138. beforebegin = 'beforebegin',
  139. beforeend = 'beforeend',
  140. ts = '<table>',
  141. te = '</table>',
  142. tbs = ts+'<tbody>',
  143. tbe = '</tbody>'+te,
  144. trs = tbs + '<tr>',
  145. tre = '</tr>'+tbe;
  146. // private
  147. function doInsert(el, o, returnElement, pos, sibling, append){
  148. var newNode = pub.insertHtml(pos, Ext.getDom(el), createHtml(o));
  149. return returnElement ? Ext.get(newNode, true) : newNode;
  150. }
  151. // build as innerHTML where available
  152. function createHtml(o){
  153. var b = '',
  154. attr,
  155. val,
  156. key,
  157. keyVal,
  158. cn;
  159. if(Ext.isString(o)){
  160. b = o;
  161. } else if (Ext.isArray(o)) {
  162. for (var i=0; i < o.length; i++) {
  163. if(o[i]) {
  164. b += createHtml(o[i]);
  165. }
  166. };
  167. } else {
  168. b += '<' + (o.tag = o.tag || 'div');
  169. Ext.iterate(o, function(attr, val){
  170. if(!/tag|children|cn|html$/i.test(attr)){
  171. if (Ext.isObject(val)) {
  172. b += ' ' + attr + '="';
  173. Ext.iterate(val, function(key, keyVal){
  174. b += key + ':' + keyVal + ';';
  175. });
  176. b += '"';
  177. }else{
  178. b += ' ' + ({cls : 'class', htmlFor : 'for'}[attr] || attr) + '="' + val + '"';
  179. }
  180. }
  181. });
  182. // Now either just close the tag or try to add children and close the tag.
  183. if (emptyTags.test(o.tag)) {
  184. b += '/>';
  185. } else {
  186. b += '>';
  187. if ((cn = o.children || o.cn)) {
  188. b += createHtml(cn);
  189. } else if(o.html){
  190. b += o.html;
  191. }
  192. b += '</' + o.tag + '>';
  193. }
  194. }
  195. return b;
  196. }
  197. function ieTable(depth, s, h, e){
  198. tempTableEl.innerHTML = [s, h, e].join('');
  199. var i = -1,
  200. el = tempTableEl,
  201. ns;
  202. while(++i < depth){
  203. el = el.firstChild;
  204. }
  205. // If the result is multiple siblings, then encapsulate them into one fragment.
  206. if(ns = el.nextSibling){
  207. var df = document.createDocumentFragment();
  208. while(el){
  209. ns = el.nextSibling;
  210. df.appendChild(el);
  211. el = ns;
  212. }
  213. el = df;
  214. }
  215. return el;
  216. }
  217. /**
  218. * @ignore
  219. * Nasty code for IE's broken table implementation
  220. */
  221. function insertIntoTable(tag, where, el, html) {
  222. var node,
  223. before;
  224. tempTableEl = tempTableEl || document.createElement('div');
  225. if(tag == 'td' && (where == afterbegin || where == beforeend) ||
  226. !/td|tr|tbody/i.test(tag) && (where == beforebegin || where == afterend)) {
  227. return;
  228. }
  229. before = where == beforebegin ? el :
  230. where == afterend ? el.nextSibling :
  231. where == afterbegin ? el.firstChild : null;
  232. if (where == beforebegin || where == afterend) {
  233. el = el.parentNode;
  234. }
  235. if (tag == 'td' || (tag == 'tr' && (where == beforeend || where == afterbegin))) {
  236. node = ieTable(4, trs, html, tre);
  237. } else if ((tag == 'tbody' && (where == beforeend || where == afterbegin)) ||
  238. (tag == 'tr' && (where == beforebegin || where == afterend))) {
  239. node = ieTable(3, tbs, html, tbe);
  240. } else {
  241. node = ieTable(2, ts, html, te);
  242. }
  243. el.insertBefore(node, before);
  244. return node;
  245. }
  246. pub = {
  247. /**
  248. * Returns the markup for the passed Element(s) config.
  249. * @param {Object} o The DOM object spec (and children)
  250. * @return {String}
  251. */
  252. markup : function(o){
  253. return createHtml(o);
  254. },
  255. /**
  256. * Applies a style specification to an element.
  257. * @param {String/HTMLElement} el The element to apply styles to
  258. * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or
  259. * a function which returns such a specification.
  260. */
  261. applyStyles : function(el, styles){
  262. if(styles){
  263. var i = 0,
  264. len,
  265. style;
  266. el = Ext.fly(el);
  267. if(Ext.isFunction(styles)){
  268. styles = styles.call();
  269. }
  270. if(Ext.isString(styles)){
  271. styles = styles.trim().split(/\s*(?::|;)\s*/);
  272. for(len = styles.length; i < len;){
  273. el.setStyle(styles[i++], styles[i++]);
  274. }
  275. }else if (Ext.isObject(styles)){
  276. el.setStyle(styles);
  277. }
  278. }
  279. },
  280. /**
  281. * Inserts an HTML fragment into the DOM.
  282. * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
  283. * @param {HTMLElement} el The context element
  284. * @param {String} html The HTML fragment
  285. * @return {HTMLElement} The new node
  286. */
  287. insertHtml : function(where, el, html){
  288. var hash = {},
  289. hashVal,
  290. setStart,
  291. range,
  292. frag,
  293. rangeEl,
  294. rs;
  295. where = where.toLowerCase();
  296. // add these here because they are used in both branches of the condition.
  297. hash[beforebegin] = ['BeforeBegin', 'previousSibling'];
  298. hash[afterend] = ['AfterEnd', 'nextSibling'];
  299. if (el.insertAdjacentHTML) {
  300. if(tableRe.test(el.tagName) && (rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html))){
  301. return rs;
  302. }
  303. // add these two to the hash.
  304. hash[afterbegin] = ['AfterBegin', 'firstChild'];
  305. hash[beforeend] = ['BeforeEnd', 'lastChild'];
  306. if ((hashVal = hash[where])) {
  307. el.insertAdjacentHTML(hashVal[0], html);
  308. return el[hashVal[1]];
  309. }
  310. } else {
  311. range = el.ownerDocument.createRange();
  312. setStart = 'setStart' + (/end/i.test(where) ? 'After' : 'Before');
  313. if (hash[where]) {
  314. range[setStart](el);
  315. frag = range.createContextualFragment(html);
  316. el.parentNode.insertBefore(frag, where == beforebegin ? el : el.nextSibling);
  317. return el[(where == beforebegin ? 'previous' : 'next') + 'Sibling'];
  318. } else {
  319. rangeEl = (where == afterbegin ? 'first' : 'last') + 'Child';
  320. if (el.firstChild) {
  321. range[setStart](el[rangeEl]);
  322. frag = range.createContextualFragment(html);
  323. if(where == afterbegin){
  324. el.insertBefore(frag, el.firstChild);
  325. }else{
  326. el.appendChild(frag);
  327. }
  328. } else {
  329. el.innerHTML = html;
  330. }
  331. return el[rangeEl];
  332. }
  333. }
  334. throw 'Illegal insertion point -> "' + where + '"';
  335. },
  336. /**
  337. * Creates new DOM element(s) and inserts them before el.
  338. * @param {Mixed} el The context element
  339. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  340. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  341. * @return {HTMLElement/Ext.Element} The new node
  342. */
  343. insertBefore : function(el, o, returnElement){
  344. return doInsert(el, o, returnElement, beforebegin);
  345. },
  346. /**
  347. * Creates new DOM element(s) and inserts them after el.
  348. * @param {Mixed} el The context element
  349. * @param {Object} o The DOM object spec (and children)
  350. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  351. * @return {HTMLElement/Ext.Element} The new node
  352. */
  353. insertAfter : function(el, o, returnElement){
  354. return doInsert(el, o, returnElement, afterend, 'nextSibling');
  355. },
  356. /**
  357. * Creates new DOM element(s) and inserts them as the first child of el.
  358. * @param {Mixed} el The context element
  359. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  360. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  361. * @return {HTMLElement/Ext.Element} The new node
  362. */
  363. insertFirst : function(el, o, returnElement){
  364. return doInsert(el, o, returnElement, afterbegin, 'firstChild');
  365. },
  366. /**
  367. * Creates new DOM element(s) and appends them to el.
  368. * @param {Mixed} el The context element
  369. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  370. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  371. * @return {HTMLElement/Ext.Element} The new node
  372. */
  373. append : function(el, o, returnElement){
  374. return doInsert(el, o, returnElement, beforeend, '', true);
  375. },
  376. /**
  377. * Creates new DOM element(s) and overwrites the contents of el with them.
  378. * @param {Mixed} el The context element
  379. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  380. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  381. * @return {HTMLElement/Ext.Element} The new node
  382. */
  383. overwrite : function(el, o, returnElement){
  384. el = Ext.getDom(el);
  385. el.innerHTML = createHtml(o);
  386. return returnElement ? Ext.get(el.firstChild) : el.firstChild;
  387. },
  388. createHtml : createHtml
  389. };
  390. return pub;
  391. }();/**
  392. * @class Ext.DomHelper
  393. */
  394. Ext.apply(Ext.DomHelper,
  395. function(){
  396. var pub,
  397. afterbegin = 'afterbegin',
  398. afterend = 'afterend',
  399. beforebegin = 'beforebegin',
  400. beforeend = 'beforeend';
  401. // private
  402. function doInsert(el, o, returnElement, pos, sibling, append){
  403. el = Ext.getDom(el);
  404. var newNode;
  405. if (pub.useDom) {
  406. newNode = createDom(o, null);
  407. if (append) {
  408. el.appendChild(newNode);
  409. } else {
  410. (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
  411. }
  412. } else {
  413. newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
  414. }
  415. return returnElement ? Ext.get(newNode, true) : newNode;
  416. }
  417. // build as dom
  418. /** @ignore */
  419. function createDom(o, parentNode){
  420. var el,
  421. doc = document,
  422. useSet,
  423. attr,
  424. val,
  425. cn;
  426. if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
  427. el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
  428. Ext.each(o, function(v) {
  429. createDom(v, el);
  430. });
  431. } else if (Ext.isString(o)) { // Allow a string as a child spec.
  432. el = doc.createTextNode(o);
  433. } else {
  434. el = doc.createElement( o.tag || 'div' );
  435. useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
  436. Ext.iterate(o, function(attr, val){
  437. if(!/tag|children|cn|html|style/.test(attr)){
  438. if(attr == 'cls'){
  439. el.className = val;
  440. }else{
  441. if(useSet){
  442. el.setAttribute(attr, val);
  443. }else{
  444. el[attr] = val;
  445. }
  446. }
  447. }
  448. });
  449. Ext.DomHelper.applyStyles(el, o.style);
  450. if ((cn = o.children || o.cn)) {
  451. createDom(cn, el);
  452. } else if (o.html) {
  453. el.innerHTML = o.html;
  454. }
  455. }
  456. if(parentNode){
  457. parentNode.appendChild(el);
  458. }
  459. return el;
  460. }
  461. pub = {
  462. /**
  463. * Creates a new Ext.Template from the DOM object spec.
  464. * @param {Object} o The DOM object spec (and children)
  465. * @return {Ext.Template} The new template
  466. */
  467. createTemplate : function(o){
  468. var html = Ext.DomHelper.createHtml(o);
  469. return new Ext.Template(html);
  470. },
  471. /** True to force the use of DOM instead of html fragments @type Boolean */
  472. useDom : false,
  473. /**
  474. * Creates new DOM element(s) and inserts them before el.
  475. * @param {Mixed} el The context element
  476. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  477. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  478. * @return {HTMLElement/Ext.Element} The new node
  479. * @hide (repeat)
  480. */
  481. insertBefore : function(el, o, returnElement){
  482. return doInsert(el, o, returnElement, beforebegin);
  483. },
  484. /**
  485. * Creates new DOM element(s) and inserts them after el.
  486. * @param {Mixed} el The context element
  487. * @param {Object} o The DOM object spec (and children)
  488. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  489. * @return {HTMLElement/Ext.Element} The new node
  490. * @hide (repeat)
  491. */
  492. insertAfter : function(el, o, returnElement){
  493. return doInsert(el, o, returnElement, afterend, 'nextSibling');
  494. },
  495. /**
  496. * Creates new DOM element(s) and inserts them as the first child of el.
  497. * @param {Mixed} el The context element
  498. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  499. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  500. * @return {HTMLElement/Ext.Element} The new node
  501. * @hide (repeat)
  502. */
  503. insertFirst : function(el, o, returnElement){
  504. return doInsert(el, o, returnElement, afterbegin, 'firstChild');
  505. },
  506. /**
  507. * Creates new DOM element(s) and appends them to el.
  508. * @param {Mixed} el The context element
  509. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  510. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  511. * @return {HTMLElement/Ext.Element} The new node
  512. * @hide (repeat)
  513. */
  514. append: function(el, o, returnElement){
  515. return doInsert(el, o, returnElement, beforeend, '', true);
  516. },
  517. /**
  518. * Creates new DOM element(s) without inserting them to the document.
  519. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  520. * @return {HTMLElement} The new uninserted node
  521. */
  522. createDom: createDom
  523. };
  524. return pub;
  525. }());/**
  526. * @class Ext.Template
  527. * <p>Represents an HTML fragment template. Templates may be {@link #compile precompiled}
  528. * for greater performance.</p>
  529. * <p>For example usage {@link #Template see the constructor}.</p>
  530. *
  531. * @constructor
  532. * An instance of this class may be created by passing to the constructor either
  533. * a single argument, or multiple arguments:
  534. * <div class="mdetail-params"><ul>
  535. * <li><b>single argument</b> : String/Array
  536. * <div class="sub-desc">
  537. * The single argument may be either a String or an Array:<ul>
  538. * <li><tt>String</tt> : </li><pre><code>
  539. var t = new Ext.Template("&lt;div>Hello {0}.&lt;/div>");
  540. t.{@link #append}('some-element', ['foo']);
  541. * </code></pre>
  542. * <li><tt>Array</tt> : </li>
  543. * An Array will be combined with <code>join('')</code>.
  544. <pre><code>
  545. var t = new Ext.Template([
  546. '&lt;div name="{id}"&gt;',
  547. '&lt;span class="{cls}"&gt;{name:trim} {value:ellipsis(10)}&lt;/span&gt;',
  548. '&lt;/div&gt;',
  549. ]);
  550. t.{@link #compile}();
  551. t.{@link #append}('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
  552. </code></pre>
  553. * </ul></div></li>
  554. * <li><b>multiple arguments</b> : String, Object, Array, ...
  555. * <div class="sub-desc">
  556. * Multiple arguments will be combined with <code>join('')</code>.
  557. * <pre><code>
  558. var t = new Ext.Template(
  559. '&lt;div name="{id}"&gt;',
  560. '&lt;span class="{cls}"&gt;{name} {value}&lt;/span&gt;',
  561. '&lt;/div&gt;',
  562. // a configuration object:
  563. {
  564. compiled: true, // {@link #compile} immediately
  565. disableFormats: true // See Notes below.
  566. }
  567. );
  568. * </code></pre>
  569. * <p><b>Notes</b>:</p>
  570. * <div class="mdetail-params"><ul>
  571. * <li>Formatting and <code>disableFormats</code> are not applicable for Ext Core.</li>
  572. * <li>For a list of available format functions, see {@link Ext.util.Format}.</li>
  573. * <li><code>disableFormats</code> reduces <code>{@link #apply}</code> time
  574. * when no formatting is required.</li>
  575. * </ul></div>
  576. * </div></li>
  577. * </ul></div>
  578. * @param {Mixed} config
  579. */
  580. Ext.Template = function(html){
  581. var me = this,
  582. a = arguments,
  583. buf = [];
  584. if (Ext.isArray(html)) {
  585. html = html.join("");
  586. } else if (a.length > 1) {
  587. Ext.each(a, function(v) {
  588. if (Ext.isObject(v)) {
  589. Ext.apply(me, v);
  590. } else {
  591. buf.push(v);
  592. }
  593. });
  594. html = buf.join('');
  595. }
  596. /**@private*/
  597. me.html = html;
  598. /**
  599. * @cfg {Boolean} compiled Specify <tt>true</tt> to compile the template
  600. * immediately (see <code>{@link #compile}</code>).
  601. * Defaults to <tt>false</tt>.
  602. */
  603. if (me.compiled) {
  604. me.compile();
  605. }
  606. };
  607. Ext.Template.prototype = {
  608. /**
  609. * @cfg {RegExp} re The regular expression used to match template variables.
  610. * Defaults to:<pre><code>
  611. * re : /\{([\w-]+)\}/g // for Ext Core
  612. * re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g // for Ext JS
  613. * </code></pre>
  614. */
  615. re : /\{([\w-]+)\}/g,
  616. /**
  617. * See <code>{@link #re}</code>.
  618. * @type RegExp
  619. * @property re
  620. */
  621. /**
  622. * Returns an HTML fragment of this template with the specified <code>values</code> applied.
  623. * @param {Object/Array} values
  624. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  625. * or an object (i.e. <code>{foo: 'bar'}</code>).
  626. * @return {String} The HTML fragment
  627. */
  628. applyTemplate : function(values){
  629. var me = this;
  630. return me.compiled ?
  631. me.compiled(values) :
  632. me.html.replace(me.re, function(m, name){
  633. return values[name] !== undefined ? values[name] : "";
  634. });
  635. },
  636. /**
  637. * Sets the HTML used as the template and optionally compiles it.
  638. * @param {String} html
  639. * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
  640. * @return {Ext.Template} this
  641. */
  642. set : function(html, compile){
  643. var me = this;
  644. me.html = html;
  645. me.compiled = null;
  646. return compile ? me.compile() : me;
  647. },
  648. /**
  649. * Compiles the template into an internal function, eliminating the RegEx overhead.
  650. * @return {Ext.Template} this
  651. */
  652. compile : function(){
  653. var me = this,
  654. sep = Ext.isGecko ? "+" : ",";
  655. function fn(m, name){
  656. name = "values['" + name + "']";
  657. return "'"+ sep + '(' + name + " == undefined ? '' : " + name + ')' + sep + "'";
  658. }
  659. eval("this.compiled = function(values){ return " + (Ext.isGecko ? "'" : "['") +
  660. me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
  661. (Ext.isGecko ? "';};" : "'].join('');};"));
  662. return me;
  663. },
  664. /**
  665. * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
  666. * @param {Mixed} el The context element
  667. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  668. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  669. * @return {HTMLElement/Ext.Element} The new node or Element
  670. */
  671. insertFirst: function(el, values, returnElement){
  672. return this.doInsert('afterBegin', el, values, returnElement);
  673. },
  674. /**
  675. * Applies the supplied values to the template and inserts the new node(s) before el.
  676. * @param {Mixed} el The context element
  677. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  678. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  679. * @return {HTMLElement/Ext.Element} The new node or Element
  680. */
  681. insertBefore: function(el, values, returnElement){
  682. return this.doInsert('beforeBegin', el, values, returnElement);
  683. },
  684. /**
  685. * Applies the supplied values to the template and inserts the new node(s) after el.
  686. * @param {Mixed} el The context element
  687. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  688. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  689. * @return {HTMLElement/Ext.Element} The new node or Element
  690. */
  691. insertAfter : function(el, values, returnElement){
  692. return this.doInsert('afterEnd', el, values, returnElement);
  693. },
  694. /**
  695. * Applies the supplied <code>values</code> to the template and appends
  696. * the new node(s) to the specified <code>el</code>.
  697. * <p>For example usage {@link #Template see the constructor}.</p>
  698. * @param {Mixed} el The context element
  699. * @param {Object/Array} values
  700. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  701. * or an object (i.e. <code>{foo: 'bar'}</code>).
  702. * @param {Boolean} returnElement (optional) true to return an Ext.Element (defaults to undefined)
  703. * @return {HTMLElement/Ext.Element} The new node or Element
  704. */
  705. append : function(el, values, returnElement){
  706. return this.doInsert('beforeEnd', el, values, returnElement);
  707. },
  708. doInsert : function(where, el, values, returnEl){
  709. el = Ext.getDom(el);
  710. var newNode = Ext.DomHelper.insertHtml(where, el, this.applyTemplate(values));
  711. return returnEl ? Ext.get(newNode, true) : newNode;
  712. },
  713. /**
  714. * Applies the supplied values to the template and overwrites the content of el with the new node(s).
  715. * @param {Mixed} el The context element
  716. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  717. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  718. * @return {HTMLElement/Ext.Element} The new node or Element
  719. */
  720. overwrite : function(el, values, returnElement){
  721. el = Ext.getDom(el);
  722. el.innerHTML = this.applyTemplate(values);
  723. return returnElement ? Ext.get(el.firstChild, true) : el.firstChild;
  724. }
  725. };
  726. /**
  727. * Alias for {@link #applyTemplate}
  728. * Returns an HTML fragment of this template with the specified <code>values</code> applied.
  729. * @param {Object/Array} values
  730. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  731. * or an object (i.e. <code>{foo: 'bar'}</code>).
  732. * @return {String} The HTML fragment
  733. * @member Ext.Template
  734. * @method apply
  735. */
  736. Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;
  737. /**
  738. * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
  739. * @param {String/HTMLElement} el A DOM element or its id
  740. * @param {Object} config A configuration object
  741. * @return {Ext.Template} The created template
  742. * @static
  743. */
  744. Ext.Template.from = function(el, config){
  745. el = Ext.getDom(el);
  746. return new Ext.Template(el.value || el.innerHTML, config || '');
  747. };/**
  748. * @class Ext.Template
  749. */
  750. Ext.apply(Ext.Template.prototype, {
  751. /**
  752. * @cfg {Boolean} disableFormats Specify <tt>true</tt> to disable format
  753. * functions in the template. If the template does not contain
  754. * {@link Ext.util.Format format functions}, setting <code>disableFormats</code>
  755. * to true will reduce <code>{@link #apply}</code> time. Defaults to <tt>false</tt>.
  756. * <pre><code>
  757. var t = new Ext.Template(
  758. '&lt;div name="{id}"&gt;',
  759. '&lt;span class="{cls}"&gt;{name} {value}&lt;/span&gt;',
  760. '&lt;/div&gt;',
  761. {
  762. compiled: true, // {@link #compile} immediately
  763. disableFormats: true // reduce <code>{@link #apply}</code> time since no formatting
  764. }
  765. );
  766. * </code></pre>
  767. * For a list of available format functions, see {@link Ext.util.Format}.
  768. */
  769. disableFormats : false,
  770. /**
  771. * See <code>{@link #disableFormats}</code>.
  772. * @type Boolean
  773. * @property disableFormats
  774. */
  775. /**
  776. * The regular expression used to match template variables
  777. * @type RegExp
  778. * @property
  779. * @hide repeat doc
  780. */
  781. re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
  782. /**
  783. * Returns an HTML fragment of this template with the specified values applied.
  784. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  785. * @return {String} The HTML fragment
  786. * @hide repeat doc
  787. */
  788. applyTemplate : function(values){
  789. var me = this,
  790. useF = me.disableFormats !== true,
  791. fm = Ext.util.Format,
  792. tpl = me;
  793. if(me.compiled){
  794. return me.compiled(values);
  795. }
  796. function fn(m, name, format, args){
  797. if (format && useF) {
  798. if (format.substr(0, 5) == "this.") {
  799. return tpl.call(format.substr(5), values[name], values);
  800. } else {
  801. if (args) {
  802. // quoted values are required for strings in compiled templates,
  803. // but for non compiled we need to strip them
  804. // quoted reversed for jsmin
  805. var re = /^\s*['"](.*)["']\s*$/;
  806. args = args.split(',');
  807. for(var i = 0, len = args.length; i < len; i++){
  808. args[i] = args[i].replace(re, "$1");
  809. }
  810. args = [values[name]].concat(args);
  811. } else {
  812. args = [values[name]];
  813. }
  814. return fm[format].apply(fm, args);
  815. }
  816. } else {
  817. return values[name] !== undefined ? values[name] : "";
  818. }
  819. }
  820. return me.html.replace(me.re, fn);
  821. },
  822. /**
  823. * Compiles the template into an internal function, eliminating the RegEx overhead.
  824. * @return {Ext.Template} this
  825. * @hide repeat doc
  826. */
  827. compile : function(){
  828. var me = this,
  829. fm = Ext.util.Format,
  830. useF = me.disableFormats !== true,
  831. sep = Ext.isGecko ? "+" : ",",
  832. body;
  833. function fn(m, name, format, args){
  834. if(format && useF){
  835. args = args ? ',' + args : "";
  836. if(format.substr(0, 5) != "this."){
  837. format = "fm." + format + '(';
  838. }else{
  839. format = 'this.call("'+ format.substr(5) + '", ';
  840. args = ", values";
  841. }
  842. }else{
  843. args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
  844. }
  845. return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
  846. }
  847. // branched to use + in gecko and [].join() in others
  848. if(Ext.isGecko){
  849. body = "this.compiled = function(values){ return '" +
  850. me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
  851. "';};";
  852. }else{
  853. body = ["this.compiled = function(values){ return ['"];
  854. body.push(me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
  855. body.push("'].join('');};");
  856. body = body.join('');
  857. }
  858. eval(body);
  859. return me;
  860. },
  861. // private function used to call members
  862. call : function(fnName, value, allValues){
  863. return this[fnName](value, allValues);
  864. }
  865. });
  866. Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate; /*
  867. * This is code is also distributed under MIT license for use
  868. * with jQuery and prototype JavaScript libraries.
  869. */
  870. /**
  871. * @class Ext.DomQuery
  872. Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
  873. <p>
  874. DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>
  875. <p>
  876. All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
  877. </p>
  878. <h4>Element Selectors:</h4>
  879. <ul class="list">
  880. <li> <b>*</b> any element</li>
  881. <li> <b>E</b> an element with the tag E</li>
  882. <li> <b>E F</b> All descendent elements of E that have the tag F</li>
  883. <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
  884. <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
  885. <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
  886. </ul>
  887. <h4>Attribute Selectors:</h4>
  888. <p>The use of &#64; and quotes are optional. For example, div[&#64;foo='bar'] is also a valid attribute selector.</p>
  889. <ul class="list">
  890. <li> <b>E[foo]</b> has an attribute "foo"</li>
  891. <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
  892. <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
  893. <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
  894. <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
  895. <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
  896. <li> <b>E[foo!=bar]</b> has an attribute "foo" that does not equal "bar"</li>
  897. </ul>
  898. <h4>Pseudo Classes:</h4>
  899. <ul class="list">
  900. <li> <b>E:first-child</b> E is the first child of its parent</li>
  901. <li> <b>E:last-child</b> E is the last child of its parent</li>
  902. <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
  903. <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
  904. <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
  905. <li> <b>E:only-child</b> E is the only child of its parent</li>
  906. <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
  907. <li> <b>E:first</b> the first E in the resultset</li>
  908. <li> <b>E:last</b> the last E in the resultset</li>
  909. <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
  910. <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
  911. <li> <b>E:even</b> shortcut for :nth-child(even)</li>
  912. <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
  913. <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
  914. <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
  915. <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
  916. <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
  917. <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
  918. <li> <b>E:any(S1|S2|S2)</b> an E element which matches any of the simple selectors S1, S2 or S3//\\</li>
  919. </ul>
  920. <h4>CSS Value Selectors:</h4>
  921. <ul class="list">
  922. <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
  923. <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
  924. <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
  925. <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
  926. <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
  927. <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
  928. </ul>
  929. * @singleton
  930. */
  931. Ext.DomQuery = function(){
  932. var cache = {},
  933. simpleCache = {},
  934. valueCache = {},
  935. nonSpace = /\S/,
  936. trimRe = /^\s+|\s+$/g,
  937. tplRe = /\{(\d+)\}/g,
  938. modeRe = /^(\s?[\/>+~]\s?|\s|$)/,
  939. tagTokenRe = /^(#)?([\w-\*]+)/,
  940. nthRe = /(\d*)n\+?(\d*)/,
  941. nthRe2 = /\D/,
  942. // This is for IE MSXML which does not support expandos.
  943. // IE runs the same speed using setAttribute, however FF slows way down
  944. // and Safari completely fails so they need to continue to use expandos.
  945. isIE = window.ActiveXObject ? true : false,
  946. key = 30803;
  947. // this eval is stop the compressor from
  948. // renaming the variable to something shorter
  949. eval("var batch = 30803;");
  950. // Retrieve the child node from a particular
  951. // parent at the specified index.
  952. function child(parent, index){
  953. var i = 0,
  954. n = parent.firstChild;
  955. while(n){
  956. if(n.nodeType == 1){
  957. if(++i == index){
  958. return n;
  959. }
  960. }
  961. n = n.nextSibling;
  962. }
  963. return null;
  964. }
  965. // retrieve the next element node
  966. function next(n){
  967. while((n = n.nextSibling) && n.nodeType != 1);
  968. return n;
  969. }
  970. // retrieve the previous element node
  971. function prev(n){
  972. while((n = n.previousSibling) && n.nodeType != 1);
  973. return n;
  974. }
  975. // Mark each child node with a nodeIndex skipping and
  976. // removing empty text nodes.
  977. function children(parent){
  978. var n = parent.firstChild,
  979. nodeIndex = -1,
  980. nextNode;
  981. while(n){
  982. nextNode = n.nextSibling;
  983. // clean worthless empty nodes.
  984. if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
  985. parent.removeChild(n);
  986. }else{
  987. // add an expando nodeIndex
  988. n.nodeIndex = ++nodeIndex;
  989. }
  990. n = nextNode;
  991. }
  992. return this;
  993. }
  994. // nodeSet - array of nodes
  995. // cls - CSS Class
  996. function byClassName(nodeSet, cls){
  997. if(!cls){
  998. return nodeSet;
  999. }
  1000. var result = [], ri = -1;
  1001. for(var i = 0, ci; ci = nodeSet[i]; i++){
  1002. if((' '+ci.className+' ').indexOf(cls) != -1){
  1003. result[++ri] = ci;
  1004. }
  1005. }
  1006. return result;
  1007. };
  1008. function attrValue(n, attr){
  1009. // if its an array, use the first node.
  1010. if(!n.tagName && typeof n.length != "undefined"){
  1011. n = n[0];
  1012. }
  1013. if(!n){
  1014. return null;
  1015. }
  1016. if(attr == "for"){
  1017. return n.htmlFor;
  1018. }
  1019. if(attr == "class" || attr == "className"){
  1020. return n.className;
  1021. }
  1022. return n.getAttribute(attr) || n[attr];
  1023. };
  1024. // ns - nodes
  1025. // mode - false, /, >, +, ~
  1026. // tagName - defaults to "*"
  1027. function getNodes(ns, mode, tagName){
  1028. var result = [], ri = -1, cs;
  1029. if(!ns){
  1030. return result;
  1031. }
  1032. tagName = tagName || "*";
  1033. // convert to array
  1034. if(typeof ns.getElementsByTagName != "undefined"){
  1035. ns = [ns];
  1036. }
  1037. // no mode specified, grab all elements by tagName
  1038. // at any depth
  1039. if(!mode){
  1040. for(var i = 0, ni; ni = ns[i]; i++){
  1041. cs = ni.getElementsByTagName(tagName);
  1042. for(var j = 0, ci; ci = cs[j]; j++){
  1043. result[++ri] = ci;
  1044. }
  1045. }
  1046. // Direct Child mode (/ or >)
  1047. // E > F or E/F all direct children elements of E that have the tag
  1048. } else if(mode == "/" || mode == ">"){
  1049. var utag = tagName.toUpperCase();
  1050. for(var i = 0, ni, cn; ni = ns[i]; i++){
  1051. cn = ni.childNodes;
  1052. for(var j = 0, cj; cj = cn[j]; j++){
  1053. if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
  1054. result[++ri] = cj;
  1055. }
  1056. }
  1057. }
  1058. // Immediately Preceding mode (+)
  1059. // E + F all elements with the tag F that are immediately preceded by an element with the tag E
  1060. }else if(mode == "+"){
  1061. var utag = tagName.toUpperCase();
  1062. for(var i = 0, n; n = ns[i]; i++){
  1063. while((n = n.nextSibling) && n.nodeType != 1);
  1064. if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
  1065. result[++ri] = n;
  1066. }
  1067. }
  1068. // Sibling mode (~)
  1069. // E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
  1070. }else if(mode == "~"){
  1071. var utag = tagName.toUpperCase();
  1072. for(var i = 0, n; n = ns[i]; i++){
  1073. while((n = n.nextSibling)){
  1074. if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
  1075. result[++ri] = n;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. return result;
  1081. }
  1082. function concat(a, b){
  1083. if(b.slice){
  1084. return a.concat(b);
  1085. }
  1086. for(var i = 0, l = b.length; i < l; i++){
  1087. a[a.length] = b[i];
  1088. }
  1089. return a;
  1090. }
  1091. function byTag(cs, tagName){
  1092. if(cs.tagName || cs == document){
  1093. cs = [cs];
  1094. }
  1095. if(!tagName){
  1096. return cs;
  1097. }
  1098. var result = [], ri = -1;
  1099. tagName = tagName.toLowerCase();
  1100. for(var i = 0, ci; ci = cs[i]; i++){
  1101. if(ci.nodeType == 1 && ci.tagName.toLowerCase() == tagName){
  1102. result[++ri] = ci;
  1103. }
  1104. }
  1105. return result;
  1106. }
  1107. function byId(cs, id){
  1108. if(cs.tagName || cs == document){
  1109. cs = [cs];
  1110. }
  1111. if(!id){
  1112. return cs;
  1113. }
  1114. var result = [], ri = -1;
  1115. for(var i = 0, ci; ci = cs[i]; i++){
  1116. if(ci && ci.id == id){
  1117. result[++ri] = ci;
  1118. return result;
  1119. }
  1120. }
  1121. return result;
  1122. }
  1123. // operators are =, !=, ^=, $=, *=, %=, |= and ~=
  1124. // custom can be "{"
  1125. function byAttribute(cs, attr, value, op, custom){
  1126. var result = [],
  1127. ri = -1,
  1128. useGetStyle = custom == "{",
  1129. fn = Ext.DomQuery.operators[op],
  1130. a,
  1131. innerHTML;
  1132. for(var i = 0, ci; ci = cs[i]; i++){
  1133. // skip non-element nodes.
  1134. if(ci.nodeType != 1){
  1135. continue;
  1136. }
  1137. innerHTML = ci.innerHTML;
  1138. // we only need to change the property names if we're dealing with html nodes, not XML
  1139. if(innerHTML !== null && innerHTML !== undefined){
  1140. if(useGetStyle){
  1141. a = Ext.DomQuery.getStyle(ci, attr);
  1142. } else if (attr == "class" || attr == "className"){
  1143. a = ci.className;
  1144. } else if (attr == "for"){
  1145. a = ci.htmlFor;
  1146. } else if (attr == "href"){
  1147. // getAttribute href bug
  1148. // http://www.glennjones.net/Post/809/getAttributehrefbug.htm
  1149. a = ci.getAttribute("href", 2);
  1150. } else{
  1151. a = ci.getAttribute(attr);
  1152. }
  1153. }else{
  1154. a = ci.getAttribute(attr);
  1155. }
  1156. if((fn && fn(a, value)) || (!fn && a)){
  1157. result[++ri] = ci;
  1158. }
  1159. }
  1160. return result;
  1161. }
  1162. function byPseudo(cs, name, value){
  1163. return Ext.DomQuery.pseudos[name](cs, value);
  1164. }
  1165. function nodupIEXml(cs){
  1166. var d = ++key,
  1167. r;
  1168. cs[0].setAttribute("_nodup", d);
  1169. r = [cs[0]];
  1170. for(var i = 1, len = cs.length; i < len; i++){
  1171. var c = cs[i];
  1172. if(!c.getAttribute("_nodup") != d){
  1173. c.setAttribute("_nodup", d);
  1174. r[r.length] = c;
  1175. }
  1176. }
  1177. for(var i = 0, len = cs.length; i < len; i++){
  1178. cs[i].removeAttribute("_nodup");
  1179. }
  1180. return r;
  1181. }
  1182. function nodup(cs){
  1183. if(!cs){
  1184. return [];
  1185. }
  1186. var len = cs.length, c, i, r = cs, cj, ri = -1;
  1187. if(!len || typeof cs.nodeType != "undefined" || len == 1){
  1188. return cs;
  1189. }
  1190. if(isIE && typeof cs[0].selectSingleNode != "undefined"){
  1191. return nodupIEXml(cs);
  1192. }
  1193. var d = ++key;
  1194. cs[0]._nodup = d;
  1195. for(i = 1; c = cs[i]; i++){
  1196. if(c._nodup != d){
  1197. c._nodup = d;
  1198. }else{
  1199. r = [];
  1200. for(var j = 0; j < i; j++){
  1201. r[++ri] = cs[j];
  1202. }
  1203. for(j = i+1; cj = cs[j]; j++){
  1204. if(cj._nodup != d){
  1205. cj._nodup = d;
  1206. r[++ri] = cj;
  1207. }
  1208. }
  1209. return r;
  1210. }
  1211. }
  1212. return r;
  1213. }
  1214. function quickDiffIEXml(c1, c2){
  1215. var d = ++key,
  1216. r = [];
  1217. for(var i = 0, len = c1.length; i < len; i++){
  1218. c1[i].setAttribute("_qdiff", d);
  1219. }
  1220. for(var i = 0, len = c2.length; i < len; i++){
  1221. if(c2[i].getAttribute("_qdiff") != d){
  1222. r[r.length] = c2[i];
  1223. }
  1224. }
  1225. for(var i = 0, len = c1.length; i < len; i++){
  1226. c1[i].removeAttribute("_qdiff");
  1227. }
  1228. return r;
  1229. }
  1230. function quickDiff(c1, c2){
  1231. var len1 = c1.length,
  1232. d = ++key,
  1233. r = [];
  1234. if(!len1){
  1235. return c2;
  1236. }
  1237. if(isIE && typeof c1[0].selectSingleNode != "undefined"){
  1238. return quickDiffIEXml(c1, c2);
  1239. }
  1240. for(var i = 0; i < len1; i++){
  1241. c1[i]._qdiff = d;
  1242. }
  1243. for(var i = 0, len = c2.length; i < len; i++){
  1244. if(c2[i]._qdiff != d){
  1245. r[r.length] = c2[i];
  1246. }
  1247. }
  1248. return r;
  1249. }
  1250. function quickId(ns, mode, root, id){
  1251. if(ns == root){
  1252. var d = root.ownerDocument || root;
  1253. return d.getElementById(id);
  1254. }
  1255. ns = getNodes(ns, mode, "*");
  1256. return byId(ns, id);
  1257. }
  1258. return {
  1259. getStyle : function(el, name){
  1260. return Ext.fly(el).getStyle(name);
  1261. },
  1262. /**
  1263. * Compiles a selector/xpath query into a reusable function. The returned function
  1264. * takes one parameter "root" (optional), which is the context node from where the query should start.
  1265. * @param {String} selector The selector/xpath query
  1266. * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
  1267. * @return {Function}
  1268. */
  1269. compile : function(path, type){
  1270. type = type || "select";
  1271. // setup fn preamble
  1272. var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"],
  1273. mode,
  1274. lastPath,
  1275. matchers = Ext.DomQuery.matchers,
  1276. matchersLn = matchers.length,
  1277. modeMatch,
  1278. // accept leading mode switch
  1279. lmode = path.match(modeRe);
  1280. if(lmode && lmode[1]){
  1281. fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
  1282. path = path.replace(lmode[1], "");
  1283. }
  1284. // strip leading slashes
  1285. while(path.substr(0, 1)=="/"){
  1286. path = path.substr(1);
  1287. }
  1288. while(path && lastPath != path){
  1289. lastPath = path;
  1290. var tokenMatch = path.match(tagTokenRe);
  1291. if(type == "select"){
  1292. if(tokenMatch){
  1293. // ID Selector
  1294. if(tokenMatch[1] == "#"){
  1295. fn[fn.length] = 'n = quickId(n, mode, root, "'+tokenMatch[2]+'");';
  1296. }else{
  1297. fn[fn.length] = 'n = getNodes(n, mode, "'+tokenMatch[2]+'");';
  1298. }
  1299. path = path.replace(tokenMatch[0], "");
  1300. }else if(path.substr(0, 1) != '@'){
  1301. fn[fn.length] = 'n = getNodes(n, mode, "*");';
  1302. }
  1303. // type of "simple"
  1304. }else{
  1305. if(tokenMatch){
  1306. if(tokenMatch[1] == "#"){
  1307. fn[fn.length] = 'n = byId(n, "'+tokenMatch[2]+'");';
  1308. }else{
  1309. fn[fn.length] = 'n = byTag(n, "'+tokenMatch[2]+'");';
  1310. }
  1311. path = path.replace(tokenMatch[0], "");
  1312. }
  1313. }
  1314. while(!(modeMatch = path.match(modeRe))){
  1315. var matched = false;
  1316. for(var j = 0; j < matchersLn; j++){
  1317. var t = matchers[j];
  1318. var m = path.match(t.re);
  1319. if(m){
  1320. fn[fn.length] = t.select.replace(tplRe, function(x, i){
  1321. return m[i];
  1322. });
  1323. path = path.replace(m[0], "");
  1324. matched = true;
  1325. break;
  1326. }
  1327. }
  1328. // prevent infinite loop on bad selector
  1329. if(!matched){
  1330. throw 'Error parsing selector, parsing failed at "' + path + '"';
  1331. }
  1332. }
  1333. if(modeMatch[1]){
  1334. fn[fn.length] = 'mode="'+modeMatch[1].replace(trimRe, "")+'";';
  1335. path = path.replace(modeMatch[1], "");
  1336. }
  1337. }
  1338. // close fn out
  1339. fn[fn.length] = "return nodup(n);\n}";
  1340. // eval fn and return it
  1341. eval(fn.join(""));
  1342. return f;
  1343. },
  1344. /**
  1345. * Selects a group of elements.
  1346. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  1347. * @param {Node/String} root (optional) The start of the query (defaults to document).
  1348. * @return {Array} An Array of DOM elements which match the selector. If there are
  1349. * no matches, and empty Array is returned.
  1350. */
  1351. jsSelect: function(path, root, type){
  1352. // set root to doc if not specified.
  1353. root = root || document;
  1354. if(typeof root == "string"){
  1355. root = document.getElementById(root);
  1356. }
  1357. var paths = path.split(","),
  1358. results = [];
  1359. // loop over each selector
  1360. for(var i = 0, len = paths.length; i < len; i++){
  1361. var subPath = paths[i].replace(trimRe, "");
  1362. // compile and place in cache
  1363. if(!cache[subPath]){
  1364. cache[subPath] = Ext.DomQuery.compile(subPath);
  1365. if(!cache[subPath]){
  1366. throw subPath + " is not a valid selector";
  1367. }
  1368. }
  1369. var result = cache[subPath](root);
  1370. if(result && result != document){
  1371. results = results.concat(result);
  1372. }
  1373. }
  1374. // if there were multiple selectors, make sure dups
  1375. // are eliminated
  1376. if(paths.length > 1){
  1377. return nodup(results);
  1378. }
  1379. return results;
  1380. },
  1381. isXml: function(el) {
  1382. var docEl = (el ? el.ownerDocument || el : 0).documentElement;
  1383. return docEl ? docEl.nodeName !== "HTML" : false;
  1384. },
  1385. select : document.querySelectorAll ? function(path, root, type) {
  1386. root = root || document;
  1387. if (!Ext.DomQuery.isXml(root)) {
  1388. try {
  1389. var cs = root.querySelectorAll(path);
  1390. return Ext.toArray(cs);
  1391. }
  1392. catch (ex) {}
  1393. }
  1394. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  1395. } : function(path, root, type) {
  1396. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  1397. },
  1398. /**
  1399. * Selects a single element.
  1400. * @param {String} selector The selector/xpath query
  1401. * @param {Node} root (optional) The start of the query (defaults to document).
  1402. * @return {Element} The DOM element which matched the selector.
  1403. */
  1404. selectNode : function(path, root){
  1405. return Ext.DomQuery.select(path, root)[0];
  1406. },
  1407. /**
  1408. * Selects the value of a node, optionally replacing null with the defaultValue.
  1409. * @param {String} selector The selector/xpath query
  1410. * @param {Node} root (optional) The start of the query (defaults to document).
  1411. * @param {String} defaultValue
  1412. * @return {String}
  1413. */
  1414. selectValue : function(path, root, defaultValue){
  1415. path = path.replace(trimRe, "");
  1416. if(!valueCache[path]){
  1417. valueCache[path] = Ext.DomQuery.compile(path, "select");
  1418. }
  1419. var n = valueCache[path](root), v;
  1420. n = n[0] ? n[0] : n;
  1421. // overcome a limitation of maximum textnode size
  1422. // Rumored to potentially crash IE6 but has not been confirmed.
  1423. // http://reference.sitepoint.com/javascript/Node/normalize
  1424. // https://developer.mozilla.org/En/DOM/Node.normalize
  1425. if (typeof n.normalize == 'function') n.normalize();
  1426. v = (n && n.firstChild ? n.firstChild.nodeValue : null);
  1427. return ((v === null||v === undefined||v==='') ? defaultValue : v);
  1428. },
  1429. /**
  1430. * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.
  1431. * @param {String} selector The selector/xpath query
  1432. * @param {Node} root (optional) The start of the query (defaults to document).
  1433. * @param {Number} defaultValue
  1434. * @return {Number}
  1435. */
  1436. selectNumber : function(path, root, defaultValue){
  1437. var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
  1438. return parseFloat(v);
  1439. },
  1440. /**
  1441. * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
  1442. * @param {String/HTMLElement/Array} el An element id, element or array of elements
  1443. * @param {String} selector The simple selector to test
  1444. * @return {Boolean}
  1445. */
  1446. is : function(el, ss){
  1447. if(typeof el == "string"){
  1448. el = document.getElementById(el);
  1449. }
  1450. var isArray = Ext.isArray(el),
  1451. result = Ext.DomQuery.filter(isArray ? el : [el], ss);
  1452. return isArray ? (result.length == el.length) : (result.length > 0);
  1453. },
  1454. /**
  1455. * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
  1456. * @param {Array} el An array of elements to filter
  1457. * @param {String} selector The simple selector to test
  1458. * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
  1459. * the selector instead of the ones that match
  1460. * @return {Array} An Array of DOM elements which match the selector. If there are
  1461. * no matches, and empty Array is returned.
  1462. */
  1463. filter : function(els, ss, nonMatches){
  1464. ss = ss.replace(trimRe, "");
  1465. if(!simpleCache[ss]){
  1466. simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
  1467. }
  1468. var result = simpleCache[ss](els);
  1469. return nonMatches ? quickDiff(result, els) : result;
  1470. },
  1471. /**
  1472. * Collection of matching regular expressions and code snippets.
  1473. * Each capture group within () will be replace the {} in the select
  1474. * statement as specified by their index.
  1475. */
  1476. matchers : [{
  1477. re: /^\.([\w-]+)/,
  1478. select: 'n = byClassName(n, " {1} ");'
  1479. }, {
  1480. re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
  1481. select: 'n = byPseudo(n, "{1}", "{2}");'
  1482. },{
  1483. re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
  1484. select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
  1485. }, {
  1486. re: /^#([\w-]+)/,
  1487. select: 'n = byId(n, "{1}");'
  1488. },{
  1489. re: /^@([\w-]+)/,
  1490. select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
  1491. }
  1492. ],
  1493. /**
  1494. * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
  1495. * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, &gt; &lt;.
  1496. */
  1497. operators : {
  1498. "=" : function(a, v){
  1499. return a == v;
  1500. },
  1501. "!=" : function(a, v){
  1502. return a != v;
  1503. },
  1504. "^=" : function(a, v){
  1505. return a && a.substr(0, v.length) == v;
  1506. },
  1507. "$=" : function(a, v){
  1508. return a && a.substr(a.length-v.length) == v;
  1509. },
  1510. "*=" : function(a, v){
  1511. return a && a.indexOf(v) !== -1;
  1512. },
  1513. "%=" : function(a, v){
  1514. return (a % v) == 0;
  1515. },
  1516. "|=" : function(a, v){
  1517. return a && (a == v || a.substr(0, v.length+1) == v+'-');
  1518. },
  1519. "~=" : function(a, v){
  1520. return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
  1521. }
  1522. },
  1523. /**
  1524. * <p>Object hash of "pseudo class" filter functions which are used when filtering selections. Each function is passed
  1525. * two parameters:</p><div class="mdetail-params"><ul>
  1526. * <li><b>c</b> : Array<div class="sub-desc">An Array of DOM elements to filter.</div></li>
  1527. * <li><b>v</b> : String<div class="sub-desc">The argument (if any) supplied in the selector.</div></li>
  1528. * </ul></div>
  1529. * <p>A filter function returns an Array of DOM elements which conform to the pseudo class.</p>
  1530. * <p>In addition to the provided pseudo classes listed above such as <code>first-child</code> and <code>nth-child</code>,
  1531. * developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.</p>
  1532. * <p>For example, to filter <code>&lt;a></code> elements to only return links to <i>external</i> resources:</p>
  1533. * <code><pre>
  1534. Ext.DomQuery.pseudos.external = function(c, v){
  1535. var r = [], ri = -1;
  1536. for(var i = 0, ci; ci = c[i]; i++){
  1537. // Include in result set only if it's a link to an external resource
  1538. if(ci.hostname != location.hostname){
  1539. r[++ri] = ci;
  1540. }
  1541. }
  1542. return r;
  1543. };</pre></code>
  1544. * Then external links could be gathered with the following statement:<code><pre>
  1545. var externalLinks = Ext.select("a:external");
  1546. </code></pre>
  1547. */
  1548. pseudos : {
  1549. "first-child" : function(c){
  1550. var r = [], ri = -1, n;
  1551. for(var i = 0, ci; ci = n = c[i]; i++){
  1552. while((n = n.previousSibling) && n.nodeType != 1);
  1553. if(!n){
  1554. r[++ri] = ci;
  1555. }
  1556. }
  1557. return r;
  1558. },
  1559. "last-child" : function(c){
  1560. var r = [], ri = -1, n;
  1561. for(var i = 0, ci; ci = n = c[i]; i++){
  1562. while((n = n.nextSibling) && n.nodeType != 1);
  1563. if(!n){
  1564. r[++ri] = ci;
  1565. }
  1566. }
  1567. return r;
  1568. },
  1569. "nth-child" : function(c, a) {
  1570. var r = [], ri = -1,
  1571. m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),
  1572. f = (m[1] || 1) - 0, l = m[2] - 0;
  1573. for(var i = 0, n; n = c[i]; i++){
  1574. var pn = n.parentNode;
  1575. if (batch != pn._batch) {
  1576. var j = 0;
  1577. for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
  1578. if(cn.nodeType == 1){
  1579. cn.nodeIndex = ++j;
  1580. }
  1581. }
  1582. pn._batch = batch;
  1583. }
  1584. if (f == 1) {
  1585. if (l == 0 || n.nodeIndex == l){
  1586. r[++ri] = n;
  1587. }
  1588. } else if ((n.nodeIndex + l) % f == 0){
  1589. r[++ri] = n;
  1590. }
  1591. }
  1592. return r;
  1593. },
  1594. "only-child" : function(c){
  1595. var r = [], ri = -1;;
  1596. for(var i = 0, ci; ci = c[i]; i++){
  1597. if(!prev(ci) && !next(ci)){
  1598. r[++ri] = ci;
  1599. }
  1600. }
  1601. return r;
  1602. },
  1603. "empty" : function(c){
  1604. var r = [], ri = -1;
  1605. for(var i = 0, ci; ci = c[i]; i++){
  1606. var cns = ci.childNodes, j = 0, cn, empty = true;
  1607. while(cn = cns[j]){
  1608. ++j;
  1609. if(cn.nodeType == 1 || cn.nodeType == 3){
  1610. empty = false;
  1611. break;
  1612. }
  1613. }
  1614. if(empty){
  1615. r[++ri] = ci;
  1616. }
  1617. }
  1618. return r;
  1619. },
  1620. "contains" : function(c, v){
  1621. var r = [], ri = -1;
  1622. for(var i = 0, ci; ci = c[i]; i++){
  1623. if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
  1624. r[++ri] = ci;
  1625. }
  1626. }
  1627. return r;
  1628. },
  1629. "nodeValue" : function(c, v){
  1630. var r = [], ri = -1;
  1631. for(var i = 0, ci; ci = c[i]; i++){
  1632. if(ci.firstChild && ci.firstChild.nodeValue == v){
  1633. r[++ri] = ci;
  1634. }
  1635. }
  1636. return r;
  1637. },
  1638. "checked" : function(c){
  1639. var r = [], ri = -1;
  1640. for(var i = 0, ci; ci = c[i]; i++){
  1641. if(ci.checked == true){
  1642. r[++ri] = ci;
  1643. }
  1644. }
  1645. return r;
  1646. },
  1647. "not" : function(c, ss){
  1648. return Ext.DomQuery.filter(c, ss, true);
  1649. },
  1650. "any" : function(c, selectors){
  1651. var ss = selectors.split('|'),
  1652. r = [], ri = -1, s;
  1653. for(var i = 0, ci; ci = c[i]; i++){
  1654. for(var j = 0; s = ss[j]; j++){
  1655. if(Ext.DomQuery.is(ci, s)){
  1656. r[++ri] = ci;
  1657. break;
  1658. }
  1659. }
  1660. }
  1661. return r;
  1662. },
  1663. "odd" : function(c){
  1664. return this["nth-child"](c, "odd");
  1665. },
  1666. "even" : function(c){
  1667. return this["nth-child"](c, "even");
  1668. },
  1669. "nth" : function(c, a){
  1670. return c[a-1] || [];
  1671. },
  1672. "first" : function(c){
  1673. return c[0] || [];
  1674. },
  1675. "last" : function(c){
  1676. return c[c.length-1] || [];
  1677. },
  1678. "has" : function(c, ss){
  1679. var s = Ext.DomQuery.select,
  1680. r = [], ri = -1;
  1681. for(var i = 0, ci; ci = c[i]; i++){
  1682. if(s(ss, ci).length > 0){
  1683. r[++ri] = ci;
  1684. }
  1685. }
  1686. return r;
  1687. },
  1688. "next" : function(c, ss){
  1689. var is = Ext.DomQuery.is,
  1690. r = [], ri = -1;
  1691. for(var i = 0, ci; ci = c[i]; i++){
  1692. var n = next(ci);
  1693. if(n && is(n, ss)){
  1694. r[++ri] = ci;
  1695. }
  1696. }
  1697. return r;
  1698. },
  1699. "prev" : function(c, ss){
  1700. var is = Ext.DomQuery.is,
  1701. r = [], ri = -1;
  1702. for(var i = 0, ci; ci = c[i]; i++){
  1703. var n = prev(ci);
  1704. if(n && is(n, ss)){
  1705. r[++ri] = ci;
  1706. }
  1707. }
  1708. return r;
  1709. }
  1710. }
  1711. };
  1712. }();
  1713. /**
  1714. * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Ext.DomQuery#select}
  1715. * @param {String} path The selector/xpath query
  1716. * @param {Node} root (optional) The start of the query (defaults to document).
  1717. * @return {Array}
  1718. * @member Ext
  1719. * @method query
  1720. */
  1721. Ext.query = Ext.DomQuery.select;
  1722. /**
  1723. * @class Ext.util.DelayedTask
  1724. * <p> The DelayedTask class provides a convenient way to "buffer" the execution of a method,
  1725. * performing setTimeout where a new timeout cancels the old timeout. When called, the
  1726. * task will wait the specified time period before executing. If durng that time period,
  1727. * the task is called again, the original call will be cancelled. This continues so that
  1728. * the function is only called a single time for each iteration.</p>
  1729. * <p>This method is especially useful for things like detecting whether a user has finished
  1730. * typing in a text field. An example would be performing validation on a keypress. You can
  1731. * use this class to buffer the keypress events for a certain number of milliseconds, and
  1732. * perform only if they stop for that amount of time. Usage:</p><pre><code>
  1733. var task = new Ext.util.DelayedTask(function(){
  1734. alert(Ext.getDom('myInputField').value.length);
  1735. });
  1736. // Wait 500ms before calling our function. If the user presses another key
  1737. // during that 500ms, it will be cancelled and we'll wait another 500ms.
  1738. Ext.get('myInputField').on('keypress', function(){
  1739. task.{@link #delay}(500);
  1740. });
  1741. * </code></pre>
  1742. * <p>Note that we are using a DelayedTask here to illustrate a point. The configuration
  1743. * option <tt>buffer</tt> for {@link Ext.util.Observable#addListener addListener/on} will
  1744. * also setup a delayed task for you to buffer events.</p>
  1745. * @constructor The parameters to this constructor serve as defaults and are not required.
  1746. * @param {Function} fn (optional) The default function to call.
  1747. * @param {Object} scope The default scope (The <code><b>this</b></code> reference) in which the
  1748. * function is called. If not specified, <code>this</code> will refer to the browser window.
  1749. * @param {Array} args (optional) The default Array of arguments.
  1750. */
  1751. Ext.util.DelayedTask = function(fn, scope, args){
  1752. var me = this,
  1753. id,
  1754. call = function(){
  1755. clearInterval(id);
  1756. id = null;
  1757. fn.apply(scope, args || []);
  1758. };
  1759. /**
  1760. * Cancels any pending timeout and queues a new one
  1761. * @param {Number} delay The milliseconds to delay
  1762. * @param {Function} newFn (optional) Overrides function passed to constructor
  1763. * @param {Object} newScope (optional) Overrides scope passed to constructor. Remember that if no scope
  1764. * is specified, <code>this</code> will refer to the browser window.
  1765. * @param {Array} newArgs (optional) Overrides args passed to constructor
  1766. */
  1767. me.delay = function(delay, newFn, newScope, newArgs){
  1768. me.cancel();
  1769. fn = newFn || fn;
  1770. scope = newScope || scope;
  1771. args = newArgs || args;
  1772. id = setInterval(call, delay);
  1773. };
  1774. /**
  1775. * Cancel the last queued timeout
  1776. */
  1777. me.cancel = function(){
  1778. if(id){
  1779. clearInterval(id);
  1780. id = null;
  1781. }
  1782. };
  1783. };(function(){
  1784. var EXTUTIL = Ext.util,
  1785. TOARRAY = Ext.toArray,
  1786. EACH = Ext.each,
  1787. ISOBJECT = Ext.isObject,
  1788. TRUE = true,
  1789. FALSE = false;
  1790. /**
  1791. * @class Ext.util.Observable
  1792. * Base class that provides a common interface for publishing events. Subclasses are expected to
  1793. * to have a property "events" with all the events defined, and, optionally, a property "listeners"
  1794. * with configured listeners defined.<br>
  1795. * For example:
  1796. * <pre><code>
  1797. Employee = Ext.extend(Ext.util.Observable, {
  1798. constructor: function(config){
  1799. this.name = config.name;
  1800. this.addEvents({
  1801. "fired" : true,
  1802. "quit" : true
  1803. });
  1804. // Copy configured listeners into *this* object so that the base class&#39;s
  1805. // constructor will add them.
  1806. this.listeners = config.listeners;
  1807. // Call our superclass constructor to complete construction process.
  1808. Employee.superclass.constructor.call(this, config)
  1809. }
  1810. });
  1811. </code></pre>
  1812. * This could then be used like this:<pre><code>
  1813. var newEmployee = new Employee({
  1814. name: employeeName,
  1815. listeners: {
  1816. quit: function() {
  1817. // By default, "this" will be the object that fired the event.
  1818. alert(this.name + " has quit!");
  1819. }
  1820. }
  1821. });
  1822. </code></pre>
  1823. */
  1824. EXTUTIL.Observable = function(){
  1825. /**
  1826. * @cfg {Object} listeners (optional) <p>A config object containing one or more event handlers to be added to this
  1827. * object during initialization. This should be a valid listeners config object as specified in the
  1828. * {@link #addListener} example for attaching multiple handlers at once.</p>
  1829. * <br><p><b><u>DOM events from ExtJs {@link Ext.Component Components}</u></b></p>
  1830. * <br><p>While <i>some</i> ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this
  1831. * is usually only done when extra value can be added. For example the {@link Ext.DataView DataView}'s
  1832. * <b><code>{@link Ext.DataView#click click}</code></b> event passing the node clicked on. To access DOM
  1833. * events directly from a Component's HTMLElement, listeners must be added to the <i>{@link Ext.Component#getEl Element}</i> after the Component
  1834. * has been rendered. A plugin can simplify this step:<pre><code>
  1835. // Plugin is configured with a listeners config object.
  1836. // The Component is appended to the argument list of all handler functions.
  1837. Ext.DomObserver = Ext.extend(Object, {
  1838. constructor: function(config) {
  1839. this.listeners = config.listeners ? config.listeners : config;
  1840. },
  1841. // Component passes itself into plugin&#39;s init method
  1842. init: function(c) {
  1843. var p, l = this.listeners;
  1844. for (p in l) {
  1845. if (Ext.isFunction(l[p])) {
  1846. l[p] = this.createHandler(l[p], c);
  1847. } else {
  1848. l[p].fn = this.createHandler(l[p].fn, c);
  1849. }
  1850. }
  1851. // Add the listeners to the Element immediately following the render call
  1852. c.render = c.render.{@link Function#createSequence createSequence}(function() {
  1853. var e = c.getEl();
  1854. if (e) {
  1855. e.on(l);
  1856. }
  1857. });
  1858. },
  1859. createHandler: function(fn, c) {
  1860. return function(e) {
  1861. fn.call(this, e, c);
  1862. };
  1863. }
  1864. });
  1865. var combo = new Ext.form.ComboBox({
  1866. // Collapse combo when its element is clicked on
  1867. plugins: [ new Ext.DomObserver({
  1868. click: function(evt, comp) {
  1869. comp.collapse();
  1870. }
  1871. })],
  1872. store: myStore,
  1873. typeAhead: true,
  1874. mode: 'local',
  1875. triggerAction: 'all'
  1876. });
  1877. * </code></pre></p>
  1878. */
  1879. var me = this, e = me.events;
  1880. if(me.listeners){
  1881. me.on(me.listeners);
  1882. delete me.listeners;
  1883. }
  1884. me.events = e || {};
  1885. };
  1886. EXTUTIL.Observable.prototype = {
  1887. // private
  1888. filterOptRe : /^(?:scope|delay|buffer|single)$/,
  1889. /**
  1890. * <p>Fires the specified event with the passed parameters (minus the event name).</p>
  1891. * <p>An event may be set to bubble up an Observable parent hierarchy (See {@link Ext.Component#getBubbleTarget})
  1892. * by calling {@link #enableBubble}.</p>
  1893. * @param {String} eventName The name of the event to fire.
  1894. * @param {Object...} args Variable number of parameters are passed to handlers.
  1895. * @return {Boolean} returns false if any of the handlers return false otherwise it returns true.
  1896. */
  1897. fireEvent : function(){
  1898. var a = TOARRAY(arguments),
  1899. ename = a[0].toLowerCase(),
  1900. me = this,
  1901. ret = TRUE,
  1902. ce = me.events[ename],
  1903. q,
  1904. c;
  1905. if (me.eventsSuspended === TRUE) {
  1906. if (q = me.eventQueue) {
  1907. q.push(a);
  1908. }
  1909. }
  1910. else if(ISOBJECT(ce) && ce.bubble){
  1911. if(ce.fire.apply(ce, a.slice(1)) === FALSE) {
  1912. return FALSE;
  1913. }
  1914. c = me.getBubbleTarget && me.getBubbleTarget();
  1915. if(c && c.enableBubble) {
  1916. if(!c.events[ename] || !Ext.isObject(c.events[ename]) || !c.events[ename].bubble) {
  1917. c.enableBubble(ename);
  1918. }
  1919. return c.fireEvent.apply(c, a);
  1920. }
  1921. }
  1922. else {
  1923. if (ISOBJECT(ce)) {
  1924. a.shift();
  1925. ret = ce.fire.apply(ce, a);
  1926. }
  1927. }
  1928. return ret;
  1929. },
  1930. /**
  1931. * Appends an event handler to this object.
  1932. * @param {String} eventName The name of the event to listen for.
  1933. * @param {Function} handler The method the event invokes.
  1934. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  1935. * <b>If omitted, defaults to the object which fired the event.</b>
  1936. * @param {Object} options (optional) An object containing handler configuration.
  1937. * properties. This may contain any of the following properties:<ul>
  1938. * <li><b>scope</b> : Object<div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  1939. * <b>If omitted, defaults to the object which fired the event.</b></div></li>
  1940. * <li><b>delay</b> : Number<div class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</div></li>
  1941. * <li><b>single</b> : Boolean<div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  1942. * <li><b>buffer</b> : Number<div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  1943. * by the specified number of milliseconds. If the event fires again within that time, the original
  1944. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  1945. * <li><b>target</b> : Observable<div class="sub-desc">Only call the handler if the event was fired on the target Observable, <i>not</i>
  1946. * if the event was bubbled up from a child Observable.</div></li>
  1947. * </ul><br>
  1948. * <p>
  1949. * <b>Combining Options</b><br>
  1950. * Using the options argument, it is possible to combine different types of listeners:<br>
  1951. * <br>
  1952. * A delayed, one-time listener.
  1953. * <pre><code>
  1954. myDataView.on('click', this.onClick, this, {
  1955. single: true,
  1956. delay: 100
  1957. });</code></pre>
  1958. * <p>
  1959. * <b>Attaching multiple handlers in 1 call</b><br>
  1960. * The method also allows for a single argument to be passed which is a config object containing properties
  1961. * which specify multiple handlers.
  1962. * <p>
  1963. * <pre><code>
  1964. myGridPanel.on({
  1965. 'click' : {
  1966. fn: this.onClick,
  1967. scope: this,
  1968. delay: 100
  1969. },
  1970. 'mouseover' : {
  1971. fn: this.onMouseOver,
  1972. scope: this
  1973. },
  1974. 'mouseout' : {
  1975. fn: this.onMouseOut,
  1976. scope: this
  1977. }
  1978. });</code></pre>
  1979. * <p>
  1980. * Or a shorthand syntax:<br>
  1981. * <pre><code>
  1982. myGridPanel.on({
  1983. 'click' : this.onClick,
  1984. 'mouseover' : this.onMouseOver,
  1985. 'mouseout' : this.onMouseOut,
  1986. scope: this
  1987. });</code></pre>
  1988. */
  1989. addListener : function(eventName, fn, scope, o){
  1990. var me = this,
  1991. e,
  1992. oe,
  1993. isF,
  1994. ce;
  1995. if (ISOBJECT(eventName)) {
  1996. o = eventName;
  1997. for (e in o){
  1998. oe = o[e];
  1999. if (!me.filterOptRe.test(e)) {
  2000. me.addListener(e, oe.fn || oe, oe.scope || o.scope, oe.fn ? oe : o);
  2001. }
  2002. }
  2003. } else {
  2004. eventName = eventName.toLowerCase();
  2005. ce = me.events[eventName] || TRUE;
  2006. if (Ext.isBoolean(ce)) {
  2007. me.events[eventName] = ce = new EXTUTIL.Event(me, eventName);
  2008. }
  2009. ce.addListener(fn, scope, ISOBJECT(o) ? o : {});
  2010. }
  2011. },
  2012. /**
  2013. * Removes an event handler.
  2014. * @param {String} eventName The type of event the handler was associated with.
  2015. * @param {Function} handler The handler to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  2016. * @param {Object} scope (optional) The scope originally specified for the handler.
  2017. */
  2018. removeListener : function(eventName, fn, scope){
  2019. var ce = this.events[eventName.toLowerCase()];
  2020. if (ISOBJECT(ce)) {
  2021. ce.removeListener(fn, scope);
  2022. }
  2023. },
  2024. /**
  2025. * Removes all listeners for this object
  2026. */
  2027. purgeListeners : function(){
  2028. var events = this.events,
  2029. evt,
  2030. key;
  2031. for(key in events){
  2032. evt = events[key];
  2033. if(ISOBJECT(evt)){
  2034. evt.clearListeners();
  2035. }
  2036. }
  2037. },
  2038. /**
  2039. * Adds the specified events to the list of events which this Observable may fire.
  2040. * @param {Object|String} o Either an object with event names as properties with a value of <code>true</code>
  2041. * or the first event name string if multiple event names are being passed as separate parameters.
  2042. * @param {string} Optional. Event name if multiple event names are being passed as separate parameters.
  2043. * Usage:<pre><code>
  2044. this.addEvents('storeloaded', 'storecleared');
  2045. </code></pre>
  2046. */
  2047. addEvents : function(o){
  2048. var me = this;
  2049. me.events = me.events || {};
  2050. if (Ext.isString(o)) {
  2051. var a = arguments,
  2052. i = a.length;
  2053. while(i--) {
  2054. me.events[a[i]] = me.events[a[i]] || TRUE;
  2055. }
  2056. } else {
  2057. Ext.applyIf(me.events, o);
  2058. }
  2059. },
  2060. /**
  2061. * Checks to see if this object has any listeners for a specified event
  2062. * @param {String} eventName The name of the event to check for
  2063. * @return {Boolean} True if the event is being listened for, else false
  2064. */
  2065. hasListener : function(eventName){
  2066. var e = this.events[eventName.toLowerCase()];
  2067. return ISOBJECT(e) && e.listeners.length > 0;
  2068. },
  2069. /**
  2070. * Suspend the firing of all events. (see {@link #resumeEvents})
  2071. * @param {Boolean} queueSuspended Pass as true to queue up suspended events to be fired
  2072. * after the {@link #resumeEvents} call instead of discarding all suspended events;
  2073. */
  2074. suspendEvents : function(queueSuspended){
  2075. this.eventsSuspended = TRUE;
  2076. if(queueSuspended && !this.eventQueue){
  2077. this.eventQueue = [];
  2078. }
  2079. },
  2080. /**
  2081. * Resume firing events. (see {@link #suspendEvents})
  2082. * If events were suspended using the <tt><b>queueSuspended</b></tt> parameter, then all
  2083. * events fired during event suspension will be sent to any listeners now.
  2084. */
  2085. resumeEvents : function(){
  2086. var me = this,
  2087. queued = me.eventQueue || [];
  2088. me.eventsSuspended = FALSE;
  2089. delete me.eventQueue;
  2090. EACH(queued, function(e) {
  2091. me.fireEvent.apply(me, e);
  2092. });
  2093. }
  2094. };
  2095. var OBSERVABLE = EXTUTIL.Observable.prototype;
  2096. /**
  2097. * Appends an event handler to this object (shorthand for {@link #addListener}.)
  2098. * @param {String} eventName The type of event to listen for
  2099. * @param {Function} handler The method the event invokes
  2100. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  2101. * <b>If omitted, defaults to the object which fired the event.</b>
  2102. * @param {Object} options (optional) An object containing handler configuration.
  2103. * @method
  2104. */
  2105. OBSERVABLE.on = OBSERVABLE.addListener;
  2106. /**
  2107. * Removes an event handler (shorthand for {@link #removeListener}.)
  2108. * @param {String} eventName The type of event the handler was associated with.
  2109. * @param {Function} handler The handler to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  2110. * @param {Object} scope (optional) The scope originally specified for the handler.
  2111. * @method
  2112. */
  2113. OBSERVABLE.un = OBSERVABLE.removeListener;
  2114. /**
  2115. * Removes <b>all</b> added captures from the Observable.
  2116. * @param {Observable} o The Observable to release
  2117. * @static
  2118. */
  2119. EXTUTIL.Observable.releaseCapture = function(o){
  2120. o.fireEvent = OBSERVABLE.fireEvent;
  2121. };
  2122. function createTargeted(h, o, scope){
  2123. return function(){
  2124. if(o.target == arguments[0]){
  2125. h.apply(scope, TOARRAY(arguments));
  2126. }
  2127. };
  2128. };
  2129. function createBuffered(h, o, l, scope){
  2130. l.task = new EXTUTIL.DelayedTask();
  2131. return function(){
  2132. l.task.delay(o.buffer, h, scope, TOARRAY(arguments));
  2133. };
  2134. };
  2135. function createSingle(h, e, fn, scope){
  2136. return function(){
  2137. e.removeListener(fn, scope);
  2138. return h.apply(scope, arguments);
  2139. };
  2140. };
  2141. function createDelayed(h, o, l, scope){
  2142. return function(){
  2143. var task = new EXTUTIL.DelayedTask();
  2144. if(!l.tasks) {
  2145. l.tasks = [];
  2146. }
  2147. l.tasks.push(task);
  2148. task.delay(o.delay || 10, h, scope, TOARRAY(arguments));
  2149. };
  2150. };
  2151. EXTUTIL.Event = function(obj, name){
  2152. this.name = name;
  2153. this.obj = obj;
  2154. this.listeners = [];
  2155. };
  2156. EXTUTIL.Event.prototype = {
  2157. addListener : function(fn, scope, options){
  2158. var me = this,
  2159. l;
  2160. scope = scope || me.obj;
  2161. if(!me.isListening(fn, scope)){
  2162. l = me.createListener(fn, scope, options);
  2163. if(me.firing){ // if we are currently firing this event, don't disturb the listener loop
  2164. me.listeners = me.listeners.slice(0);
  2165. }
  2166. me.listeners.push(l);
  2167. }
  2168. },
  2169. createListener: function(fn, scope, o){
  2170. o = o || {}, scope = scope || this.obj;
  2171. var l = {
  2172. fn: fn,
  2173. scope: scope,
  2174. options: o
  2175. }, h = fn;
  2176. if(o.target){
  2177. h = createTargeted(h, o, scope);
  2178. }
  2179. if(o.delay){
  2180. h = createDelayed(h, o, l, scope);
  2181. }
  2182. if(o.single){
  2183. h = createSingle(h, this, fn, scope);
  2184. }
  2185. if(o.buffer){
  2186. h = createBuffered(h, o, l, scope);
  2187. }
  2188. l.fireFn = h;
  2189. return l;
  2190. },
  2191. findListener : function(fn, scope){
  2192. var list = this.listeners,
  2193. i = list.length,
  2194. l;
  2195. scope = scope || this.obj;
  2196. while(i--){
  2197. l = list[i];
  2198. if(l){
  2199. if(l.fn == fn && l.scope == scope){
  2200. return i;
  2201. }
  2202. }
  2203. }
  2204. return -1;
  2205. },
  2206. isListening : function(fn, scope){
  2207. return this.findListener(fn, scope) != -1;
  2208. },
  2209. removeListener : function(fn, scope){
  2210. var index,
  2211. l,
  2212. k,
  2213. me = this,
  2214. ret = FALSE;
  2215. if((index = me.findListener(fn, scope)) != -1){
  2216. if (me.firing) {
  2217. me.listeners = me.listeners.slice(0);
  2218. }
  2219. l = me.listeners[index];
  2220. if(l.task) {
  2221. l.task.cancel();
  2222. delete l.task;
  2223. }
  2224. k = l.tasks && l.tasks.length;
  2225. if(k) {
  2226. while(k--) {
  2227. l.tasks[k].cancel();
  2228. }
  2229. delete l.tasks;
  2230. }
  2231. me.listeners.splice(index, 1);
  2232. ret = TRUE;
  2233. }
  2234. return ret;
  2235. },
  2236. // Iterate to stop any buffered/delayed events
  2237. clearListeners : function(){
  2238. var me = this,
  2239. l = me.listeners,
  2240. i = l.length;
  2241. while(i--) {
  2242. me.removeListener(l[i].fn, l[i].scope);
  2243. }
  2244. },
  2245. fire : function(){
  2246. var me = this,
  2247. args = TOARRAY(arguments),
  2248. listeners = me.listeners,
  2249. len = listeners.length,
  2250. i = 0,
  2251. l;
  2252. if(len > 0){
  2253. me.firing = TRUE;
  2254. for (; i < len; i++) {
  2255. l = listeners[i];
  2256. if(l && l.fireFn.apply(l.scope || me.obj || window, args) === FALSE) {
  2257. return (me.firing = FALSE);
  2258. }
  2259. }
  2260. }
  2261. me.firing = FALSE;
  2262. return TRUE;
  2263. }
  2264. };
  2265. })();/**
  2266. * @class Ext.util.Observable
  2267. */
  2268. Ext.apply(Ext.util.Observable.prototype, function(){
  2269. // this is considered experimental (along with beforeMethod, afterMethod, removeMethodListener?)
  2270. // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
  2271. // private
  2272. function getMethodEvent(method){
  2273. var e = (this.methodEvents = this.methodEvents ||
  2274. {})[method], returnValue, v, cancel, obj = this;
  2275. if (!e) {
  2276. this.methodEvents[method] = e = {};
  2277. e.originalFn = this[method];
  2278. e.methodName = method;
  2279. e.before = [];
  2280. e.after = [];
  2281. var makeCall = function(fn, scope, args){
  2282. if (!Ext.isEmpty(v = fn.apply(scope || obj, args))) {
  2283. if (Ext.isObject(v)) {
  2284. returnValue = !Ext.isEmpty(v.returnValue) ? v.returnValue : v;
  2285. cancel = !!v.cancel;
  2286. }
  2287. else
  2288. if (v === false) {
  2289. cancel = true;
  2290. }
  2291. else {
  2292. returnValue = v;
  2293. }
  2294. }
  2295. };
  2296. this[method] = function(){
  2297. var args = Ext.toArray(arguments);
  2298. returnValue = v = undefined;
  2299. cancel = false;
  2300. Ext.each(e.before, function(b){
  2301. makeCall(b.fn, b.scope, args);
  2302. if (cancel) {
  2303. return returnValue;
  2304. }
  2305. });
  2306. if (!Ext.isEmpty(v = e.originalFn.apply(obj, args))) {
  2307. returnValue = v;
  2308. }
  2309. Ext.each(e.after, function(a){
  2310. makeCall(a.fn, a.scope, args);
  2311. if (cancel) {
  2312. return returnValue;
  2313. }
  2314. });
  2315. return returnValue;
  2316. };
  2317. }
  2318. return e;
  2319. }
  2320. return {
  2321. // these are considered experimental
  2322. // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
  2323. // adds an 'interceptor' called before the original method
  2324. beforeMethod : function(method, fn, scope){
  2325. getMethodEvent.call(this, method).before.push({
  2326. fn: fn,
  2327. scope: scope
  2328. });
  2329. },
  2330. // adds a 'sequence' called after the original method
  2331. afterMethod : function(method, fn, scope){
  2332. getMethodEvent.call(this, method).after.push({
  2333. fn: fn,
  2334. scope: scope
  2335. });
  2336. },
  2337. removeMethodListener: function(method, fn, scope){
  2338. var e = getMethodEvent.call(this, method), found = false;
  2339. Ext.each(e.before, function(b, i, arr){
  2340. if (b.fn == fn && b.scope == scope) {
  2341. arr.splice(i, 1);
  2342. found = true;
  2343. return false;
  2344. }
  2345. });
  2346. if (!found) {
  2347. Ext.each(e.after, function(a, i, arr){
  2348. if (a.fn == fn && a.scope == scope) {
  2349. arr.splice(i, 1);
  2350. return false;
  2351. }
  2352. });
  2353. }
  2354. },
  2355. /**
  2356. * Relays selected events from the specified Observable as if the events were fired by <tt><b>this</b></tt>.
  2357. * @param {Object} o The Observable whose events this object is to relay.
  2358. * @param {Array} events Array of event names to relay.
  2359. */
  2360. relayEvents : function(o, events){
  2361. var me = this;
  2362. function createHandler(ename){
  2363. return function(){
  2364. return me.fireEvent.apply(me, [ename].concat(Ext.toArray(arguments)));
  2365. };
  2366. }
  2367. Ext.each(events, function(ename){
  2368. me.events[ename] = me.events[ename] || true;
  2369. o.on(ename, createHandler(ename), me);
  2370. });
  2371. },
  2372. /**
  2373. * <p>Enables events fired by this Observable to bubble up an owner hierarchy by calling
  2374. * <code>this.getBubbleTarget()</code> if present. There is no implementation in the Observable base class.</p>
  2375. * <p>This is commonly used by Ext.Components to bubble events to owner Containers. See {@link Ext.Component.getBubbleTarget}. The default
  2376. * implementation in Ext.Component returns the Component's immediate owner. But if a known target is required, this can be overridden to
  2377. * access the required target more quickly.</p>
  2378. * <p>Example:</p><pre><code>
  2379. Ext.override(Ext.form.Field, {
  2380. // Add functionality to Field&#39;s initComponent to enable the change event to bubble
  2381. initComponent : Ext.form.Field.prototype.initComponent.createSequence(function() {
  2382. this.enableBubble('change');
  2383. }),
  2384. // We know that we want Field&#39;s events to bubble directly to the FormPanel.
  2385. getBubbleTarget : function() {
  2386. if (!this.formPanel) {
  2387. this.formPanel = this.findParentByType('form');
  2388. }
  2389. return this.formPanel;
  2390. }
  2391. });
  2392. var myForm = new Ext.formPanel({
  2393. title: 'User Details',
  2394. items: [{
  2395. ...
  2396. }],
  2397. listeners: {
  2398. change: function() {
  2399. // Title goes red if form has been modified.
  2400. myForm.header.setStyle('color', 'red');
  2401. }
  2402. }
  2403. });
  2404. </code></pre>
  2405. * @param {String/Array} events The event name to bubble, or an Array of event names.
  2406. */
  2407. enableBubble : function(events){
  2408. var me = this;
  2409. if(!Ext.isEmpty(events)){
  2410. events = Ext.isArray(events) ? events : Ext.toArray(arguments);
  2411. Ext.each(events, function(ename){
  2412. ename = ename.toLowerCase();
  2413. var ce = me.events[ename] || true;
  2414. if (Ext.isBoolean(ce)) {
  2415. ce = new Ext.util.Event(me, ename);
  2416. me.events[ename] = ce;
  2417. }
  2418. ce.bubble = true;
  2419. });
  2420. }
  2421. }
  2422. };
  2423. }());
  2424. /**
  2425. * Starts capture on the specified Observable. All events will be passed
  2426. * to the supplied function with the event name + standard signature of the event
  2427. * <b>before</b> the event is fired. If the supplied function returns false,
  2428. * the event will not fire.
  2429. * @param {Observable} o The Observable to capture events from.
  2430. * @param {Function} fn The function to call when an event is fired.
  2431. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Observable firing the event.
  2432. * @static
  2433. */
  2434. Ext.util.Observable.capture = function(o, fn, scope){
  2435. o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
  2436. };
  2437. /**
  2438. * Sets observability on the passed class constructor.<p>
  2439. * <p>This makes any event fired on any instance of the passed class also fire a single event through
  2440. * the <i>class</i> allowing for central handling of events on many instances at once.</p>
  2441. * <p>Usage:</p><pre><code>
  2442. Ext.util.Observable.observeClass(Ext.data.Connection);
  2443. Ext.data.Connection.on('beforerequest', function(con, options) {
  2444. console.log('Ajax request made to ' + options.url);
  2445. });</code></pre>
  2446. * @param {Function} c The class constructor to make observable.
  2447. * @param {Object} listeners An object containing a series of listeners to add. See {@link #addListener}.
  2448. * @static
  2449. */
  2450. Ext.util.Observable.observeClass = function(c, listeners){
  2451. if(c){
  2452. if(!c.fireEvent){
  2453. Ext.apply(c, new Ext.util.Observable());
  2454. Ext.util.Observable.capture(c.prototype, c.fireEvent, c);
  2455. }
  2456. if(Ext.isObject(listeners)){
  2457. c.on(listeners);
  2458. }
  2459. return c;
  2460. }
  2461. };/**
  2462. * @class Ext.EventManager
  2463. * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
  2464. * several useful events directly.
  2465. * See {@link Ext.EventObject} for more details on normalized event objects.
  2466. * @singleton
  2467. */
  2468. Ext.EventManager = function(){
  2469. var docReadyEvent,
  2470. docReadyProcId,
  2471. docReadyState = false,
  2472. DETECT_NATIVE = Ext.isGecko || Ext.isWebKit || Ext.isSafari,
  2473. E = Ext.lib.Event,
  2474. D = Ext.lib.Dom,
  2475. DOC = document,
  2476. WINDOW = window,
  2477. DOMCONTENTLOADED = "DOMContentLoaded",
  2478. COMPLETE = 'complete',
  2479. propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,
  2480. /*
  2481. * This cache is used to hold special js objects, the document and window, that don't have an id. We need to keep
  2482. * a reference to them so we can look them up at a later point.
  2483. */
  2484. specialElCache = [];
  2485. function getId(el){
  2486. var id = false,
  2487. i = 0,
  2488. len = specialElCache.length,
  2489. id = false,
  2490. skip = false,
  2491. o;
  2492. if(el){
  2493. if(el.getElementById || el.navigator){
  2494. // look up the id
  2495. for(; i < len; ++i){
  2496. o = specialElCache[i];
  2497. if(o.el === el){
  2498. id = o.id;
  2499. break;
  2500. }
  2501. }
  2502. if(!id){
  2503. // for browsers that support it, ensure that give the el the same id
  2504. id = Ext.id(el);
  2505. specialElCache.push({
  2506. id: id,
  2507. el: el
  2508. });
  2509. skip = true;
  2510. }
  2511. }else{
  2512. id = Ext.id(el);
  2513. }
  2514. if(!Ext.elCache[id]){
  2515. Ext.Element.addToCache(new Ext.Element(el), id);
  2516. if(skip){
  2517. Ext.elCache[id].skipGC = true;
  2518. }
  2519. }
  2520. }
  2521. return id;
  2522. };
  2523. /// There is some jquery work around stuff here that isn't needed in Ext Core.
  2524. function addListener(el, ename, fn, task, wrap, scope){
  2525. el = Ext.getDom(el);
  2526. var id = getId(el),
  2527. es = Ext.elCache[id].events,
  2528. wfn;
  2529. wfn = E.on(el, ename, wrap);
  2530. es[ename] = es[ename] || [];
  2531. /* 0 = Original Function,
  2532. 1 = Event Manager Wrapped Function,
  2533. 2 = Scope,
  2534. 3 = Adapter Wrapped Function,
  2535. 4 = Buffered Task
  2536. */
  2537. es[ename].push([fn, wrap, scope, wfn, task]);
  2538. // this is a workaround for jQuery and should somehow be removed from Ext Core in the future
  2539. // without breaking ExtJS.
  2540. // workaround for jQuery
  2541. if(el.addEventListener && ename == "mousewheel"){
  2542. var args = ["DOMMouseScroll", wrap, false];
  2543. el.addEventListener.apply(el, args);
  2544. Ext.EventManager.addListener(WINDOW, 'unload', function(){
  2545. el.removeEventListener.apply(el, args);
  2546. });
  2547. }
  2548. // fix stopped mousedowns on the document
  2549. if(el == DOC && ename == "mousedown"){
  2550. Ext.EventManager.stoppedMouseDownEvent.addListener(wrap);
  2551. }
  2552. };
  2553. function doScrollChk(){
  2554. /* Notes:
  2555. 'doScroll' will NOT work in a IFRAME/FRAMESET.
  2556. The method succeeds but, a DOM query done immediately after -- FAILS.
  2557. */
  2558. if(window != top){
  2559. return false;
  2560. }
  2561. try{
  2562. DOC.documentElement.doScroll('left');
  2563. }catch(e){
  2564. return false;
  2565. }
  2566. fireDocReady();
  2567. return true;
  2568. }
  2569. /**
  2570. * @return {Boolean} True if the document is in a 'complete' state (or was determined to
  2571. * be true by other means). If false, the state is evaluated again until canceled.
  2572. */
  2573. function checkReadyState(e){
  2574. if(Ext.isIE && doScrollChk()){
  2575. return true;
  2576. }
  2577. if(DOC.readyState == COMPLETE){
  2578. fireDocReady();
  2579. return true;
  2580. }
  2581. docReadyState || (docReadyProcId = setTimeout(arguments.callee, 2));
  2582. return false;
  2583. }
  2584. var styles;
  2585. function checkStyleSheets(e){
  2586. styles || (styles = Ext.query('style, link[rel=stylesheet]'));
  2587. if(styles.length == DOC.styleSheets.length){
  2588. fireDocReady();
  2589. return true;
  2590. }
  2591. docReadyState || (docReadyProcId = setTimeout(arguments.callee, 2));
  2592. return false;
  2593. }
  2594. function OperaDOMContentLoaded(e){
  2595. DOC.removeEventListener(DOMCONTENTLOADED, arguments.callee, false);
  2596. checkStyleSheets();
  2597. }
  2598. function fireDocReady(e){
  2599. if(!docReadyState){
  2600. docReadyState = true; //only attempt listener removal once
  2601. if(docReadyProcId){
  2602. clearTimeout(docReadyProcId);
  2603. }
  2604. if(DETECT_NATIVE) {
  2605. DOC.removeEventListener(DOMCONTENTLOADED, fireDocReady, false);
  2606. }
  2607. if(Ext.isIE && checkReadyState.bindIE){ //was this was actually set ??
  2608. DOC.detachEvent('onreadystatechange', checkReadyState);
  2609. }
  2610. E.un(WINDOW, "load", arguments.callee);
  2611. }
  2612. if(docReadyEvent && !Ext.isReady){
  2613. Ext.isReady = true;
  2614. docReadyEvent.fire();
  2615. docReadyEvent.listeners = [];
  2616. }
  2617. };
  2618. function initDocReady(){
  2619. docReadyEvent || (docReadyEvent = new Ext.util.Event());
  2620. if (DETECT_NATIVE) {
  2621. DOC.addEventListener(DOMCONTENTLOADED, fireDocReady, false);
  2622. }
  2623. /*
  2624. * Handle additional (exceptional) detection strategies here
  2625. */
  2626. if (Ext.isIE){
  2627. //Use readystatechange as a backup AND primary detection mechanism for a FRAME/IFRAME
  2628. //See if page is already loaded
  2629. if(!checkReadyState()){
  2630. checkReadyState.bindIE = true;
  2631. DOC.attachEvent('onreadystatechange', checkReadyState);
  2632. }
  2633. }else if(Ext.isOpera ){
  2634. /* Notes:
  2635. Opera needs special treatment needed here because CSS rules are NOT QUITE
  2636. available after DOMContentLoaded is raised.
  2637. */
  2638. //See if page is already loaded and all styleSheets are in place
  2639. (DOC.readyState == COMPLETE && checkStyleSheets()) ||
  2640. DOC.addEventListener(DOMCONTENTLOADED, OperaDOMContentLoaded, false);
  2641. }else if (Ext.isWebKit){
  2642. //Fallback for older Webkits without DOMCONTENTLOADED support
  2643. checkReadyState();
  2644. }
  2645. // no matter what, make sure it fires on load
  2646. E.on(WINDOW, "load", fireDocReady);
  2647. };
  2648. function createTargeted(h, o){
  2649. return function(){
  2650. var args = Ext.toArray(arguments);
  2651. if(o.target == Ext.EventObject.setEvent(args[0]).target){
  2652. h.apply(this, args);
  2653. }
  2654. };
  2655. };
  2656. function createBuffered(h, o, task){
  2657. return function(e){
  2658. // create new event object impl so new events don't wipe out properties
  2659. task.delay(o.buffer, h, null, [new Ext.EventObjectImpl(e)]);
  2660. };
  2661. };
  2662. function createSingle(h, el, ename, fn, scope){
  2663. return function(e){
  2664. Ext.EventManager.removeListener(el, ename, fn, scope);
  2665. h(e);
  2666. };
  2667. };
  2668. function createDelayed(h, o, fn){
  2669. return function(e){
  2670. var task = new Ext.util.DelayedTask(h);
  2671. if(!fn.tasks) {
  2672. fn.tasks = [];
  2673. }
  2674. fn.tasks.push(task);
  2675. task.delay(o.delay || 10, h, null, [new Ext.EventObjectImpl(e)]);
  2676. };
  2677. };
  2678. function listen(element, ename, opt, fn, scope){
  2679. var o = !Ext.isObject(opt) ? {} : opt,
  2680. el = Ext.getDom(element), task;
  2681. fn = fn || o.fn;
  2682. scope = scope || o.scope;
  2683. if(!el){
  2684. throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
  2685. }
  2686. function h(e){
  2687. // prevent errors while unload occurring
  2688. if(!Ext){// !window[xname]){ ==> can't we do this?
  2689. return;
  2690. }
  2691. e = Ext.EventObject.setEvent(e);
  2692. var t;
  2693. if (o.delegate) {
  2694. if(!(t = e.getTarget(o.delegate, el))){
  2695. return;
  2696. }
  2697. } else {
  2698. t = e.target;
  2699. }
  2700. if (o.stopEvent) {
  2701. e.stopEvent();
  2702. }
  2703. if (o.preventDefault) {
  2704. e.preventDefault();
  2705. }
  2706. if (o.stopPropagation) {
  2707. e.stopPropagation();
  2708. }
  2709. if (o.normalized) {
  2710. e = e.browserEvent;
  2711. }
  2712. fn.call(scope || el, e, t, o);
  2713. };
  2714. if(o.target){
  2715. h = createTargeted(h, o);
  2716. }
  2717. if(o.delay){
  2718. h = createDelayed(h, o, fn);
  2719. }
  2720. if(o.single){
  2721. h = createSingle(h, el, ename, fn, scope);
  2722. }
  2723. if(o.buffer){
  2724. task = new Ext.util.DelayedTask(h);
  2725. h = createBuffered(h, o, task);
  2726. }
  2727. addListener(el, ename, fn, task, h, scope);
  2728. return h;
  2729. };
  2730. var pub = {
  2731. /**
  2732. * Appends an event handler to an element. The shorthand version {@link #on} is equivalent. Typically you will
  2733. * use {@link Ext.Element#addListener} directly on an Element in favor of calling this version.
  2734. * @param {String/HTMLElement} el The html element or id to assign the event handler to.
  2735. * @param {String} eventName The name of the event to listen for.
  2736. * @param {Function} handler The handler function the event invokes. This function is passed
  2737. * the following parameters:<ul>
  2738. * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
  2739. * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.
  2740. * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
  2741. * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li>
  2742. * </ul>
  2743. * @param {Object} scope (optional) The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.
  2744. * @param {Object} options (optional) An object containing handler configuration properties.
  2745. * This may contain any of the following properties:<ul>
  2746. * <li>scope : Object<div class="sub-desc">The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.</div></li>
  2747. * <li>delegate : String<div class="sub-desc">A simple selector to filter the target or look for a descendant of the target</div></li>
  2748. * <li>stopEvent : Boolean<div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
  2749. * <li>preventDefault : Boolean<div class="sub-desc">True to prevent the default action</div></li>
  2750. * <li>stopPropagation : Boolean<div class="sub-desc">True to prevent event propagation</div></li>
  2751. * <li>normalized : Boolean<div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
  2752. * <li>delay : Number<div class="sub-desc">The number of milliseconds to delay the invocation of the handler after te event fires.</div></li>
  2753. * <li>single : Boolean<div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  2754. * <li>buffer : Number<div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  2755. * by the specified number of milliseconds. If the event fires again within that time, the original
  2756. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  2757. * <li>target : Element<div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
  2758. * </ul><br>
  2759. * <p>See {@link Ext.Element#addListener} for examples of how to use these options.</p>
  2760. */
  2761. addListener : function(element, eventName, fn, scope, options){
  2762. if(Ext.isObject(eventName)){
  2763. var o = eventName, e, val;
  2764. for(e in o){
  2765. val = o[e];
  2766. if(!propRe.test(e)){
  2767. if(Ext.isFunction(val)){
  2768. // shared options
  2769. listen(element, e, o, val, o.scope);
  2770. }else{
  2771. // individual options
  2772. listen(element, e, val);
  2773. }
  2774. }
  2775. }
  2776. } else {
  2777. listen(element, eventName, options, fn, scope);
  2778. }
  2779. },
  2780. /**
  2781. * Removes an event handler from an element. The shorthand version {@link #un} is equivalent. Typically
  2782. * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version.
  2783. * @param {String/HTMLElement} el The id or html element from which to remove the listener.
  2784. * @param {String} eventName The name of the event.
  2785. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  2786. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  2787. * then this must refer to the same object.
  2788. */
  2789. removeListener : function(el, eventName, fn, scope){
  2790. el = Ext.getDom(el);
  2791. var id = getId(el),
  2792. f = el && (Ext.elCache[id].events)[eventName] || [],
  2793. wrap, i, l, k, len, fnc;
  2794. for (i = 0, len = f.length; i < len; i++) {
  2795. /* 0 = Original Function,
  2796. 1 = Event Manager Wrapped Function,
  2797. 2 = Scope,
  2798. 3 = Adapter Wrapped Function,
  2799. 4 = Buffered Task
  2800. */
  2801. if (Ext.isArray(fnc = f[i]) && fnc[0] == fn && (!scope || fnc[2] == scope)) {
  2802. if(fnc[4]) {
  2803. fnc[4].cancel();
  2804. }
  2805. k = fn.tasks && fn.tasks.length;
  2806. if(k) {
  2807. while(k--) {
  2808. fn.tasks[k].cancel();
  2809. }
  2810. delete fn.tasks;
  2811. }
  2812. wrap = fnc[1];
  2813. E.un(el, eventName, E.extAdapter ? fnc[3] : wrap);
  2814. // jQuery workaround that should be removed from Ext Core
  2815. if(wrap && el.addEventListener && eventName == "mousewheel"){
  2816. el.removeEventListener("DOMMouseScroll", wrap, false);
  2817. }
  2818. // fix stopped mousedowns on the document
  2819. if(wrap && el == DOC && eventName == "mousedown"){
  2820. Ext.EventManager.stoppedMouseDownEvent.removeListener(wrap);
  2821. }
  2822. f.splice(i, 1);
  2823. if (f.length === 0) {
  2824. delete Ext.elCache[id].events[eventName];
  2825. }
  2826. for (k in Ext.elCache[id].events) {
  2827. return false;
  2828. }
  2829. Ext.elCache[id].events = {};
  2830. return false;
  2831. }
  2832. }
  2833. },
  2834. /**
  2835. * Removes all event handers from an element. Typically you will use {@link Ext.Element#removeAllListeners}
  2836. * directly on an Element in favor of calling this version.
  2837. * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
  2838. */
  2839. removeAll : function(el){
  2840. el = Ext.getDom(el);
  2841. var id = getId(el),
  2842. ec = Ext.elCache[id] || {},
  2843. es = ec.events || {},
  2844. f, i, len, ename, fn, k, wrap;
  2845. for(ename in es){
  2846. if(es.hasOwnProperty(ename)){
  2847. f = es[ename];
  2848. /* 0 = Original Function,
  2849. 1 = Event Manager Wrapped Function,
  2850. 2 = Scope,
  2851. 3 = Adapter Wrapped Function,
  2852. 4 = Buffered Task
  2853. */
  2854. for (i = 0, len = f.length; i < len; i++) {
  2855. fn = f[i];
  2856. if(fn[4]) {
  2857. fn[4].cancel();
  2858. }
  2859. if(fn[0].tasks && (k = fn[0].tasks.length)) {
  2860. while(k--) {
  2861. fn[0].tasks[k].cancel();
  2862. }
  2863. delete fn.tasks;
  2864. }
  2865. wrap = fn[1];
  2866. E.un(el, ename, E.extAdapter ? fn[3] : wrap);
  2867. // jQuery workaround that should be removed from Ext Core
  2868. if(el.addEventListener && wrap && ename == "mousewheel"){
  2869. el.removeEventListener("DOMMouseScroll", wrap, false);
  2870. }
  2871. // fix stopped mousedowns on the document
  2872. if(wrap && el == DOC && ename == "mousedown"){
  2873. Ext.EventManager.stoppedMouseDownEvent.removeListener(wrap);
  2874. }
  2875. }
  2876. }
  2877. }
  2878. if (Ext.elCache[id]) {
  2879. Ext.elCache[id].events = {};
  2880. }
  2881. },
  2882. getListeners : function(el, eventName) {
  2883. el = Ext.getDom(el);
  2884. var id = getId(el),
  2885. ec = Ext.elCache[id] || {},
  2886. es = ec.events || {},
  2887. results = [];
  2888. if (es && es[eventName]) {
  2889. return es[eventName];
  2890. } else {
  2891. return null;
  2892. }
  2893. },
  2894. purgeElement : function(el, recurse, eventName) {
  2895. el = Ext.getDom(el);
  2896. var id = getId(el),
  2897. ec = Ext.elCache[id] || {},
  2898. es = ec.events || {},
  2899. i, f, len;
  2900. if (eventName) {
  2901. if (es && es.hasOwnProperty(eventName)) {
  2902. f = es[eventName];
  2903. for (i = 0, len = f.length; i < len; i++) {
  2904. Ext.EventManager.removeListener(el, eventName, f[i][0]);
  2905. }
  2906. }
  2907. } else {
  2908. Ext.EventManager.removeAll(el);
  2909. }
  2910. if (recurse && el && el.childNodes) {
  2911. for (i = 0, len = el.childNodes.length; i < len; i++) {
  2912. Ext.EventManager.purgeElement(el.childNodes[i], recurse, eventName);
  2913. }
  2914. }
  2915. },
  2916. _unload : function() {
  2917. var el;
  2918. for (el in Ext.elCache) {
  2919. Ext.EventManager.removeAll(el);
  2920. }
  2921. delete Ext.elCache;
  2922. delete Ext.Element._flyweights;
  2923. // Abort any outstanding Ajax requests
  2924. var c,
  2925. conn,
  2926. tid,
  2927. ajax = Ext.lib.Ajax;
  2928. (Ext.isObject(ajax.conn)) ? conn = ajax.conn : conn = {};
  2929. for (tid in conn) {
  2930. c = conn[tid];
  2931. if (c) {
  2932. ajax.abort({conn: c, tId: tid});
  2933. }
  2934. }
  2935. },
  2936. /**
  2937. * Adds a listener to be notified when the document is ready (before onload and before images are loaded). Can be
  2938. * accessed shorthanded as Ext.onReady().
  2939. * @param {Function} fn The method the event invokes.
  2940. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  2941. * @param {boolean} options (optional) Options object as passed to {@link Ext.Element#addListener}. It is recommended that the options
  2942. * <code>{single: true}</code> be used so that the handler is removed on first invocation.
  2943. */
  2944. onDocumentReady : function(fn, scope, options){
  2945. if(Ext.isReady){ // if it already fired or document.body is present
  2946. docReadyEvent || (docReadyEvent = new Ext.util.Event());
  2947. docReadyEvent.addListener(fn, scope, options);
  2948. docReadyEvent.fire();
  2949. docReadyEvent.listeners = [];
  2950. }else{
  2951. if(!docReadyEvent){
  2952. initDocReady();
  2953. }
  2954. options = options || {};
  2955. options.delay = options.delay || 1;
  2956. docReadyEvent.addListener(fn, scope, options);
  2957. }
  2958. },
  2959. /**
  2960. * Forces a document ready state transition for the framework. Used when Ext is loaded
  2961. * into a DOM structure AFTER initial page load (Google API or other dynamic load scenario.
  2962. * Any pending 'onDocumentReady' handlers will be fired (if not already handled).
  2963. */
  2964. fireDocReady : fireDocReady
  2965. };
  2966. /**
  2967. * Appends an event handler to an element. Shorthand for {@link #addListener}.
  2968. * @param {String/HTMLElement} el The html element or id to assign the event handler to
  2969. * @param {String} eventName The name of the event to listen for.
  2970. * @param {Function} handler The handler function the event invokes.
  2971. * @param {Object} scope (optional) (<code>this</code> reference) in which the handler function executes. <b>Defaults to the Element</b>.
  2972. * @param {Object} options (optional) An object containing standard {@link #addListener} options
  2973. * @member Ext.EventManager
  2974. * @method on
  2975. */
  2976. pub.on = pub.addListener;
  2977. /**
  2978. * Removes an event handler from an element. Shorthand for {@link #removeListener}.
  2979. * @param {String/HTMLElement} el The id or html element from which to remove the listener.
  2980. * @param {String} eventName The name of the event.
  2981. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #on} call.</b>
  2982. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  2983. * then this must refer to the same object.
  2984. * @member Ext.EventManager
  2985. * @method un
  2986. */
  2987. pub.un = pub.removeListener;
  2988. pub.stoppedMouseDownEvent = new Ext.util.Event();
  2989. return pub;
  2990. }();
  2991. /**
  2992. * Adds a listener to be notified when the document is ready (before onload and before images are loaded). Shorthand of {@link Ext.EventManager#onDocumentReady}.
  2993. * @param {Function} fn The method the event invokes.
  2994. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  2995. * @param {boolean} options (optional) Options object as passed to {@link Ext.Element#addListener}. It is recommended that the options
  2996. * <code>{single: true}</code> be used so that the handler is removed on first invocation.
  2997. * @member Ext
  2998. * @method onReady
  2999. */
  3000. Ext.onReady = Ext.EventManager.onDocumentReady;
  3001. //Initialize doc classes
  3002. (function(){
  3003. var initExtCss = function(){
  3004. // find the body element
  3005. var bd = document.body || document.getElementsByTagName('body')[0];
  3006. if(!bd){ return false; }
  3007. var cls = [' ',
  3008. Ext.isIE ? "ext-ie " + (Ext.isIE6 ? 'ext-ie6' : (Ext.isIE7 ? 'ext-ie7' : 'ext-ie8'))
  3009. : Ext.isGecko ? "ext-gecko " + (Ext.isGecko2 ? 'ext-gecko2' : 'ext-gecko3')
  3010. : Ext.isOpera ? "ext-opera"
  3011. : Ext.isWebKit ? "ext-webkit" : ""];
  3012. if(Ext.isSafari){
  3013. cls.push("ext-safari " + (Ext.isSafari2 ? 'ext-safari2' : (Ext.isSafari3 ? 'ext-safari3' : 'ext-safari4')));
  3014. }else if(Ext.isChrome){
  3015. cls.push("ext-chrome");
  3016. }
  3017. if(Ext.isMac){
  3018. cls.push("ext-mac");
  3019. }
  3020. if(Ext.isLinux){
  3021. cls.push("ext-linux");
  3022. }
  3023. if(Ext.isStrict || Ext.isBorderBox){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
  3024. var p = bd.parentNode;
  3025. if(p){
  3026. p.className += Ext.isStrict ? ' ext-strict' : ' ext-border-box';
  3027. }
  3028. }
  3029. bd.className += cls.join(' ');
  3030. return true;
  3031. }
  3032. if(!initExtCss()){
  3033. Ext.onReady(initExtCss);
  3034. }
  3035. })();
  3036. /**
  3037. * @class Ext.EventObject
  3038. * Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject
  3039. * wraps the browser's native event-object normalizing cross-browser differences,
  3040. * such as which mouse button is clicked, keys pressed, mechanisms to stop
  3041. * event-propagation along with a method to prevent default actions from taking place.
  3042. * <p>For example:</p>
  3043. * <pre><code>
  3044. function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject
  3045. e.preventDefault();
  3046. var target = e.getTarget(); // same as t (the target HTMLElement)
  3047. ...
  3048. }
  3049. var myDiv = {@link Ext#get Ext.get}("myDiv"); // get reference to an {@link Ext.Element}
  3050. myDiv.on( // 'on' is shorthand for addListener
  3051. "click", // perform an action on click of myDiv
  3052. handleClick // reference to the action handler
  3053. );
  3054. // other methods to do the same:
  3055. Ext.EventManager.on("myDiv", 'click', handleClick);
  3056. Ext.EventManager.addListener("myDiv", 'click', handleClick);
  3057. </code></pre>
  3058. * @singleton
  3059. */
  3060. Ext.EventObject = function(){
  3061. var E = Ext.lib.Event,
  3062. // safari keypress events for special keys return bad keycodes
  3063. safariKeys = {
  3064. 3 : 13, // enter
  3065. 63234 : 37, // left
  3066. 63235 : 39, // right
  3067. 63232 : 38, // up
  3068. 63233 : 40, // down
  3069. 63276 : 33, // page up
  3070. 63277 : 34, // page down
  3071. 63272 : 46, // delete
  3072. 63273 : 36, // home
  3073. 63275 : 35 // end
  3074. },
  3075. // normalize button clicks
  3076. btnMap = Ext.isIE ? {1:0,4:1,2:2} :
  3077. (Ext.isWebKit ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
  3078. Ext.EventObjectImpl = function(e){
  3079. if(e){
  3080. this.setEvent(e.browserEvent || e);
  3081. }
  3082. };
  3083. Ext.EventObjectImpl.prototype = {
  3084. /** @private */
  3085. setEvent : function(e){
  3086. var me = this;
  3087. if(e == me || (e && e.browserEvent)){ // already wrapped
  3088. return e;
  3089. }
  3090. me.browserEvent = e;
  3091. if(e){
  3092. // normalize buttons
  3093. me.button = e.button ? btnMap[e.button] : (e.which ? e.which - 1 : -1);
  3094. if(e.type == 'click' && me.button == -1){
  3095. me.button = 0;
  3096. }
  3097. me.type = e.type;
  3098. me.shiftKey = e.shiftKey;
  3099. // mac metaKey behaves like ctrlKey
  3100. me.ctrlKey = e.ctrlKey || e.metaKey || false;
  3101. me.altKey = e.altKey;
  3102. // in getKey these will be normalized for the mac
  3103. me.keyCode = e.keyCode;
  3104. me.charCode = e.charCode;
  3105. // cache the target for the delayed and or buffered events
  3106. me.target = E.getTarget(e);
  3107. // same for XY
  3108. me.xy = E.getXY(e);
  3109. }else{
  3110. me.button = -1;
  3111. me.shiftKey = false;
  3112. me.ctrlKey = false;
  3113. me.altKey = false;
  3114. me.keyCode = 0;
  3115. me.charCode = 0;
  3116. me.target = null;
  3117. me.xy = [0, 0];
  3118. }
  3119. return me;
  3120. },
  3121. /**
  3122. * Stop the event (preventDefault and stopPropagation)
  3123. */
  3124. stopEvent : function(){
  3125. var me = this;
  3126. if(me.browserEvent){
  3127. if(me.browserEvent.type == 'mousedown'){
  3128. Ext.EventManager.stoppedMouseDownEvent.fire(me);
  3129. }
  3130. E.stopEvent(me.browserEvent);
  3131. }
  3132. },
  3133. /**
  3134. * Prevents the browsers default handling of the event.
  3135. */
  3136. preventDefault : function(){
  3137. if(this.browserEvent){
  3138. E.preventDefault(this.browserEvent);
  3139. }
  3140. },
  3141. /**
  3142. * Cancels bubbling of the event.
  3143. */
  3144. stopPropagation : function(){
  3145. var me = this;
  3146. if(me.browserEvent){
  3147. if(me.browserEvent.type == 'mousedown'){
  3148. Ext.EventManager.stoppedMouseDownEvent.fire(me);
  3149. }
  3150. E.stopPropagation(me.browserEvent);
  3151. }
  3152. },
  3153. /**
  3154. * Gets the character code for the event.
  3155. * @return {Number}
  3156. */
  3157. getCharCode : function(){
  3158. return this.charCode || this.keyCode;
  3159. },
  3160. /**
  3161. * Returns a normalized keyCode for the event.
  3162. * @return {Number} The key code
  3163. */
  3164. getKey : function(){
  3165. return this.normalizeKey(this.keyCode || this.charCode)
  3166. },
  3167. // private
  3168. normalizeKey: function(k){
  3169. return Ext.isSafari ? (safariKeys[k] || k) : k;
  3170. },
  3171. /**
  3172. * Gets the x coordinate of the event.
  3173. * @return {Number}
  3174. */
  3175. getPageX : function(){
  3176. return this.xy[0];
  3177. },
  3178. /**
  3179. * Gets the y coordinate of the event.
  3180. * @return {Number}
  3181. */
  3182. getPageY : function(){
  3183. return this.xy[1];
  3184. },
  3185. /**
  3186. * Gets the page coordinates of the event.
  3187. * @return {Array} The xy values like [x, y]
  3188. */
  3189. getXY : function(){
  3190. return this.xy;
  3191. },
  3192. /**
  3193. * Gets the target for the event.
  3194. * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
  3195. * @param {Number/Mixed} maxDepth (optional) The max depth to
  3196. search as a number or element (defaults to 10 || document.body)
  3197. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  3198. * @return {HTMLelement}
  3199. */
  3200. getTarget : function(selector, maxDepth, returnEl){
  3201. return selector ? Ext.fly(this.target).findParent(selector, maxDepth, returnEl) : (returnEl ? Ext.get(this.target) : this.target);
  3202. },
  3203. /**
  3204. * Gets the related target.
  3205. * @return {HTMLElement}
  3206. */
  3207. getRelatedTarget : function(){
  3208. return this.browserEvent ? E.getRelatedTarget(this.browserEvent) : null;
  3209. },
  3210. /**
  3211. * Normalizes mouse wheel delta across browsers
  3212. * @return {Number} The delta
  3213. */
  3214. getWheelDelta : function(){
  3215. var e = this.browserEvent;
  3216. var delta = 0;
  3217. if(e.wheelDelta){ /* IE/Opera. */
  3218. delta = e.wheelDelta/120;
  3219. }else if(e.detail){ /* Mozilla case. */
  3220. delta = -e.detail/3;
  3221. }
  3222. return delta;
  3223. },
  3224. /**
  3225. * Returns true if the target of this event is a child of el. Unless the allowEl parameter is set, it will return false if if the target is el.
  3226. * Example usage:<pre><code>
  3227. // Handle click on any child of an element
  3228. Ext.getBody().on('click', function(e){
  3229. if(e.within('some-el')){
  3230. alert('Clicked on a child of some-el!');
  3231. }
  3232. });
  3233. // Handle click directly on an element, ignoring clicks on child nodes
  3234. Ext.getBody().on('click', function(e,t){
  3235. if((t.id == 'some-el') && !e.within(t, true)){
  3236. alert('Clicked directly on some-el!');
  3237. }
  3238. });
  3239. </code></pre>
  3240. * @param {Mixed} el The id, DOM element or Ext.Element to check
  3241. * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
  3242. * @param {Boolean} allowEl {optional} true to also check if the passed element is the target or related target
  3243. * @return {Boolean}
  3244. */
  3245. within : function(el, related, allowEl){
  3246. if(el){
  3247. var t = this[related ? "getRelatedTarget" : "getTarget"]();
  3248. return t && ((allowEl ? (t == Ext.getDom(el)) : false) || Ext.fly(el).contains(t));
  3249. }
  3250. return false;
  3251. }
  3252. };
  3253. return new Ext.EventObjectImpl();
  3254. }();
  3255. /**
  3256. * @class Ext.EventManager
  3257. */
  3258. Ext.apply(Ext.EventManager, function(){
  3259. var resizeEvent,
  3260. resizeTask,
  3261. textEvent,
  3262. textSize,
  3263. D = Ext.lib.Dom,
  3264. propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,
  3265. curWidth = 0,
  3266. curHeight = 0,
  3267. // note 1: IE fires ONLY the keydown event on specialkey autorepeat
  3268. // note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
  3269. // (research done by @Jan Wolter at http://unixpapa.com/js/key.html)
  3270. useKeydown = Ext.isWebKit ?
  3271. Ext.num(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1]) >= 525 :
  3272. !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera);
  3273. return {
  3274. // private
  3275. doResizeEvent: function(){
  3276. var h = D.getViewHeight(),
  3277. w = D.getViewWidth();
  3278. //whacky problem in IE where the resize event will fire even though the w/h are the same.
  3279. if(curHeight != h || curWidth != w){
  3280. resizeEvent.fire(curWidth = w, curHeight = h);
  3281. }
  3282. },
  3283. /**
  3284. * Adds a listener to be notified when the browser window is resized and provides resize event buffering (100 milliseconds),
  3285. * passes new viewport width and height to handlers.
  3286. * @param {Function} fn The handler function the window resize event invokes.
  3287. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  3288. * @param {boolean} options Options object as passed to {@link Ext.Element#addListener}
  3289. */
  3290. onWindowResize : function(fn, scope, options){
  3291. if(!resizeEvent){
  3292. resizeEvent = new Ext.util.Event();
  3293. resizeTask = new Ext.util.DelayedTask(this.doResizeEvent);
  3294. Ext.EventManager.on(window, "resize", this.fireWindowResize, this);
  3295. }
  3296. resizeEvent.addListener(fn, scope, options);
  3297. },
  3298. // exposed only to allow manual firing
  3299. fireWindowResize : function(){
  3300. if(resizeEvent){
  3301. resizeTask.delay(100);
  3302. }
  3303. },
  3304. /**
  3305. * Adds a listener to be notified when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
  3306. * @param {Function} fn The function the event invokes.
  3307. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  3308. * @param {boolean} options Options object as passed to {@link Ext.Element#addListener}
  3309. */
  3310. onTextResize : function(fn, scope, options){
  3311. if(!textEvent){
  3312. textEvent = new Ext.util.Event();
  3313. var textEl = new Ext.Element(document.createElement('div'));
  3314. textEl.dom.className = 'x-text-resize';
  3315. textEl.dom.innerHTML = 'X';
  3316. textEl.appendTo(document.body);
  3317. textSize = textEl.dom.offsetHeight;
  3318. setInterval(function(){
  3319. if(textEl.dom.offsetHeight != textSize){
  3320. textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
  3321. }
  3322. }, this.textResizeInterval);
  3323. }
  3324. textEvent.addListener(fn, scope, options);
  3325. },
  3326. /**
  3327. * Removes the passed window resize listener.
  3328. * @param {Function} fn The method the event invokes
  3329. * @param {Object} scope The scope of handler
  3330. */
  3331. removeResizeListener : function(fn, scope){
  3332. if(resizeEvent){
  3333. resizeEvent.removeListener(fn, scope);
  3334. }
  3335. },
  3336. // private
  3337. fireResize : function(){
  3338. if(resizeEvent){
  3339. resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
  3340. }
  3341. },
  3342. /**
  3343. * The frequency, in milliseconds, to check for text resize events (defaults to 50)
  3344. */
  3345. textResizeInterval : 50,
  3346. /**
  3347. * Url used for onDocumentReady with using SSL (defaults to Ext.SSL_SECURE_URL)
  3348. */
  3349. ieDeferSrc : false,
  3350. // protected for use inside the framework
  3351. // detects whether we should use keydown or keypress based on the browser.
  3352. useKeydown: useKeydown
  3353. };
  3354. }());
  3355. Ext.EventManager.on = Ext.EventManager.addListener;
  3356. Ext.apply(Ext.EventObjectImpl.prototype, {
  3357. /** Key constant @type Number */
  3358. BACKSPACE: 8,
  3359. /** Key constant @type Number */
  3360. TAB: 9,
  3361. /** Key constant @type Number */
  3362. NUM_CENTER: 12,
  3363. /** Key constant @type Number */
  3364. ENTER: 13,
  3365. /** Key constant @type Number */
  3366. RETURN: 13,
  3367. /** Key constant @type Number */
  3368. SHIFT: 16,
  3369. /** Key constant @type Number */
  3370. CTRL: 17,
  3371. CONTROL : 17, // legacy
  3372. /** Key constant @type Number */
  3373. ALT: 18,
  3374. /** Key constant @type Number */
  3375. PAUSE: 19,
  3376. /** Key constant @type Number */
  3377. CAPS_LOCK: 20,
  3378. /** Key constant @type Number */
  3379. ESC: 27,
  3380. /** Key constant @type Number */
  3381. SPACE: 32,
  3382. /** Key constant @type Number */
  3383. PAGE_UP: 33,
  3384. PAGEUP : 33, // legacy
  3385. /** Key constant @type Number */
  3386. PAGE_DOWN: 34,
  3387. PAGEDOWN : 34, // legacy
  3388. /** Key constant @type Number */
  3389. END: 35,
  3390. /** Key constant @type Number */
  3391. HOME: 36,
  3392. /** Key constant @type Number */
  3393. LEFT: 37,
  3394. /** Key constant @type Number */
  3395. UP: 38,
  3396. /** Key constant @type Number */
  3397. RIGHT: 39,
  3398. /** Key constant @type Number */
  3399. DOWN: 40,
  3400. /** Key constant @type Number */
  3401. PRINT_SCREEN: 44,
  3402. /** Key constant @type Number */
  3403. INSERT: 45,
  3404. /** Key constant @type Number */
  3405. DELETE: 46,
  3406. /** Key constant @type Number */
  3407. ZERO: 48,
  3408. /** Key constant @type Number */
  3409. ONE: 49,
  3410. /** Key constant @type Number */
  3411. TWO: 50,
  3412. /** Key constant @type Number */
  3413. THREE: 51,
  3414. /** Key constant @type Number */
  3415. FOUR: 52,
  3416. /** Key constant @type Number */
  3417. FIVE: 53,
  3418. /** Key constant @type Number */
  3419. SIX: 54,
  3420. /** Key constant @type Number */
  3421. SEVEN: 55,
  3422. /** Key constant @type Number */
  3423. EIGHT: 56,
  3424. /** Key constant @type Number */
  3425. NINE: 57,
  3426. /** Key constant @type Number */
  3427. A: 65,
  3428. /** Key constant @type Number */
  3429. B: 66,
  3430. /** Key constant @type Number */
  3431. C: 67,
  3432. /** Key constant @type Number */
  3433. D: 68,
  3434. /** Key constant @type Number */
  3435. E: 69,
  3436. /** Key constant @type Number */
  3437. F: 70,
  3438. /** Key constant @type Number */
  3439. G: 71,
  3440. /** Key constant @type Number */
  3441. H: 72,
  3442. /** Key constant @type Number */
  3443. I: 73,
  3444. /** Key constant @type Number */
  3445. J: 74,
  3446. /** Key constant @type Number */
  3447. K: 75,
  3448. /** Key constant @type Number */
  3449. L: 76,
  3450. /** Key constant @type Number */
  3451. M: 77,
  3452. /** Key constant @type Number */
  3453. N: 78,
  3454. /** Key constant @type Number */
  3455. O: 79,
  3456. /** Key constant @type Number */
  3457. P: 80,
  3458. /** Key constant @type Number */
  3459. Q: 81,
  3460. /** Key constant @type Number */
  3461. R: 82,
  3462. /** Key constant @type Number */
  3463. S: 83,
  3464. /** Key constant @type Number */
  3465. T: 84,
  3466. /** Key constant @type Number */
  3467. U: 85,
  3468. /** Key constant @type Number */
  3469. V: 86,
  3470. /** Key constant @type Number */
  3471. W: 87,
  3472. /** Key constant @type Number */
  3473. X: 88,
  3474. /** Key constant @type Number */
  3475. Y: 89,
  3476. /** Key constant @type Number */
  3477. Z: 90,
  3478. /** Key constant @type Number */
  3479. CONTEXT_MENU: 93,
  3480. /** Key constant @type Number */
  3481. NUM_ZERO: 96,
  3482. /** Key constant @type Number */
  3483. NUM_ONE: 97,
  3484. /** Key constant @type Number */
  3485. NUM_TWO: 98,
  3486. /** Key constant @type Number */
  3487. NUM_THREE: 99,
  3488. /** Key constant @type Number */
  3489. NUM_FOUR: 100,
  3490. /** Key constant @type Number */
  3491. NUM_FIVE: 101,
  3492. /** Key constant @type Number */
  3493. NUM_SIX: 102,
  3494. /** Key constant @type Number */
  3495. NUM_SEVEN: 103,
  3496. /** Key constant @type Number */
  3497. NUM_EIGHT: 104,
  3498. /** Key constant @type Number */
  3499. NUM_NINE: 105,
  3500. /** Key constant @type Number */
  3501. NUM_MULTIPLY: 106,
  3502. /** Key constant @type Number */
  3503. NUM_PLUS: 107,
  3504. /** Key constant @type Number */
  3505. NUM_MINUS: 109,
  3506. /** Key constant @type Number */
  3507. NUM_PERIOD: 110,
  3508. /** Key constant @type Number */
  3509. NUM_DIVISION: 111,
  3510. /** Key constant @type Number */
  3511. F1: 112,
  3512. /** Key constant @type Number */
  3513. F2: 113,
  3514. /** Key constant @type Number */
  3515. F3: 114,
  3516. /** Key constant @type Number */
  3517. F4: 115,
  3518. /** Key constant @type Number */
  3519. F5: 116,
  3520. /** Key constant @type Number */
  3521. F6: 117,
  3522. /** Key constant @type Number */
  3523. F7: 118,
  3524. /** Key constant @type Number */
  3525. F8: 119,
  3526. /** Key constant @type Number */
  3527. F9: 120,
  3528. /** Key constant @type Number */
  3529. F10: 121,
  3530. /** Key constant @type Number */
  3531. F11: 122,
  3532. /** Key constant @type Number */
  3533. F12: 123,
  3534. /** @private */
  3535. isNavKeyPress : function(){
  3536. var me = this,
  3537. k = this.normalizeKey(me.keyCode);
  3538. return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
  3539. k == me.RETURN ||
  3540. k == me.TAB ||
  3541. k == me.ESC;
  3542. },
  3543. isSpecialKey : function(){
  3544. var k = this.normalizeKey(this.keyCode);
  3545. return (this.type == 'keypress' && this.ctrlKey) ||
  3546. this.isNavKeyPress() ||
  3547. (k == this.BACKSPACE) || // Backspace
  3548. (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
  3549. (k >= 44 && k <= 46); // Print Screen, Insert, Delete
  3550. },
  3551. getPoint : function(){
  3552. return new Ext.lib.Point(this.xy[0], this.xy[1]);
  3553. },
  3554. /**
  3555. * Returns true if the control, meta, shift or alt key was pressed during this event.
  3556. * @return {Boolean}
  3557. */
  3558. hasModifier : function(){
  3559. return ((this.ctrlKey || this.altKey) || this.shiftKey);
  3560. }
  3561. });/**
  3562. * @class Ext.Element
  3563. * <p>Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.</p>
  3564. * <p>All instances of this class inherit the methods of {@link Ext.Fx} making visual effects easily available to all DOM elements.</p>
  3565. * <p>Note that the events documented in this class are not Ext events, they encapsulate browser events. To
  3566. * access the underlying browser event, see {@link Ext.EventObject#browserEvent}. Some older
  3567. * browsers may not support the full range of events. Which events are supported is beyond the control of ExtJs.</p>
  3568. * Usage:<br>
  3569. <pre><code>
  3570. // by id
  3571. var el = Ext.get("my-div");
  3572. // by DOM element reference
  3573. var el = Ext.get(myDivElement);
  3574. </code></pre>
  3575. * <b>Animations</b><br />
  3576. * <p>When an element is manipulated, by default there is no animation.</p>
  3577. * <pre><code>
  3578. var el = Ext.get("my-div");
  3579. // no animation
  3580. el.setWidth(100);
  3581. * </code></pre>
  3582. * <p>Many of the functions for manipulating an element have an optional "animate" parameter. This
  3583. * parameter can be specified as boolean (<tt>true</tt>) for default animation effects.</p>
  3584. * <pre><code>
  3585. // default animation
  3586. el.setWidth(100, true);
  3587. * </code></pre>
  3588. *
  3589. * <p>To configure the effects, an object literal with animation options to use as the Element animation
  3590. * configuration object can also be specified. Note that the supported Element animation configuration
  3591. * options are a subset of the {@link Ext.Fx} animation options specific to Fx effects. The supported
  3592. * Element animation configuration options are:</p>
  3593. <pre>
  3594. Option Default Description
  3595. --------- -------- ---------------------------------------------
  3596. {@link Ext.Fx#duration duration} .35 The duration of the animation in seconds
  3597. {@link Ext.Fx#easing easing} easeOut The easing method
  3598. {@link Ext.Fx#callback callback} none A function to execute when the anim completes
  3599. {@link Ext.Fx#scope scope} this The scope (this) of the callback function
  3600. </pre>
  3601. *
  3602. * <pre><code>
  3603. // Element animation options object
  3604. var opt = {
  3605. {@link Ext.Fx#duration duration}: 1,
  3606. {@link Ext.Fx#easing easing}: 'elasticIn',
  3607. {@link Ext.Fx#callback callback}: this.foo,
  3608. {@link Ext.Fx#scope scope}: this
  3609. };
  3610. // animation with some options set
  3611. el.setWidth(100, opt);
  3612. * </code></pre>
  3613. * <p>The Element animation object being used for the animation will be set on the options
  3614. * object as "anim", which allows you to stop or manipulate the animation. Here is an example:</p>
  3615. * <pre><code>
  3616. // using the "anim" property to get the Anim object
  3617. if(opt.anim.isAnimated()){
  3618. opt.anim.stop();
  3619. }
  3620. * </code></pre>
  3621. * <p>Also see the <tt>{@link #animate}</tt> method for another animation technique.</p>
  3622. * <p><b> Composite (Collections of) Elements</b></p>
  3623. * <p>For working with collections of Elements, see {@link Ext.CompositeElement}</p>
  3624. * @constructor Create a new Element directly.
  3625. * @param {String/HTMLElement} element
  3626. * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).
  3627. */
  3628. (function(){
  3629. var DOC = document;
  3630. Ext.Element = function(element, forceNew){
  3631. var dom = typeof element == "string" ?
  3632. DOC.getElementById(element) : element,
  3633. id;
  3634. if(!dom) return null;
  3635. id = dom.id;
  3636. if(!forceNew && id && Ext.elCache[id]){ // element object already exists
  3637. return Ext.elCache[id].el;
  3638. }
  3639. /**
  3640. * The DOM element
  3641. * @type HTMLElement
  3642. */
  3643. this.dom = dom;
  3644. /**
  3645. * The DOM element ID
  3646. * @type String
  3647. */
  3648. this.id = id || Ext.id(dom);
  3649. };
  3650. var D = Ext.lib.Dom,
  3651. DH = Ext.DomHelper,
  3652. E = Ext.lib.Event,
  3653. A = Ext.lib.Anim,
  3654. El = Ext.Element,
  3655. EC = Ext.elCache;
  3656. El.prototype = {
  3657. /**
  3658. * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
  3659. * @param {Object} o The object with the attributes
  3660. * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
  3661. * @return {Ext.Element} this
  3662. */
  3663. set : function(o, useSet){
  3664. var el = this.dom,
  3665. attr,
  3666. val,
  3667. useSet = (useSet !== false) && !!el.setAttribute;
  3668. for(attr in o){
  3669. if (o.hasOwnProperty(attr)) {
  3670. val = o[attr];
  3671. if (attr == 'style') {
  3672. DH.applyStyles(el, val);
  3673. } else if (attr == 'cls') {
  3674. el.className = val;
  3675. } else if (useSet) {
  3676. el.setAttribute(attr, val);
  3677. } else {
  3678. el[attr] = val;
  3679. }
  3680. }
  3681. }
  3682. return this;
  3683. },
  3684. // Mouse events
  3685. /**
  3686. * @event click
  3687. * Fires when a mouse click is detected within the element.
  3688. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3689. * @param {HtmlElement} t The target of the event.
  3690. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3691. */
  3692. /**
  3693. * @event contextmenu
  3694. * Fires when a right click is detected within the element.
  3695. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3696. * @param {HtmlElement} t The target of the event.
  3697. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3698. */
  3699. /**
  3700. * @event dblclick
  3701. * Fires when a mouse double click is detected within the element.
  3702. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3703. * @param {HtmlElement} t The target of the event.
  3704. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3705. */
  3706. /**
  3707. * @event mousedown
  3708. * Fires when a mousedown is detected within the element.
  3709. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3710. * @param {HtmlElement} t The target of the event.
  3711. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3712. */
  3713. /**
  3714. * @event mouseup
  3715. * Fires when a mouseup is detected within the element.
  3716. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3717. * @param {HtmlElement} t The target of the event.
  3718. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3719. */
  3720. /**
  3721. * @event mouseover
  3722. * Fires when a mouseover is detected within the element.
  3723. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3724. * @param {HtmlElement} t The target of the event.
  3725. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3726. */
  3727. /**
  3728. * @event mousemove
  3729. * Fires when a mousemove is detected with the element.
  3730. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3731. * @param {HtmlElement} t The target of the event.
  3732. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3733. */
  3734. /**
  3735. * @event mouseout
  3736. * Fires when a mouseout is detected with the element.
  3737. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3738. * @param {HtmlElement} t The target of the event.
  3739. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3740. */
  3741. /**
  3742. * @event mouseenter
  3743. * Fires when the mouse enters the element.
  3744. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3745. * @param {HtmlElement} t The target of the event.
  3746. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3747. */
  3748. /**
  3749. * @event mouseleave
  3750. * Fires when the mouse leaves the element.
  3751. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3752. * @param {HtmlElement} t The target of the event.
  3753. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3754. */
  3755. // Keyboard events
  3756. /**
  3757. * @event keypress
  3758. * Fires when a keypress is detected within the element.
  3759. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3760. * @param {HtmlElement} t The target of the event.
  3761. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3762. */
  3763. /**
  3764. * @event keydown
  3765. * Fires when a keydown is detected within the element.
  3766. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3767. * @param {HtmlElement} t The target of the event.
  3768. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3769. */
  3770. /**
  3771. * @event keyup
  3772. * Fires when a keyup is detected within the element.
  3773. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3774. * @param {HtmlElement} t The target of the event.
  3775. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3776. */
  3777. // HTML frame/object events
  3778. /**
  3779. * @event load
  3780. * Fires when the user agent finishes loading all content within the element. Only supported by window, frames, objects and images.
  3781. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3782. * @param {HtmlElement} t The target of the event.
  3783. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3784. */
  3785. /**
  3786. * @event unload
  3787. * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target element or any of its content has been removed.
  3788. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3789. * @param {HtmlElement} t The target of the event.
  3790. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3791. */
  3792. /**
  3793. * @event abort
  3794. * Fires when an object/image is stopped from loading before completely loaded.
  3795. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3796. * @param {HtmlElement} t The target of the event.
  3797. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3798. */
  3799. /**
  3800. * @event error
  3801. * Fires when an object/image/frame cannot be loaded properly.
  3802. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3803. * @param {HtmlElement} t The target of the event.
  3804. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3805. */
  3806. /**
  3807. * @event resize
  3808. * Fires when a document view is resized.
  3809. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3810. * @param {HtmlElement} t The target of the event.
  3811. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3812. */
  3813. /**
  3814. * @event scroll
  3815. * Fires when a document view is scrolled.
  3816. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3817. * @param {HtmlElement} t The target of the event.
  3818. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3819. */
  3820. // Form events
  3821. /**
  3822. * @event select
  3823. * Fires when a user selects some text in a text field, including input and textarea.
  3824. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3825. * @param {HtmlElement} t The target of the event.
  3826. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3827. */
  3828. /**
  3829. * @event change
  3830. * Fires when a control loses the input focus and its value has been modified since gaining focus.
  3831. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3832. * @param {HtmlElement} t The target of the event.
  3833. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3834. */
  3835. /**
  3836. * @event submit
  3837. * Fires when a form is submitted.
  3838. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3839. * @param {HtmlElement} t The target of the event.
  3840. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3841. */
  3842. /**
  3843. * @event reset
  3844. * Fires when a form is reset.
  3845. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3846. * @param {HtmlElement} t The target of the event.
  3847. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3848. */
  3849. /**
  3850. * @event focus
  3851. * Fires when an element receives focus either via the pointing device or by tab navigation.
  3852. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3853. * @param {HtmlElement} t The target of the event.
  3854. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3855. */
  3856. /**
  3857. * @event blur
  3858. * Fires when an element loses focus either via the pointing device or by tabbing navigation.
  3859. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3860. * @param {HtmlElement} t The target of the event.
  3861. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3862. */
  3863. // User Interface events
  3864. /**
  3865. * @event DOMFocusIn
  3866. * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
  3867. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3868. * @param {HtmlElement} t The target of the event.
  3869. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3870. */
  3871. /**
  3872. * @event DOMFocusOut
  3873. * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
  3874. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3875. * @param {HtmlElement} t The target of the event.
  3876. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3877. */
  3878. /**
  3879. * @event DOMActivate
  3880. * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
  3881. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3882. * @param {HtmlElement} t The target of the event.
  3883. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3884. */
  3885. // DOM Mutation events
  3886. /**
  3887. * @event DOMSubtreeModified
  3888. * Where supported. Fires when the subtree is modified.
  3889. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3890. * @param {HtmlElement} t The target of the event.
  3891. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3892. */
  3893. /**
  3894. * @event DOMNodeInserted
  3895. * Where supported. Fires when a node has been added as a child of another node.
  3896. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3897. * @param {HtmlElement} t The target of the event.
  3898. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3899. */
  3900. /**
  3901. * @event DOMNodeRemoved
  3902. * Where supported. Fires when a descendant node of the element is removed.
  3903. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3904. * @param {HtmlElement} t The target of the event.
  3905. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3906. */
  3907. /**
  3908. * @event DOMNodeRemovedFromDocument
  3909. * Where supported. Fires when a node is being removed from a document.
  3910. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3911. * @param {HtmlElement} t The target of the event.
  3912. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3913. */
  3914. /**
  3915. * @event DOMNodeInsertedIntoDocument
  3916. * Where supported. Fires when a node is being inserted into a document.
  3917. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3918. * @param {HtmlElement} t The target of the event.
  3919. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3920. */
  3921. /**
  3922. * @event DOMAttrModified
  3923. * Where supported. Fires when an attribute has been modified.
  3924. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3925. * @param {HtmlElement} t The target of the event.
  3926. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3927. */
  3928. /**
  3929. * @event DOMCharacterDataModified
  3930. * Where supported. Fires when the character data has been modified.
  3931. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  3932. * @param {HtmlElement} t The target of the event.
  3933. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  3934. */
  3935. /**
  3936. * The default unit to append to CSS values where a unit isn't provided (defaults to px).
  3937. * @type String
  3938. */
  3939. defaultUnit : "px",
  3940. /**
  3941. * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
  3942. * @param {String} selector The simple selector to test
  3943. * @return {Boolean} True if this element matches the selector, else false
  3944. */
  3945. is : function(simpleSelector){
  3946. return Ext.DomQuery.is(this.dom, simpleSelector);
  3947. },
  3948. /**
  3949. * Tries to focus the element. Any exceptions are caught and ignored.
  3950. * @param {Number} defer (optional) Milliseconds to defer the focus
  3951. * @return {Ext.Element} this
  3952. */
  3953. focus : function(defer, /* private */ dom) {
  3954. var me = this,
  3955. dom = dom || me.dom;
  3956. try{
  3957. if(Number(defer)){
  3958. me.focus.defer(defer, null, [null, dom]);
  3959. }else{
  3960. dom.focus();
  3961. }
  3962. }catch(e){}
  3963. return me;
  3964. },
  3965. /**
  3966. * Tries to blur the element. Any exceptions are caught and ignored.
  3967. * @return {Ext.Element} this
  3968. */
  3969. blur : function() {
  3970. try{
  3971. this.dom.blur();
  3972. }catch(e){}
  3973. return this;
  3974. },
  3975. /**
  3976. * Returns the value of the "value" attribute
  3977. * @param {Boolean} asNumber true to parse the value as a number
  3978. * @return {String/Number}
  3979. */
  3980. getValue : function(asNumber){
  3981. var val = this.dom.value;
  3982. return asNumber ? parseInt(val, 10) : val;
  3983. },
  3984. /**
  3985. * Appends an event handler to this element. The shorthand version {@link #on} is equivalent.
  3986. * @param {String} eventName The name of event to handle.
  3987. * @param {Function} fn The handler function the event invokes. This function is passed
  3988. * the following parameters:<ul>
  3989. * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
  3990. * <li><b>el</b> : HtmlElement<div class="sub-desc">The DOM element which was the target of the event.
  3991. * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
  3992. * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li>
  3993. * </ul>
  3994. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  3995. * <b>If omitted, defaults to this Element.</b>.
  3996. * @param {Object} options (optional) An object containing handler configuration properties.
  3997. * This may contain any of the following properties:<ul>
  3998. * <li><b>scope</b> Object : <div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  3999. * <b>If omitted, defaults to this Element.</b></div></li>
  4000. * <li><b>delegate</b> String: <div class="sub-desc">A simple selector to filter the target or look for a descendant of the target. See below for additional details.</div></li>
  4001. * <li><b>stopEvent</b> Boolean: <div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
  4002. * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li>
  4003. * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li>
  4004. * <li><b>normalized</b> Boolean: <div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
  4005. * <li><b>target</b> Ext.Element: <div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
  4006. * <li><b>delay</b> Number: <div class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</div></li>
  4007. * <li><b>single</b> Boolean: <div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  4008. * <li><b>buffer</b> Number: <div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  4009. * by the specified number of milliseconds. If the event fires again within that time, the original
  4010. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  4011. * </ul><br>
  4012. * <p>
  4013. * <b>Combining Options</b><br>
  4014. * In the following examples, the shorthand form {@link #on} is used rather than the more verbose
  4015. * addListener. The two are equivalent. Using the options argument, it is possible to combine different
  4016. * types of listeners:<br>
  4017. * <br>
  4018. * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the
  4019. * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;">
  4020. * Code:<pre><code>
  4021. el.on('click', this.onClick, this, {
  4022. single: true,
  4023. delay: 100,
  4024. stopEvent : true,
  4025. forumId: 4
  4026. });</code></pre></p>
  4027. * <p>
  4028. * <b>Attaching multiple handlers in 1 call</b><br>
  4029. * The method also allows for a single argument to be passed which is a config object containing properties
  4030. * which specify multiple handlers.</p>
  4031. * <p>
  4032. * Code:<pre><code>
  4033. el.on({
  4034. 'click' : {
  4035. fn: this.onClick,
  4036. scope: this,
  4037. delay: 100
  4038. },
  4039. 'mouseover' : {
  4040. fn: this.onMouseOver,
  4041. scope: this
  4042. },
  4043. 'mouseout' : {
  4044. fn: this.onMouseOut,
  4045. scope: this
  4046. }
  4047. });</code></pre>
  4048. * <p>
  4049. * Or a shorthand syntax:<br>
  4050. * Code:<pre><code></p>
  4051. el.on({
  4052. 'click' : this.onClick,
  4053. 'mouseover' : this.onMouseOver,
  4054. 'mouseout' : this.onMouseOut,
  4055. scope: this
  4056. });
  4057. * </code></pre></p>
  4058. * <p><b>delegate</b></p>
  4059. * <p>This is a configuration option that you can pass along when registering a handler for
  4060. * an event to assist with event delegation. Event delegation is a technique that is used to
  4061. * reduce memory consumption and prevent exposure to memory-leaks. By registering an event
  4062. * for a container element as opposed to each element within a container. By setting this
  4063. * configuration option to a simple selector, the target element will be filtered to look for
  4064. * a descendant of the target.
  4065. * For example:<pre><code>
  4066. // using this markup:
  4067. &lt;div id='elId'>
  4068. &lt;p id='p1'>paragraph one&lt;/p>
  4069. &lt;p id='p2' class='clickable'>paragraph two&lt;/p>
  4070. &lt;p id='p3'>paragraph three&lt;/p>
  4071. &lt;/div>
  4072. // utilize event delegation to registering just one handler on the container element:
  4073. el = Ext.get('elId');
  4074. el.on(
  4075. 'click',
  4076. function(e,t) {
  4077. // handle click
  4078. console.info(t.id); // 'p2'
  4079. },
  4080. this,
  4081. {
  4082. // filter the target element to be a descendant with the class 'clickable'
  4083. delegate: '.clickable'
  4084. }
  4085. );
  4086. * </code></pre></p>
  4087. * @return {Ext.Element} this
  4088. */
  4089. addListener : function(eventName, fn, scope, options){
  4090. Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
  4091. return this;
  4092. },
  4093. /**
  4094. * Removes an event handler from this element. The shorthand version {@link #un} is equivalent.
  4095. * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the
  4096. * listener, the same scope must be specified here.
  4097. * Example:
  4098. * <pre><code>
  4099. el.removeListener('click', this.handlerFn);
  4100. // or
  4101. el.un('click', this.handlerFn);
  4102. </code></pre>
  4103. * @param {String} eventName The name of the event from which to remove the handler.
  4104. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  4105. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  4106. * then this must refer to the same object.
  4107. * @return {Ext.Element} this
  4108. */
  4109. removeListener : function(eventName, fn, scope){
  4110. Ext.EventManager.removeListener(this.dom, eventName, fn, scope || this);
  4111. return this;
  4112. },
  4113. /**
  4114. * Removes all previous added listeners from this element
  4115. * @return {Ext.Element} this
  4116. */
  4117. removeAllListeners : function(){
  4118. Ext.EventManager.removeAll(this.dom);
  4119. return this;
  4120. },
  4121. /**
  4122. * Recursively removes all previous added listeners from this element and its children
  4123. * @return {Ext.Element} this
  4124. */
  4125. purgeAllListeners : function() {
  4126. Ext.EventManager.purgeElement(this, true);
  4127. return this;
  4128. },
  4129. /**
  4130. * @private Test if size has a unit, otherwise appends the default
  4131. */
  4132. addUnits : function(size){
  4133. if(size === "" || size == "auto" || size === undefined){
  4134. size = size || '';
  4135. } else if(!isNaN(size) || !unitPattern.test(size)){
  4136. size = size + (this.defaultUnit || 'px');
  4137. }
  4138. return size;
  4139. },
  4140. /**
  4141. * <p>Updates the <a href="http://developer.mozilla.org/en/DOM/element.innerHTML">innerHTML</a> of this Element
  4142. * from a specified URL. Note that this is subject to the <a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same Origin Policy</a></p>
  4143. * <p>Updating innerHTML of an element will <b>not</b> execute embedded <tt>&lt;script></tt> elements. This is a browser restriction.</p>
  4144. * @param {Mixed} options. Either a sring containing the URL from which to load the HTML, or an {@link Ext.Ajax#request} options object specifying
  4145. * exactly how to request the HTML.
  4146. * @return {Ext.Element} this
  4147. */
  4148. load : function(url, params, cb){
  4149. Ext.Ajax.request(Ext.apply({
  4150. params: params,
  4151. url: url.url || url,
  4152. callback: cb,
  4153. el: this.dom,
  4154. indicatorText: url.indicatorText || ''
  4155. }, Ext.isObject(url) ? url : {}));
  4156. return this;
  4157. },
  4158. /**
  4159. * Tests various css rules/browsers to determine if this element uses a border box
  4160. * @return {Boolean}
  4161. */
  4162. isBorderBox : function(){
  4163. return noBoxAdjust[(this.dom.tagName || "").toLowerCase()] || Ext.isBorderBox;
  4164. },
  4165. /**
  4166. * <p>Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode}</p>
  4167. */
  4168. remove : function(){
  4169. var me = this,
  4170. dom = me.dom;
  4171. if (dom) {
  4172. delete me.dom;
  4173. Ext.removeNode(dom);
  4174. }
  4175. },
  4176. /**
  4177. * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
  4178. * @param {Function} overFn The function to call when the mouse enters the Element.
  4179. * @param {Function} outFn The function to call when the mouse leaves the Element.
  4180. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the functions are executed. Defaults to the Element's DOM element.
  4181. * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}.
  4182. * @return {Ext.Element} this
  4183. */
  4184. hover : function(overFn, outFn, scope, options){
  4185. var me = this;
  4186. me.on('mouseenter', overFn, scope || me.dom, options);
  4187. me.on('mouseleave', outFn, scope || me.dom, options);
  4188. return me;
  4189. },
  4190. /**
  4191. * Returns true if this element is an ancestor of the passed element
  4192. * @param {HTMLElement/String} el The element to check
  4193. * @return {Boolean} True if this element is an ancestor of el, else false
  4194. */
  4195. contains : function(el){
  4196. return !el ? false : Ext.lib.Dom.isAncestor(this.dom, el.dom ? el.dom : el);
  4197. },
  4198. /**
  4199. * Returns the value of a namespaced attribute from the element's underlying DOM node.
  4200. * @param {String} namespace The namespace in which to look for the attribute
  4201. * @param {String} name The attribute name
  4202. * @return {String} The attribute value
  4203. * @deprecated
  4204. */
  4205. getAttributeNS : function(ns, name){
  4206. return this.getAttribute(name, ns);
  4207. },
  4208. /**
  4209. * Returns the value of an attribute from the element's underlying DOM node.
  4210. * @param {String} name The attribute name
  4211. * @param {String} namespace (optional) The namespace in which to look for the attribute
  4212. * @return {String} The attribute value
  4213. */
  4214. getAttribute : Ext.isIE ? function(name, ns){
  4215. var d = this.dom,
  4216. type = typeof d[ns + ":" + name];
  4217. if(['undefined', 'unknown'].indexOf(type) == -1){
  4218. return d[ns + ":" + name];
  4219. }
  4220. return d[name];
  4221. } : function(name, ns){
  4222. var d = this.dom;
  4223. return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name) || d.getAttribute(name) || d[name];
  4224. },
  4225. /**
  4226. * Update the innerHTML of this element
  4227. * @param {String} html The new HTML
  4228. * @return {Ext.Element} this
  4229. */
  4230. update : function(html) {
  4231. if (this.dom) {
  4232. this.dom.innerHTML = html;
  4233. }
  4234. return this;
  4235. }
  4236. };
  4237. var ep = El.prototype;
  4238. El.addMethods = function(o){
  4239. Ext.apply(ep, o);
  4240. };
  4241. /**
  4242. * Appends an event handler (shorthand for {@link #addListener}).
  4243. * @param {String} eventName The name of event to handle.
  4244. * @param {Function} fn The handler function the event invokes.
  4245. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
  4246. * @param {Object} options (optional) An object containing standard {@link #addListener} options
  4247. * @member Ext.Element
  4248. * @method on
  4249. */
  4250. ep.on = ep.addListener;
  4251. /**
  4252. * Removes an event handler from this element (see {@link #removeListener} for additional notes).
  4253. * @param {String} eventName The name of the event from which to remove the handler.
  4254. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  4255. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  4256. * then this must refer to the same object.
  4257. * @return {Ext.Element} this
  4258. * @member Ext.Element
  4259. * @method un
  4260. */
  4261. ep.un = ep.removeListener;
  4262. /**
  4263. * true to automatically adjust width and height settings for box-model issues (default to true)
  4264. */
  4265. ep.autoBoxAdjust = true;
  4266. // private
  4267. var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
  4268. docEl;
  4269. /**
  4270. * @private
  4271. */
  4272. /**
  4273. * Retrieves Ext.Element objects.
  4274. * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
  4275. * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
  4276. * its ID, use {@link Ext.ComponentMgr#get}.</p>
  4277. * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
  4278. * object was recreated with the same id via AJAX or DOM.</p>
  4279. * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
  4280. * @return {Element} The Element object (or null if no matching element was found)
  4281. * @static
  4282. * @member Ext.Element
  4283. * @method get
  4284. */
  4285. El.get = function(el){
  4286. var ex,
  4287. elm,
  4288. id;
  4289. if(!el){ return null; }
  4290. if (typeof el == "string") { // element id
  4291. if (!(elm = DOC.getElementById(el))) {
  4292. return null;
  4293. }
  4294. if (EC[el] && EC[el].el) {
  4295. ex = EC[el].el;
  4296. ex.dom = elm;
  4297. } else {
  4298. ex = El.addToCache(new El(elm));
  4299. }
  4300. return ex;
  4301. } else if (el.tagName) { // dom element
  4302. if(!(id = el.id)){
  4303. id = Ext.id(el);
  4304. }
  4305. if (EC[id] && EC[id].el) {
  4306. ex = EC[id].el;
  4307. ex.dom = el;
  4308. } else {
  4309. ex = El.addToCache(new El(el));
  4310. }
  4311. return ex;
  4312. } else if (el instanceof El) {
  4313. if(el != docEl){
  4314. // refresh dom element in case no longer valid,
  4315. // catch case where it hasn't been appended
  4316. // If an el instance is passed, don't pass to getElementById without some kind of id
  4317. if (Ext.isIE && (el.id == undefined || el.id == '')) {
  4318. el.dom = el.dom;
  4319. } else {
  4320. el.dom = DOC.getElementById(el.id) || el.dom;
  4321. }
  4322. }
  4323. return el;
  4324. } else if(el.isComposite) {
  4325. return el;
  4326. } else if(Ext.isArray(el)) {
  4327. return El.select(el);
  4328. } else if(el == DOC) {
  4329. // create a bogus element object representing the document object
  4330. if(!docEl){
  4331. var f = function(){};
  4332. f.prototype = El.prototype;
  4333. docEl = new f();
  4334. docEl.dom = DOC;
  4335. }
  4336. return docEl;
  4337. }
  4338. return null;
  4339. };
  4340. El.addToCache = function(el, id){
  4341. id = id || el.id;
  4342. EC[id] = {
  4343. el: el,
  4344. data: {},
  4345. events: {}
  4346. };
  4347. return el;
  4348. };
  4349. // private method for getting and setting element data
  4350. El.data = function(el, key, value){
  4351. el = El.get(el);
  4352. if (!el) {
  4353. return null;
  4354. }
  4355. var c = EC[el.id].data;
  4356. if(arguments.length == 2){
  4357. return c[key];
  4358. }else{
  4359. return (c[key] = value);
  4360. }
  4361. };
  4362. // private
  4363. // Garbage collection - uncache elements/purge listeners on orphaned elements
  4364. // so we don't hold a reference and cause the browser to retain them
  4365. function garbageCollect(){
  4366. if(!Ext.enableGarbageCollector){
  4367. clearInterval(El.collectorThreadId);
  4368. } else {
  4369. var eid,
  4370. el,
  4371. d,
  4372. o;
  4373. for(eid in EC){
  4374. o = EC[eid];
  4375. if(o.skipGC){
  4376. continue;
  4377. }
  4378. el = o.el;
  4379. d = el.dom;
  4380. // -------------------------------------------------------
  4381. // Determining what is garbage:
  4382. // -------------------------------------------------------
  4383. // !d
  4384. // dom node is null, definitely garbage
  4385. // -------------------------------------------------------
  4386. // !d.parentNode
  4387. // no parentNode == direct orphan, definitely garbage
  4388. // -------------------------------------------------------
  4389. // !d.offsetParent && !document.getElementById(eid)
  4390. // display none elements have no offsetParent so we will
  4391. // also try to look it up by it's id. However, check
  4392. // offsetParent first so we don't do unneeded lookups.
  4393. // This enables collection of elements that are not orphans
  4394. // directly, but somewhere up the line they have an orphan
  4395. // parent.
  4396. // -------------------------------------------------------
  4397. if(!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))){
  4398. if(Ext.enableListenerCollection){
  4399. Ext.EventManager.removeAll(d);
  4400. }
  4401. delete EC[eid];
  4402. }
  4403. }
  4404. // Cleanup IE Object leaks
  4405. if (Ext.isIE) {
  4406. var t = {};
  4407. for (eid in EC) {
  4408. t[eid] = EC[eid];
  4409. }
  4410. EC = Ext.elCache = t;
  4411. }
  4412. }
  4413. }
  4414. El.collectorThreadId = setInterval(garbageCollect, 30000);
  4415. var flyFn = function(){};
  4416. flyFn.prototype = El.prototype;
  4417. // dom is optional
  4418. El.Flyweight = function(dom){
  4419. this.dom = dom;
  4420. };
  4421. El.Flyweight.prototype = new flyFn();
  4422. El.Flyweight.prototype.isFlyweight = true;
  4423. El._flyweights = {};
  4424. /**
  4425. * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
  4426. * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
  4427. * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
  4428. * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
  4429. * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
  4430. * @param {String/HTMLElement} el The dom node or id
  4431. * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
  4432. * (e.g. internally Ext uses "_global")
  4433. * @return {Element} The shared Element object (or null if no matching element was found)
  4434. * @member Ext.Element
  4435. * @method fly
  4436. */
  4437. El.fly = function(el, named){
  4438. var ret = null;
  4439. named = named || '_global';
  4440. if (el = Ext.getDom(el)) {
  4441. (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;
  4442. ret = El._flyweights[named];
  4443. }
  4444. return ret;
  4445. };
  4446. /**
  4447. * Retrieves Ext.Element objects.
  4448. * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
  4449. * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
  4450. * its ID, use {@link Ext.ComponentMgr#get}.</p>
  4451. * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
  4452. * object was recreated with the same id via AJAX or DOM.</p>
  4453. * Shorthand of {@link Ext.Element#get}
  4454. * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
  4455. * @return {Element} The Element object (or null if no matching element was found)
  4456. * @member Ext
  4457. * @method get
  4458. */
  4459. Ext.get = El.get;
  4460. /**
  4461. * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
  4462. * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
  4463. * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
  4464. * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
  4465. * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
  4466. * @param {String/HTMLElement} el The dom node or id
  4467. * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
  4468. * (e.g. internally Ext uses "_global")
  4469. * @return {Element} The shared Element object (or null if no matching element was found)
  4470. * @member Ext
  4471. * @method fly
  4472. */
  4473. Ext.fly = El.fly;
  4474. // speedy lookup for elements never to box adjust
  4475. var noBoxAdjust = Ext.isStrict ? {
  4476. select:1
  4477. } : {
  4478. input:1, select:1, textarea:1
  4479. };
  4480. if(Ext.isIE || Ext.isGecko){
  4481. noBoxAdjust['button'] = 1;
  4482. }
  4483. })();
  4484. /**
  4485. * @class Ext.Element
  4486. */
  4487. Ext.Element.addMethods({
  4488. /**
  4489. * Stops the specified event(s) from bubbling and optionally prevents the default action
  4490. * @param {String/Array} eventName an event / array of events to stop from bubbling
  4491. * @param {Boolean} preventDefault (optional) true to prevent the default action too
  4492. * @return {Ext.Element} this
  4493. */
  4494. swallowEvent : function(eventName, preventDefault){
  4495. var me = this;
  4496. function fn(e){
  4497. e.stopPropagation();
  4498. if(preventDefault){
  4499. e.preventDefault();
  4500. }
  4501. }
  4502. if(Ext.isArray(eventName)){
  4503. Ext.each(eventName, function(e) {
  4504. me.on(e, fn);
  4505. });
  4506. return me;
  4507. }
  4508. me.on(eventName, fn);
  4509. return me;
  4510. },
  4511. /**
  4512. * Create an event handler on this element such that when the event fires and is handled by this element,
  4513. * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
  4514. * @param {String} eventName The type of event to relay
  4515. * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
  4516. * for firing the relayed event
  4517. */
  4518. relayEvent : function(eventName, observable){
  4519. this.on(eventName, function(e){
  4520. observable.fireEvent(eventName, e);
  4521. });
  4522. },
  4523. /**
  4524. * Removes worthless text nodes
  4525. * @param {Boolean} forceReclean (optional) By default the element
  4526. * keeps track if it has been cleaned already so
  4527. * you can call this over and over. However, if you update the element and
  4528. * need to force a reclean, you can pass true.
  4529. */
  4530. clean : function(forceReclean){
  4531. var me = this,
  4532. dom = me.dom,
  4533. n = dom.firstChild,
  4534. ni = -1;
  4535. if(Ext.Element.data(dom, 'isCleaned') && forceReclean !== true){
  4536. return me;
  4537. }
  4538. while(n){
  4539. var nx = n.nextSibling;
  4540. if(n.nodeType == 3 && !/\S/.test(n.nodeValue)){
  4541. dom.removeChild(n);
  4542. }else{
  4543. n.nodeIndex = ++ni;
  4544. }
  4545. n = nx;
  4546. }
  4547. Ext.Element.data(dom, 'isCleaned', true);
  4548. return me;
  4549. },
  4550. /**
  4551. * Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object
  4552. * parameter as {@link Ext.Updater#update}
  4553. * @return {Ext.Element} this
  4554. */
  4555. load : function(){
  4556. var um = this.getUpdater();
  4557. um.update.apply(um, arguments);
  4558. return this;
  4559. },
  4560. /**
  4561. * Gets this element's {@link Ext.Updater Updater}
  4562. * @return {Ext.Updater} The Updater
  4563. */
  4564. getUpdater : function(){
  4565. return this.updateManager || (this.updateManager = new Ext.Updater(this));
  4566. },
  4567. /**
  4568. * Update the innerHTML of this element, optionally searching for and processing scripts
  4569. * @param {String} html The new HTML
  4570. * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
  4571. * @param {Function} callback (optional) For async script loading you can be notified when the update completes
  4572. * @return {Ext.Element} this
  4573. */
  4574. update : function(html, loadScripts, callback){
  4575. if (!this.dom) {
  4576. return this;
  4577. }
  4578. html = html || "";
  4579. if(loadScripts !== true){
  4580. this.dom.innerHTML = html;
  4581. if(Ext.isFunction(callback)){
  4582. callback();
  4583. }
  4584. return this;
  4585. }
  4586. var id = Ext.id(),
  4587. dom = this.dom;
  4588. html += '<span id="' + id + '"></span>';
  4589. Ext.lib.Event.onAvailable(id, function(){
  4590. var DOC = document,
  4591. hd = DOC.getElementsByTagName("head")[0],
  4592. re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  4593. srcRe = /\ssrc=([\'\"])(.*?)\1/i,
  4594. typeRe = /\stype=([\'\"])(.*?)\1/i,
  4595. match,
  4596. attrs,
  4597. srcMatch,
  4598. typeMatch,
  4599. el,
  4600. s;
  4601. while((match = re.exec(html))){
  4602. attrs = match[1];
  4603. srcMatch = attrs ? attrs.match(srcRe) : false;
  4604. if(srcMatch && srcMatch[2]){
  4605. s = DOC.createElement("script");
  4606. s.src = srcMatch[2];
  4607. typeMatch = attrs.match(typeRe);
  4608. if(typeMatch && typeMatch[2]){
  4609. s.type = typeMatch[2];
  4610. }
  4611. hd.appendChild(s);
  4612. }else if(match[2] && match[2].length > 0){
  4613. if(window.execScript) {
  4614. window.execScript(match[2]);
  4615. } else {
  4616. window.eval(match[2]);
  4617. }
  4618. }
  4619. }
  4620. el = DOC.getElementById(id);
  4621. if(el){Ext.removeNode(el);}
  4622. if(Ext.isFunction(callback)){
  4623. callback();
  4624. }
  4625. });
  4626. dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
  4627. return this;
  4628. },
  4629. // inherit docs, overridden so we can add removeAnchor
  4630. removeAllListeners : function(){
  4631. this.removeAnchor();
  4632. Ext.EventManager.removeAll(this.dom);
  4633. return this;
  4634. },
  4635. /**
  4636. * Creates a proxy element of this element
  4637. * @param {String/Object} config The class name of the proxy element or a DomHelper config object
  4638. * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
  4639. * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
  4640. * @return {Ext.Element} The new proxy element
  4641. */
  4642. createProxy : function(config, renderTo, matchBox){
  4643. config = Ext.isObject(config) ? config : {tag : "div", cls: config};
  4644. var me = this,
  4645. proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
  4646. Ext.DomHelper.insertBefore(me.dom, config, true);
  4647. if(matchBox && me.setBox && me.getBox){ // check to make sure Element.position.js is loaded
  4648. proxy.setBox(me.getBox());
  4649. }
  4650. return proxy;
  4651. }
  4652. });
  4653. Ext.Element.prototype.getUpdateManager = Ext.Element.prototype.getUpdater;
  4654. /**
  4655. * @class Ext.Element
  4656. */
  4657. Ext.Element.addMethods({
  4658. /**
  4659. * Gets the x,y coordinates specified by the anchor position on the element.
  4660. * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo}
  4661. * for details on supported anchor positions.
  4662. * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead
  4663. * of page coordinates
  4664. * @param {Object} size (optional) An object containing the size to use for calculating anchor position
  4665. * {width: (target width), height: (target height)} (defaults to the element's current size)
  4666. * @return {Array} [x, y] An array containing the element's x and y coordinates
  4667. */
  4668. getAnchorXY : function(anchor, local, s){
  4669. //Passing a different size is useful for pre-calculating anchors,
  4670. //especially for anchored animations that change the el size.
  4671. anchor = (anchor || "tl").toLowerCase();
  4672. s = s || {};
  4673. var me = this,
  4674. vp = me.dom == document.body || me.dom == document,
  4675. w = s.width || vp ? Ext.lib.Dom.getViewWidth() : me.getWidth(),
  4676. h = s.height || vp ? Ext.lib.Dom.getViewHeight() : me.getHeight(),
  4677. xy,
  4678. r = Math.round,
  4679. o = me.getXY(),
  4680. scroll = me.getScroll(),
  4681. extraX = vp ? scroll.left : !local ? o[0] : 0,
  4682. extraY = vp ? scroll.top : !local ? o[1] : 0,
  4683. hash = {
  4684. c : [r(w * 0.5), r(h * 0.5)],
  4685. t : [r(w * 0.5), 0],
  4686. l : [0, r(h * 0.5)],
  4687. r : [w, r(h * 0.5)],
  4688. b : [r(w * 0.5), h],
  4689. tl : [0, 0],
  4690. bl : [0, h],
  4691. br : [w, h],
  4692. tr : [w, 0]
  4693. };
  4694. xy = hash[anchor];
  4695. return [xy[0] + extraX, xy[1] + extraY];
  4696. },
  4697. /**
  4698. * Anchors an element to another element and realigns it when the window is resized.
  4699. * @param {Mixed} element The element to align to.
  4700. * @param {String} position The position to align to.
  4701. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  4702. * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
  4703. * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
  4704. * is a number, it is used as the buffer delay (defaults to 50ms).
  4705. * @param {Function} callback The function to call after the animation finishes
  4706. * @return {Ext.Element} this
  4707. */
  4708. anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
  4709. var me = this,
  4710. dom = me.dom,
  4711. scroll = !Ext.isEmpty(monitorScroll),
  4712. action = function(){
  4713. Ext.fly(dom).alignTo(el, alignment, offsets, animate);
  4714. Ext.callback(callback, Ext.fly(dom));
  4715. },
  4716. anchor = this.getAnchor();
  4717. // previous listener anchor, remove it
  4718. this.removeAnchor();
  4719. Ext.apply(anchor, {
  4720. fn: action,
  4721. scroll: scroll
  4722. });
  4723. Ext.EventManager.onWindowResize(action, null);
  4724. if(scroll){
  4725. Ext.EventManager.on(window, 'scroll', action, null,
  4726. {buffer: !isNaN(monitorScroll) ? monitorScroll : 50});
  4727. }
  4728. action.call(me); // align immediately
  4729. return me;
  4730. },
  4731. /**
  4732. * Remove any anchor to this element. See {@link #anchorTo}.
  4733. * @return {Ext.Element} this
  4734. */
  4735. removeAnchor : function(){
  4736. var me = this,
  4737. anchor = this.getAnchor();
  4738. if(anchor && anchor.fn){
  4739. Ext.EventManager.removeResizeListener(anchor.fn);
  4740. if(anchor.scroll){
  4741. Ext.EventManager.un(window, 'scroll', anchor.fn);
  4742. }
  4743. delete anchor.fn;
  4744. }
  4745. return me;
  4746. },
  4747. // private
  4748. getAnchor : function(){
  4749. var data = Ext.Element.data,
  4750. dom = this.dom;
  4751. if (!dom) {
  4752. return;
  4753. }
  4754. var anchor = data(dom, '_anchor');
  4755. if(!anchor){
  4756. anchor = data(dom, '_anchor', {});
  4757. }
  4758. return anchor;
  4759. },
  4760. /**
  4761. * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
  4762. * supported position values.
  4763. * @param {Mixed} element The element to align to.
  4764. * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
  4765. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  4766. * @return {Array} [x, y]
  4767. */
  4768. getAlignToXY : function(el, p, o){
  4769. el = Ext.get(el);
  4770. if(!el || !el.dom){
  4771. throw "Element.alignToXY with an element that doesn't exist";
  4772. }
  4773. o = o || [0,0];
  4774. p = (!p || p == "?" ? "tl-bl?" : (!/-/.test(p) && p !== "" ? "tl-" + p : p || "tl-bl")).toLowerCase();
  4775. var me = this,
  4776. d = me.dom,
  4777. a1,
  4778. a2,
  4779. x,
  4780. y,
  4781. //constrain the aligned el to viewport if necessary
  4782. w,
  4783. h,
  4784. r,
  4785. dw = Ext.lib.Dom.getViewWidth() -10, // 10px of margin for ie
  4786. dh = Ext.lib.Dom.getViewHeight()-10, // 10px of margin for ie
  4787. p1y,
  4788. p1x,
  4789. p2y,
  4790. p2x,
  4791. swapY,
  4792. swapX,
  4793. doc = document,
  4794. docElement = doc.documentElement,
  4795. docBody = doc.body,
  4796. scrollX = (docElement.scrollLeft || docBody.scrollLeft || 0)+5,
  4797. scrollY = (docElement.scrollTop || docBody.scrollTop || 0)+5,
  4798. c = false, //constrain to viewport
  4799. p1 = "",
  4800. p2 = "",
  4801. m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
  4802. if(!m){
  4803. throw "Element.alignTo with an invalid alignment " + p;
  4804. }
  4805. p1 = m[1];
  4806. p2 = m[2];
  4807. c = !!m[3];
  4808. //Subtract the aligned el's internal xy from the target's offset xy
  4809. //plus custom offset to get the aligned el's new offset xy
  4810. a1 = me.getAnchorXY(p1, true);
  4811. a2 = el.getAnchorXY(p2, false);
  4812. x = a2[0] - a1[0] + o[0];
  4813. y = a2[1] - a1[1] + o[1];
  4814. if(c){
  4815. w = me.getWidth();
  4816. h = me.getHeight();
  4817. r = el.getRegion();
  4818. //If we are at a viewport boundary and the aligned el is anchored on a target border that is
  4819. //perpendicular to the vp border, allow the aligned el to slide on that border,
  4820. //otherwise swap the aligned el to the opposite border of the target.
  4821. p1y = p1.charAt(0);
  4822. p1x = p1.charAt(p1.length-1);
  4823. p2y = p2.charAt(0);
  4824. p2x = p2.charAt(p2.length-1);
  4825. swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
  4826. swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
  4827. if (x + w > dw + scrollX) {
  4828. x = swapX ? r.left-w : dw+scrollX-w;
  4829. }
  4830. if (x < scrollX) {
  4831. x = swapX ? r.right : scrollX;
  4832. }
  4833. if (y + h > dh + scrollY) {
  4834. y = swapY ? r.top-h : dh+scrollY-h;
  4835. }
  4836. if (y < scrollY){
  4837. y = swapY ? r.bottom : scrollY;
  4838. }
  4839. }
  4840. return [x,y];
  4841. },
  4842. /**
  4843. * Aligns this element with another element relative to the specified anchor points. If the other element is the
  4844. * document it aligns it to the viewport.
  4845. * The position parameter is optional, and can be specified in any one of the following formats:
  4846. * <ul>
  4847. * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
  4848. * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
  4849. * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
  4850. * deprecated in favor of the newer two anchor syntax below</i>.</li>
  4851. * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
  4852. * element's anchor point, and the second value is used as the target's anchor point.</li>
  4853. * </ul>
  4854. * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
  4855. * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
  4856. * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
  4857. * that specified in order to enforce the viewport constraints.
  4858. * Following are all of the supported anchor positions:
  4859. <pre>
  4860. Value Description
  4861. ----- -----------------------------
  4862. tl The top left corner (default)
  4863. t The center of the top edge
  4864. tr The top right corner
  4865. l The center of the left edge
  4866. c In the center of the element
  4867. r The center of the right edge
  4868. bl The bottom left corner
  4869. b The center of the bottom edge
  4870. br The bottom right corner
  4871. </pre>
  4872. Example Usage:
  4873. <pre><code>
  4874. // align el to other-el using the default positioning ("tl-bl", non-constrained)
  4875. el.alignTo("other-el");
  4876. // align the top left corner of el with the top right corner of other-el (constrained to viewport)
  4877. el.alignTo("other-el", "tr?");
  4878. // align the bottom right corner of el with the center left edge of other-el
  4879. el.alignTo("other-el", "br-l?");
  4880. // align the center of el with the bottom left corner of other-el and
  4881. // adjust the x position by -6 pixels (and the y position by 0)
  4882. el.alignTo("other-el", "c-bl", [-6, 0]);
  4883. </code></pre>
  4884. * @param {Mixed} element The element to align to.
  4885. * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
  4886. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  4887. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  4888. * @return {Ext.Element} this
  4889. */
  4890. alignTo : function(element, position, offsets, animate){
  4891. var me = this;
  4892. return me.setXY(me.getAlignToXY(element, position, offsets),
  4893. me.preanim && !!animate ? me.preanim(arguments, 3) : false);
  4894. },
  4895. // private ==> used outside of core
  4896. adjustForConstraints : function(xy, parent, offsets){
  4897. return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
  4898. },
  4899. // private ==> used outside of core
  4900. getConstrainToXY : function(el, local, offsets, proposedXY){
  4901. var os = {top:0, left:0, bottom:0, right: 0};
  4902. return function(el, local, offsets, proposedXY){
  4903. el = Ext.get(el);
  4904. offsets = offsets ? Ext.applyIf(offsets, os) : os;
  4905. var vw, vh, vx = 0, vy = 0;
  4906. if(el.dom == document.body || el.dom == document){
  4907. vw =Ext.lib.Dom.getViewWidth();
  4908. vh = Ext.lib.Dom.getViewHeight();
  4909. }else{
  4910. vw = el.dom.clientWidth;
  4911. vh = el.dom.clientHeight;
  4912. if(!local){
  4913. var vxy = el.getXY();
  4914. vx = vxy[0];
  4915. vy = vxy[1];
  4916. }
  4917. }
  4918. var s = el.getScroll();
  4919. vx += offsets.left + s.left;
  4920. vy += offsets.top + s.top;
  4921. vw -= offsets.right;
  4922. vh -= offsets.bottom;
  4923. var vr = vx+vw;
  4924. var vb = vy+vh;
  4925. var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
  4926. var x = xy[0], y = xy[1];
  4927. var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
  4928. // only move it if it needs it
  4929. var moved = false;
  4930. // first validate right/bottom
  4931. if((x + w) > vr){
  4932. x = vr - w;
  4933. moved = true;
  4934. }
  4935. if((y + h) > vb){
  4936. y = vb - h;
  4937. moved = true;
  4938. }
  4939. // then make sure top/left isn't negative
  4940. if(x < vx){
  4941. x = vx;
  4942. moved = true;
  4943. }
  4944. if(y < vy){
  4945. y = vy;
  4946. moved = true;
  4947. }
  4948. return moved ? [x, y] : false;
  4949. };
  4950. }(),
  4951. // el = Ext.get(el);
  4952. // offsets = Ext.applyIf(offsets || {}, {top : 0, left : 0, bottom : 0, right : 0});
  4953. // var me = this,
  4954. // doc = document,
  4955. // s = el.getScroll(),
  4956. // vxy = el.getXY(),
  4957. // vx = offsets.left + s.left,
  4958. // vy = offsets.top + s.top,
  4959. // vw = -offsets.right,
  4960. // vh = -offsets.bottom,
  4961. // vr,
  4962. // vb,
  4963. // xy = proposedXY || (!local ? me.getXY() : [me.getLeft(true), me.getTop(true)]),
  4964. // x = xy[0],
  4965. // y = xy[1],
  4966. // w = me.dom.offsetWidth, h = me.dom.offsetHeight,
  4967. // moved = false; // only move it if it needs it
  4968. //
  4969. //
  4970. // if(el.dom == doc.body || el.dom == doc){
  4971. // vw += Ext.lib.Dom.getViewWidth();
  4972. // vh += Ext.lib.Dom.getViewHeight();
  4973. // }else{
  4974. // vw += el.dom.clientWidth;
  4975. // vh += el.dom.clientHeight;
  4976. // if(!local){
  4977. // vx += vxy[0];
  4978. // vy += vxy[1];
  4979. // }
  4980. // }
  4981. // // first validate right/bottom
  4982. // if(x + w > vx + vw){
  4983. // x = vx + vw - w;
  4984. // moved = true;
  4985. // }
  4986. // if(y + h > vy + vh){
  4987. // y = vy + vh - h;
  4988. // moved = true;
  4989. // }
  4990. // // then make sure top/left isn't negative
  4991. // if(x < vx){
  4992. // x = vx;
  4993. // moved = true;
  4994. // }
  4995. // if(y < vy){
  4996. // y = vy;
  4997. // moved = true;
  4998. // }
  4999. // return moved ? [x, y] : false;
  5000. // },
  5001. /**
  5002. * Calculates the x, y to center this element on the screen
  5003. * @return {Array} The x, y values [x, y]
  5004. */
  5005. getCenterXY : function(){
  5006. return this.getAlignToXY(document, 'c-c');
  5007. },
  5008. /**
  5009. * Centers the Element in either the viewport, or another Element.
  5010. * @param {Mixed} centerIn (optional) The element in which to center the element.
  5011. */
  5012. center : function(centerIn){
  5013. return this.alignTo(centerIn || document, 'c-c');
  5014. }
  5015. });
  5016. /**
  5017. * @class Ext.Element
  5018. */
  5019. Ext.Element.addMethods(function(){
  5020. var PARENTNODE = 'parentNode',
  5021. NEXTSIBLING = 'nextSibling',
  5022. PREVIOUSSIBLING = 'previousSibling',
  5023. DQ = Ext.DomQuery,
  5024. GET = Ext.get;
  5025. return {
  5026. /**
  5027. * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  5028. * @param {String} selector The simple selector to test
  5029. * @param {Number/Mixed} maxDepth (optional) The max depth to search as a number or element (defaults to 50 || document.body)
  5030. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  5031. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  5032. */
  5033. findParent : function(simpleSelector, maxDepth, returnEl){
  5034. var p = this.dom,
  5035. b = document.body,
  5036. depth = 0,
  5037. stopEl;
  5038. if(Ext.isGecko && Object.prototype.toString.call(p) == '[object XULElement]') {
  5039. return null;
  5040. }
  5041. maxDepth = maxDepth || 50;
  5042. if (isNaN(maxDepth)) {
  5043. stopEl = Ext.getDom(maxDepth);
  5044. maxDepth = Number.MAX_VALUE;
  5045. }
  5046. while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
  5047. if(DQ.is(p, simpleSelector)){
  5048. return returnEl ? GET(p) : p;
  5049. }
  5050. depth++;
  5051. p = p.parentNode;
  5052. }
  5053. return null;
  5054. },
  5055. /**
  5056. * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  5057. * @param {String} selector The simple selector to test
  5058. * @param {Number/Mixed} maxDepth (optional) The max depth to
  5059. search as a number or element (defaults to 10 || document.body)
  5060. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  5061. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  5062. */
  5063. findParentNode : function(simpleSelector, maxDepth, returnEl){
  5064. var p = Ext.fly(this.dom.parentNode, '_internal');
  5065. return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
  5066. },
  5067. /**
  5068. * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
  5069. * This is a shortcut for findParentNode() that always returns an Ext.Element.
  5070. * @param {String} selector The simple selector to test
  5071. * @param {Number/Mixed} maxDepth (optional) The max depth to
  5072. search as a number or element (defaults to 10 || document.body)
  5073. * @return {Ext.Element} The matching DOM node (or null if no match was found)
  5074. */
  5075. up : function(simpleSelector, maxDepth){
  5076. return this.findParentNode(simpleSelector, maxDepth, true);
  5077. },
  5078. /**
  5079. * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
  5080. * @param {String} selector The CSS selector
  5081. * @return {CompositeElement/CompositeElementLite} The composite element
  5082. */
  5083. select : function(selector){
  5084. return Ext.Element.select(selector, this.dom);
  5085. },
  5086. /**
  5087. * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
  5088. * @param {String} selector The CSS selector
  5089. * @return {Array} An array of the matched nodes
  5090. */
  5091. query : function(selector){
  5092. return DQ.select(selector, this.dom);
  5093. },
  5094. /**
  5095. * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
  5096. * @param {String} selector The CSS selector
  5097. * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
  5098. * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
  5099. */
  5100. child : function(selector, returnDom){
  5101. var n = DQ.selectNode(selector, this.dom);
  5102. return returnDom ? n : GET(n);
  5103. },
  5104. /**
  5105. * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
  5106. * @param {String} selector The CSS selector
  5107. * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
  5108. * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
  5109. */
  5110. down : function(selector, returnDom){
  5111. var n = DQ.selectNode(" > " + selector, this.dom);
  5112. return returnDom ? n : GET(n);
  5113. },
  5114. /**
  5115. * Gets the parent node for this element, optionally chaining up trying to match a selector
  5116. * @param {String} selector (optional) Find a parent node that matches the passed simple selector
  5117. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  5118. * @return {Ext.Element/HTMLElement} The parent node or null
  5119. */
  5120. parent : function(selector, returnDom){
  5121. return this.matchNode(PARENTNODE, PARENTNODE, selector, returnDom);
  5122. },
  5123. /**
  5124. * Gets the next sibling, skipping text nodes
  5125. * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
  5126. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  5127. * @return {Ext.Element/HTMLElement} The next sibling or null
  5128. */
  5129. next : function(selector, returnDom){
  5130. return this.matchNode(NEXTSIBLING, NEXTSIBLING, selector, returnDom);
  5131. },
  5132. /**
  5133. * Gets the previous sibling, skipping text nodes
  5134. * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
  5135. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  5136. * @return {Ext.Element/HTMLElement} The previous sibling or null
  5137. */
  5138. prev : function(selector, returnDom){
  5139. return this.matchNode(PREVIOUSSIBLING, PREVIOUSSIBLING, selector, returnDom);
  5140. },
  5141. /**
  5142. * Gets the first child, skipping text nodes
  5143. * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
  5144. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  5145. * @return {Ext.Element/HTMLElement} The first child or null
  5146. */
  5147. first : function(selector, returnDom){
  5148. return this.matchNode(NEXTSIBLING, 'firstChild', selector, returnDom);
  5149. },
  5150. /**
  5151. * Gets the last child, skipping text nodes
  5152. * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
  5153. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  5154. * @return {Ext.Element/HTMLElement} The last child or null
  5155. */
  5156. last : function(selector, returnDom){
  5157. return this.matchNode(PREVIOUSSIBLING, 'lastChild', selector, returnDom);
  5158. },
  5159. matchNode : function(dir, start, selector, returnDom){
  5160. var n = this.dom[start];
  5161. while(n){
  5162. if(n.nodeType == 1 && (!selector || DQ.is(n, selector))){
  5163. return !returnDom ? GET(n) : n;
  5164. }
  5165. n = n[dir];
  5166. }
  5167. return null;
  5168. }
  5169. }
  5170. }());/**
  5171. * @class Ext.Element
  5172. */
  5173. Ext.Element.addMethods({
  5174. /**
  5175. * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
  5176. * @param {String} selector The CSS selector
  5177. * @param {Boolean} unique (optional) True to create a unique Ext.Element for each child (defaults to false, which creates a single shared flyweight object)
  5178. * @return {CompositeElement/CompositeElementLite} The composite element
  5179. */
  5180. select : function(selector, unique){
  5181. return Ext.Element.select(selector, unique, this.dom);
  5182. }
  5183. });/**
  5184. * @class Ext.Element
  5185. */
  5186. Ext.Element.addMethods(
  5187. function() {
  5188. var GETDOM = Ext.getDom,
  5189. GET = Ext.get,
  5190. DH = Ext.DomHelper;
  5191. return {
  5192. /**
  5193. * Appends the passed element(s) to this element
  5194. * @param {String/HTMLElement/Array/Element/CompositeElement} el
  5195. * @return {Ext.Element} this
  5196. */
  5197. appendChild: function(el){
  5198. return GET(el).appendTo(this);
  5199. },
  5200. /**
  5201. * Appends this element to the passed element
  5202. * @param {Mixed} el The new parent element
  5203. * @return {Ext.Element} this
  5204. */
  5205. appendTo: function(el){
  5206. GETDOM(el).appendChild(this.dom);
  5207. return this;
  5208. },
  5209. /**
  5210. * Inserts this element before the passed element in the DOM
  5211. * @param {Mixed} el The element before which this element will be inserted
  5212. * @return {Ext.Element} this
  5213. */
  5214. insertBefore: function(el){
  5215. (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);
  5216. return this;
  5217. },
  5218. /**
  5219. * Inserts this element after the passed element in the DOM
  5220. * @param {Mixed} el The element to insert after
  5221. * @return {Ext.Element} this
  5222. */
  5223. insertAfter: function(el){
  5224. (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);
  5225. return this;
  5226. },
  5227. /**
  5228. * Inserts (or creates) an element (or DomHelper config) as the first child of this element
  5229. * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
  5230. * @return {Ext.Element} The new child
  5231. */
  5232. insertFirst: function(el, returnDom){
  5233. el = el || {};
  5234. if(el.nodeType || el.dom || typeof el == 'string'){ // element
  5235. el = GETDOM(el);
  5236. this.dom.insertBefore(el, this.dom.firstChild);
  5237. return !returnDom ? GET(el) : el;
  5238. }else{ // dh config
  5239. return this.createChild(el, this.dom.firstChild, returnDom);
  5240. }
  5241. },
  5242. /**
  5243. * Replaces the passed element with this element
  5244. * @param {Mixed} el The element to replace
  5245. * @return {Ext.Element} this
  5246. */
  5247. replace: function(el){
  5248. el = GET(el);
  5249. this.insertBefore(el);
  5250. el.remove();
  5251. return this;
  5252. },
  5253. /**
  5254. * Replaces this element with the passed element
  5255. * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
  5256. * @return {Ext.Element} this
  5257. */
  5258. replaceWith: function(el){
  5259. var me = this;
  5260. if(el.nodeType || el.dom || typeof el == 'string'){
  5261. el = GETDOM(el);
  5262. me.dom.parentNode.insertBefore(el, me.dom);
  5263. }else{
  5264. el = DH.insertBefore(me.dom, el);
  5265. }
  5266. delete Ext.elCache[me.id];
  5267. Ext.removeNode(me.dom);
  5268. me.id = Ext.id(me.dom = el);
  5269. Ext.Element.addToCache(me.isFlyweight ? new Ext.Element(me.dom) : me);
  5270. return me;
  5271. },
  5272. /**
  5273. * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
  5274. * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
  5275. * automatically generated with the specified attributes.
  5276. * @param {HTMLElement} insertBefore (optional) a child element of this element
  5277. * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
  5278. * @return {Ext.Element} The new child element
  5279. */
  5280. createChild: function(config, insertBefore, returnDom){
  5281. config = config || {tag:'div'};
  5282. return insertBefore ?
  5283. DH.insertBefore(insertBefore, config, returnDom !== true) :
  5284. DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
  5285. },
  5286. /**
  5287. * Creates and wraps this element with another element
  5288. * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
  5289. * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
  5290. * @return {HTMLElement/Element} The newly created wrapper element
  5291. */
  5292. wrap: function(config, returnDom){
  5293. var newEl = DH.insertBefore(this.dom, config || {tag: "div"}, !returnDom);
  5294. newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
  5295. return newEl;
  5296. },
  5297. /**
  5298. * Inserts an html fragment into this element
  5299. * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
  5300. * @param {String} html The HTML fragment
  5301. * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
  5302. * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
  5303. */
  5304. insertHtml : function(where, html, returnEl){
  5305. var el = DH.insertHtml(where, this.dom, html);
  5306. return returnEl ? Ext.get(el) : el;
  5307. }
  5308. }
  5309. }());/**
  5310. * @class Ext.Element
  5311. */
  5312. Ext.apply(Ext.Element.prototype, function() {
  5313. var GETDOM = Ext.getDom,
  5314. GET = Ext.get,
  5315. DH = Ext.DomHelper;
  5316. return {
  5317. /**
  5318. * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
  5319. * @param {Mixed/Object/Array} el The id, element to insert or a DomHelper config to create and insert *or* an array of any of those.
  5320. * @param {String} where (optional) 'before' or 'after' defaults to before
  5321. * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
  5322. * @return {Ext.Element} The inserted Element. If an array is passed, the last inserted element is returned.
  5323. */
  5324. insertSibling: function(el, where, returnDom){
  5325. var me = this,
  5326. rt,
  5327. isAfter = (where || 'before').toLowerCase() == 'after',
  5328. insertEl;
  5329. if(Ext.isArray(el)){
  5330. insertEl = me;
  5331. Ext.each(el, function(e) {
  5332. rt = Ext.fly(insertEl, '_internal').insertSibling(e, where, returnDom);
  5333. if(isAfter){
  5334. insertEl = rt;
  5335. }
  5336. });
  5337. return rt;
  5338. }
  5339. el = el || {};
  5340. if(el.nodeType || el.dom){
  5341. rt = me.dom.parentNode.insertBefore(GETDOM(el), isAfter ? me.dom.nextSibling : me.dom);
  5342. if (!returnDom) {
  5343. rt = GET(rt);
  5344. }
  5345. }else{
  5346. if (isAfter && !me.dom.nextSibling) {
  5347. rt = DH.append(me.dom.parentNode, el, !returnDom);
  5348. } else {
  5349. rt = DH[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);
  5350. }
  5351. }
  5352. return rt;
  5353. }
  5354. };
  5355. }());/**
  5356. * @class Ext.Element
  5357. */
  5358. Ext.Element.addMethods(function(){
  5359. // local style camelizing for speed
  5360. var propCache = {},
  5361. camelRe = /(-[a-z])/gi,
  5362. classReCache = {},
  5363. view = document.defaultView,
  5364. propFloat = Ext.isIE ? 'styleFloat' : 'cssFloat',
  5365. opacityRe = /alpha\(opacity=(.*)\)/i,
  5366. trimRe = /^\s+|\s+$/g,
  5367. EL = Ext.Element,
  5368. PADDING = "padding",
  5369. MARGIN = "margin",
  5370. BORDER = "border",
  5371. LEFT = "-left",
  5372. RIGHT = "-right",
  5373. TOP = "-top",
  5374. BOTTOM = "-bottom",
  5375. WIDTH = "-width",
  5376. MATH = Math,
  5377. HIDDEN = 'hidden',
  5378. ISCLIPPED = 'isClipped',
  5379. OVERFLOW = 'overflow',
  5380. OVERFLOWX = 'overflow-x',
  5381. OVERFLOWY = 'overflow-y',
  5382. ORIGINALCLIP = 'originalClip',
  5383. // special markup used throughout Ext when box wrapping elements
  5384. borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
  5385. paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
  5386. margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
  5387. data = Ext.Element.data;
  5388. // private
  5389. function camelFn(m, a) {
  5390. return a.charAt(1).toUpperCase();
  5391. }
  5392. function chkCache(prop) {
  5393. return propCache[prop] || (propCache[prop] = prop == 'float' ? propFloat : prop.replace(camelRe, camelFn));
  5394. }
  5395. return {
  5396. // private ==> used by Fx
  5397. adjustWidth : function(width) {
  5398. var me = this;
  5399. var isNum = Ext.isNumber(width);
  5400. if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
  5401. width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  5402. }
  5403. return (isNum && width < 0) ? 0 : width;
  5404. },
  5405. // private ==> used by Fx
  5406. adjustHeight : function(height) {
  5407. var me = this;
  5408. var isNum = Ext.isNumber(height);
  5409. if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
  5410. height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  5411. }
  5412. return (isNum && height < 0) ? 0 : height;
  5413. },
  5414. /**
  5415. * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
  5416. * @param {String/Array} className The CSS class to add, or an array of classes
  5417. * @return {Ext.Element} this
  5418. */
  5419. addClass : function(className){
  5420. var me = this, i, len, v;
  5421. className = Ext.isArray(className) ? className : [className];
  5422. for (i=0, len = className.length; i < len; i++) {
  5423. v = className[i];
  5424. if (v) {
  5425. me.dom.className += (!me.hasClass(v) && v ? " " + v : "");
  5426. };
  5427. };
  5428. return me;
  5429. },
  5430. /**
  5431. * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
  5432. * @param {String/Array} className The CSS class to add, or an array of classes
  5433. * @return {Ext.Element} this
  5434. */
  5435. radioClass : function(className){
  5436. var cn = this.dom.parentNode.childNodes, v;
  5437. className = Ext.isArray(className) ? className : [className];
  5438. for (var i=0, len = cn.length; i < len; i++) {
  5439. v = cn[i];
  5440. if(v && v.nodeType == 1) {
  5441. Ext.fly(v, '_internal').removeClass(className);
  5442. }
  5443. };
  5444. return this.addClass(className);
  5445. },
  5446. /**
  5447. * Removes one or more CSS classes from the element.
  5448. * @param {String/Array} className The CSS class to remove, or an array of classes
  5449. * @return {Ext.Element} this
  5450. */
  5451. removeClass : function(className){
  5452. var me = this, v;
  5453. className = Ext.isArray(className) ? className : [className];
  5454. if (me.dom && me.dom.className) {
  5455. for (var i=0, len=className.length; i < len; i++) {
  5456. v = className[i];
  5457. if(v) {
  5458. me.dom.className = me.dom.className.replace(
  5459. classReCache[v] = classReCache[v] || new RegExp('(?:^|\\s+)' + v + '(?:\\s+|$)', "g"), " "
  5460. );
  5461. }
  5462. };
  5463. }
  5464. return me;
  5465. },
  5466. /**
  5467. * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
  5468. * @param {String} className The CSS class to toggle
  5469. * @return {Ext.Element} this
  5470. */
  5471. toggleClass : function(className){
  5472. return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
  5473. },
  5474. /**
  5475. * Checks if the specified CSS class exists on this element's DOM node.
  5476. * @param {String} className The CSS class to check for
  5477. * @return {Boolean} True if the class exists, else false
  5478. */
  5479. hasClass : function(className){
  5480. return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
  5481. },
  5482. /**
  5483. * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
  5484. * @param {String} oldClassName The CSS class to replace
  5485. * @param {String} newClassName The replacement CSS class
  5486. * @return {Ext.Element} this
  5487. */
  5488. replaceClass : function(oldClassName, newClassName){
  5489. return this.removeClass(oldClassName).addClass(newClassName);
  5490. },
  5491. isStyle : function(style, val) {
  5492. return this.getStyle(style) == val;
  5493. },
  5494. /**
  5495. * Normalizes currentStyle and computedStyle.
  5496. * @param {String} property The style property whose value is returned.
  5497. * @return {String} The current value of the style property for this element.
  5498. */
  5499. getStyle : function(){
  5500. return view && view.getComputedStyle ?
  5501. function(prop){
  5502. var el = this.dom,
  5503. v,
  5504. cs,
  5505. out,
  5506. display,
  5507. wk = Ext.isWebKit,
  5508. display;
  5509. if(el == document){
  5510. return null;
  5511. }
  5512. prop = chkCache(prop);
  5513. // Fix bug caused by this: https://bugs.webkit.org/show_bug.cgi?id=13343
  5514. if(wk && /marginRight/.test(prop)){
  5515. display = this.getStyle('display');
  5516. el.style.display = 'inline-block';
  5517. }
  5518. out = (v = el.style[prop]) ? v :
  5519. (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
  5520. // Webkit returns rgb values for transparent.
  5521. if(wk){
  5522. if(out == 'rgba(0, 0, 0, 0)'){
  5523. out = 'transparent';
  5524. }else if(display){
  5525. el.style.display = display;
  5526. }
  5527. }
  5528. return out;
  5529. } :
  5530. function(prop){
  5531. var el = this.dom,
  5532. m,
  5533. cs;
  5534. if(el == document) return null;
  5535. if (prop == 'opacity') {
  5536. if (el.style.filter.match) {
  5537. if(m = el.style.filter.match(opacityRe)){
  5538. var fv = parseFloat(m[1]);
  5539. if(!isNaN(fv)){
  5540. return fv ? fv / 100 : 0;
  5541. }
  5542. }
  5543. }
  5544. return 1;
  5545. }
  5546. prop = chkCache(prop);
  5547. return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
  5548. };
  5549. }(),
  5550. /**
  5551. * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
  5552. * are convert to standard 6 digit hex color.
  5553. * @param {String} attr The css attribute
  5554. * @param {String} defaultValue The default value to use when a valid color isn't found
  5555. * @param {String} prefix (optional) defaults to #. Use an empty string when working with
  5556. * color anims.
  5557. */
  5558. getColor : function(attr, defaultValue, prefix){
  5559. var v = this.getStyle(attr),
  5560. color = Ext.isDefined(prefix) ? prefix : '#',
  5561. h;
  5562. if(!v || /transparent|inherit/.test(v)){
  5563. return defaultValue;
  5564. }
  5565. if(/^r/.test(v)){
  5566. Ext.each(v.slice(4, v.length -1).split(','), function(s){
  5567. h = parseInt(s, 10);
  5568. color += (h < 16 ? '0' : '') + h.toString(16);
  5569. });
  5570. }else{
  5571. v = v.replace('#', '');
  5572. color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
  5573. }
  5574. return(color.length > 5 ? color.toLowerCase() : defaultValue);
  5575. },
  5576. /**
  5577. * Wrapper for setting style properties, also takes single object parameter of multiple styles.
  5578. * @param {String/Object} property The style property to be set, or an object of multiple styles.
  5579. * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
  5580. * @return {Ext.Element} this
  5581. */
  5582. setStyle : function(prop, value){
  5583. var tmp,
  5584. style,
  5585. camel;
  5586. if (!Ext.isObject(prop)) {
  5587. tmp = {};
  5588. tmp[prop] = value;
  5589. prop = tmp;
  5590. }
  5591. for (style in prop) {
  5592. value = prop[style];
  5593. style == 'opacity' ?
  5594. this.setOpacity(value) :
  5595. this.dom.style[chkCache(style)] = value;
  5596. }
  5597. return this;
  5598. },
  5599. /**
  5600. * Set the opacity of the element
  5601. * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
  5602. * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
  5603. * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
  5604. * @return {Ext.Element} this
  5605. */
  5606. setOpacity : function(opacity, animate){
  5607. var me = this,
  5608. s = me.dom.style;
  5609. if(!animate || !me.anim){
  5610. if(Ext.isIE){
  5611. var opac = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')' : '',
  5612. val = s.filter.replace(opacityRe, '').replace(trimRe, '');
  5613. s.zoom = 1;
  5614. s.filter = val + (val.length > 0 ? ' ' : '') + opac;
  5615. }else{
  5616. s.opacity = opacity;
  5617. }
  5618. }else{
  5619. me.anim({opacity: {to: opacity}}, me.preanim(arguments, 1), null, .35, 'easeIn');
  5620. }
  5621. return me;
  5622. },
  5623. /**
  5624. * Clears any opacity settings from this element. Required in some cases for IE.
  5625. * @return {Ext.Element} this
  5626. */
  5627. clearOpacity : function(){
  5628. var style = this.dom.style;
  5629. if(Ext.isIE){
  5630. if(!Ext.isEmpty(style.filter)){
  5631. style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
  5632. }
  5633. }else{
  5634. style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
  5635. }
  5636. return this;
  5637. },
  5638. /**
  5639. * Returns the offset height of the element
  5640. * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
  5641. * @return {Number} The element's height
  5642. */
  5643. getHeight : function(contentHeight){
  5644. var me = this,
  5645. dom = me.dom,
  5646. hidden = Ext.isIE && me.isStyle('display', 'none'),
  5647. h = MATH.max(dom.offsetHeight, hidden ? 0 : dom.clientHeight) || 0;
  5648. h = !contentHeight ? h : h - me.getBorderWidth("tb") - me.getPadding("tb");
  5649. return h < 0 ? 0 : h;
  5650. },
  5651. /**
  5652. * Returns the offset width of the element
  5653. * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
  5654. * @return {Number} The element's width
  5655. */
  5656. getWidth : function(contentWidth){
  5657. var me = this,
  5658. dom = me.dom,
  5659. hidden = Ext.isIE && me.isStyle('display', 'none'),
  5660. w = MATH.max(dom.offsetWidth, hidden ? 0 : dom.clientWidth) || 0;
  5661. w = !contentWidth ? w : w - me.getBorderWidth("lr") - me.getPadding("lr");
  5662. return w < 0 ? 0 : w;
  5663. },
  5664. /**
  5665. * Set the width of this Element.
  5666. * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
  5667. * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
  5668. * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
  5669. * </ul></div>
  5670. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  5671. * @return {Ext.Element} this
  5672. */
  5673. setWidth : function(width, animate){
  5674. var me = this;
  5675. width = me.adjustWidth(width);
  5676. !animate || !me.anim ?
  5677. me.dom.style.width = me.addUnits(width) :
  5678. me.anim({width : {to : width}}, me.preanim(arguments, 1));
  5679. return me;
  5680. },
  5681. /**
  5682. * Set the height of this Element.
  5683. * <pre><code>
  5684. // change the height to 200px and animate with default configuration
  5685. Ext.fly('elementId').setHeight(200, true);
  5686. // change the height to 150px and animate with a custom configuration
  5687. Ext.fly('elId').setHeight(150, {
  5688. duration : .5, // animation will have a duration of .5 seconds
  5689. // will change the content to "finished"
  5690. callback: function(){ this.{@link #update}("finished"); }
  5691. });
  5692. * </code></pre>
  5693. * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
  5694. * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
  5695. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  5696. * </ul></div>
  5697. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  5698. * @return {Ext.Element} this
  5699. */
  5700. setHeight : function(height, animate){
  5701. var me = this;
  5702. height = me.adjustHeight(height);
  5703. !animate || !me.anim ?
  5704. me.dom.style.height = me.addUnits(height) :
  5705. me.anim({height : {to : height}}, me.preanim(arguments, 1));
  5706. return me;
  5707. },
  5708. /**
  5709. * Gets the width of the border(s) for the specified side(s)
  5710. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  5711. * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
  5712. * @return {Number} The width of the sides passed added together
  5713. */
  5714. getBorderWidth : function(side){
  5715. return this.addStyles(side, borders);
  5716. },
  5717. /**
  5718. * Gets the width of the padding(s) for the specified side(s)
  5719. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  5720. * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
  5721. * @return {Number} The padding of the sides passed added together
  5722. */
  5723. getPadding : function(side){
  5724. return this.addStyles(side, paddings);
  5725. },
  5726. /**
  5727. * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
  5728. * @return {Ext.Element} this
  5729. */
  5730. clip : function(){
  5731. var me = this,
  5732. dom = me.dom;
  5733. if(!data(dom, ISCLIPPED)){
  5734. data(dom, ISCLIPPED, true);
  5735. data(dom, ORIGINALCLIP, {
  5736. o: me.getStyle(OVERFLOW),
  5737. x: me.getStyle(OVERFLOWX),
  5738. y: me.getStyle(OVERFLOWY)
  5739. });
  5740. me.setStyle(OVERFLOW, HIDDEN);
  5741. me.setStyle(OVERFLOWX, HIDDEN);
  5742. me.setStyle(OVERFLOWY, HIDDEN);
  5743. }
  5744. return me;
  5745. },
  5746. /**
  5747. * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
  5748. * @return {Ext.Element} this
  5749. */
  5750. unclip : function(){
  5751. var me = this,
  5752. dom = me.dom;
  5753. if(data(dom, ISCLIPPED)){
  5754. data(dom, ISCLIPPED, false);
  5755. var o = data(dom, ORIGINALCLIP);
  5756. if(o.o){
  5757. me.setStyle(OVERFLOW, o.o);
  5758. }
  5759. if(o.x){
  5760. me.setStyle(OVERFLOWX, o.x);
  5761. }
  5762. if(o.y){
  5763. me.setStyle(OVERFLOWY, o.y);
  5764. }
  5765. }
  5766. return me;
  5767. },
  5768. // private
  5769. addStyles : function(sides, styles){
  5770. var val = 0,
  5771. m = sides.match(/\w/g),
  5772. s;
  5773. for (var i=0, len=m.length; i<len; i++) {
  5774. s = m[i] && parseInt(this.getStyle(styles[m[i]]), 10);
  5775. if (s) {
  5776. val += MATH.abs(s);
  5777. }
  5778. }
  5779. return val;
  5780. },
  5781. margins : margins
  5782. }
  5783. }()
  5784. );
  5785. /**
  5786. * @class Ext.Element
  5787. */
  5788. // special markup used throughout Ext when box wrapping elements
  5789. Ext.Element.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
  5790. Ext.Element.addMethods(function(){
  5791. var INTERNAL = "_internal",
  5792. pxMatch = /(\d+\.?\d+)px/;
  5793. return {
  5794. /**
  5795. * More flexible version of {@link #setStyle} for setting style properties.
  5796. * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
  5797. * a function which returns such a specification.
  5798. * @return {Ext.Element} this
  5799. */
  5800. applyStyles : function(style){
  5801. Ext.DomHelper.applyStyles(this.dom, style);
  5802. return this;
  5803. },
  5804. /**
  5805. * Returns an object with properties matching the styles requested.
  5806. * For example, el.getStyles('color', 'font-size', 'width') might return
  5807. * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
  5808. * @param {String} style1 A style name
  5809. * @param {String} style2 A style name
  5810. * @param {String} etc.
  5811. * @return {Object} The style object
  5812. */
  5813. getStyles : function(){
  5814. var ret = {};
  5815. Ext.each(arguments, function(v) {
  5816. ret[v] = this.getStyle(v);
  5817. },
  5818. this);
  5819. return ret;
  5820. },
  5821. // private ==> used by ext full
  5822. setOverflow : function(v){
  5823. var dom = this.dom;
  5824. if(v=='auto' && Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
  5825. dom.style.overflow = 'hidden';
  5826. (function(){dom.style.overflow = 'auto';}).defer(1);
  5827. }else{
  5828. dom.style.overflow = v;
  5829. }
  5830. },
  5831. /**
  5832. * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
  5833. * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
  5834. * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.Button},
  5835. * {@link Ext.Panel} when <tt>{@link Ext.Panel#frame frame=true}</tt>, {@link Ext.Window}). The markup
  5836. * is of this form:</p>
  5837. * <pre><code>
  5838. Ext.Element.boxMarkup =
  5839. &#39;&lt;div class="{0}-tl">&lt;div class="{0}-tr">&lt;div class="{0}-tc">&lt;/div>&lt;/div>&lt;/div>
  5840. &lt;div class="{0}-ml">&lt;div class="{0}-mr">&lt;div class="{0}-mc">&lt;/div>&lt;/div>&lt;/div>
  5841. &lt;div class="{0}-bl">&lt;div class="{0}-br">&lt;div class="{0}-bc">&lt;/div>&lt;/div>&lt;/div>&#39;;
  5842. * </code></pre>
  5843. * <p>Example usage:</p>
  5844. * <pre><code>
  5845. // Basic box wrap
  5846. Ext.get("foo").boxWrap();
  5847. // You can also add a custom class and use CSS inheritance rules to customize the box look.
  5848. // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
  5849. // for how to create a custom box wrap style.
  5850. Ext.get("foo").boxWrap().addClass("x-box-blue");
  5851. * </code></pre>
  5852. * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
  5853. * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
  5854. * this name to make the overall effect work, so if you supply an alternate base class, make sure you
  5855. * also supply all of the necessary rules.
  5856. * @return {Ext.Element} The outermost wrapping element of the created box structure.
  5857. */
  5858. boxWrap : function(cls){
  5859. cls = cls || 'x-box';
  5860. var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + String.format(Ext.Element.boxMarkup, cls) + "</div>")); //String.format('<div class="{0}">'+Ext.Element.boxMarkup+'</div>', cls)));
  5861. Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
  5862. return el;
  5863. },
  5864. /**
  5865. * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
  5866. * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
  5867. * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
  5868. * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
  5869. * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
  5870. * </ul></div>
  5871. * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
  5872. * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
  5873. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  5874. * </ul></div>
  5875. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  5876. * @return {Ext.Element} this
  5877. */
  5878. setSize : function(width, height, animate){
  5879. var me = this;
  5880. if(Ext.isObject(width)){ // in case of object from getSize()
  5881. height = width.height;
  5882. width = width.width;
  5883. }
  5884. width = me.adjustWidth(width);
  5885. height = me.adjustHeight(height);
  5886. if(!animate || !me.anim){
  5887. me.dom.style.width = me.addUnits(width);
  5888. me.dom.style.height = me.addUnits(height);
  5889. }else{
  5890. me.anim({width: {to: width}, height: {to: height}}, me.preanim(arguments, 2));
  5891. }
  5892. return me;
  5893. },
  5894. /**
  5895. * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
  5896. * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
  5897. * if a height has not been set using CSS.
  5898. * @return {Number}
  5899. */
  5900. getComputedHeight : function(){
  5901. var me = this,
  5902. h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
  5903. if(!h){
  5904. h = parseFloat(me.getStyle('height')) || 0;
  5905. if(!me.isBorderBox()){
  5906. h += me.getFrameWidth('tb');
  5907. }
  5908. }
  5909. return h;
  5910. },
  5911. /**
  5912. * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
  5913. * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
  5914. * if a width has not been set using CSS.
  5915. * @return {Number}
  5916. */
  5917. getComputedWidth : function(){
  5918. var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
  5919. if(!w){
  5920. w = parseFloat(this.getStyle('width')) || 0;
  5921. if(!this.isBorderBox()){
  5922. w += this.getFrameWidth('lr');
  5923. }
  5924. }
  5925. return w;
  5926. },
  5927. /**
  5928. * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
  5929. for more information about the sides.
  5930. * @param {String} sides
  5931. * @return {Number}
  5932. */
  5933. getFrameWidth : function(sides, onlyContentBox){
  5934. return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
  5935. },
  5936. /**
  5937. * Sets up event handlers to add and remove a css class when the mouse is over this element
  5938. * @param {String} className
  5939. * @return {Ext.Element} this
  5940. */
  5941. addClassOnOver : function(className){
  5942. this.hover(
  5943. function(){
  5944. Ext.fly(this, INTERNAL).addClass(className);
  5945. },
  5946. function(){
  5947. Ext.fly(this, INTERNAL).removeClass(className);
  5948. }
  5949. );
  5950. return this;
  5951. },
  5952. /**
  5953. * Sets up event handlers to add and remove a css class when this element has the focus
  5954. * @param {String} className
  5955. * @return {Ext.Element} this
  5956. */
  5957. addClassOnFocus : function(className){
  5958. this.on("focus", function(){
  5959. Ext.fly(this, INTERNAL).addClass(className);
  5960. }, this.dom);
  5961. this.on("blur", function(){
  5962. Ext.fly(this, INTERNAL).removeClass(className);
  5963. }, this.dom);
  5964. return this;
  5965. },
  5966. /**
  5967. * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
  5968. * @param {String} className
  5969. * @return {Ext.Element} this
  5970. */
  5971. addClassOnClick : function(className){
  5972. var dom = this.dom;
  5973. this.on("mousedown", function(){
  5974. Ext.fly(dom, INTERNAL).addClass(className);
  5975. var d = Ext.getDoc(),
  5976. fn = function(){
  5977. Ext.fly(dom, INTERNAL).removeClass(className);
  5978. d.removeListener("mouseup", fn);
  5979. };
  5980. d.on("mouseup", fn);
  5981. });
  5982. return this;
  5983. },
  5984. /**
  5985. * <p>Returns the dimensions of the element available to lay content out in.<p>
  5986. * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
  5987. * example:<pre><code>
  5988. var vpSize = Ext.getBody().getViewSize();
  5989. // all Windows created afterwards will have a default value of 90% height and 95% width
  5990. Ext.Window.override({
  5991. width: vpSize.width * 0.9,
  5992. height: vpSize.height * 0.95
  5993. });
  5994. // To handle window resizing you would have to hook onto onWindowResize.
  5995. * </code></pre>
  5996. *
  5997. * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
  5998. * To obtain the size including scrollbars, use getStyleSize
  5999. *
  6000. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  6001. */
  6002. getViewSize : function(){
  6003. var doc = document,
  6004. d = this.dom,
  6005. isDoc = (d == doc || d == doc.body);
  6006. // If the body, use Ext.lib.Dom
  6007. if (isDoc) {
  6008. var extdom = Ext.lib.Dom;
  6009. return {
  6010. width : extdom.getViewWidth(),
  6011. height : extdom.getViewHeight()
  6012. };
  6013. // Else use clientHeight/clientWidth
  6014. } else {
  6015. return {
  6016. width : d.clientWidth,
  6017. height : d.clientHeight
  6018. }
  6019. }
  6020. },
  6021. /**
  6022. * <p>Returns the dimensions of the element available to lay content out in.<p>
  6023. *
  6024. * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
  6025. * To obtain the size excluding scrollbars, use getViewSize
  6026. *
  6027. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  6028. */
  6029. getStyleSize : function(){
  6030. var me = this,
  6031. w, h,
  6032. doc = document,
  6033. d = this.dom,
  6034. isDoc = (d == doc || d == doc.body),
  6035. s = d.style;
  6036. // If the body, use Ext.lib.Dom
  6037. if (isDoc) {
  6038. var extdom = Ext.lib.Dom;
  6039. return {
  6040. width : extdom.getViewWidth(),
  6041. height : extdom.getViewHeight()
  6042. }
  6043. }
  6044. // Use Styles if they are set
  6045. if(s.width && s.width != 'auto'){
  6046. w = parseFloat(s.width);
  6047. if(me.isBorderBox()){
  6048. w -= me.getFrameWidth('lr');
  6049. }
  6050. }
  6051. // Use Styles if they are set
  6052. if(s.height && s.height != 'auto'){
  6053. h = parseFloat(s.height);
  6054. if(me.isBorderBox()){
  6055. h -= me.getFrameWidth('tb');
  6056. }
  6057. }
  6058. // Use getWidth/getHeight if style not set.
  6059. return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
  6060. },
  6061. /**
  6062. * Returns the size of the element.
  6063. * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
  6064. * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
  6065. */
  6066. getSize : function(contentSize){
  6067. return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
  6068. },
  6069. /**
  6070. * Forces the browser to repaint this element
  6071. * @return {Ext.Element} this
  6072. */
  6073. repaint : function(){
  6074. var dom = this.dom;
  6075. this.addClass("x-repaint");
  6076. setTimeout(function(){
  6077. Ext.fly(dom).removeClass("x-repaint");
  6078. }, 1);
  6079. return this;
  6080. },
  6081. /**
  6082. * Disables text selection for this element (normalized across browsers)
  6083. * @return {Ext.Element} this
  6084. */
  6085. unselectable : function(){
  6086. this.dom.unselectable = "on";
  6087. return this.swallowEvent("selectstart", true).
  6088. applyStyles("-moz-user-select:none;-khtml-user-select:none;").
  6089. addClass("x-unselectable");
  6090. },
  6091. /**
  6092. * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
  6093. * then it returns the calculated width of the sides (see getPadding)
  6094. * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
  6095. * @return {Object/Number}
  6096. */
  6097. getMargins : function(side){
  6098. var me = this,
  6099. key,
  6100. hash = {t:"top", l:"left", r:"right", b: "bottom"},
  6101. o = {};
  6102. if (!side) {
  6103. for (key in me.margins){
  6104. o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
  6105. }
  6106. return o;
  6107. } else {
  6108. return me.addStyles.call(me, side, me.margins);
  6109. }
  6110. }
  6111. };
  6112. }());
  6113. /**
  6114. * @class Ext.Element
  6115. */
  6116. (function(){
  6117. var D = Ext.lib.Dom,
  6118. LEFT = "left",
  6119. RIGHT = "right",
  6120. TOP = "top",
  6121. BOTTOM = "bottom",
  6122. POSITION = "position",
  6123. STATIC = "static",
  6124. RELATIVE = "relative",
  6125. AUTO = "auto",
  6126. ZINDEX = "z-index";
  6127. Ext.Element.addMethods({
  6128. /**
  6129. * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6130. * @return {Number} The X position of the element
  6131. */
  6132. getX : function(){
  6133. return D.getX(this.dom);
  6134. },
  6135. /**
  6136. * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6137. * @return {Number} The Y position of the element
  6138. */
  6139. getY : function(){
  6140. return D.getY(this.dom);
  6141. },
  6142. /**
  6143. * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6144. * @return {Array} The XY position of the element
  6145. */
  6146. getXY : function(){
  6147. return D.getXY(this.dom);
  6148. },
  6149. /**
  6150. * Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates.
  6151. * @param {Mixed} element The element to get the offsets from.
  6152. * @return {Array} The XY page offsets (e.g. [100, -200])
  6153. */
  6154. getOffsetsTo : function(el){
  6155. var o = this.getXY(),
  6156. e = Ext.fly(el, '_internal').getXY();
  6157. return [o[0]-e[0],o[1]-e[1]];
  6158. },
  6159. /**
  6160. * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6161. * @param {Number} The X position of the element
  6162. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  6163. * @return {Ext.Element} this
  6164. */
  6165. setX : function(x, animate){
  6166. return this.setXY([x, this.getY()], this.animTest(arguments, animate, 1));
  6167. },
  6168. /**
  6169. * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6170. * @param {Number} The Y position of the element
  6171. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  6172. * @return {Ext.Element} this
  6173. */
  6174. setY : function(y, animate){
  6175. return this.setXY([this.getX(), y], this.animTest(arguments, animate, 1));
  6176. },
  6177. /**
  6178. * Sets the element's left position directly using CSS style (instead of {@link #setX}).
  6179. * @param {String} left The left CSS property value
  6180. * @return {Ext.Element} this
  6181. */
  6182. setLeft : function(left){
  6183. this.setStyle(LEFT, this.addUnits(left));
  6184. return this;
  6185. },
  6186. /**
  6187. * Sets the element's top position directly using CSS style (instead of {@link #setY}).
  6188. * @param {String} top The top CSS property value
  6189. * @return {Ext.Element} this
  6190. */
  6191. setTop : function(top){
  6192. this.setStyle(TOP, this.addUnits(top));
  6193. return this;
  6194. },
  6195. /**
  6196. * Sets the element's CSS right style.
  6197. * @param {String} right The right CSS property value
  6198. * @return {Ext.Element} this
  6199. */
  6200. setRight : function(right){
  6201. this.setStyle(RIGHT, this.addUnits(right));
  6202. return this;
  6203. },
  6204. /**
  6205. * Sets the element's CSS bottom style.
  6206. * @param {String} bottom The bottom CSS property value
  6207. * @return {Ext.Element} this
  6208. */
  6209. setBottom : function(bottom){
  6210. this.setStyle(BOTTOM, this.addUnits(bottom));
  6211. return this;
  6212. },
  6213. /**
  6214. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  6215. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6216. * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
  6217. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  6218. * @return {Ext.Element} this
  6219. */
  6220. setXY : function(pos, animate){
  6221. var me = this;
  6222. if(!animate || !me.anim){
  6223. D.setXY(me.dom, pos);
  6224. }else{
  6225. me.anim({points: {to: pos}}, me.preanim(arguments, 1), 'motion');
  6226. }
  6227. return me;
  6228. },
  6229. /**
  6230. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  6231. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6232. * @param {Number} x X value for new position (coordinates are page-based)
  6233. * @param {Number} y Y value for new position (coordinates are page-based)
  6234. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  6235. * @return {Ext.Element} this
  6236. */
  6237. setLocation : function(x, y, animate){
  6238. return this.setXY([x, y], this.animTest(arguments, animate, 2));
  6239. },
  6240. /**
  6241. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  6242. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  6243. * @param {Number} x X value for new position (coordinates are page-based)
  6244. * @param {Number} y Y value for new position (coordinates are page-based)
  6245. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  6246. * @return {Ext.Element} this
  6247. */
  6248. moveTo : function(x, y, animate){
  6249. return this.setXY([x, y], this.animTest(arguments, animate, 2));
  6250. },
  6251. /**
  6252. * Gets the left X coordinate
  6253. * @param {Boolean} local True to get the local css position instead of page coordinate
  6254. * @return {Number}
  6255. */
  6256. getLeft : function(local){
  6257. return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
  6258. },
  6259. /**
  6260. * Gets the right X coordinate of the element (element X position + element width)
  6261. * @param {Boolean} local True to get the local css position instead of page coordinate
  6262. * @return {Number}
  6263. */
  6264. getRight : function(local){
  6265. var me = this;
  6266. return !local ? me.getX() + me.getWidth() : (me.getLeft(true) + me.getWidth()) || 0;
  6267. },
  6268. /**
  6269. * Gets the top Y coordinate
  6270. * @param {Boolean} local True to get the local css position instead of page coordinate
  6271. * @return {Number}
  6272. */
  6273. getTop : function(local) {
  6274. return !local ? this.getY() : parseInt(this.getStyle(TOP), 10) || 0;
  6275. },
  6276. /**
  6277. * Gets the bottom Y coordinate of the element (element Y position + element height)
  6278. * @param {Boolean} local True to get the local css position instead of page coordinate
  6279. * @return {Number}
  6280. */
  6281. getBottom : function(local){
  6282. var me = this;
  6283. return !local ? me.getY() + me.getHeight() : (me.getTop(true) + me.getHeight()) || 0;
  6284. },
  6285. /**
  6286. * Initializes positioning on this element. If a desired position is not passed, it will make the
  6287. * the element positioned relative IF it is not already positioned.
  6288. * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
  6289. * @param {Number} zIndex (optional) The zIndex to apply
  6290. * @param {Number} x (optional) Set the page X position
  6291. * @param {Number} y (optional) Set the page Y position
  6292. */
  6293. position : function(pos, zIndex, x, y){
  6294. var me = this;
  6295. if(!pos && me.isStyle(POSITION, STATIC)){
  6296. me.setStyle(POSITION, RELATIVE);
  6297. } else if(pos) {
  6298. me.setStyle(POSITION, pos);
  6299. }
  6300. if(zIndex){
  6301. me.setStyle(ZINDEX, zIndex);
  6302. }
  6303. if(x || y) me.setXY([x || false, y || false]);
  6304. },
  6305. /**
  6306. * Clear positioning back to the default when the document was loaded
  6307. * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
  6308. * @return {Ext.Element} this
  6309. */
  6310. clearPositioning : function(value){
  6311. value = value || '';
  6312. this.setStyle({
  6313. left : value,
  6314. right : value,
  6315. top : value,
  6316. bottom : value,
  6317. "z-index" : "",
  6318. position : STATIC
  6319. });
  6320. return this;
  6321. },
  6322. /**
  6323. * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
  6324. * snapshot before performing an update and then restoring the element.
  6325. * @return {Object}
  6326. */
  6327. getPositioning : function(){
  6328. var l = this.getStyle(LEFT);
  6329. var t = this.getStyle(TOP);
  6330. return {
  6331. "position" : this.getStyle(POSITION),
  6332. "left" : l,
  6333. "right" : l ? "" : this.getStyle(RIGHT),
  6334. "top" : t,
  6335. "bottom" : t ? "" : this.getStyle(BOTTOM),
  6336. "z-index" : this.getStyle(ZINDEX)
  6337. };
  6338. },
  6339. /**
  6340. * Set positioning with an object returned by getPositioning().
  6341. * @param {Object} posCfg
  6342. * @return {Ext.Element} this
  6343. */
  6344. setPositioning : function(pc){
  6345. var me = this,
  6346. style = me.dom.style;
  6347. me.setStyle(pc);
  6348. if(pc.right == AUTO){
  6349. style.right = "";
  6350. }
  6351. if(pc.bottom == AUTO){
  6352. style.bottom = "";
  6353. }
  6354. return me;
  6355. },
  6356. /**
  6357. * Translates the passed page coordinates into left/top css values for this element
  6358. * @param {Number/Array} x The page x or an array containing [x, y]
  6359. * @param {Number} y (optional) The page y, required if x is not an array
  6360. * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
  6361. */
  6362. translatePoints : function(x, y){
  6363. y = isNaN(x[1]) ? y : x[1];
  6364. x = isNaN(x[0]) ? x : x[0];
  6365. var me = this,
  6366. relative = me.isStyle(POSITION, RELATIVE),
  6367. o = me.getXY(),
  6368. l = parseInt(me.getStyle(LEFT), 10),
  6369. t = parseInt(me.getStyle(TOP), 10);
  6370. l = !isNaN(l) ? l : (relative ? 0 : me.dom.offsetLeft);
  6371. t = !isNaN(t) ? t : (relative ? 0 : me.dom.offsetTop);
  6372. return {left: (x - o[0] + l), top: (y - o[1] + t)};
  6373. },
  6374. animTest : function(args, animate, i) {
  6375. return !!animate && this.preanim ? this.preanim(args, i) : false;
  6376. }
  6377. });
  6378. })();/**
  6379. * @class Ext.Element
  6380. */
  6381. Ext.Element.addMethods({
  6382. /**
  6383. * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.
  6384. * @param {Object} box The box to fill {x, y, width, height}
  6385. * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
  6386. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  6387. * @return {Ext.Element} this
  6388. */
  6389. setBox : function(box, adjust, animate){
  6390. var me = this,
  6391. w = box.width,
  6392. h = box.height;
  6393. if((adjust && !me.autoBoxAdjust) && !me.isBorderBox()){
  6394. w -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  6395. h -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  6396. }
  6397. me.setBounds(box.x, box.y, w, h, me.animTest.call(me, arguments, animate, 2));
  6398. return me;
  6399. },
  6400. /**
  6401. * Return an object defining the area of this Element which can be passed to {@link #setBox} to
  6402. * set another Element's size/location to match this element.
  6403. * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
  6404. * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
  6405. * @return {Object} box An object in the format<pre><code>
  6406. {
  6407. x: &lt;Element's X position>,
  6408. y: &lt;Element's Y position>,
  6409. width: &lt;Element's width>,
  6410. height: &lt;Element's height>,
  6411. bottom: &lt;Element's lower bound>,
  6412. right: &lt;Element's rightmost bound>
  6413. }
  6414. </code></pre>
  6415. * The returned object may also be addressed as an Array where index 0 contains the X position
  6416. * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
  6417. */
  6418. getBox : function(contentBox, local) {
  6419. var me = this,
  6420. xy,
  6421. left,
  6422. top,
  6423. getBorderWidth = me.getBorderWidth,
  6424. getPadding = me.getPadding,
  6425. l,
  6426. r,
  6427. t,
  6428. b;
  6429. if(!local){
  6430. xy = me.getXY();
  6431. }else{
  6432. left = parseInt(me.getStyle("left"), 10) || 0;
  6433. top = parseInt(me.getStyle("top"), 10) || 0;
  6434. xy = [left, top];
  6435. }
  6436. var el = me.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
  6437. if(!contentBox){
  6438. bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
  6439. }else{
  6440. l = getBorderWidth.call(me, "l") + getPadding.call(me, "l");
  6441. r = getBorderWidth.call(me, "r") + getPadding.call(me, "r");
  6442. t = getBorderWidth.call(me, "t") + getPadding.call(me, "t");
  6443. b = getBorderWidth.call(me, "b") + getPadding.call(me, "b");
  6444. bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};
  6445. }
  6446. bx.right = bx.x + bx.width;
  6447. bx.bottom = bx.y + bx.height;
  6448. return bx;
  6449. },
  6450. /**
  6451. * Move this element relative to its current position.
  6452. * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
  6453. * @param {Number} distance How far to move the element in pixels
  6454. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  6455. * @return {Ext.Element} this
  6456. */
  6457. move : function(direction, distance, animate){
  6458. var me = this,
  6459. xy = me.getXY(),
  6460. x = xy[0],
  6461. y = xy[1],
  6462. left = [x - distance, y],
  6463. right = [x + distance, y],
  6464. top = [x, y - distance],
  6465. bottom = [x, y + distance],
  6466. hash = {
  6467. l : left,
  6468. left : left,
  6469. r : right,
  6470. right : right,
  6471. t : top,
  6472. top : top,
  6473. up : top,
  6474. b : bottom,
  6475. bottom : bottom,
  6476. down : bottom
  6477. };
  6478. direction = direction.toLowerCase();
  6479. me.moveTo(hash[direction][0], hash[direction][1], me.animTest.call(me, arguments, animate, 2));
  6480. },
  6481. /**
  6482. * Quick set left and top adding default units
  6483. * @param {String} left The left CSS property value
  6484. * @param {String} top The top CSS property value
  6485. * @return {Ext.Element} this
  6486. */
  6487. setLeftTop : function(left, top){
  6488. var me = this,
  6489. style = me.dom.style;
  6490. style.left = me.addUnits(left);
  6491. style.top = me.addUnits(top);
  6492. return me;
  6493. },
  6494. /**
  6495. * Returns the region of the given element.
  6496. * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
  6497. * @return {Region} A Ext.lib.Region containing "top, left, bottom, right" member data.
  6498. */
  6499. getRegion : function(){
  6500. return Ext.lib.Dom.getRegion(this.dom);
  6501. },
  6502. /**
  6503. * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
  6504. * @param {Number} x X value for new position (coordinates are page-based)
  6505. * @param {Number} y Y value for new position (coordinates are page-based)
  6506. * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
  6507. * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)</li>
  6508. * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
  6509. * </ul></div>
  6510. * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
  6511. * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)</li>
  6512. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  6513. * </ul></div>
  6514. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  6515. * @return {Ext.Element} this
  6516. */
  6517. setBounds : function(x, y, width, height, animate){
  6518. var me = this;
  6519. if (!animate || !me.anim) {
  6520. me.setSize(width, height);
  6521. me.setLocation(x, y);
  6522. } else {
  6523. me.anim({points: {to: [x, y]},
  6524. width: {to: me.adjustWidth(width)},
  6525. height: {to: me.adjustHeight(height)}},
  6526. me.preanim(arguments, 4),
  6527. 'motion');
  6528. }
  6529. return me;
  6530. },
  6531. /**
  6532. * Sets the element's position and size the specified region. If animation is true then width, height, x and y will be animated concurrently.
  6533. * @param {Ext.lib.Region} region The region to fill
  6534. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  6535. * @return {Ext.Element} this
  6536. */
  6537. setRegion : function(region, animate) {
  6538. return this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.animTest.call(this, arguments, animate, 1));
  6539. }
  6540. });/**
  6541. * @class Ext.Element
  6542. */
  6543. Ext.Element.addMethods({
  6544. /**
  6545. * Returns true if this element is scrollable.
  6546. * @return {Boolean}
  6547. */
  6548. isScrollable : function(){
  6549. var dom = this.dom;
  6550. return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
  6551. },
  6552. /**
  6553. * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
  6554. * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
  6555. * @param {Number} value The new scroll value.
  6556. * @return {Element} this
  6557. */
  6558. scrollTo : function(side, value){
  6559. this.dom["scroll" + (/top/i.test(side) ? "Top" : "Left")] = value;
  6560. return this;
  6561. },
  6562. /**
  6563. * Returns the current scroll position of the element.
  6564. * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
  6565. */
  6566. getScroll : function(){
  6567. var d = this.dom,
  6568. doc = document,
  6569. body = doc.body,
  6570. docElement = doc.documentElement,
  6571. l,
  6572. t,
  6573. ret;
  6574. if(d == doc || d == body){
  6575. if(Ext.isIE && Ext.isStrict){
  6576. l = docElement.scrollLeft;
  6577. t = docElement.scrollTop;
  6578. }else{
  6579. l = window.pageXOffset;
  6580. t = window.pageYOffset;
  6581. }
  6582. ret = {left: l || (body ? body.scrollLeft : 0), top: t || (body ? body.scrollTop : 0)};
  6583. }else{
  6584. ret = {left: d.scrollLeft, top: d.scrollTop};
  6585. }
  6586. return ret;
  6587. }
  6588. });/**
  6589. * @class Ext.Element
  6590. */
  6591. Ext.Element.addMethods({
  6592. /**
  6593. * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
  6594. * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
  6595. * @param {Number} value The new scroll value
  6596. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  6597. * @return {Element} this
  6598. */
  6599. scrollTo : function(side, value, animate){
  6600. var top = /top/i.test(side), //check if we're scrolling top or left
  6601. me = this,
  6602. dom = me.dom,
  6603. prop;
  6604. if (!animate || !me.anim) {
  6605. prop = 'scroll' + (top ? 'Top' : 'Left'), // just setting the value, so grab the direction
  6606. dom[prop] = value;
  6607. }else{
  6608. prop = 'scroll' + (top ? 'Left' : 'Top'), // if scrolling top, we need to grab scrollLeft, if left, scrollTop
  6609. me.anim({scroll: {to: top ? [dom[prop], value] : [value, dom[prop]]}},
  6610. me.preanim(arguments, 2), 'scroll');
  6611. }
  6612. return me;
  6613. },
  6614. /**
  6615. * Scrolls this element into view within the passed container.
  6616. * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a
  6617. * string (id), dom node, or Ext.Element.
  6618. * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
  6619. * @return {Ext.Element} this
  6620. */
  6621. scrollIntoView : function(container, hscroll){
  6622. var c = Ext.getDom(container) || Ext.getBody().dom,
  6623. el = this.dom,
  6624. o = this.getOffsetsTo(c),
  6625. l = o[0] + c.scrollLeft,
  6626. t = o[1] + c.scrollTop,
  6627. b = t + el.offsetHeight,
  6628. r = l + el.offsetWidth,
  6629. ch = c.clientHeight,
  6630. ct = parseInt(c.scrollTop, 10),
  6631. cl = parseInt(c.scrollLeft, 10),
  6632. cb = ct + ch,
  6633. cr = cl + c.clientWidth;
  6634. if (el.offsetHeight > ch || t < ct) {
  6635. c.scrollTop = t;
  6636. } else if (b > cb){
  6637. c.scrollTop = b-ch;
  6638. }
  6639. c.scrollTop = c.scrollTop; // corrects IE, other browsers will ignore
  6640. if(hscroll !== false){
  6641. if(el.offsetWidth > c.clientWidth || l < cl){
  6642. c.scrollLeft = l;
  6643. }else if(r > cr){
  6644. c.scrollLeft = r - c.clientWidth;
  6645. }
  6646. c.scrollLeft = c.scrollLeft;
  6647. }
  6648. return this;
  6649. },
  6650. // private
  6651. scrollChildIntoView : function(child, hscroll){
  6652. Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
  6653. },
  6654. /**
  6655. * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
  6656. * within this element's scrollable range.
  6657. * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
  6658. * @param {Number} distance How far to scroll the element in pixels
  6659. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  6660. * @return {Boolean} Returns true if a scroll was triggered or false if the element
  6661. * was scrolled as far as it could go.
  6662. */
  6663. scroll : function(direction, distance, animate){
  6664. if(!this.isScrollable()){
  6665. return;
  6666. }
  6667. var el = this.dom,
  6668. l = el.scrollLeft, t = el.scrollTop,
  6669. w = el.scrollWidth, h = el.scrollHeight,
  6670. cw = el.clientWidth, ch = el.clientHeight,
  6671. scrolled = false, v,
  6672. hash = {
  6673. l: Math.min(l + distance, w-cw),
  6674. r: v = Math.max(l - distance, 0),
  6675. t: Math.max(t - distance, 0),
  6676. b: Math.min(t + distance, h-ch)
  6677. };
  6678. hash.d = hash.b;
  6679. hash.u = hash.t;
  6680. direction = direction.substr(0, 1);
  6681. if((v = hash[direction]) > -1){
  6682. scrolled = true;
  6683. this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2));
  6684. }
  6685. return scrolled;
  6686. }
  6687. });/**
  6688. * @class Ext.Element
  6689. */
  6690. /**
  6691. * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
  6692. * @static
  6693. * @type Number
  6694. */
  6695. Ext.Element.VISIBILITY = 1;
  6696. /**
  6697. * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
  6698. * @static
  6699. * @type Number
  6700. */
  6701. Ext.Element.DISPLAY = 2;
  6702. Ext.Element.addMethods(function(){
  6703. var VISIBILITY = "visibility",
  6704. DISPLAY = "display",
  6705. HIDDEN = "hidden",
  6706. OFFSETS = "offsets",
  6707. NONE = "none",
  6708. ORIGINALDISPLAY = 'originalDisplay',
  6709. VISMODE = 'visibilityMode',
  6710. ELDISPLAY = Ext.Element.DISPLAY,
  6711. data = Ext.Element.data,
  6712. getDisplay = function(dom){
  6713. var d = data(dom, ORIGINALDISPLAY);
  6714. if(d === undefined){
  6715. data(dom, ORIGINALDISPLAY, d = '');
  6716. }
  6717. return d;
  6718. },
  6719. getVisMode = function(dom){
  6720. var m = data(dom, VISMODE);
  6721. if(m === undefined){
  6722. data(dom, VISMODE, m = 1);
  6723. }
  6724. return m;
  6725. };
  6726. return {
  6727. /**
  6728. * The element's default display mode (defaults to "")
  6729. * @type String
  6730. */
  6731. originalDisplay : "",
  6732. visibilityMode : 1,
  6733. /**
  6734. * Sets the element's visibility mode. When setVisible() is called it
  6735. * will use this to determine whether to set the visibility or the display property.
  6736. * @param {Number} visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY
  6737. * @return {Ext.Element} this
  6738. */
  6739. setVisibilityMode : function(visMode){
  6740. data(this.dom, VISMODE, visMode);
  6741. return this;
  6742. },
  6743. /**
  6744. * Perform custom animation on this element.
  6745. * <div><ul class="mdetail-params">
  6746. * <li><u>Animation Properties</u></li>
  6747. *
  6748. * <p>The Animation Control Object enables gradual transitions for any member of an
  6749. * element's style object that takes a numeric value including but not limited to
  6750. * these properties:</p><div><ul class="mdetail-params">
  6751. * <li><tt>bottom, top, left, right</tt></li>
  6752. * <li><tt>height, width</tt></li>
  6753. * <li><tt>margin, padding</tt></li>
  6754. * <li><tt>borderWidth</tt></li>
  6755. * <li><tt>opacity</tt></li>
  6756. * <li><tt>fontSize</tt></li>
  6757. * <li><tt>lineHeight</tt></li>
  6758. * </ul></div>
  6759. *
  6760. *
  6761. * <li><u>Animation Property Attributes</u></li>
  6762. *
  6763. * <p>Each Animation Property is a config object with optional properties:</p>
  6764. * <div><ul class="mdetail-params">
  6765. * <li><tt>by</tt>* : relative change - start at current value, change by this value</li>
  6766. * <li><tt>from</tt> : ignore current value, start from this value</li>
  6767. * <li><tt>to</tt>* : start at current value, go to this value</li>
  6768. * <li><tt>unit</tt> : any allowable unit specification</li>
  6769. * <p>* do not specify both <tt>to</tt> and <tt>by</tt> for an animation property</p>
  6770. * </ul></div>
  6771. *
  6772. * <li><u>Animation Types</u></li>
  6773. *
  6774. * <p>The supported animation types:</p><div><ul class="mdetail-params">
  6775. * <li><tt>'run'</tt> : Default
  6776. * <pre><code>
  6777. var el = Ext.get('complexEl');
  6778. el.animate(
  6779. // animation control object
  6780. {
  6781. borderWidth: {to: 3, from: 0},
  6782. opacity: {to: .3, from: 1},
  6783. height: {to: 50, from: el.getHeight()},
  6784. width: {to: 300, from: el.getWidth()},
  6785. top : {by: - 100, unit: 'px'},
  6786. },
  6787. 0.35, // animation duration
  6788. null, // callback
  6789. 'easeOut', // easing method
  6790. 'run' // animation type ('run','color','motion','scroll')
  6791. );
  6792. * </code></pre>
  6793. * </li>
  6794. * <li><tt>'color'</tt>
  6795. * <p>Animates transition of background, text, or border colors.</p>
  6796. * <pre><code>
  6797. el.animate(
  6798. // animation control object
  6799. {
  6800. color: { to: '#06e' },
  6801. backgroundColor: { to: '#e06' }
  6802. },
  6803. 0.35, // animation duration
  6804. null, // callback
  6805. 'easeOut', // easing method
  6806. 'color' // animation type ('run','color','motion','scroll')
  6807. );
  6808. * </code></pre>
  6809. * </li>
  6810. *
  6811. * <li><tt>'motion'</tt>
  6812. * <p>Animates the motion of an element to/from specific points using optional bezier
  6813. * way points during transit.</p>
  6814. * <pre><code>
  6815. el.animate(
  6816. // animation control object
  6817. {
  6818. borderWidth: {to: 3, from: 0},
  6819. opacity: {to: .3, from: 1},
  6820. height: {to: 50, from: el.getHeight()},
  6821. width: {to: 300, from: el.getWidth()},
  6822. top : {by: - 100, unit: 'px'},
  6823. points: {
  6824. to: [50, 100], // go to this point
  6825. control: [ // optional bezier way points
  6826. [ 600, 800],
  6827. [-100, 200]
  6828. ]
  6829. }
  6830. },
  6831. 3000, // animation duration (milliseconds!)
  6832. null, // callback
  6833. 'easeOut', // easing method
  6834. 'motion' // animation type ('run','color','motion','scroll')
  6835. );
  6836. * </code></pre>
  6837. * </li>
  6838. * <li><tt>'scroll'</tt>
  6839. * <p>Animate horizontal or vertical scrolling of an overflowing page element.</p>
  6840. * <pre><code>
  6841. el.animate(
  6842. // animation control object
  6843. {
  6844. scroll: {to: [400, 300]}
  6845. },
  6846. 0.35, // animation duration
  6847. null, // callback
  6848. 'easeOut', // easing method
  6849. 'scroll' // animation type ('run','color','motion','scroll')
  6850. );
  6851. * </code></pre>
  6852. * </li>
  6853. * </ul></div>
  6854. *
  6855. * </ul></div>
  6856. *
  6857. * @param {Object} args The animation control args
  6858. * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to <tt>.35</tt>)
  6859. * @param {Function} onComplete (optional) Function to call when animation completes
  6860. * @param {String} easing (optional) {@link Ext.Fx#easing} method to use (defaults to <tt>'easeOut'</tt>)
  6861. * @param {String} animType (optional) <tt>'run'</tt> is the default. Can also be <tt>'color'</tt>,
  6862. * <tt>'motion'</tt>, or <tt>'scroll'</tt>
  6863. * @return {Ext.Element} this
  6864. */
  6865. animate : function(args, duration, onComplete, easing, animType){
  6866. this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
  6867. return this;
  6868. },
  6869. /*
  6870. * @private Internal animation call
  6871. */
  6872. anim : function(args, opt, animType, defaultDur, defaultEase, cb){
  6873. animType = animType || 'run';
  6874. opt = opt || {};
  6875. var me = this,
  6876. anim = Ext.lib.Anim[animType](
  6877. me.dom,
  6878. args,
  6879. (opt.duration || defaultDur) || .35,
  6880. (opt.easing || defaultEase) || 'easeOut',
  6881. function(){
  6882. if(cb) cb.call(me);
  6883. if(opt.callback) opt.callback.call(opt.scope || me, me, opt);
  6884. },
  6885. me
  6886. );
  6887. opt.anim = anim;
  6888. return anim;
  6889. },
  6890. // private legacy anim prep
  6891. preanim : function(a, i){
  6892. return !a[i] ? false : (Ext.isObject(a[i]) ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
  6893. },
  6894. /**
  6895. * Checks whether the element is currently visible using both visibility and display properties.
  6896. * @return {Boolean} True if the element is currently visible, else false
  6897. */
  6898. isVisible : function() {
  6899. return !this.isStyle(VISIBILITY, HIDDEN) && !this.isStyle(DISPLAY, NONE);
  6900. },
  6901. /**
  6902. * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  6903. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  6904. * @param {Boolean} visible Whether the element is visible
  6905. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  6906. * @return {Ext.Element} this
  6907. */
  6908. setVisible : function(visible, animate){
  6909. var me = this, isDisplay, isVisible, isOffsets,
  6910. dom = me.dom;
  6911. // hideMode string override
  6912. if (Ext.isString(animate)){
  6913. isDisplay = animate == DISPLAY;
  6914. isVisible = animate == VISIBILITY;
  6915. isOffsets = animate == OFFSETS;
  6916. animate = false;
  6917. } else {
  6918. isDisplay = getVisMode(this.dom) == ELDISPLAY;
  6919. isVisible = !isDisplay;
  6920. }
  6921. if (!animate || !me.anim) {
  6922. if (isDisplay){
  6923. me.setDisplayed(visible);
  6924. } else if (isOffsets){
  6925. if (!visible){
  6926. me.hideModeStyles = {
  6927. position: me.getStyle('position'),
  6928. top: me.getStyle('top'),
  6929. left: me.getStyle('left')
  6930. };
  6931. me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
  6932. } else {
  6933. me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
  6934. }
  6935. }else{
  6936. me.fixDisplay();
  6937. dom.style.visibility = visible ? "visible" : HIDDEN;
  6938. }
  6939. }else{
  6940. // closure for composites
  6941. if (visible){
  6942. me.setOpacity(.01);
  6943. me.setVisible(true);
  6944. }
  6945. me.anim({opacity: { to: (visible?1:0) }},
  6946. me.preanim(arguments, 1),
  6947. null,
  6948. .35,
  6949. 'easeIn',
  6950. function(){
  6951. if(!visible){
  6952. dom.style[isDisplay ? DISPLAY : VISIBILITY] = (isDisplay) ? NONE : HIDDEN;
  6953. Ext.fly(dom).setOpacity(1);
  6954. }
  6955. });
  6956. }
  6957. return me;
  6958. },
  6959. /**
  6960. * Toggles the element's visibility or display, depending on visibility mode.
  6961. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  6962. * @return {Ext.Element} this
  6963. */
  6964. toggle : function(animate){
  6965. var me = this;
  6966. me.setVisible(!me.isVisible(), me.preanim(arguments, 0));
  6967. return me;
  6968. },
  6969. /**
  6970. * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
  6971. * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
  6972. * @return {Ext.Element} this
  6973. */
  6974. setDisplayed : function(value) {
  6975. if(typeof value == "boolean"){
  6976. value = value ? getDisplay(this.dom) : NONE;
  6977. }
  6978. this.setStyle(DISPLAY, value);
  6979. return this;
  6980. },
  6981. // private
  6982. fixDisplay : function(){
  6983. var me = this;
  6984. if(me.isStyle(DISPLAY, NONE)){
  6985. me.setStyle(VISIBILITY, HIDDEN);
  6986. me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
  6987. if(me.isStyle(DISPLAY, NONE)){ // if that fails, default to block
  6988. me.setStyle(DISPLAY, "block");
  6989. }
  6990. }
  6991. },
  6992. /**
  6993. * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  6994. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  6995. * @return {Ext.Element} this
  6996. */
  6997. hide : function(animate){
  6998. // hideMode override
  6999. if (Ext.isString(animate)){
  7000. this.setVisible(false, animate);
  7001. return this;
  7002. }
  7003. this.setVisible(false, this.preanim(arguments, 0));
  7004. return this;
  7005. },
  7006. /**
  7007. * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  7008. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  7009. * @return {Ext.Element} this
  7010. */
  7011. show : function(animate){
  7012. // hideMode override
  7013. if (Ext.isString(animate)){
  7014. this.setVisible(true, animate);
  7015. return this;
  7016. }
  7017. this.setVisible(true, this.preanim(arguments, 0));
  7018. return this;
  7019. }
  7020. };
  7021. }());/**
  7022. * @class Ext.Element
  7023. */
  7024. Ext.Element.addMethods(
  7025. function(){
  7026. var VISIBILITY = "visibility",
  7027. DISPLAY = "display",
  7028. HIDDEN = "hidden",
  7029. NONE = "none",
  7030. XMASKED = "x-masked",
  7031. XMASKEDRELATIVE = "x-masked-relative",
  7032. data = Ext.Element.data;
  7033. return {
  7034. /**
  7035. * Checks whether the element is currently visible using both visibility and display properties.
  7036. * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
  7037. * @return {Boolean} True if the element is currently visible, else false
  7038. */
  7039. isVisible : function(deep) {
  7040. var vis = !this.isStyle(VISIBILITY,HIDDEN) && !this.isStyle(DISPLAY,NONE),
  7041. p = this.dom.parentNode;
  7042. if(deep !== true || !vis){
  7043. return vis;
  7044. }
  7045. while(p && !/^body/i.test(p.tagName)){
  7046. if(!Ext.fly(p, '_isVisible').isVisible()){
  7047. return false;
  7048. }
  7049. p = p.parentNode;
  7050. }
  7051. return true;
  7052. },
  7053. /**
  7054. * Returns true if display is not "none"
  7055. * @return {Boolean}
  7056. */
  7057. isDisplayed : function() {
  7058. return !this.isStyle(DISPLAY, NONE);
  7059. },
  7060. /**
  7061. * Convenience method for setVisibilityMode(Element.DISPLAY)
  7062. * @param {String} display (optional) What to set display to when visible
  7063. * @return {Ext.Element} this
  7064. */
  7065. enableDisplayMode : function(display){
  7066. this.setVisibilityMode(Ext.Element.DISPLAY);
  7067. if(!Ext.isEmpty(display)){
  7068. data(this.dom, 'originalDisplay', display);
  7069. }
  7070. return this;
  7071. },
  7072. /**
  7073. * Puts a mask over this element to disable user interaction. Requires core.css.
  7074. * This method can only be applied to elements which accept child nodes.
  7075. * @param {String} msg (optional) A message to display in the mask
  7076. * @param {String} msgCls (optional) A css class to apply to the msg element
  7077. * @return {Element} The mask element
  7078. */
  7079. mask : function(msg, msgCls){
  7080. var me = this,
  7081. dom = me.dom,
  7082. dh = Ext.DomHelper,
  7083. EXTELMASKMSG = "ext-el-mask-msg",
  7084. el,
  7085. mask;
  7086. if(!/^body/i.test(dom.tagName) && me.getStyle('position') == 'static'){
  7087. me.addClass(XMASKEDRELATIVE);
  7088. }
  7089. if((el = data(dom, 'maskMsg'))){
  7090. el.remove();
  7091. }
  7092. if((el = data(dom, 'mask'))){
  7093. el.remove();
  7094. }
  7095. mask = dh.append(dom, {cls : "ext-el-mask"}, true);
  7096. data(dom, 'mask', mask);
  7097. me.addClass(XMASKED);
  7098. mask.setDisplayed(true);
  7099. if(typeof msg == 'string'){
  7100. var mm = dh.append(dom, {cls : EXTELMASKMSG, cn:{tag:'div'}}, true);
  7101. data(dom, 'maskMsg', mm);
  7102. mm.dom.className = msgCls ? EXTELMASKMSG + " " + msgCls : EXTELMASKMSG;
  7103. mm.dom.firstChild.innerHTML = msg;
  7104. mm.setDisplayed(true);
  7105. mm.center(me);
  7106. }
  7107. if(Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && me.getStyle('height') == 'auto'){ // ie will not expand full height automatically
  7108. mask.setSize(undefined, me.getHeight());
  7109. }
  7110. return mask;
  7111. },
  7112. /**
  7113. * Removes a previously applied mask.
  7114. */
  7115. unmask : function(){
  7116. var me = this,
  7117. dom = me.dom,
  7118. mask = data(dom, 'mask'),
  7119. maskMsg = data(dom, 'maskMsg');
  7120. if(mask){
  7121. if(maskMsg){
  7122. maskMsg.remove();
  7123. data(dom, 'maskMsg', undefined);
  7124. }
  7125. mask.remove();
  7126. data(dom, 'mask', undefined);
  7127. }
  7128. me.removeClass([XMASKED, XMASKEDRELATIVE]);
  7129. },
  7130. /**
  7131. * Returns true if this element is masked
  7132. * @return {Boolean}
  7133. */
  7134. isMasked : function(){
  7135. var m = data(this.dom, 'mask');
  7136. return m && m.isVisible();
  7137. },
  7138. /**
  7139. * Creates an iframe shim for this element to keep selects and other windowed objects from
  7140. * showing through.
  7141. * @return {Ext.Element} The new shim element
  7142. */
  7143. createShim : function(){
  7144. var el = document.createElement('iframe'),
  7145. shim;
  7146. el.frameBorder = '0';
  7147. el.className = 'ext-shim';
  7148. el.src = Ext.SSL_SECURE_URL;
  7149. shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
  7150. shim.autoBoxAdjust = false;
  7151. return shim;
  7152. }
  7153. };
  7154. }());/**
  7155. * @class Ext.Element
  7156. */
  7157. Ext.Element.addMethods({
  7158. /**
  7159. * Convenience method for constructing a KeyMap
  7160. * @param {Number/Array/Object/String} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options:
  7161. * <code>{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</code>
  7162. * @param {Function} fn The function to call
  7163. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed. Defaults to this Element.
  7164. * @return {Ext.KeyMap} The KeyMap created
  7165. */
  7166. addKeyListener : function(key, fn, scope){
  7167. var config;
  7168. if(!Ext.isObject(key) || Ext.isArray(key)){
  7169. config = {
  7170. key: key,
  7171. fn: fn,
  7172. scope: scope
  7173. };
  7174. }else{
  7175. config = {
  7176. key : key.key,
  7177. shift : key.shift,
  7178. ctrl : key.ctrl,
  7179. alt : key.alt,
  7180. fn: fn,
  7181. scope: scope
  7182. };
  7183. }
  7184. return new Ext.KeyMap(this, config);
  7185. },
  7186. /**
  7187. * Creates a KeyMap for this element
  7188. * @param {Object} config The KeyMap config. See {@link Ext.KeyMap} for more details
  7189. * @return {Ext.KeyMap} The KeyMap created
  7190. */
  7191. addKeyMap : function(config){
  7192. return new Ext.KeyMap(this, config);
  7193. }
  7194. });(function(){
  7195. // contants
  7196. var NULL = null,
  7197. UNDEFINED = undefined,
  7198. TRUE = true,
  7199. FALSE = false,
  7200. SETX = "setX",
  7201. SETY = "setY",
  7202. SETXY = "setXY",
  7203. LEFT = "left",
  7204. BOTTOM = "bottom",
  7205. TOP = "top",
  7206. RIGHT = "right",
  7207. HEIGHT = "height",
  7208. WIDTH = "width",
  7209. POINTS = "points",
  7210. HIDDEN = "hidden",
  7211. ABSOLUTE = "absolute",
  7212. VISIBLE = "visible",
  7213. MOTION = "motion",
  7214. POSITION = "position",
  7215. EASEOUT = "easeOut",
  7216. /*
  7217. * Use a light flyweight here since we are using so many callbacks and are always assured a DOM element
  7218. */
  7219. flyEl = new Ext.Element.Flyweight(),
  7220. queues = {},
  7221. getObject = function(o){
  7222. return o || {};
  7223. },
  7224. fly = function(dom){
  7225. flyEl.dom = dom;
  7226. flyEl.id = Ext.id(dom);
  7227. return flyEl;
  7228. },
  7229. /*
  7230. * Queueing now stored outside of the element due to closure issues
  7231. */
  7232. getQueue = function(id){
  7233. if(!queues[id]){
  7234. queues[id] = [];
  7235. }
  7236. return queues[id];
  7237. },
  7238. setQueue = function(id, value){
  7239. queues[id] = value;
  7240. };
  7241. //Notifies Element that fx methods are available
  7242. Ext.enableFx = TRUE;
  7243. /**
  7244. * @class Ext.Fx
  7245. * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied
  7246. * to the {@link Ext.Element} interface when included, so all effects calls should be performed via {@link Ext.Element}.
  7247. * Conversely, since the effects are not actually defined in {@link Ext.Element}, Ext.Fx <b>must</b> be
  7248. * {@link Ext#enableFx included} in order for the Element effects to work.</p><br/>
  7249. *
  7250. * <p><b><u>Method Chaining</u></b></p>
  7251. * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that
  7252. * they return the Element object itself as the method return value, it is not always possible to mix the two in a single
  7253. * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.
  7254. * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason,
  7255. * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the
  7256. * expected results and should be done with care. Also see <tt>{@link #callback}</tt>.</p><br/>
  7257. *
  7258. * <p><b><u>Anchor Options for Motion Effects</u></b></p>
  7259. * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element
  7260. * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p>
  7261. <pre>
  7262. Value Description
  7263. ----- -----------------------------
  7264. tl The top left corner
  7265. t The center of the top edge
  7266. tr The top right corner
  7267. l The center of the left edge
  7268. r The center of the right edge
  7269. bl The bottom left corner
  7270. b The center of the bottom edge
  7271. br The bottom right corner
  7272. </pre>
  7273. * <b>Note</b>: some Fx methods accept specific custom config parameters. The options shown in the Config Options
  7274. * section below are common options that can be passed to any Fx method unless otherwise noted.</b>
  7275. *
  7276. * @cfg {Function} callback A function called when the effect is finished. Note that effects are queued internally by the
  7277. * Fx class, so a callback is not required to specify another effect -- effects can simply be chained together
  7278. * and called in sequence (see note for <b><u>Method Chaining</u></b> above), for example:<pre><code>
  7279. * el.slideIn().highlight();
  7280. * </code></pre>
  7281. * The callback is intended for any additional code that should run once a particular effect has completed. The Element
  7282. * being operated upon is passed as the first parameter.
  7283. *
  7284. * @cfg {Object} scope The scope (<code>this</code> reference) in which the <tt>{@link #callback}</tt> function is executed. Defaults to the browser window.
  7285. *
  7286. * @cfg {String} easing A valid Ext.lib.Easing value for the effect:</p><div class="mdetail-params"><ul>
  7287. * <li><b><tt>backBoth</tt></b></li>
  7288. * <li><b><tt>backIn</tt></b></li>
  7289. * <li><b><tt>backOut</tt></b></li>
  7290. * <li><b><tt>bounceBoth</tt></b></li>
  7291. * <li><b><tt>bounceIn</tt></b></li>
  7292. * <li><b><tt>bounceOut</tt></b></li>
  7293. * <li><b><tt>easeBoth</tt></b></li>
  7294. * <li><b><tt>easeBothStrong</tt></b></li>
  7295. * <li><b><tt>easeIn</tt></b></li>
  7296. * <li><b><tt>easeInStrong</tt></b></li>
  7297. * <li><b><tt>easeNone</tt></b></li>
  7298. * <li><b><tt>easeOut</tt></b></li>
  7299. * <li><b><tt>easeOutStrong</tt></b></li>
  7300. * <li><b><tt>elasticBoth</tt></b></li>
  7301. * <li><b><tt>elasticIn</tt></b></li>
  7302. * <li><b><tt>elasticOut</tt></b></li>
  7303. * </ul></div>
  7304. *
  7305. * @cfg {String} afterCls A css class to apply after the effect
  7306. * @cfg {Number} duration The length of time (in seconds) that the effect should last
  7307. *
  7308. * @cfg {Number} endOpacity Only applicable for {@link #fadeIn} or {@link #fadeOut}, a number between
  7309. * <tt>0</tt> and <tt>1</tt> inclusive to configure the ending opacity value.
  7310. *
  7311. * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes
  7312. * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to
  7313. * effects that end with the element being visually hidden, ignored otherwise)
  7314. * @cfg {String/Object/Function} afterStyle A style specification string, e.g. <tt>"width:100px"</tt>, or an object
  7315. * in the form <tt>{width:"100px"}</tt>, or a function which returns such a specification that will be applied to the
  7316. * Element after the effect finishes.
  7317. * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs
  7318. * @cfg {Boolean} concurrent Whether to allow subsequently-queued effects to run at the same time as the current effect, or to ensure that they run in sequence
  7319. * @cfg {Boolean} stopFx Whether preceding effects should be stopped and removed before running current effect (only applies to non blocking effects)
  7320. */
  7321. Ext.Fx = {
  7322. // private - calls the function taking arguments from the argHash based on the key. Returns the return value of the function.
  7323. // this is useful for replacing switch statements (for example).
  7324. switchStatements : function(key, fn, argHash){
  7325. return fn.apply(this, argHash[key]);
  7326. },
  7327. /**
  7328. * Slides the element into view. An anchor point can be optionally passed to set the point of
  7329. * origin for the slide effect. This function automatically handles wrapping the element with
  7330. * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
  7331. * Usage:
  7332. *<pre><code>
  7333. // default: slide the element in from the top
  7334. el.slideIn();
  7335. // custom: slide the element in from the right with a 2-second duration
  7336. el.slideIn('r', { duration: 2 });
  7337. // common config options shown with default values
  7338. el.slideIn('t', {
  7339. easing: 'easeOut',
  7340. duration: .5
  7341. });
  7342. </code></pre>
  7343. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  7344. * @param {Object} options (optional) Object literal with any of the Fx config options
  7345. * @return {Ext.Element} The Element
  7346. */
  7347. slideIn : function(anchor, o){
  7348. o = getObject(o);
  7349. var me = this,
  7350. dom = me.dom,
  7351. st = dom.style,
  7352. xy,
  7353. r,
  7354. b,
  7355. wrap,
  7356. after,
  7357. st,
  7358. args,
  7359. pt,
  7360. bw,
  7361. bh;
  7362. anchor = anchor || "t";
  7363. me.queueFx(o, function(){
  7364. xy = fly(dom).getXY();
  7365. // fix display to visibility
  7366. fly(dom).fixDisplay();
  7367. // restore values after effect
  7368. r = fly(dom).getFxRestore();
  7369. b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight};
  7370. b.right = b.x + b.width;
  7371. b.bottom = b.y + b.height;
  7372. // fixed size for slide
  7373. fly(dom).setWidth(b.width).setHeight(b.height);
  7374. // wrap if needed
  7375. wrap = fly(dom).fxWrap(r.pos, o, HIDDEN);
  7376. st.visibility = VISIBLE;
  7377. st.position = ABSOLUTE;
  7378. // clear out temp styles after slide and unwrap
  7379. function after(){
  7380. fly(dom).fxUnwrap(wrap, r.pos, o);
  7381. st.width = r.width;
  7382. st.height = r.height;
  7383. fly(dom).afterFx(o);
  7384. }
  7385. // time to calculate the positions
  7386. pt = {to: [b.x, b.y]};
  7387. bw = {to: b.width};
  7388. bh = {to: b.height};
  7389. function argCalc(wrap, style, ww, wh, sXY, sXYval, s1, s2, w, h, p){
  7390. var ret = {};
  7391. fly(wrap).setWidth(ww).setHeight(wh);
  7392. if(fly(wrap)[sXY]){
  7393. fly(wrap)[sXY](sXYval);
  7394. }
  7395. style[s1] = style[s2] = "0";
  7396. if(w){
  7397. ret.width = w
  7398. };
  7399. if(h){
  7400. ret.height = h;
  7401. }
  7402. if(p){
  7403. ret.points = p;
  7404. }
  7405. return ret;
  7406. };
  7407. args = fly(dom).switchStatements(anchor.toLowerCase(), argCalc, {
  7408. t : [wrap, st, b.width, 0, NULL, NULL, LEFT, BOTTOM, NULL, bh, NULL],
  7409. l : [wrap, st, 0, b.height, NULL, NULL, RIGHT, TOP, bw, NULL, NULL],
  7410. r : [wrap, st, b.width, b.height, SETX, b.right, LEFT, TOP, NULL, NULL, pt],
  7411. b : [wrap, st, b.width, b.height, SETY, b.bottom, LEFT, TOP, NULL, bh, pt],
  7412. tl : [wrap, st, 0, 0, NULL, NULL, RIGHT, BOTTOM, bw, bh, pt],
  7413. bl : [wrap, st, 0, 0, SETY, b.y + b.height, RIGHT, TOP, bw, bh, pt],
  7414. br : [wrap, st, 0, 0, SETXY, [b.right, b.bottom], LEFT, TOP, bw, bh, pt],
  7415. tr : [wrap, st, 0, 0, SETX, b.x + b.width, LEFT, BOTTOM, bw, bh, pt]
  7416. });
  7417. st.visibility = VISIBLE;
  7418. fly(wrap).show();
  7419. arguments.callee.anim = fly(wrap).fxanim(args,
  7420. o,
  7421. MOTION,
  7422. .5,
  7423. EASEOUT,
  7424. after);
  7425. });
  7426. return me;
  7427. },
  7428. /**
  7429. * Slides the element out of view. An anchor point can be optionally passed to set the end point
  7430. * for the slide effect. When the effect is completed, the element will be hidden (visibility =
  7431. * 'hidden') but block elements will still take up space in the document. The element must be removed
  7432. * from the DOM using the 'remove' config option if desired. This function automatically handles
  7433. * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
  7434. * Usage:
  7435. *<pre><code>
  7436. // default: slide the element out to the top
  7437. el.slideOut();
  7438. // custom: slide the element out to the right with a 2-second duration
  7439. el.slideOut('r', { duration: 2 });
  7440. // common config options shown with default values
  7441. el.slideOut('t', {
  7442. easing: 'easeOut',
  7443. duration: .5,
  7444. remove: false,
  7445. useDisplay: false
  7446. });
  7447. </code></pre>
  7448. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  7449. * @param {Object} options (optional) Object literal with any of the Fx config options
  7450. * @return {Ext.Element} The Element
  7451. */
  7452. slideOut : function(anchor, o){
  7453. o = getObject(o);
  7454. var me = this,
  7455. dom = me.dom,
  7456. st = dom.style,
  7457. xy = me.getXY(),
  7458. wrap,
  7459. r,
  7460. b,
  7461. a,
  7462. zero = {to: 0};
  7463. anchor = anchor || "t";
  7464. me.queueFx(o, function(){
  7465. // restore values after effect
  7466. r = fly(dom).getFxRestore();
  7467. b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight};
  7468. b.right = b.x + b.width;
  7469. b.bottom = b.y + b.height;
  7470. // fixed size for slide
  7471. fly(dom).setWidth(b.width).setHeight(b.height);
  7472. // wrap if needed
  7473. wrap = fly(dom).fxWrap(r.pos, o, VISIBLE);
  7474. st.visibility = VISIBLE;
  7475. st.position = ABSOLUTE;
  7476. fly(wrap).setWidth(b.width).setHeight(b.height);
  7477. function after(){
  7478. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  7479. fly(dom).fxUnwrap(wrap, r.pos, o);
  7480. st.width = r.width;
  7481. st.height = r.height;
  7482. fly(dom).afterFx(o);
  7483. }
  7484. function argCalc(style, s1, s2, p1, v1, p2, v2, p3, v3){
  7485. var ret = {};
  7486. style[s1] = style[s2] = "0";
  7487. ret[p1] = v1;
  7488. if(p2){
  7489. ret[p2] = v2;
  7490. }
  7491. if(p3){
  7492. ret[p3] = v3;
  7493. }
  7494. return ret;
  7495. };
  7496. a = fly(dom).switchStatements(anchor.toLowerCase(), argCalc, {
  7497. t : [st, LEFT, BOTTOM, HEIGHT, zero],
  7498. l : [st, RIGHT, TOP, WIDTH, zero],
  7499. r : [st, LEFT, TOP, WIDTH, zero, POINTS, {to : [b.right, b.y]}],
  7500. b : [st, LEFT, TOP, HEIGHT, zero, POINTS, {to : [b.x, b.bottom]}],
  7501. tl : [st, RIGHT, BOTTOM, WIDTH, zero, HEIGHT, zero],
  7502. bl : [st, RIGHT, TOP, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.x, b.bottom]}],
  7503. br : [st, LEFT, TOP, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.x + b.width, b.bottom]}],
  7504. tr : [st, LEFT, BOTTOM, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.right, b.y]}]
  7505. });
  7506. arguments.callee.anim = fly(wrap).fxanim(a,
  7507. o,
  7508. MOTION,
  7509. .5,
  7510. EASEOUT,
  7511. after);
  7512. });
  7513. return me;
  7514. },
  7515. /**
  7516. * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
  7517. * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
  7518. * The element must be removed from the DOM using the 'remove' config option if desired.
  7519. * Usage:
  7520. *<pre><code>
  7521. // default
  7522. el.puff();
  7523. // common config options shown with default values
  7524. el.puff({
  7525. easing: 'easeOut',
  7526. duration: .5,
  7527. remove: false,
  7528. useDisplay: false
  7529. });
  7530. </code></pre>
  7531. * @param {Object} options (optional) Object literal with any of the Fx config options
  7532. * @return {Ext.Element} The Element
  7533. */
  7534. puff : function(o){
  7535. o = getObject(o);
  7536. var me = this,
  7537. dom = me.dom,
  7538. st = dom.style,
  7539. width,
  7540. height,
  7541. r;
  7542. me.queueFx(o, function(){
  7543. width = fly(dom).getWidth();
  7544. height = fly(dom).getHeight();
  7545. fly(dom).clearOpacity();
  7546. fly(dom).show();
  7547. // restore values after effect
  7548. r = fly(dom).getFxRestore();
  7549. function after(){
  7550. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  7551. fly(dom).clearOpacity();
  7552. fly(dom).setPositioning(r.pos);
  7553. st.width = r.width;
  7554. st.height = r.height;
  7555. st.fontSize = '';
  7556. fly(dom).afterFx(o);
  7557. }
  7558. arguments.callee.anim = fly(dom).fxanim({
  7559. width : {to : fly(dom).adjustWidth(width * 2)},
  7560. height : {to : fly(dom).adjustHeight(height * 2)},
  7561. points : {by : [-width * .5, -height * .5]},
  7562. opacity : {to : 0},
  7563. fontSize: {to : 200, unit: "%"}
  7564. },
  7565. o,
  7566. MOTION,
  7567. .5,
  7568. EASEOUT,
  7569. after);
  7570. });
  7571. return me;
  7572. },
  7573. /**
  7574. * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
  7575. * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
  7576. * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
  7577. * Usage:
  7578. *<pre><code>
  7579. // default
  7580. el.switchOff();
  7581. // all config options shown with default values
  7582. el.switchOff({
  7583. easing: 'easeIn',
  7584. duration: .3,
  7585. remove: false,
  7586. useDisplay: false
  7587. });
  7588. </code></pre>
  7589. * @param {Object} options (optional) Object literal with any of the Fx config options
  7590. * @return {Ext.Element} The Element
  7591. */
  7592. switchOff : function(o){
  7593. o = getObject(o);
  7594. var me = this,
  7595. dom = me.dom,
  7596. st = dom.style,
  7597. r;
  7598. me.queueFx(o, function(){
  7599. fly(dom).clearOpacity();
  7600. fly(dom).clip();
  7601. // restore values after effect
  7602. r = fly(dom).getFxRestore();
  7603. function after(){
  7604. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  7605. fly(dom).clearOpacity();
  7606. fly(dom).setPositioning(r.pos);
  7607. st.width = r.width;
  7608. st.height = r.height;
  7609. fly(dom).afterFx(o);
  7610. };
  7611. fly(dom).fxanim({opacity : {to : 0.3}},
  7612. NULL,
  7613. NULL,
  7614. .1,
  7615. NULL,
  7616. function(){
  7617. fly(dom).clearOpacity();
  7618. (function(){
  7619. fly(dom).fxanim({
  7620. height : {to : 1},
  7621. points : {by : [0, fly(dom).getHeight() * .5]}
  7622. },
  7623. o,
  7624. MOTION,
  7625. 0.3,
  7626. 'easeIn',
  7627. after);
  7628. }).defer(100);
  7629. });
  7630. });
  7631. return me;
  7632. },
  7633. /**
  7634. * Highlights the Element by setting a color (applies to the background-color by default, but can be
  7635. * changed using the "attr" config option) and then fading back to the original color. If no original
  7636. * color is available, you should provide the "endColor" config option which will be cleared after the animation.
  7637. * Usage:
  7638. <pre><code>
  7639. // default: highlight background to yellow
  7640. el.highlight();
  7641. // custom: highlight foreground text to blue for 2 seconds
  7642. el.highlight("0000ff", { attr: 'color', duration: 2 });
  7643. // common config options shown with default values
  7644. el.highlight("ffff9c", {
  7645. attr: "background-color", //can be any valid CSS property (attribute) that supports a color value
  7646. endColor: (current color) or "ffffff",
  7647. easing: 'easeIn',
  7648. duration: 1
  7649. });
  7650. </code></pre>
  7651. * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
  7652. * @param {Object} options (optional) Object literal with any of the Fx config options
  7653. * @return {Ext.Element} The Element
  7654. */
  7655. highlight : function(color, o){
  7656. o = getObject(o);
  7657. var me = this,
  7658. dom = me.dom,
  7659. attr = o.attr || "backgroundColor",
  7660. a = {},
  7661. restore;
  7662. me.queueFx(o, function(){
  7663. fly(dom).clearOpacity();
  7664. fly(dom).show();
  7665. function after(){
  7666. dom.style[attr] = restore;
  7667. fly(dom).afterFx(o);
  7668. }
  7669. restore = dom.style[attr];
  7670. a[attr] = {from: color || "ffff9c", to: o.endColor || fly(dom).getColor(attr) || "ffffff"};
  7671. arguments.callee.anim = fly(dom).fxanim(a,
  7672. o,
  7673. 'color',
  7674. 1,
  7675. 'easeIn',
  7676. after);
  7677. });
  7678. return me;
  7679. },
  7680. /**
  7681. * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
  7682. * Usage:
  7683. <pre><code>
  7684. // default: a single light blue ripple
  7685. el.frame();
  7686. // custom: 3 red ripples lasting 3 seconds total
  7687. el.frame("ff0000", 3, { duration: 3 });
  7688. // common config options shown with default values
  7689. el.frame("C3DAF9", 1, {
  7690. duration: 1 //duration of each individual ripple.
  7691. // Note: Easing is not configurable and will be ignored if included
  7692. });
  7693. </code></pre>
  7694. * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
  7695. * @param {Number} count (optional) The number of ripples to display (defaults to 1)
  7696. * @param {Object} options (optional) Object literal with any of the Fx config options
  7697. * @return {Ext.Element} The Element
  7698. */
  7699. frame : function(color, count, o){
  7700. o = getObject(o);
  7701. var me = this,
  7702. dom = me.dom,
  7703. proxy,
  7704. active;
  7705. me.queueFx(o, function(){
  7706. color = color || '#C3DAF9';
  7707. if(color.length == 6){
  7708. color = '#' + color;
  7709. }
  7710. count = count || 1;
  7711. fly(dom).show();
  7712. var xy = fly(dom).getXY(),
  7713. b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight},
  7714. queue = function(){
  7715. proxy = fly(document.body || document.documentElement).createChild({
  7716. style:{
  7717. position : ABSOLUTE,
  7718. 'z-index': 35000, // yee haw
  7719. border : '0px solid ' + color
  7720. }
  7721. });
  7722. return proxy.queueFx({}, animFn);
  7723. };
  7724. arguments.callee.anim = {
  7725. isAnimated: true,
  7726. stop: function() {
  7727. count = 0;
  7728. proxy.stopFx();
  7729. }
  7730. };
  7731. function animFn(){
  7732. var scale = Ext.isBorderBox ? 2 : 1;
  7733. active = proxy.anim({
  7734. top : {from : b.y, to : b.y - 20},
  7735. left : {from : b.x, to : b.x - 20},
  7736. borderWidth : {from : 0, to : 10},
  7737. opacity : {from : 1, to : 0},
  7738. height : {from : b.height, to : b.height + 20 * scale},
  7739. width : {from : b.width, to : b.width + 20 * scale}
  7740. },{
  7741. duration: o.duration || 1,
  7742. callback: function() {
  7743. proxy.remove();
  7744. --count > 0 ? queue() : fly(dom).afterFx(o);
  7745. }
  7746. });
  7747. arguments.callee.anim = {
  7748. isAnimated: true,
  7749. stop: function(){
  7750. active.stop();
  7751. }
  7752. };
  7753. };
  7754. queue();
  7755. });
  7756. return me;
  7757. },
  7758. /**
  7759. * Creates a pause before any subsequent queued effects begin. If there are
  7760. * no effects queued after the pause it will have no effect.
  7761. * Usage:
  7762. <pre><code>
  7763. el.pause(1);
  7764. </code></pre>
  7765. * @param {Number} seconds The length of time to pause (in seconds)
  7766. * @return {Ext.Element} The Element
  7767. */
  7768. pause : function(seconds){
  7769. var dom = this.dom,
  7770. t;
  7771. this.queueFx({}, function(){
  7772. t = setTimeout(function(){
  7773. fly(dom).afterFx({});
  7774. }, seconds * 1000);
  7775. arguments.callee.anim = {
  7776. isAnimated: true,
  7777. stop: function(){
  7778. clearTimeout(t);
  7779. fly(dom).afterFx({});
  7780. }
  7781. };
  7782. });
  7783. return this;
  7784. },
  7785. /**
  7786. * Fade an element in (from transparent to opaque). The ending opacity can be specified
  7787. * using the <tt>{@link #endOpacity}</tt> config option.
  7788. * Usage:
  7789. <pre><code>
  7790. // default: fade in from opacity 0 to 100%
  7791. el.fadeIn();
  7792. // custom: fade in from opacity 0 to 75% over 2 seconds
  7793. el.fadeIn({ endOpacity: .75, duration: 2});
  7794. // common config options shown with default values
  7795. el.fadeIn({
  7796. endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
  7797. easing: 'easeOut',
  7798. duration: .5
  7799. });
  7800. </code></pre>
  7801. * @param {Object} options (optional) Object literal with any of the Fx config options
  7802. * @return {Ext.Element} The Element
  7803. */
  7804. fadeIn : function(o){
  7805. o = getObject(o);
  7806. var me = this,
  7807. dom = me.dom,
  7808. to = o.endOpacity || 1;
  7809. me.queueFx(o, function(){
  7810. fly(dom).setOpacity(0);
  7811. fly(dom).fixDisplay();
  7812. dom.style.visibility = VISIBLE;
  7813. arguments.callee.anim = fly(dom).fxanim({opacity:{to:to}},
  7814. o, NULL, .5, EASEOUT, function(){
  7815. if(to == 1){
  7816. fly(dom).clearOpacity();
  7817. }
  7818. fly(dom).afterFx(o);
  7819. });
  7820. });
  7821. return me;
  7822. },
  7823. /**
  7824. * Fade an element out (from opaque to transparent). The ending opacity can be specified
  7825. * using the <tt>{@link #endOpacity}</tt> config option. Note that IE may require
  7826. * <tt>{@link #useDisplay}:true</tt> in order to redisplay correctly.
  7827. * Usage:
  7828. <pre><code>
  7829. // default: fade out from the element's current opacity to 0
  7830. el.fadeOut();
  7831. // custom: fade out from the element's current opacity to 25% over 2 seconds
  7832. el.fadeOut({ endOpacity: .25, duration: 2});
  7833. // common config options shown with default values
  7834. el.fadeOut({
  7835. endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
  7836. easing: 'easeOut',
  7837. duration: .5,
  7838. remove: false,
  7839. useDisplay: false
  7840. });
  7841. </code></pre>
  7842. * @param {Object} options (optional) Object literal with any of the Fx config options
  7843. * @return {Ext.Element} The Element
  7844. */
  7845. fadeOut : function(o){
  7846. o = getObject(o);
  7847. var me = this,
  7848. dom = me.dom,
  7849. style = dom.style,
  7850. to = o.endOpacity || 0;
  7851. me.queueFx(o, function(){
  7852. arguments.callee.anim = fly(dom).fxanim({
  7853. opacity : {to : to}},
  7854. o,
  7855. NULL,
  7856. .5,
  7857. EASEOUT,
  7858. function(){
  7859. if(to == 0){
  7860. Ext.Element.data(dom, 'visibilityMode') == Ext.Element.DISPLAY || o.useDisplay ?
  7861. style.display = "none" :
  7862. style.visibility = HIDDEN;
  7863. fly(dom).clearOpacity();
  7864. }
  7865. fly(dom).afterFx(o);
  7866. });
  7867. });
  7868. return me;
  7869. },
  7870. /**
  7871. * Animates the transition of an element's dimensions from a starting height/width
  7872. * to an ending height/width. This method is a convenience implementation of {@link shift}.
  7873. * Usage:
  7874. <pre><code>
  7875. // change height and width to 100x100 pixels
  7876. el.scale(100, 100);
  7877. // common config options shown with default values. The height and width will default to
  7878. // the element&#39;s existing values if passed as null.
  7879. el.scale(
  7880. [element&#39;s width],
  7881. [element&#39;s height], {
  7882. easing: 'easeOut',
  7883. duration: .35
  7884. }
  7885. );
  7886. </code></pre>
  7887. * @param {Number} width The new width (pass undefined to keep the original width)
  7888. * @param {Number} height The new height (pass undefined to keep the original height)
  7889. * @param {Object} options (optional) Object literal with any of the Fx config options
  7890. * @return {Ext.Element} The Element
  7891. */
  7892. scale : function(w, h, o){
  7893. this.shift(Ext.apply({}, o, {
  7894. width: w,
  7895. height: h
  7896. }));
  7897. return this;
  7898. },
  7899. /**
  7900. * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
  7901. * Any of these properties not specified in the config object will not be changed. This effect
  7902. * requires that at least one new dimension, position or opacity setting must be passed in on
  7903. * the config object in order for the function to have any effect.
  7904. * Usage:
  7905. <pre><code>
  7906. // slide the element horizontally to x position 200 while changing the height and opacity
  7907. el.shift({ x: 200, height: 50, opacity: .8 });
  7908. // common config options shown with default values.
  7909. el.shift({
  7910. width: [element&#39;s width],
  7911. height: [element&#39;s height],
  7912. x: [element&#39;s x position],
  7913. y: [element&#39;s y position],
  7914. opacity: [element&#39;s opacity],
  7915. easing: 'easeOut',
  7916. duration: .35
  7917. });
  7918. </code></pre>
  7919. * @param {Object} options Object literal with any of the Fx config options
  7920. * @return {Ext.Element} The Element
  7921. */
  7922. shift : function(o){
  7923. o = getObject(o);
  7924. var dom = this.dom,
  7925. a = {};
  7926. this.queueFx(o, function(){
  7927. for (var prop in o) {
  7928. if (o[prop] != UNDEFINED) {
  7929. a[prop] = {to : o[prop]};
  7930. }
  7931. }
  7932. a.width ? a.width.to = fly(dom).adjustWidth(o.width) : a;
  7933. a.height ? a.height.to = fly(dom).adjustWidth(o.height) : a;
  7934. if (a.x || a.y || a.xy) {
  7935. a.points = a.xy ||
  7936. {to : [ a.x ? a.x.to : fly(dom).getX(),
  7937. a.y ? a.y.to : fly(dom).getY()]};
  7938. }
  7939. arguments.callee.anim = fly(dom).fxanim(a,
  7940. o,
  7941. MOTION,
  7942. .35,
  7943. EASEOUT,
  7944. function(){
  7945. fly(dom).afterFx(o);
  7946. });
  7947. });
  7948. return this;
  7949. },
  7950. /**
  7951. * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
  7952. * ending point of the effect.
  7953. * Usage:
  7954. *<pre><code>
  7955. // default: slide the element downward while fading out
  7956. el.ghost();
  7957. // custom: slide the element out to the right with a 2-second duration
  7958. el.ghost('r', { duration: 2 });
  7959. // common config options shown with default values
  7960. el.ghost('b', {
  7961. easing: 'easeOut',
  7962. duration: .5,
  7963. remove: false,
  7964. useDisplay: false
  7965. });
  7966. </code></pre>
  7967. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
  7968. * @param {Object} options (optional) Object literal with any of the Fx config options
  7969. * @return {Ext.Element} The Element
  7970. */
  7971. ghost : function(anchor, o){
  7972. o = getObject(o);
  7973. var me = this,
  7974. dom = me.dom,
  7975. st = dom.style,
  7976. a = {opacity: {to: 0}, points: {}},
  7977. pt = a.points,
  7978. r,
  7979. w,
  7980. h;
  7981. anchor = anchor || "b";
  7982. me.queueFx(o, function(){
  7983. // restore values after effect
  7984. r = fly(dom).getFxRestore();
  7985. w = fly(dom).getWidth();
  7986. h = fly(dom).getHeight();
  7987. function after(){
  7988. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  7989. fly(dom).clearOpacity();
  7990. fly(dom).setPositioning(r.pos);
  7991. st.width = r.width;
  7992. st.height = r.height;
  7993. fly(dom).afterFx(o);
  7994. }
  7995. pt.by = fly(dom).switchStatements(anchor.toLowerCase(), function(v1,v2){ return [v1, v2];}, {
  7996. t : [0, -h],
  7997. l : [-w, 0],
  7998. r : [w, 0],
  7999. b : [0, h],
  8000. tl : [-w, -h],
  8001. bl : [-w, h],
  8002. br : [w, h],
  8003. tr : [w, -h]
  8004. });
  8005. arguments.callee.anim = fly(dom).fxanim(a,
  8006. o,
  8007. MOTION,
  8008. .5,
  8009. EASEOUT, after);
  8010. });
  8011. return me;
  8012. },
  8013. /**
  8014. * Ensures that all effects queued after syncFx is called on the element are
  8015. * run concurrently. This is the opposite of {@link #sequenceFx}.
  8016. * @return {Ext.Element} The Element
  8017. */
  8018. syncFx : function(){
  8019. var me = this;
  8020. me.fxDefaults = Ext.apply(me.fxDefaults || {}, {
  8021. block : FALSE,
  8022. concurrent : TRUE,
  8023. stopFx : FALSE
  8024. });
  8025. return me;
  8026. },
  8027. /**
  8028. * Ensures that all effects queued after sequenceFx is called on the element are
  8029. * run in sequence. This is the opposite of {@link #syncFx}.
  8030. * @return {Ext.Element} The Element
  8031. */
  8032. sequenceFx : function(){
  8033. var me = this;
  8034. me.fxDefaults = Ext.apply(me.fxDefaults || {}, {
  8035. block : FALSE,
  8036. concurrent : FALSE,
  8037. stopFx : FALSE
  8038. });
  8039. return me;
  8040. },
  8041. /* @private */
  8042. nextFx : function(){
  8043. var ef = getQueue(this.dom.id)[0];
  8044. if(ef){
  8045. ef.call(this);
  8046. }
  8047. },
  8048. /**
  8049. * Returns true if the element has any effects actively running or queued, else returns false.
  8050. * @return {Boolean} True if element has active effects, else false
  8051. */
  8052. hasActiveFx : function(){
  8053. return getQueue(this.dom.id)[0];
  8054. },
  8055. /**
  8056. * Stops any running effects and clears the element's internal effects queue if it contains
  8057. * any additional effects that haven't started yet.
  8058. * @return {Ext.Element} The Element
  8059. */
  8060. stopFx : function(finish){
  8061. var me = this,
  8062. id = me.dom.id;
  8063. if(me.hasActiveFx()){
  8064. var cur = getQueue(id)[0];
  8065. if(cur && cur.anim){
  8066. if(cur.anim.isAnimated){
  8067. setQueue(id, [cur]); //clear
  8068. cur.anim.stop(finish !== undefined ? finish : TRUE);
  8069. }else{
  8070. setQueue(id, []);
  8071. }
  8072. }
  8073. }
  8074. return me;
  8075. },
  8076. /* @private */
  8077. beforeFx : function(o){
  8078. if(this.hasActiveFx() && !o.concurrent){
  8079. if(o.stopFx){
  8080. this.stopFx();
  8081. return TRUE;
  8082. }
  8083. return FALSE;
  8084. }
  8085. return TRUE;
  8086. },
  8087. /**
  8088. * Returns true if the element is currently blocking so that no other effect can be queued
  8089. * until this effect is finished, else returns false if blocking is not set. This is commonly
  8090. * used to ensure that an effect initiated by a user action runs to completion prior to the
  8091. * same effect being restarted (e.g., firing only one effect even if the user clicks several times).
  8092. * @return {Boolean} True if blocking, else false
  8093. */
  8094. hasFxBlock : function(){
  8095. var q = getQueue(this.dom.id);
  8096. return q && q[0] && q[0].block;
  8097. },
  8098. /* @private */
  8099. queueFx : function(o, fn){
  8100. var me = fly(this.dom);
  8101. if(!me.hasFxBlock()){
  8102. Ext.applyIf(o, me.fxDefaults);
  8103. if(!o.concurrent){
  8104. var run = me.beforeFx(o);
  8105. fn.block = o.block;
  8106. getQueue(me.dom.id).push(fn);
  8107. if(run){
  8108. me.nextFx();
  8109. }
  8110. }else{
  8111. fn.call(me);
  8112. }
  8113. }
  8114. return me;
  8115. },
  8116. /* @private */
  8117. fxWrap : function(pos, o, vis){
  8118. var dom = this.dom,
  8119. wrap,
  8120. wrapXY;
  8121. if(!o.wrap || !(wrap = Ext.getDom(o.wrap))){
  8122. if(o.fixPosition){
  8123. wrapXY = fly(dom).getXY();
  8124. }
  8125. var div = document.createElement("div");
  8126. div.style.visibility = vis;
  8127. wrap = dom.parentNode.insertBefore(div, dom);
  8128. fly(wrap).setPositioning(pos);
  8129. if(fly(wrap).isStyle(POSITION, "static")){
  8130. fly(wrap).position("relative");
  8131. }
  8132. fly(dom).clearPositioning('auto');
  8133. fly(wrap).clip();
  8134. wrap.appendChild(dom);
  8135. if(wrapXY){
  8136. fly(wrap).setXY(wrapXY);
  8137. }
  8138. }
  8139. return wrap;
  8140. },
  8141. /* @private */
  8142. fxUnwrap : function(wrap, pos, o){
  8143. var dom = this.dom;
  8144. fly(dom).clearPositioning();
  8145. fly(dom).setPositioning(pos);
  8146. if(!o.wrap){
  8147. var pn = fly(wrap).dom.parentNode;
  8148. pn.insertBefore(dom, wrap);
  8149. fly(wrap).remove();
  8150. }
  8151. },
  8152. /* @private */
  8153. getFxRestore : function(){
  8154. var st = this.dom.style;
  8155. return {pos: this.getPositioning(), width: st.width, height : st.height};
  8156. },
  8157. /* @private */
  8158. afterFx : function(o){
  8159. var dom = this.dom,
  8160. id = dom.id;
  8161. if(o.afterStyle){
  8162. fly(dom).setStyle(o.afterStyle);
  8163. }
  8164. if(o.afterCls){
  8165. fly(dom).addClass(o.afterCls);
  8166. }
  8167. if(o.remove == TRUE){
  8168. fly(dom).remove();
  8169. }
  8170. if(o.callback){
  8171. o.callback.call(o.scope, fly(dom));
  8172. }
  8173. if(!o.concurrent){
  8174. getQueue(id).shift();
  8175. fly(dom).nextFx();
  8176. }
  8177. },
  8178. /* @private */
  8179. fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){
  8180. animType = animType || 'run';
  8181. opt = opt || {};
  8182. var anim = Ext.lib.Anim[animType](
  8183. this.dom,
  8184. args,
  8185. (opt.duration || defaultDur) || .35,
  8186. (opt.easing || defaultEase) || EASEOUT,
  8187. cb,
  8188. this
  8189. );
  8190. opt.anim = anim;
  8191. return anim;
  8192. }
  8193. };
  8194. // backwards compat
  8195. Ext.Fx.resize = Ext.Fx.scale;
  8196. //When included, Ext.Fx is automatically applied to Element so that all basic
  8197. //effects are available directly via the Element API
  8198. Ext.Element.addMethods(Ext.Fx);
  8199. })();
  8200. /**
  8201. * @class Ext.CompositeElementLite
  8202. * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
  8203. * members, or to perform collective actions upon the whole set.</p>
  8204. * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
  8205. * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>
  8206. * Example:<pre><code>
  8207. var els = Ext.select("#some-el div.some-class");
  8208. // or select directly from an existing element
  8209. var el = Ext.get('some-el');
  8210. el.select('div.some-class');
  8211. els.setWidth(100); // all elements become 100 width
  8212. els.hide(true); // all elements fade out and hide
  8213. // or
  8214. els.setWidth(100).hide(true);
  8215. </code>
  8216. */
  8217. Ext.CompositeElementLite = function(els, root){
  8218. /**
  8219. * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>
  8220. * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing
  8221. * to augment the capabilities of the CompositeElementLite class may use it when adding
  8222. * methods to the class.</p>
  8223. * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all
  8224. * following siblings of selected elements, the code would be</p><code><pre>
  8225. Ext.override(Ext.CompositeElementLite, {
  8226. nextAll: function() {
  8227. var els = this.elements, i, l = els.length, n, r = [], ri = -1;
  8228. // Loop through all elements in this Composite, accumulating
  8229. // an Array of all siblings.
  8230. for (i = 0; i < l; i++) {
  8231. for (n = els[i].nextSibling; n; n = n.nextSibling) {
  8232. r[++ri] = n;
  8233. }
  8234. }
  8235. // Add all found siblings to this Composite
  8236. return this.add(r);
  8237. }
  8238. });</pre></code>
  8239. * @type Array
  8240. * @property elements
  8241. */
  8242. this.elements = [];
  8243. this.add(els, root);
  8244. this.el = new Ext.Element.Flyweight();
  8245. };
  8246. Ext.CompositeElementLite.prototype = {
  8247. isComposite: true,
  8248. // private
  8249. getElement : function(el){
  8250. // Set the shared flyweight dom property to the current element
  8251. var e = this.el;
  8252. e.dom = el;
  8253. e.id = el.id;
  8254. return e;
  8255. },
  8256. // private
  8257. transformElement : function(el){
  8258. return Ext.getDom(el);
  8259. },
  8260. /**
  8261. * Returns the number of elements in this Composite.
  8262. * @return Number
  8263. */
  8264. getCount : function(){
  8265. return this.elements.length;
  8266. },
  8267. /**
  8268. * Adds elements to this Composite object.
  8269. * @param {Mixed} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
  8270. * @return {CompositeElement} This Composite object.
  8271. */
  8272. add : function(els, root){
  8273. var me = this,
  8274. elements = me.elements;
  8275. if(!els){
  8276. return this;
  8277. }
  8278. if(Ext.isString(els)){
  8279. els = Ext.Element.selectorFunction(els, root);
  8280. }else if(els.isComposite){
  8281. els = els.elements;
  8282. }else if(!Ext.isIterable(els)){
  8283. els = [els];
  8284. }
  8285. for(var i = 0, len = els.length; i < len; ++i){
  8286. elements.push(me.transformElement(els[i]));
  8287. }
  8288. return me;
  8289. },
  8290. invoke : function(fn, args){
  8291. var me = this,
  8292. els = me.elements,
  8293. len = els.length,
  8294. e,
  8295. i;
  8296. for(i = 0; i < len; i++) {
  8297. e = els[i];
  8298. if(e){
  8299. Ext.Element.prototype[fn].apply(me.getElement(e), args);
  8300. }
  8301. }
  8302. return me;
  8303. },
  8304. /**
  8305. * Returns a flyweight Element of the dom element object at the specified index
  8306. * @param {Number} index
  8307. * @return {Ext.Element}
  8308. */
  8309. item : function(index){
  8310. var me = this,
  8311. el = me.elements[index],
  8312. out = null;
  8313. if(el){
  8314. out = me.getElement(el);
  8315. }
  8316. return out;
  8317. },
  8318. // fixes scope with flyweight
  8319. addListener : function(eventName, handler, scope, opt){
  8320. var els = this.elements,
  8321. len = els.length,
  8322. i, e;
  8323. for(i = 0; i<len; i++) {
  8324. e = els[i];
  8325. if(e) {
  8326. Ext.EventManager.on(e, eventName, handler, scope || e, opt);
  8327. }
  8328. }
  8329. return this;
  8330. },
  8331. /**
  8332. * <p>Calls the passed function for each element in this composite.</p>
  8333. * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
  8334. * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
  8335. * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
  8336. * a reference to the dom node, use el.dom.</b></div></li>
  8337. * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
  8338. * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
  8339. * </ul>
  8340. * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
  8341. * @return {CompositeElement} this
  8342. */
  8343. each : function(fn, scope){
  8344. var me = this,
  8345. els = me.elements,
  8346. len = els.length,
  8347. i, e;
  8348. for(i = 0; i<len; i++) {
  8349. e = els[i];
  8350. if(e){
  8351. e = this.getElement(e);
  8352. if(fn.call(scope || e, e, me, i) === false){
  8353. break;
  8354. }
  8355. }
  8356. }
  8357. return me;
  8358. },
  8359. /**
  8360. * Clears this Composite and adds the elements passed.
  8361. * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.
  8362. * @return {CompositeElement} this
  8363. */
  8364. fill : function(els){
  8365. var me = this;
  8366. me.elements = [];
  8367. me.add(els);
  8368. return me;
  8369. },
  8370. /**
  8371. * Filters this composite to only elements that match the passed selector.
  8372. * @param {String/Function} selector A string CSS selector or a comparison function.
  8373. * The comparison function will be called with the following arguments:<ul>
  8374. * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
  8375. * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
  8376. * </ul>
  8377. * @return {CompositeElement} this
  8378. */
  8379. filter : function(selector){
  8380. var els = [],
  8381. me = this,
  8382. elements = me.elements,
  8383. fn = Ext.isFunction(selector) ? selector
  8384. : function(el){
  8385. return el.is(selector);
  8386. };
  8387. me.each(function(el, self, i){
  8388. if(fn(el, i) !== false){
  8389. els[els.length] = me.transformElement(el);
  8390. }
  8391. });
  8392. me.elements = els;
  8393. return me;
  8394. },
  8395. /**
  8396. * Find the index of the passed element within the composite collection.
  8397. * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
  8398. * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
  8399. */
  8400. indexOf : function(el){
  8401. return this.elements.indexOf(this.transformElement(el));
  8402. },
  8403. /**
  8404. * Replaces the specified element with the passed element.
  8405. * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
  8406. * to replace.
  8407. * @param {Mixed} replacement The id of an element or the Element itself.
  8408. * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
  8409. * @return {CompositeElement} this
  8410. */
  8411. replaceElement : function(el, replacement, domReplace){
  8412. var index = !isNaN(el) ? el : this.indexOf(el),
  8413. d;
  8414. if(index > -1){
  8415. replacement = Ext.getDom(replacement);
  8416. if(domReplace){
  8417. d = this.elements[index];
  8418. d.parentNode.insertBefore(replacement, d);
  8419. Ext.removeNode(d);
  8420. }
  8421. this.elements.splice(index, 1, replacement);
  8422. }
  8423. return this;
  8424. },
  8425. /**
  8426. * Removes all elements.
  8427. */
  8428. clear : function(){
  8429. this.elements = [];
  8430. }
  8431. };
  8432. Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
  8433. (function(){
  8434. var fnName,
  8435. ElProto = Ext.Element.prototype,
  8436. CelProto = Ext.CompositeElementLite.prototype;
  8437. for(fnName in ElProto){
  8438. if(Ext.isFunction(ElProto[fnName])){
  8439. (function(fnName){
  8440. CelProto[fnName] = CelProto[fnName] || function(){
  8441. return this.invoke(fnName, arguments);
  8442. };
  8443. }).call(CelProto, fnName);
  8444. }
  8445. }
  8446. })();
  8447. if(Ext.DomQuery){
  8448. Ext.Element.selectorFunction = Ext.DomQuery.select;
  8449. }
  8450. /**
  8451. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  8452. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  8453. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  8454. * @param {String/Array} selector The CSS selector or an array of elements
  8455. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  8456. * @return {CompositeElementLite/CompositeElement}
  8457. * @member Ext.Element
  8458. * @method select
  8459. */
  8460. Ext.Element.select = function(selector, root){
  8461. var els;
  8462. if(typeof selector == "string"){
  8463. els = Ext.Element.selectorFunction(selector, root);
  8464. }else if(selector.length !== undefined){
  8465. els = selector;
  8466. }else{
  8467. throw "Invalid selector";
  8468. }
  8469. return new Ext.CompositeElementLite(els);
  8470. };
  8471. /**
  8472. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  8473. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  8474. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  8475. * @param {String/Array} selector The CSS selector or an array of elements
  8476. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  8477. * @return {CompositeElementLite/CompositeElement}
  8478. * @member Ext
  8479. * @method select
  8480. */
  8481. Ext.select = Ext.Element.select;/**
  8482. * @class Ext.CompositeElementLite
  8483. */
  8484. Ext.apply(Ext.CompositeElementLite.prototype, {
  8485. addElements : function(els, root){
  8486. if(!els){
  8487. return this;
  8488. }
  8489. if(typeof els == "string"){
  8490. els = Ext.Element.selectorFunction(els, root);
  8491. }
  8492. var yels = this.elements;
  8493. Ext.each(els, function(e) {
  8494. yels.push(Ext.get(e));
  8495. });
  8496. return this;
  8497. },
  8498. /**
  8499. * Returns the first Element
  8500. * @return {Ext.Element}
  8501. */
  8502. first : function(){
  8503. return this.item(0);
  8504. },
  8505. /**
  8506. * Returns the last Element
  8507. * @return {Ext.Element}
  8508. */
  8509. last : function(){
  8510. return this.item(this.getCount()-1);
  8511. },
  8512. /**
  8513. * Returns true if this composite contains the passed element
  8514. * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
  8515. * @return Boolean
  8516. */
  8517. contains : function(el){
  8518. return this.indexOf(el) != -1;
  8519. },
  8520. /**
  8521. * Removes the specified element(s).
  8522. * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
  8523. * or an array of any of those.
  8524. * @param {Boolean} removeDom (optional) True to also remove the element from the document
  8525. * @return {CompositeElement} this
  8526. */
  8527. removeElement : function(keys, removeDom){
  8528. var me = this,
  8529. els = this.elements,
  8530. el;
  8531. Ext.each(keys, function(val){
  8532. if ((el = (els[val] || els[val = me.indexOf(val)]))) {
  8533. if(removeDom){
  8534. if(el.dom){
  8535. el.remove();
  8536. }else{
  8537. Ext.removeNode(el);
  8538. }
  8539. }
  8540. els.splice(val, 1);
  8541. }
  8542. });
  8543. return this;
  8544. }
  8545. });
  8546. /**
  8547. * @class Ext.CompositeElement
  8548. * @extends Ext.CompositeElementLite
  8549. * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
  8550. * members, or to perform collective actions upon the whole set.</p>
  8551. * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
  8552. * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>
  8553. * <p>All methods return <i>this</i> and can be chained.</p>
  8554. * Usage:
  8555. <pre><code>
  8556. var els = Ext.select("#some-el div.some-class", true);
  8557. // or select directly from an existing element
  8558. var el = Ext.get('some-el');
  8559. el.select('div.some-class', true);
  8560. els.setWidth(100); // all elements become 100 width
  8561. els.hide(true); // all elements fade out and hide
  8562. // or
  8563. els.setWidth(100).hide(true);
  8564. </code></pre>
  8565. */
  8566. Ext.CompositeElement = function(els, root){
  8567. this.elements = [];
  8568. this.add(els, root);
  8569. };
  8570. Ext.extend(Ext.CompositeElement, Ext.CompositeElementLite, {
  8571. // private
  8572. getElement : function(el){
  8573. // In this case just return it, since we already have a reference to it
  8574. return el;
  8575. },
  8576. // private
  8577. transformElement : function(el){
  8578. return Ext.get(el);
  8579. }
  8580. /**
  8581. * Adds elements to this composite.
  8582. * @param {String/Array} els A string CSS selector, an array of elements or an element
  8583. * @return {CompositeElement} this
  8584. */
  8585. /**
  8586. * Returns the Element object at the specified index
  8587. * @param {Number} index
  8588. * @return {Ext.Element}
  8589. */
  8590. /**
  8591. * Iterates each <code>element</code> in this <code>composite</code>
  8592. * calling the supplied function using {@link Ext#each}.
  8593. * @param {Function} fn The function to be called with each
  8594. * <code>element</code>. If the supplied function returns <tt>false</tt>,
  8595. * iteration stops. This function is called with the following arguments:
  8596. * <div class="mdetail-params"><ul>
  8597. * <li><code>element</code> : <i>Ext.Element</i><div class="sub-desc">The element at the current <code>index</code>
  8598. * in the <code>composite</code></div></li>
  8599. * <li><code>composite</code> : <i>Object</i> <div class="sub-desc">This composite.</div></li>
  8600. * <li><code>index</code> : <i>Number</i> <div class="sub-desc">The current index within the <code>composite</code> </div></li>
  8601. * </ul></div>
  8602. * @param {Object} scope (optional) The scope (<code><this</code> reference) in which the specified function is executed.
  8603. * Defaults to the <code>element</code> at the current <code>index</code>
  8604. * within the composite.
  8605. * @return {CompositeElement} this
  8606. */
  8607. });
  8608. /**
  8609. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  8610. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  8611. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  8612. * @param {String/Array} selector The CSS selector or an array of elements
  8613. * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
  8614. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  8615. * @return {CompositeElementLite/CompositeElement}
  8616. * @member Ext.Element
  8617. * @method select
  8618. */
  8619. Ext.Element.select = function(selector, unique, root){
  8620. var els;
  8621. if(typeof selector == "string"){
  8622. els = Ext.Element.selectorFunction(selector, root);
  8623. }else if(selector.length !== undefined){
  8624. els = selector;
  8625. }else{
  8626. throw "Invalid selector";
  8627. }
  8628. return (unique === true) ? new Ext.CompositeElement(els) : new Ext.CompositeElementLite(els);
  8629. };
  8630. /**
  8631. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  8632. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  8633. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  8634. * @param {String/Array} selector The CSS selector or an array of elements
  8635. * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
  8636. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  8637. * @return {CompositeElementLite/CompositeElement}
  8638. * @member Ext.Element
  8639. * @method select
  8640. */
  8641. Ext.select = Ext.Element.select;(function(){
  8642. var BEFOREREQUEST = "beforerequest",
  8643. REQUESTCOMPLETE = "requestcomplete",
  8644. REQUESTEXCEPTION = "requestexception",
  8645. UNDEFINED = undefined,
  8646. LOAD = 'load',
  8647. POST = 'POST',
  8648. GET = 'GET',
  8649. WINDOW = window;
  8650. /**
  8651. * @class Ext.data.Connection
  8652. * @extends Ext.util.Observable
  8653. * <p>The class encapsulates a connection to the page's originating domain, allowing requests to be made
  8654. * either to a configured URL, or to a URL specified at request time.</p>
  8655. * <p>Requests made by this class are asynchronous, and will return immediately. No data from
  8656. * the server will be available to the statement immediately following the {@link #request} call.
  8657. * To process returned data, use a
  8658. * <a href="#request-option-success" ext:member="request-option-success" ext:cls="Ext.data.Connection">success callback</a>
  8659. * in the request options object,
  8660. * or an {@link #requestcomplete event listener}.</p>
  8661. * <p><h3>File Uploads</h3><a href="#request-option-isUpload" ext:member="request-option-isUpload" ext:cls="Ext.data.Connection">File uploads</a> are not performed using normal "Ajax" techniques, that
  8662. * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard
  8663. * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its
  8664. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  8665. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  8666. * but removed after the return data has been gathered.</p>
  8667. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  8668. * server is using JSON to send the return object, then the
  8669. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  8670. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  8671. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  8672. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  8673. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  8674. * is created containing a <tt>responseText</tt> property in order to conform to the
  8675. * requirements of event handlers and callbacks.</p>
  8676. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  8677. * and some server technologies (notably JEE) may require some custom processing in order to
  8678. * retrieve parameter names and parameter values from the packet content.</p>
  8679. * @constructor
  8680. * @param {Object} config a configuration object.
  8681. */
  8682. Ext.data.Connection = function(config){
  8683. Ext.apply(this, config);
  8684. this.addEvents(
  8685. /**
  8686. * @event beforerequest
  8687. * Fires before a network request is made to retrieve a data object.
  8688. * @param {Connection} conn This Connection object.
  8689. * @param {Object} options The options config object passed to the {@link #request} method.
  8690. */
  8691. BEFOREREQUEST,
  8692. /**
  8693. * @event requestcomplete
  8694. * Fires if the request was successfully completed.
  8695. * @param {Connection} conn This Connection object.
  8696. * @param {Object} response The XHR object containing the response data.
  8697. * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>
  8698. * for details.
  8699. * @param {Object} options The options config object passed to the {@link #request} method.
  8700. */
  8701. REQUESTCOMPLETE,
  8702. /**
  8703. * @event requestexception
  8704. * Fires if an error HTTP status was returned from the server.
  8705. * See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP Status Code Definitions</a>
  8706. * for details of HTTP status codes.
  8707. * @param {Connection} conn This Connection object.
  8708. * @param {Object} response The XHR object containing the response data.
  8709. * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>
  8710. * for details.
  8711. * @param {Object} options The options config object passed to the {@link #request} method.
  8712. */
  8713. REQUESTEXCEPTION
  8714. );
  8715. Ext.data.Connection.superclass.constructor.call(this);
  8716. };
  8717. Ext.extend(Ext.data.Connection, Ext.util.Observable, {
  8718. /**
  8719. * @cfg {String} url (Optional) <p>The default URL to be used for requests to the server. Defaults to undefined.</p>
  8720. * <p>The <code>url</code> config may be a function which <i>returns</i> the URL to use for the Ajax request. The scope
  8721. * (<code><b>this</b></code> reference) of the function is the <code>scope</code> option passed to the {@link #request} method.</p>
  8722. */
  8723. /**
  8724. * @cfg {Object} extraParams (Optional) An object containing properties which are used as
  8725. * extra parameters to each request made by this object. (defaults to undefined)
  8726. */
  8727. /**
  8728. * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
  8729. * to each request made by this object. (defaults to undefined)
  8730. */
  8731. /**
  8732. * @cfg {String} method (Optional) The default HTTP method to be used for requests.
  8733. * (defaults to undefined; if not set, but {@link #request} params are present, POST will be used;
  8734. * otherwise, GET will be used.)
  8735. */
  8736. /**
  8737. * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
  8738. */
  8739. timeout : 30000,
  8740. /**
  8741. * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
  8742. * @type Boolean
  8743. */
  8744. autoAbort:false,
  8745. /**
  8746. * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
  8747. * @type Boolean
  8748. */
  8749. disableCaching: true,
  8750. /**
  8751. * @cfg {String} disableCachingParam (Optional) Change the parameter which is sent went disabling caching
  8752. * through a cache buster. Defaults to '_dc'
  8753. * @type String
  8754. */
  8755. disableCachingParam: '_dc',
  8756. /**
  8757. * <p>Sends an HTTP request to a remote server.</p>
  8758. * <p><b>Important:</b> Ajax server requests are asynchronous, and this call will
  8759. * return before the response has been received. Process any returned data
  8760. * in a callback function.</p>
  8761. * <pre><code>
  8762. Ext.Ajax.request({
  8763. url: 'ajax_demo/sample.json',
  8764. success: function(response, opts) {
  8765. var obj = Ext.decode(response.responseText);
  8766. console.dir(obj);
  8767. },
  8768. failure: function(response, opts) {
  8769. console.log('server-side failure with status code ' + response.status);
  8770. }
  8771. });
  8772. * </code></pre>
  8773. * <p>To execute a callback function in the correct scope, use the <tt>scope</tt> option.</p>
  8774. * @param {Object} options An object which may contain the following properties:<ul>
  8775. * <li><b>url</b> : String/Function (Optional)<div class="sub-desc">The URL to
  8776. * which to send the request, or a function to call which returns a URL string. The scope of the
  8777. * function is specified by the <tt>scope</tt> option. Defaults to the configured
  8778. * <tt>{@link #url}</tt>.</div></li>
  8779. * <li><b>params</b> : Object/String/Function (Optional)<div class="sub-desc">
  8780. * An object containing properties which are used as parameters to the
  8781. * request, a url encoded string or a function to call to get either. The scope of the function
  8782. * is specified by the <tt>scope</tt> option.</div></li>
  8783. * <li><b>method</b> : String (Optional)<div class="sub-desc">The HTTP method to use
  8784. * for the request. Defaults to the configured method, or if no method was configured,
  8785. * "GET" if no parameters are being sent, and "POST" if parameters are being sent. Note that
  8786. * the method name is case-sensitive and should be all caps.</div></li>
  8787. * <li><b>callback</b> : Function (Optional)<div class="sub-desc">The
  8788. * function to be called upon receipt of the HTTP response. The callback is
  8789. * called regardless of success or failure and is passed the following
  8790. * parameters:<ul>
  8791. * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>
  8792. * <li><b>success</b> : Boolean<div class="sub-desc">True if the request succeeded.</div></li>
  8793. * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.
  8794. * See <a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a> for details about
  8795. * accessing elements of the response.</div></li>
  8796. * </ul></div></li>
  8797. * <li><a id="request-option-success"></a><b>success</b> : Function (Optional)<div class="sub-desc">The function
  8798. * to be called upon success of the request. The callback is passed the following
  8799. * parameters:<ul>
  8800. * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>
  8801. * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>
  8802. * </ul></div></li>
  8803. * <li><b>failure</b> : Function (Optional)<div class="sub-desc">The function
  8804. * to be called upon failure of the request. The callback is passed the
  8805. * following parameters:<ul>
  8806. * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>
  8807. * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>
  8808. * </ul></div></li>
  8809. * <li><b>scope</b> : Object (Optional)<div class="sub-desc">The scope in
  8810. * which to execute the callbacks: The "this" object for the callback function. If the <tt>url</tt>, or <tt>params</tt> options were
  8811. * specified as functions from which to draw values, then this also serves as the scope for those function calls.
  8812. * Defaults to the browser window.</div></li>
  8813. * <li><b>timeout</b> : Number (Optional)<div class="sub-desc">The timeout in milliseconds to be used for this request. Defaults to 30 seconds.</div></li>
  8814. * <li><b>form</b> : Element/HTMLElement/String (Optional)<div class="sub-desc">The <tt>&lt;form&gt;</tt>
  8815. * Element or the id of the <tt>&lt;form&gt;</tt> to pull parameters from.</div></li>
  8816. * <li><a id="request-option-isUpload"></a><b>isUpload</b> : Boolean (Optional)<div class="sub-desc"><b>Only meaningful when used
  8817. * with the <tt>form</tt> option</b>.
  8818. * <p>True if the form object is a file upload (will be set automatically if the form was
  8819. * configured with <b><tt>enctype</tt></b> "multipart/form-data").</p>
  8820. * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>
  8821. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  8822. * DOM <tt>&lt;form></tt> element temporarily modified to have its
  8823. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  8824. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  8825. * but removed after the return data has been gathered.</p>
  8826. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  8827. * server is using JSON to send the return object, then the
  8828. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  8829. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  8830. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  8831. * is created containing a <tt>responseText</tt> property in order to conform to the
  8832. * requirements of event handlers and callbacks.</p>
  8833. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  8834. * and some server technologies (notably JEE) may require some custom processing in order to
  8835. * retrieve parameter names and parameter values from the packet content.</p>
  8836. * </div></li>
  8837. * <li><b>headers</b> : Object (Optional)<div class="sub-desc">Request
  8838. * headers to set for the request.</div></li>
  8839. * <li><b>xmlData</b> : Object (Optional)<div class="sub-desc">XML document
  8840. * to use for the post. Note: This will be used instead of params for the post
  8841. * data. Any params will be appended to the URL.</div></li>
  8842. * <li><b>jsonData</b> : Object/String (Optional)<div class="sub-desc">JSON
  8843. * data to use as the post. Note: This will be used instead of params for the post
  8844. * data. Any params will be appended to the URL.</div></li>
  8845. * <li><b>disableCaching</b> : Boolean (Optional)<div class="sub-desc">True
  8846. * to add a unique cache-buster param to GET requests.</div></li>
  8847. * </ul></p>
  8848. * <p>The options object may also contain any other property which might be needed to perform
  8849. * postprocessing in a callback because it is passed to callback functions.</p>
  8850. * @return {Number} transactionId The id of the server transaction. This may be used
  8851. * to cancel the request.
  8852. */
  8853. request : function(o){
  8854. var me = this;
  8855. if(me.fireEvent(BEFOREREQUEST, me, o)){
  8856. if (o.el) {
  8857. if(!Ext.isEmpty(o.indicatorText)){
  8858. me.indicatorText = '<div class="loading-indicator">'+o.indicatorText+"</div>";
  8859. }
  8860. if(me.indicatorText) {
  8861. Ext.getDom(o.el).innerHTML = me.indicatorText;
  8862. }
  8863. o.success = (Ext.isFunction(o.success) ? o.success : function(){}).createInterceptor(function(response) {
  8864. Ext.getDom(o.el).innerHTML = response.responseText;
  8865. });
  8866. }
  8867. var p = o.params,
  8868. url = o.url || me.url,
  8869. method,
  8870. cb = {success: me.handleResponse,
  8871. failure: me.handleFailure,
  8872. scope: me,
  8873. argument: {options: o},
  8874. timeout : o.timeout || me.timeout
  8875. },
  8876. form,
  8877. serForm;
  8878. if (Ext.isFunction(p)) {
  8879. p = p.call(o.scope||WINDOW, o);
  8880. }
  8881. p = Ext.urlEncode(me.extraParams, Ext.isObject(p) ? Ext.urlEncode(p) : p);
  8882. if (Ext.isFunction(url)) {
  8883. url = url.call(o.scope || WINDOW, o);
  8884. }
  8885. if((form = Ext.getDom(o.form))){
  8886. url = url || form.action;
  8887. if(o.isUpload || /multipart\/form-data/i.test(form.getAttribute("enctype"))) {
  8888. return me.doFormUpload.call(me, o, p, url);
  8889. }
  8890. serForm = Ext.lib.Ajax.serializeForm(form);
  8891. p = p ? (p + '&' + serForm) : serForm;
  8892. }
  8893. method = o.method || me.method || ((p || o.xmlData || o.jsonData) ? POST : GET);
  8894. if(method === GET && (me.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
  8895. var dcp = o.disableCachingParam || me.disableCachingParam;
  8896. url = Ext.urlAppend(url, dcp + '=' + (new Date().getTime()));
  8897. }
  8898. o.headers = Ext.apply(o.headers || {}, me.defaultHeaders || {});
  8899. if(o.autoAbort === true || me.autoAbort) {
  8900. me.abort();
  8901. }
  8902. if((method == GET || o.xmlData || o.jsonData) && p){
  8903. url = Ext.urlAppend(url, p);
  8904. p = '';
  8905. }
  8906. return (me.transId = Ext.lib.Ajax.request(method, url, cb, p, o));
  8907. }else{
  8908. return o.callback ? o.callback.apply(o.scope, [o,UNDEFINED,UNDEFINED]) : null;
  8909. }
  8910. },
  8911. /**
  8912. * Determine whether this object has a request outstanding.
  8913. * @param {Number} transactionId (Optional) defaults to the last transaction
  8914. * @return {Boolean} True if there is an outstanding request.
  8915. */
  8916. isLoading : function(transId){
  8917. return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId;
  8918. },
  8919. /**
  8920. * Aborts any outstanding request.
  8921. * @param {Number} transactionId (Optional) defaults to the last transaction
  8922. */
  8923. abort : function(transId){
  8924. if(transId || this.isLoading()){
  8925. Ext.lib.Ajax.abort(transId || this.transId);
  8926. }
  8927. },
  8928. // private
  8929. handleResponse : function(response){
  8930. this.transId = false;
  8931. var options = response.argument.options;
  8932. response.argument = options ? options.argument : null;
  8933. this.fireEvent(REQUESTCOMPLETE, this, response, options);
  8934. if(options.success){
  8935. options.success.call(options.scope, response, options);
  8936. }
  8937. if(options.callback){
  8938. options.callback.call(options.scope, options, true, response);
  8939. }
  8940. },
  8941. // private
  8942. handleFailure : function(response, e){
  8943. this.transId = false;
  8944. var options = response.argument.options;
  8945. response.argument = options ? options.argument : null;
  8946. this.fireEvent(REQUESTEXCEPTION, this, response, options, e);
  8947. if(options.failure){
  8948. options.failure.call(options.scope, response, options);
  8949. }
  8950. if(options.callback){
  8951. options.callback.call(options.scope, options, false, response);
  8952. }
  8953. },
  8954. // private
  8955. doFormUpload : function(o, ps, url){
  8956. var id = Ext.id(),
  8957. doc = document,
  8958. frame = doc.createElement('iframe'),
  8959. form = Ext.getDom(o.form),
  8960. hiddens = [],
  8961. hd,
  8962. encoding = 'multipart/form-data',
  8963. buf = {
  8964. target: form.target,
  8965. method: form.method,
  8966. encoding: form.encoding,
  8967. enctype: form.enctype,
  8968. action: form.action
  8969. };
  8970. Ext.fly(frame).set({
  8971. id: id,
  8972. name: id,
  8973. cls: 'x-hidden'
  8974. });
  8975. doc.body.appendChild(frame);
  8976. //Reset the Frame to neutral domain
  8977. Ext.fly(frame).set({
  8978. src : Ext.SSL_SECURE_URL
  8979. });
  8980. // This is required so that IE doesn't pop the response up in a new window.
  8981. if(Ext.isIE){
  8982. document.frames[id].name = id;
  8983. }
  8984. Ext.fly(form).set({
  8985. target: id,
  8986. method: POST,
  8987. enctype: encoding,
  8988. encoding: encoding,
  8989. action: url || buf.action
  8990. });
  8991. // add dynamic params
  8992. Ext.iterate(Ext.urlDecode(ps, false), function(k, v){
  8993. hd = doc.createElement('input');
  8994. Ext.fly(hd).set({
  8995. type: 'hidden',
  8996. value: v,
  8997. name: k
  8998. });
  8999. form.appendChild(hd);
  9000. hiddens.push(hd);
  9001. });
  9002. function cb(){
  9003. var me = this,
  9004. // bogus response object
  9005. r = {responseText : '',
  9006. responseXML : null,
  9007. argument : o.argument},
  9008. doc,
  9009. firstChild;
  9010. try{
  9011. doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;
  9012. if(doc){
  9013. if(doc.body){
  9014. if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea
  9015. r.responseText = firstChild.value;
  9016. }else{
  9017. r.responseText = doc.body.innerHTML;
  9018. }
  9019. }
  9020. //in IE the document may still have a body even if returns XML.
  9021. r.responseXML = doc.XMLDocument || doc;
  9022. }
  9023. }
  9024. catch(e) {}
  9025. Ext.EventManager.removeListener(frame, LOAD, cb, me);
  9026. me.fireEvent(REQUESTCOMPLETE, me, r, o);
  9027. function runCallback(fn, scope, args){
  9028. if(Ext.isFunction(fn)){
  9029. fn.apply(scope, args);
  9030. }
  9031. }
  9032. runCallback(o.success, o.scope, [r, o]);
  9033. runCallback(o.callback, o.scope, [o, true, r]);
  9034. if(!me.debugUploads){
  9035. setTimeout(function(){Ext.removeNode(frame);}, 100);
  9036. }
  9037. }
  9038. Ext.EventManager.on(frame, LOAD, cb, this);
  9039. form.submit();
  9040. Ext.fly(form).set(buf);
  9041. Ext.each(hiddens, function(h) {
  9042. Ext.removeNode(h);
  9043. });
  9044. }
  9045. });
  9046. })();
  9047. /**
  9048. * @class Ext.Ajax
  9049. * @extends Ext.data.Connection
  9050. * <p>The global Ajax request class that provides a simple way to make Ajax requests
  9051. * with maximum flexibility.</p>
  9052. * <p>Since Ext.Ajax is a singleton, you can set common properties/events for it once
  9053. * and override them at the request function level only if necessary.</p>
  9054. * <p>Common <b>Properties</b> you may want to set are:<div class="mdetail-params"><ul>
  9055. * <li><b><tt>{@link #method}</tt></b><p class="sub-desc"></p></li>
  9056. * <li><b><tt>{@link #extraParams}</tt></b><p class="sub-desc"></p></li>
  9057. * <li><b><tt>{@link #url}</tt></b><p class="sub-desc"></p></li>
  9058. * </ul></div>
  9059. * <pre><code>
  9060. // Default headers to pass in every request
  9061. Ext.Ajax.defaultHeaders = {
  9062. 'Powered-By': 'Ext'
  9063. };
  9064. * </code></pre>
  9065. * </p>
  9066. * <p>Common <b>Events</b> you may want to set are:<div class="mdetail-params"><ul>
  9067. * <li><b><tt>{@link Ext.data.Connection#beforerequest beforerequest}</tt></b><p class="sub-desc"></p></li>
  9068. * <li><b><tt>{@link Ext.data.Connection#requestcomplete requestcomplete}</tt></b><p class="sub-desc"></p></li>
  9069. * <li><b><tt>{@link Ext.data.Connection#requestexception requestexception}</tt></b><p class="sub-desc"></p></li>
  9070. * </ul></div>
  9071. * <pre><code>
  9072. // Example: show a spinner during all Ajax requests
  9073. Ext.Ajax.on('beforerequest', this.showSpinner, this);
  9074. Ext.Ajax.on('requestcomplete', this.hideSpinner, this);
  9075. Ext.Ajax.on('requestexception', this.hideSpinner, this);
  9076. * </code></pre>
  9077. * </p>
  9078. * <p>An example request:</p>
  9079. * <pre><code>
  9080. // Basic request
  9081. Ext.Ajax.{@link Ext.data.Connection#request request}({
  9082. url: 'foo.php',
  9083. success: someFn,
  9084. failure: otherFn,
  9085. headers: {
  9086. 'my-header': 'foo'
  9087. },
  9088. params: { foo: 'bar' }
  9089. });
  9090. // Simple ajax form submission
  9091. Ext.Ajax.{@link Ext.data.Connection#request request}({
  9092. form: 'some-form',
  9093. params: 'foo=bar'
  9094. });
  9095. * </code></pre>
  9096. * </p>
  9097. * @singleton
  9098. */
  9099. Ext.Ajax = new Ext.data.Connection({
  9100. /**
  9101. * @cfg {String} url @hide
  9102. */
  9103. /**
  9104. * @cfg {Object} extraParams @hide
  9105. */
  9106. /**
  9107. * @cfg {Object} defaultHeaders @hide
  9108. */
  9109. /**
  9110. * @cfg {String} method (Optional) @hide
  9111. */
  9112. /**
  9113. * @cfg {Number} timeout (Optional) @hide
  9114. */
  9115. /**
  9116. * @cfg {Boolean} autoAbort (Optional) @hide
  9117. */
  9118. /**
  9119. * @cfg {Boolean} disableCaching (Optional) @hide
  9120. */
  9121. /**
  9122. * @property disableCaching
  9123. * True to add a unique cache-buster param to GET requests. (defaults to true)
  9124. * @type Boolean
  9125. */
  9126. /**
  9127. * @property url
  9128. * The default URL to be used for requests to the server. (defaults to undefined)
  9129. * If the server receives all requests through one URL, setting this once is easier than
  9130. * entering it on every request.
  9131. * @type String
  9132. */
  9133. /**
  9134. * @property extraParams
  9135. * An object containing properties which are used as extra parameters to each request made
  9136. * by this object (defaults to undefined). Session information and other data that you need
  9137. * to pass with each request are commonly put here.
  9138. * @type Object
  9139. */
  9140. /**
  9141. * @property defaultHeaders
  9142. * An object containing request headers which are added to each request made by this object
  9143. * (defaults to undefined).
  9144. * @type Object
  9145. */
  9146. /**
  9147. * @property method
  9148. * The default HTTP method to be used for requests. Note that this is case-sensitive and
  9149. * should be all caps (defaults to undefined; if not set but params are present will use
  9150. * <tt>"POST"</tt>, otherwise will use <tt>"GET"</tt>.)
  9151. * @type String
  9152. */
  9153. /**
  9154. * @property timeout
  9155. * The timeout in milliseconds to be used for requests. (defaults to 30000)
  9156. * @type Number
  9157. */
  9158. /**
  9159. * @property autoAbort
  9160. * Whether a new request should abort any pending requests. (defaults to false)
  9161. * @type Boolean
  9162. */
  9163. autoAbort : false,
  9164. /**
  9165. * Serialize the passed form into a url encoded string
  9166. * @param {String/HTMLElement} form
  9167. * @return {String}
  9168. */
  9169. serializeForm : function(form){
  9170. return Ext.lib.Ajax.serializeForm(form);
  9171. }
  9172. });
  9173. /**
  9174. * @class Ext.Updater
  9175. * @extends Ext.util.Observable
  9176. * Provides AJAX-style update capabilities for Element objects. Updater can be used to {@link #update}
  9177. * an {@link Ext.Element} once, or you can use {@link #startAutoRefresh} to set up an auto-updating
  9178. * {@link Ext.Element Element} on a specific interval.<br><br>
  9179. * Usage:<br>
  9180. * <pre><code>
  9181. * var el = Ext.get("foo"); // Get Ext.Element object
  9182. * var mgr = el.getUpdater();
  9183. * mgr.update({
  9184. url: "http://myserver.com/index.php",
  9185. params: {
  9186. param1: "foo",
  9187. param2: "bar"
  9188. }
  9189. * });
  9190. * ...
  9191. * mgr.formUpdate("myFormId", "http://myserver.com/index.php");
  9192. * <br>
  9193. * // or directly (returns the same Updater instance)
  9194. * var mgr = new Ext.Updater("myElementId");
  9195. * mgr.startAutoRefresh(60, "http://myserver.com/index.php");
  9196. * mgr.on("update", myFcnNeedsToKnow);
  9197. * <br>
  9198. * // short handed call directly from the element object
  9199. * Ext.get("foo").load({
  9200. url: "bar.php",
  9201. scripts: true,
  9202. params: "param1=foo&amp;param2=bar",
  9203. text: "Loading Foo..."
  9204. * });
  9205. * </code></pre>
  9206. * @constructor
  9207. * Create new Updater directly.
  9208. * @param {Mixed} el The element to update
  9209. * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already
  9210. * has an Updater and if it does it returns the same instance. This will skip that check (useful for extending this class).
  9211. */
  9212. Ext.UpdateManager = Ext.Updater = Ext.extend(Ext.util.Observable,
  9213. function() {
  9214. var BEFOREUPDATE = "beforeupdate",
  9215. UPDATE = "update",
  9216. FAILURE = "failure";
  9217. // private
  9218. function processSuccess(response){
  9219. var me = this;
  9220. me.transaction = null;
  9221. if (response.argument.form && response.argument.reset) {
  9222. try { // put in try/catch since some older FF releases had problems with this
  9223. response.argument.form.reset();
  9224. } catch(e){}
  9225. }
  9226. if (me.loadScripts) {
  9227. me.renderer.render(me.el, response, me,
  9228. updateComplete.createDelegate(me, [response]));
  9229. } else {
  9230. me.renderer.render(me.el, response, me);
  9231. updateComplete.call(me, response);
  9232. }
  9233. }
  9234. // private
  9235. function updateComplete(response, type, success){
  9236. this.fireEvent(type || UPDATE, this.el, response);
  9237. if(Ext.isFunction(response.argument.callback)){
  9238. response.argument.callback.call(response.argument.scope, this.el, Ext.isEmpty(success) ? true : false, response, response.argument.options);
  9239. }
  9240. }
  9241. // private
  9242. function processFailure(response){
  9243. updateComplete.call(this, response, FAILURE, !!(this.transaction = null));
  9244. }
  9245. return {
  9246. constructor: function(el, forceNew){
  9247. var me = this;
  9248. el = Ext.get(el);
  9249. if(!forceNew && el.updateManager){
  9250. return el.updateManager;
  9251. }
  9252. /**
  9253. * The Element object
  9254. * @type Ext.Element
  9255. */
  9256. me.el = el;
  9257. /**
  9258. * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
  9259. * @type String
  9260. */
  9261. me.defaultUrl = null;
  9262. me.addEvents(
  9263. /**
  9264. * @event beforeupdate
  9265. * Fired before an update is made, return false from your handler and the update is cancelled.
  9266. * @param {Ext.Element} el
  9267. * @param {String/Object/Function} url
  9268. * @param {String/Object} params
  9269. */
  9270. BEFOREUPDATE,
  9271. /**
  9272. * @event update
  9273. * Fired after successful update is made.
  9274. * @param {Ext.Element} el
  9275. * @param {Object} oResponseObject The response Object
  9276. */
  9277. UPDATE,
  9278. /**
  9279. * @event failure
  9280. * Fired on update failure.
  9281. * @param {Ext.Element} el
  9282. * @param {Object} oResponseObject The response Object
  9283. */
  9284. FAILURE
  9285. );
  9286. Ext.apply(me, Ext.Updater.defaults);
  9287. /**
  9288. * Blank page URL to use with SSL file uploads (defaults to {@link Ext.Updater.defaults#sslBlankUrl}).
  9289. * @property sslBlankUrl
  9290. * @type String
  9291. */
  9292. /**
  9293. * Whether to append unique parameter on get request to disable caching (defaults to {@link Ext.Updater.defaults#disableCaching}).
  9294. * @property disableCaching
  9295. * @type Boolean
  9296. */
  9297. /**
  9298. * Text for loading indicator (defaults to {@link Ext.Updater.defaults#indicatorText}).
  9299. * @property indicatorText
  9300. * @type String
  9301. */
  9302. /**
  9303. * Whether to show indicatorText when loading (defaults to {@link Ext.Updater.defaults#showLoadIndicator}).
  9304. * @property showLoadIndicator
  9305. * @type String
  9306. */
  9307. /**
  9308. * Timeout for requests or form posts in seconds (defaults to {@link Ext.Updater.defaults#timeout}).
  9309. * @property timeout
  9310. * @type Number
  9311. */
  9312. /**
  9313. * True to process scripts in the output (defaults to {@link Ext.Updater.defaults#loadScripts}).
  9314. * @property loadScripts
  9315. * @type Boolean
  9316. */
  9317. /**
  9318. * Transaction object of the current executing transaction, or null if there is no active transaction.
  9319. */
  9320. me.transaction = null;
  9321. /**
  9322. * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
  9323. * @type Function
  9324. */
  9325. me.refreshDelegate = me.refresh.createDelegate(me);
  9326. /**
  9327. * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
  9328. * @type Function
  9329. */
  9330. me.updateDelegate = me.update.createDelegate(me);
  9331. /**
  9332. * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
  9333. * @type Function
  9334. */
  9335. me.formUpdateDelegate = (me.formUpdate || function(){}).createDelegate(me);
  9336. /**
  9337. * The renderer for this Updater (defaults to {@link Ext.Updater.BasicRenderer}).
  9338. */
  9339. me.renderer = me.renderer || me.getDefaultRenderer();
  9340. Ext.Updater.superclass.constructor.call(me);
  9341. },
  9342. /**
  9343. * Sets the content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.
  9344. * @param {Object} renderer The object implementing the render() method
  9345. */
  9346. setRenderer : function(renderer){
  9347. this.renderer = renderer;
  9348. },
  9349. /**
  9350. * Returns the current content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.
  9351. * @return {Object}
  9352. */
  9353. getRenderer : function(){
  9354. return this.renderer;
  9355. },
  9356. /**
  9357. * This is an overrideable method which returns a reference to a default
  9358. * renderer class if none is specified when creating the Ext.Updater.
  9359. * Defaults to {@link Ext.Updater.BasicRenderer}
  9360. */
  9361. getDefaultRenderer: function() {
  9362. return new Ext.Updater.BasicRenderer();
  9363. },
  9364. /**
  9365. * Sets the default URL used for updates.
  9366. * @param {String/Function} defaultUrl The url or a function to call to get the url
  9367. */
  9368. setDefaultUrl : function(defaultUrl){
  9369. this.defaultUrl = defaultUrl;
  9370. },
  9371. /**
  9372. * Get the Element this Updater is bound to
  9373. * @return {Ext.Element} The element
  9374. */
  9375. getEl : function(){
  9376. return this.el;
  9377. },
  9378. /**
  9379. * Performs an <b>asynchronous</b> request, updating this element with the response.
  9380. * If params are specified it uses POST, otherwise it uses GET.<br><br>
  9381. * <b>Note:</b> Due to the asynchronous nature of remote server requests, the Element
  9382. * will not have been fully updated when the function returns. To post-process the returned
  9383. * data, use the callback option, or an <b><code>update</code></b> event handler.
  9384. * @param {Object} options A config object containing any of the following options:<ul>
  9385. * <li>url : <b>String/Function</b><p class="sub-desc">The URL to request or a function which
  9386. * <i>returns</i> the URL (defaults to the value of {@link Ext.Ajax#url} if not specified).</p></li>
  9387. * <li>method : <b>String</b><p class="sub-desc">The HTTP method to
  9388. * use. Defaults to POST if the <code>params</code> argument is present, otherwise GET.</p></li>
  9389. * <li>params : <b>String/Object/Function</b><p class="sub-desc">The
  9390. * parameters to pass to the server (defaults to none). These may be specified as a url-encoded
  9391. * string, or as an object containing properties which represent parameters,
  9392. * or as a function, which returns such an object.</p></li>
  9393. * <li>scripts : <b>Boolean</b><p class="sub-desc">If <code>true</code>
  9394. * any &lt;script&gt; tags embedded in the response text will be extracted
  9395. * and executed (defaults to {@link Ext.Updater.defaults#loadScripts}). If this option is specified,
  9396. * the callback will be called <i>after</i> the execution of the scripts.</p></li>
  9397. * <li>callback : <b>Function</b><p class="sub-desc">A function to
  9398. * be called when the response from the server arrives. The following
  9399. * parameters are passed:<ul>
  9400. * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>
  9401. * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li>
  9402. * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li>
  9403. * <li><b>options</b> : Object<p class="sub-desc">The config object passed to the update call.</p></li></ul>
  9404. * </p></li>
  9405. * <li>scope : <b>Object</b><p class="sub-desc">The scope in which
  9406. * to execute the callback (The callback's <code>this</code> reference.) If the
  9407. * <code>params</code> argument is a function, this scope is used for that function also.</p></li>
  9408. * <li>discardUrl : <b>Boolean</b><p class="sub-desc">By default, the URL of this request becomes
  9409. * the default URL for this Updater object, and will be subsequently used in {@link #refresh}
  9410. * calls. To bypass this behavior, pass <code>discardUrl:true</code> (defaults to false).</p></li>
  9411. * <li>timeout : <b>Number</b><p class="sub-desc">The number of seconds to wait for a response before
  9412. * timing out (defaults to {@link Ext.Updater.defaults#timeout}).</p></li>
  9413. * <li>text : <b>String</b><p class="sub-desc">The text to use as the innerHTML of the
  9414. * {@link Ext.Updater.defaults#indicatorText} div (defaults to 'Loading...'). To replace the entire div, not
  9415. * just the text, override {@link Ext.Updater.defaults#indicatorText} directly.</p></li>
  9416. * <li>nocache : <b>Boolean</b><p class="sub-desc">Only needed for GET
  9417. * requests, this option causes an extra, auto-generated parameter to be appended to the request
  9418. * to defeat caching (defaults to {@link Ext.Updater.defaults#disableCaching}).</p></li></ul>
  9419. * <p>
  9420. * For example:
  9421. <pre><code>
  9422. um.update({
  9423. url: "your-url.php",
  9424. params: {param1: "foo", param2: "bar"}, // or a URL encoded string
  9425. callback: yourFunction,
  9426. scope: yourObject, //(optional scope)
  9427. discardUrl: true,
  9428. nocache: true,
  9429. text: "Loading...",
  9430. timeout: 60,
  9431. scripts: false // Save time by avoiding RegExp execution.
  9432. });
  9433. </code></pre>
  9434. */
  9435. update : function(url, params, callback, discardUrl){
  9436. var me = this,
  9437. cfg,
  9438. callerScope;
  9439. if(me.fireEvent(BEFOREUPDATE, me.el, url, params) !== false){
  9440. if(Ext.isObject(url)){ // must be config object
  9441. cfg = url;
  9442. url = cfg.url;
  9443. params = params || cfg.params;
  9444. callback = callback || cfg.callback;
  9445. discardUrl = discardUrl || cfg.discardUrl;
  9446. callerScope = cfg.scope;
  9447. if(!Ext.isEmpty(cfg.nocache)){me.disableCaching = cfg.nocache;};
  9448. if(!Ext.isEmpty(cfg.text)){me.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
  9449. if(!Ext.isEmpty(cfg.scripts)){me.loadScripts = cfg.scripts;};
  9450. if(!Ext.isEmpty(cfg.timeout)){me.timeout = cfg.timeout;};
  9451. }
  9452. me.showLoading();
  9453. if(!discardUrl){
  9454. me.defaultUrl = url;
  9455. }
  9456. if(Ext.isFunction(url)){
  9457. url = url.call(me);
  9458. }
  9459. var o = Ext.apply({}, {
  9460. url : url,
  9461. params: (Ext.isFunction(params) && callerScope) ? params.createDelegate(callerScope) : params,
  9462. success: processSuccess,
  9463. failure: processFailure,
  9464. scope: me,
  9465. callback: undefined,
  9466. timeout: (me.timeout*1000),
  9467. disableCaching: me.disableCaching,
  9468. argument: {
  9469. "options": cfg,
  9470. "url": url,
  9471. "form": null,
  9472. "callback": callback,
  9473. "scope": callerScope || window,
  9474. "params": params
  9475. }
  9476. }, cfg);
  9477. me.transaction = Ext.Ajax.request(o);
  9478. }
  9479. },
  9480. /**
  9481. * <p>Performs an asynchronous form post, updating this element with the response. If the form has the attribute
  9482. * enctype="<a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a>", it assumes it's a file upload.
  9483. * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.</p>
  9484. * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>
  9485. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  9486. * DOM <code>&lt;form></code> element temporarily modified to have its
  9487. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  9488. * to a dynamically generated, hidden <code>&lt;iframe></code> which is inserted into the document
  9489. * but removed after the return data has been gathered.</p>
  9490. * <p>Be aware that file upload packets, sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a>
  9491. * and some server technologies (notably JEE) may require some custom processing in order to
  9492. * retrieve parameter names and parameter values from the packet content.</p>
  9493. * @param {String/HTMLElement} form The form Id or form element
  9494. * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
  9495. * @param {Boolean} reset (optional) Whether to try to reset the form after the update
  9496. * @param {Function} callback (optional) Callback when transaction is complete. The following
  9497. * parameters are passed:<ul>
  9498. * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>
  9499. * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li>
  9500. * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li></ul>
  9501. */
  9502. formUpdate : function(form, url, reset, callback){
  9503. var me = this;
  9504. if(me.fireEvent(BEFOREUPDATE, me.el, form, url) !== false){
  9505. if(Ext.isFunction(url)){
  9506. url = url.call(me);
  9507. }
  9508. form = Ext.getDom(form);
  9509. me.transaction = Ext.Ajax.request({
  9510. form: form,
  9511. url:url,
  9512. success: processSuccess,
  9513. failure: processFailure,
  9514. scope: me,
  9515. timeout: (me.timeout*1000),
  9516. argument: {
  9517. "url": url,
  9518. "form": form,
  9519. "callback": callback,
  9520. "reset": reset
  9521. }
  9522. });
  9523. me.showLoading.defer(1, me);
  9524. }
  9525. },
  9526. /**
  9527. * Set this element to auto refresh. Can be canceled by calling {@link #stopAutoRefresh}.
  9528. * @param {Number} interval How often to update (in seconds).
  9529. * @param {String/Object/Function} url (optional) The url for this request, a config object in the same format
  9530. * supported by {@link #load}, or a function to call to get the url (defaults to the last used url). Note that while
  9531. * the url used in a load call can be reused by this method, other load config options will not be reused and must be
  9532. * sepcified as part of a config object passed as this paramter if needed.
  9533. * @param {String/Object} params (optional) The parameters to pass as either a url encoded string
  9534. * "&param1=1&param2=2" or as an object {param1: 1, param2: 2}
  9535. * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
  9536. * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
  9537. */
  9538. startAutoRefresh : function(interval, url, params, callback, refreshNow){
  9539. var me = this;
  9540. if(refreshNow){
  9541. me.update(url || me.defaultUrl, params, callback, true);
  9542. }
  9543. if(me.autoRefreshProcId){
  9544. clearInterval(me.autoRefreshProcId);
  9545. }
  9546. me.autoRefreshProcId = setInterval(me.update.createDelegate(me, [url || me.defaultUrl, params, callback, true]), interval * 1000);
  9547. },
  9548. /**
  9549. * Stop auto refresh on this element.
  9550. */
  9551. stopAutoRefresh : function(){
  9552. if(this.autoRefreshProcId){
  9553. clearInterval(this.autoRefreshProcId);
  9554. delete this.autoRefreshProcId;
  9555. }
  9556. },
  9557. /**
  9558. * Returns true if the Updater is currently set to auto refresh its content (see {@link #startAutoRefresh}), otherwise false.
  9559. */
  9560. isAutoRefreshing : function(){
  9561. return !!this.autoRefreshProcId;
  9562. },
  9563. /**
  9564. * Display the element's "loading" state. By default, the element is updated with {@link #indicatorText}. This
  9565. * method may be overridden to perform a custom action while this Updater is actively updating its contents.
  9566. */
  9567. showLoading : function(){
  9568. if(this.showLoadIndicator){
  9569. this.el.dom.innerHTML = this.indicatorText;
  9570. }
  9571. },
  9572. /**
  9573. * Aborts the currently executing transaction, if any.
  9574. */
  9575. abort : function(){
  9576. if(this.transaction){
  9577. Ext.Ajax.abort(this.transaction);
  9578. }
  9579. },
  9580. /**
  9581. * Returns true if an update is in progress, otherwise false.
  9582. * @return {Boolean}
  9583. */
  9584. isUpdating : function(){
  9585. return this.transaction ? Ext.Ajax.isLoading(this.transaction) : false;
  9586. },
  9587. /**
  9588. * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
  9589. * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
  9590. */
  9591. refresh : function(callback){
  9592. if(this.defaultUrl){
  9593. this.update(this.defaultUrl, null, callback, true);
  9594. }
  9595. }
  9596. }
  9597. }());
  9598. /**
  9599. * @class Ext.Updater.defaults
  9600. * The defaults collection enables customizing the default properties of Updater
  9601. */
  9602. Ext.Updater.defaults = {
  9603. /**
  9604. * Timeout for requests or form posts in seconds (defaults to 30 seconds).
  9605. * @type Number
  9606. */
  9607. timeout : 30,
  9608. /**
  9609. * True to append a unique parameter to GET requests to disable caching (defaults to false).
  9610. * @type Boolean
  9611. */
  9612. disableCaching : false,
  9613. /**
  9614. * Whether or not to show {@link #indicatorText} during loading (defaults to true).
  9615. * @type Boolean
  9616. */
  9617. showLoadIndicator : true,
  9618. /**
  9619. * Text for loading indicator (defaults to '&lt;div class="loading-indicator"&gt;Loading...&lt;/div&gt;').
  9620. * @type String
  9621. */
  9622. indicatorText : '<div class="loading-indicator">Loading...</div>',
  9623. /**
  9624. * True to process scripts by default (defaults to false).
  9625. * @type Boolean
  9626. */
  9627. loadScripts : false,
  9628. /**
  9629. * Blank page URL to use with SSL file uploads (defaults to {@link Ext#SSL_SECURE_URL} if set, or "javascript:false").
  9630. * @type String
  9631. */
  9632. sslBlankUrl : Ext.SSL_SECURE_URL
  9633. };
  9634. /**
  9635. * Static convenience method. <b>This method is deprecated in favor of el.load({url:'foo.php', ...})</b>.
  9636. * Usage:
  9637. * <pre><code>Ext.Updater.updateElement("my-div", "stuff.php");</code></pre>
  9638. * @param {Mixed} el The element to update
  9639. * @param {String} url The url
  9640. * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
  9641. * @param {Object} options (optional) A config object with any of the Updater properties you want to set - for
  9642. * example: {disableCaching:true, indicatorText: "Loading data..."}
  9643. * @static
  9644. * @deprecated
  9645. * @member Ext.Updater
  9646. */
  9647. Ext.Updater.updateElement = function(el, url, params, options){
  9648. var um = Ext.get(el).getUpdater();
  9649. Ext.apply(um, options);
  9650. um.update(url, params, options ? options.callback : null);
  9651. };
  9652. /**
  9653. * @class Ext.Updater.BasicRenderer
  9654. * <p>This class is a base class implementing a simple render method which updates an element using results from an Ajax request.</p>
  9655. * <p>The BasicRenderer updates the element's innerHTML with the responseText. To perform a custom render (i.e. XML or JSON processing),
  9656. * create an object with a conforming {@link #render} method and pass it to setRenderer on the Updater.</p>
  9657. */
  9658. Ext.Updater.BasicRenderer = function(){};
  9659. Ext.Updater.BasicRenderer.prototype = {
  9660. /**
  9661. * This method is called when an Ajax response is received, and an Element needs updating.
  9662. * @param {Ext.Element} el The element being rendered
  9663. * @param {Object} xhr The XMLHttpRequest object
  9664. * @param {Updater} updateManager The calling update manager
  9665. * @param {Function} callback A callback that will need to be called if loadScripts is true on the Updater
  9666. */
  9667. render : function(el, response, updateManager, callback){
  9668. el.update(response.responseText, updateManager.loadScripts, callback);
  9669. }
  9670. };/**
  9671. * @class Date
  9672. *
  9673. * The date parsing and formatting syntax contains a subset of
  9674. * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
  9675. * supported will provide results equivalent to their PHP versions.
  9676. *
  9677. * The following is a list of all currently supported formats:
  9678. * <pre>
  9679. Format Description Example returned values
  9680. ------ ----------------------------------------------------------------------- -----------------------
  9681. d Day of the month, 2 digits with leading zeros 01 to 31
  9682. D A short textual representation of the day of the week Mon to Sun
  9683. j Day of the month without leading zeros 1 to 31
  9684. l A full textual representation of the day of the week Sunday to Saturday
  9685. N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
  9686. S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
  9687. w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
  9688. z The day of the year (starting from 0) 0 to 364 (365 in leap years)
  9689. W ISO-8601 week number of year, weeks starting on Monday 01 to 53
  9690. F A full textual representation of a month, such as January or March January to December
  9691. m Numeric representation of a month, with leading zeros 01 to 12
  9692. M A short textual representation of a month Jan to Dec
  9693. n Numeric representation of a month, without leading zeros 1 to 12
  9694. t Number of days in the given month 28 to 31
  9695. L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
  9696. o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
  9697. belongs to the previous or next year, that year is used instead)
  9698. Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
  9699. y A two digit representation of a year Examples: 99 or 03
  9700. a Lowercase Ante meridiem and Post meridiem am or pm
  9701. A Uppercase Ante meridiem and Post meridiem AM or PM
  9702. g 12-hour format of an hour without leading zeros 1 to 12
  9703. G 24-hour format of an hour without leading zeros 0 to 23
  9704. h 12-hour format of an hour with leading zeros 01 to 12
  9705. H 24-hour format of an hour with leading zeros 00 to 23
  9706. i Minutes, with leading zeros 00 to 59
  9707. s Seconds, with leading zeros 00 to 59
  9708. u Decimal fraction of a second Examples:
  9709. (minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
  9710. 100 (i.e. 0.100s) or
  9711. 999 (i.e. 0.999s) or
  9712. 999876543210 (i.e. 0.999876543210s)
  9713. O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
  9714. P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
  9715. T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
  9716. Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
  9717. c ISO 8601 date
  9718. Notes: Examples:
  9719. 1) If unspecified, the month / day defaults to the current month / day, 1991 or
  9720. the time defaults to midnight, while the timezone defaults to the 1992-10 or
  9721. browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
  9722. and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
  9723. are optional. 1995-07-18T17:21:28-02:00 or
  9724. 2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
  9725. least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
  9726. of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
  9727. Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
  9728. date-time granularity which are supported, or see 2000-02-13T21:25:33
  9729. http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
  9730. U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
  9731. M$ Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
  9732. \/Date(1238606590509+0800)\/
  9733. </pre>
  9734. *
  9735. * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
  9736. * <pre><code>
  9737. // Sample date:
  9738. // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
  9739. var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
  9740. document.write(dt.format('Y-m-d')); // 2007-01-10
  9741. document.write(dt.format('F j, Y, g:i a')); // January 10, 2007, 3:05 pm
  9742. document.write(dt.format('l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
  9743. </code></pre>
  9744. *
  9745. * Here are some standard date/time patterns that you might find helpful. They
  9746. * are not part of the source of Date.js, but to use them you can simply copy this
  9747. * block of code into any script that is included after Date.js and they will also become
  9748. * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
  9749. * <pre><code>
  9750. Date.patterns = {
  9751. ISO8601Long:"Y-m-d H:i:s",
  9752. ISO8601Short:"Y-m-d",
  9753. ShortDate: "n/j/Y",
  9754. LongDate: "l, F d, Y",
  9755. FullDateTime: "l, F d, Y g:i:s A",
  9756. MonthDay: "F d",
  9757. ShortTime: "g:i A",
  9758. LongTime: "g:i:s A",
  9759. SortableDateTime: "Y-m-d\\TH:i:s",
  9760. UniversalSortableDateTime: "Y-m-d H:i:sO",
  9761. YearMonth: "F, Y"
  9762. };
  9763. </code></pre>
  9764. *
  9765. * Example usage:
  9766. * <pre><code>
  9767. var dt = new Date();
  9768. document.write(dt.format(Date.patterns.ShortDate));
  9769. </code></pre>
  9770. * <p>Developer-written, custom formats may be used by supplying both a formatting and a parsing function
  9771. * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.</p>
  9772. */
  9773. /*
  9774. * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
  9775. * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
  9776. * They generate precompiled functions from format patterns instead of parsing and
  9777. * processing each pattern every time a date is formatted. These functions are available
  9778. * on every Date object.
  9779. */
  9780. (function() {
  9781. /**
  9782. * Global flag which determines if strict date parsing should be used.
  9783. * Strict date parsing will not roll-over invalid dates, which is the
  9784. * default behaviour of javascript Date objects.
  9785. * (see {@link #parseDate} for more information)
  9786. * Defaults to <tt>false</tt>.
  9787. * @static
  9788. * @type Boolean
  9789. */
  9790. Date.useStrict = false;
  9791. // create private copy of Ext's String.format() method
  9792. // - to remove unnecessary dependency
  9793. // - to resolve namespace conflict with M$-Ajax's implementation
  9794. function xf(format) {
  9795. var args = Array.prototype.slice.call(arguments, 1);
  9796. return format.replace(/\{(\d+)\}/g, function(m, i) {
  9797. return args[i];
  9798. });
  9799. }
  9800. // private
  9801. Date.formatCodeToRegex = function(character, currentGroup) {
  9802. // Note: currentGroup - position in regex result array (see notes for Date.parseCodes below)
  9803. var p = Date.parseCodes[character];
  9804. if (p) {
  9805. p = typeof p == 'function'? p() : p;
  9806. Date.parseCodes[character] = p; // reassign function result to prevent repeated execution
  9807. }
  9808. return p ? Ext.applyIf({
  9809. c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
  9810. }, p) : {
  9811. g:0,
  9812. c:null,
  9813. s:Ext.escapeRe(character) // treat unrecognised characters as literals
  9814. }
  9815. };
  9816. // private shorthand for Date.formatCodeToRegex since we'll be using it fairly often
  9817. var $f = Date.formatCodeToRegex;
  9818. Ext.apply(Date, {
  9819. /**
  9820. * <p>An object hash in which each property is a date parsing function. The property name is the
  9821. * format string which that function parses.</p>
  9822. * <p>This object is automatically populated with date parsing functions as
  9823. * date formats are requested for Ext standard formatting strings.</p>
  9824. * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
  9825. * may be used as a format string to {@link #parseDate}.<p>
  9826. * <p>Example:</p><pre><code>
  9827. Date.parseFunctions['x-date-format'] = myDateParser;
  9828. </code></pre>
  9829. * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  9830. * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
  9831. * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
  9832. * (i.e. prevent javascript Date "rollover") (The default must be false).
  9833. * Invalid date strings should return null when parsed.</div></li>
  9834. * </ul></div></p>
  9835. * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
  9836. * formatting function must be placed into the {@link #formatFunctions} property.
  9837. * @property parseFunctions
  9838. * @static
  9839. * @type Object
  9840. */
  9841. parseFunctions: {
  9842. "M$": function(input, strict) {
  9843. // note: the timezone offset is ignored since the M$ Ajax server sends
  9844. // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
  9845. var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/');
  9846. var r = (input || '').match(re);
  9847. return r? new Date(((r[1] || '') + r[2]) * 1) : null;
  9848. }
  9849. },
  9850. parseRegexes: [],
  9851. /**
  9852. * <p>An object hash in which each property is a date formatting function. The property name is the
  9853. * format string which corresponds to the produced formatted date string.</p>
  9854. * <p>This object is automatically populated with date formatting functions as
  9855. * date formats are requested for Ext standard formatting strings.</p>
  9856. * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
  9857. * may be used as a format string to {@link #format}. Example:</p><pre><code>
  9858. Date.formatFunctions['x-date-format'] = myDateFormatter;
  9859. </code></pre>
  9860. * <p>A formatting function should return a string representation of the passed Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  9861. * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
  9862. * </ul></div></p>
  9863. * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
  9864. * parsing function must be placed into the {@link #parseFunctions} property.
  9865. * @property formatFunctions
  9866. * @static
  9867. * @type Object
  9868. */
  9869. formatFunctions: {
  9870. "M$": function() {
  9871. // UTC milliseconds since Unix epoch (M$-AJAX serialized date format (MRSF))
  9872. return '\\/Date(' + this.getTime() + ')\\/';
  9873. }
  9874. },
  9875. y2kYear : 50,
  9876. /**
  9877. * Date interval constant
  9878. * @static
  9879. * @type String
  9880. */
  9881. MILLI : "ms",
  9882. /**
  9883. * Date interval constant
  9884. * @static
  9885. * @type String
  9886. */
  9887. SECOND : "s",
  9888. /**
  9889. * Date interval constant
  9890. * @static
  9891. * @type String
  9892. */
  9893. MINUTE : "mi",
  9894. /** Date interval constant
  9895. * @static
  9896. * @type String
  9897. */
  9898. HOUR : "h",
  9899. /**
  9900. * Date interval constant
  9901. * @static
  9902. * @type String
  9903. */
  9904. DAY : "d",
  9905. /**
  9906. * Date interval constant
  9907. * @static
  9908. * @type String
  9909. */
  9910. MONTH : "mo",
  9911. /**
  9912. * Date interval constant
  9913. * @static
  9914. * @type String
  9915. */
  9916. YEAR : "y",
  9917. /**
  9918. * <p>An object hash containing default date values used during date parsing.</p>
  9919. * <p>The following properties are available:<div class="mdetail-params"><ul>
  9920. * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
  9921. * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
  9922. * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
  9923. * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
  9924. * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
  9925. * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
  9926. * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
  9927. * </ul></div></p>
  9928. * <p>Override these properties to customize the default date values used by the {@link #parseDate} method.</p>
  9929. * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
  9930. * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
  9931. * It is the responsiblity of the developer to account for this.</b></p>
  9932. * Example Usage:
  9933. * <pre><code>
  9934. // set default day value to the first day of the month
  9935. Date.defaults.d = 1;
  9936. // parse a February date string containing only year and month values.
  9937. // setting the default day value to 1 prevents weird date rollover issues
  9938. // when attempting to parse the following date string on, for example, March 31st 2009.
  9939. Date.parseDate('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
  9940. </code></pre>
  9941. * @property defaults
  9942. * @static
  9943. * @type Object
  9944. */
  9945. defaults: {},
  9946. /**
  9947. * An array of textual day names.
  9948. * Override these values for international dates.
  9949. * Example:
  9950. * <pre><code>
  9951. Date.dayNames = [
  9952. 'SundayInYourLang',
  9953. 'MondayInYourLang',
  9954. ...
  9955. ];
  9956. </code></pre>
  9957. * @type Array
  9958. * @static
  9959. */
  9960. dayNames : [
  9961. "Sunday",
  9962. "Monday",
  9963. "Tuesday",
  9964. "Wednesday",
  9965. "Thursday",
  9966. "Friday",
  9967. "Saturday"
  9968. ],
  9969. /**
  9970. * An array of textual month names.
  9971. * Override these values for international dates.
  9972. * Example:
  9973. * <pre><code>
  9974. Date.monthNames = [
  9975. 'JanInYourLang',
  9976. 'FebInYourLang',
  9977. ...
  9978. ];
  9979. </code></pre>
  9980. * @type Array
  9981. * @static
  9982. */
  9983. monthNames : [
  9984. "January",
  9985. "February",
  9986. "March",
  9987. "April",
  9988. "May",
  9989. "June",
  9990. "July",
  9991. "August",
  9992. "September",
  9993. "October",
  9994. "November",
  9995. "December"
  9996. ],
  9997. /**
  9998. * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
  9999. * Override these values for international dates.
  10000. * Example:
  10001. * <pre><code>
  10002. Date.monthNumbers = {
  10003. 'ShortJanNameInYourLang':0,
  10004. 'ShortFebNameInYourLang':1,
  10005. ...
  10006. };
  10007. </code></pre>
  10008. * @type Object
  10009. * @static
  10010. */
  10011. monthNumbers : {
  10012. Jan:0,
  10013. Feb:1,
  10014. Mar:2,
  10015. Apr:3,
  10016. May:4,
  10017. Jun:5,
  10018. Jul:6,
  10019. Aug:7,
  10020. Sep:8,
  10021. Oct:9,
  10022. Nov:10,
  10023. Dec:11
  10024. },
  10025. /**
  10026. * Get the short month name for the given month number.
  10027. * Override this function for international dates.
  10028. * @param {Number} month A zero-based javascript month number.
  10029. * @return {String} The short month name.
  10030. * @static
  10031. */
  10032. getShortMonthName : function(month) {
  10033. return Date.monthNames[month].substring(0, 3);
  10034. },
  10035. /**
  10036. * Get the short day name for the given day number.
  10037. * Override this function for international dates.
  10038. * @param {Number} day A zero-based javascript day number.
  10039. * @return {String} The short day name.
  10040. * @static
  10041. */
  10042. getShortDayName : function(day) {
  10043. return Date.dayNames[day].substring(0, 3);
  10044. },
  10045. /**
  10046. * Get the zero-based javascript month number for the given short/full month name.
  10047. * Override this function for international dates.
  10048. * @param {String} name The short/full month name.
  10049. * @return {Number} The zero-based javascript month number.
  10050. * @static
  10051. */
  10052. getMonthNumber : function(name) {
  10053. // handle camel casing for english month names (since the keys for the Date.monthNumbers hash are case sensitive)
  10054. return Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
  10055. },
  10056. /**
  10057. * The base format-code to formatting-function hashmap used by the {@link #format} method.
  10058. * Formatting functions are strings (or functions which return strings) which
  10059. * will return the appropriate value when evaluated in the context of the Date object
  10060. * from which the {@link #format} method is called.
  10061. * Add to / override these mappings for custom date formatting.
  10062. * Note: Date.format() treats characters as literals if an appropriate mapping cannot be found.
  10063. * Example:
  10064. * <pre><code>
  10065. Date.formatCodes.x = "String.leftPad(this.getDate(), 2, '0')";
  10066. (new Date()).format("X"); // returns the current day of the month
  10067. </code></pre>
  10068. * @type Object
  10069. * @static
  10070. */
  10071. formatCodes : {
  10072. d: "String.leftPad(this.getDate(), 2, '0')",
  10073. D: "Date.getShortDayName(this.getDay())", // get localised short day name
  10074. j: "this.getDate()",
  10075. l: "Date.dayNames[this.getDay()]",
  10076. N: "(this.getDay() ? this.getDay() : 7)",
  10077. S: "this.getSuffix()",
  10078. w: "this.getDay()",
  10079. z: "this.getDayOfYear()",
  10080. W: "String.leftPad(this.getWeekOfYear(), 2, '0')",
  10081. F: "Date.monthNames[this.getMonth()]",
  10082. m: "String.leftPad(this.getMonth() + 1, 2, '0')",
  10083. M: "Date.getShortMonthName(this.getMonth())", // get localised short month name
  10084. n: "(this.getMonth() + 1)",
  10085. t: "this.getDaysInMonth()",
  10086. L: "(this.isLeapYear() ? 1 : 0)",
  10087. o: "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0)))",
  10088. Y: "this.getFullYear()",
  10089. y: "('' + this.getFullYear()).substring(2, 4)",
  10090. a: "(this.getHours() < 12 ? 'am' : 'pm')",
  10091. A: "(this.getHours() < 12 ? 'AM' : 'PM')",
  10092. g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
  10093. G: "this.getHours()",
  10094. h: "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
  10095. H: "String.leftPad(this.getHours(), 2, '0')",
  10096. i: "String.leftPad(this.getMinutes(), 2, '0')",
  10097. s: "String.leftPad(this.getSeconds(), 2, '0')",
  10098. u: "String.leftPad(this.getMilliseconds(), 3, '0')",
  10099. O: "this.getGMTOffset()",
  10100. P: "this.getGMTOffset(true)",
  10101. T: "this.getTimezone()",
  10102. Z: "(this.getTimezoneOffset() * -60)",
  10103. c: function() { // ISO-8601 -- GMT format
  10104. for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
  10105. var e = c.charAt(i);
  10106. code.push(e == "T" ? "'T'" : Date.getFormatCode(e)); // treat T as a character literal
  10107. }
  10108. return code.join(" + ");
  10109. },
  10110. /*
  10111. c: function() { // ISO-8601 -- UTC format
  10112. return [
  10113. "this.getUTCFullYear()", "'-'",
  10114. "String.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
  10115. "String.leftPad(this.getUTCDate(), 2, '0')",
  10116. "'T'",
  10117. "String.leftPad(this.getUTCHours(), 2, '0')", "':'",
  10118. "String.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
  10119. "String.leftPad(this.getUTCSeconds(), 2, '0')",
  10120. "'Z'"
  10121. ].join(" + ");
  10122. },
  10123. */
  10124. U: "Math.round(this.getTime() / 1000)"
  10125. },
  10126. /**
  10127. * Checks if the passed Date parameters will cause a javascript Date "rollover".
  10128. * @param {Number} year 4-digit year
  10129. * @param {Number} month 1-based month-of-year
  10130. * @param {Number} day Day of month
  10131. * @param {Number} hour (optional) Hour
  10132. * @param {Number} minute (optional) Minute
  10133. * @param {Number} second (optional) Second
  10134. * @param {Number} millisecond (optional) Millisecond
  10135. * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
  10136. * @static
  10137. */
  10138. isValid : function(y, m, d, h, i, s, ms) {
  10139. // setup defaults
  10140. h = h || 0;
  10141. i = i || 0;
  10142. s = s || 0;
  10143. ms = ms || 0;
  10144. var dt = new Date(y, m - 1, d, h, i, s, ms);
  10145. return y == dt.getFullYear() &&
  10146. m == dt.getMonth() + 1 &&
  10147. d == dt.getDate() &&
  10148. h == dt.getHours() &&
  10149. i == dt.getMinutes() &&
  10150. s == dt.getSeconds() &&
  10151. ms == dt.getMilliseconds();
  10152. },
  10153. /**
  10154. * Parses the passed string using the specified date format.
  10155. * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
  10156. * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
  10157. * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
  10158. * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
  10159. * Keep in mind that the input date string must precisely match the specified format string
  10160. * in order for the parse operation to be successful (failed parse operations return a null value).
  10161. * <p>Example:</p><pre><code>
  10162. //dt = Fri May 25 2007 (current date)
  10163. var dt = new Date();
  10164. //dt = Thu May 25 2006 (today&#39;s month/day in 2006)
  10165. dt = Date.parseDate("2006", "Y");
  10166. //dt = Sun Jan 15 2006 (all date parts specified)
  10167. dt = Date.parseDate("2006-01-15", "Y-m-d");
  10168. //dt = Sun Jan 15 2006 15:20:01
  10169. dt = Date.parseDate("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
  10170. // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
  10171. dt = Date.parseDate("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
  10172. </code></pre>
  10173. * @param {String} input The raw date string.
  10174. * @param {String} format The expected date string format.
  10175. * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
  10176. (defaults to false). Invalid date strings will return null when parsed.
  10177. * @return {Date} The parsed Date.
  10178. * @static
  10179. */
  10180. parseDate : function(input, format, strict) {
  10181. var p = Date.parseFunctions;
  10182. if (p[format] == null) {
  10183. Date.createParser(format);
  10184. }
  10185. return p[format](input, Ext.isDefined(strict) ? strict : Date.useStrict);
  10186. },
  10187. // private
  10188. getFormatCode : function(character) {
  10189. var f = Date.formatCodes[character];
  10190. if (f) {
  10191. f = typeof f == 'function'? f() : f;
  10192. Date.formatCodes[character] = f; // reassign function result to prevent repeated execution
  10193. }
  10194. // note: unknown characters are treated as literals
  10195. return f || ("'" + String.escape(character) + "'");
  10196. },
  10197. // private
  10198. createFormat : function(format) {
  10199. var code = [],
  10200. special = false,
  10201. ch = '';
  10202. for (var i = 0; i < format.length; ++i) {
  10203. ch = format.charAt(i);
  10204. if (!special && ch == "\\") {
  10205. special = true;
  10206. } else if (special) {
  10207. special = false;
  10208. code.push("'" + String.escape(ch) + "'");
  10209. } else {
  10210. code.push(Date.getFormatCode(ch))
  10211. }
  10212. }
  10213. Date.formatFunctions[format] = new Function("return " + code.join('+'));
  10214. },
  10215. // private
  10216. createParser : function() {
  10217. var code = [
  10218. "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
  10219. "def = Date.defaults,",
  10220. "results = String(input).match(Date.parseRegexes[{0}]);", // either null, or an array of matched strings
  10221. "if(results){",
  10222. "{1}",
  10223. "if(u != null){", // i.e. unix time is defined
  10224. "v = new Date(u * 1000);", // give top priority to UNIX time
  10225. "}else{",
  10226. // create Date object representing midnight of the current day;
  10227. // this will provide us with our date defaults
  10228. // (note: clearTime() handles Daylight Saving Time automatically)
  10229. "dt = (new Date()).clearTime();",
  10230. // date calculations (note: these calculations create a dependency on Ext.num())
  10231. "y = Ext.num(y, Ext.num(def.y, dt.getFullYear()));",
  10232. "m = Ext.num(m, Ext.num(def.m - 1, dt.getMonth()));",
  10233. "d = Ext.num(d, Ext.num(def.d, dt.getDate()));",
  10234. // time calculations (note: these calculations create a dependency on Ext.num())
  10235. "h = Ext.num(h, Ext.num(def.h, dt.getHours()));",
  10236. "i = Ext.num(i, Ext.num(def.i, dt.getMinutes()));",
  10237. "s = Ext.num(s, Ext.num(def.s, dt.getSeconds()));",
  10238. "ms = Ext.num(ms, Ext.num(def.ms, dt.getMilliseconds()));",
  10239. "if(z >= 0 && y >= 0){",
  10240. // both the year and zero-based day of year are defined and >= 0.
  10241. // these 2 values alone provide sufficient info to create a full date object
  10242. // create Date object representing January 1st for the given year
  10243. "v = new Date(y, 0, 1, h, i, s, ms);",
  10244. // then add day of year, checking for Date "rollover" if necessary
  10245. "v = !strict? v : (strict === true && (z <= 364 || (v.isLeapYear() && z <= 365))? v.add(Date.DAY, z) : null);",
  10246. "}else if(strict === true && !Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
  10247. "v = null;", // invalid date, so return null
  10248. "}else{",
  10249. // plain old Date object
  10250. "v = new Date(y, m, d, h, i, s, ms);",
  10251. "}",
  10252. "}",
  10253. "}",
  10254. "if(v){",
  10255. // favour UTC offset over GMT offset
  10256. "if(zz != null){",
  10257. // reset to UTC, then add offset
  10258. "v = v.add(Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
  10259. "}else if(o){",
  10260. // reset to GMT, then add offset
  10261. "v = v.add(Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
  10262. "}",
  10263. "}",
  10264. "return v;"
  10265. ].join('\n');
  10266. return function(format) {
  10267. var regexNum = Date.parseRegexes.length,
  10268. currentGroup = 1,
  10269. calc = [],
  10270. regex = [],
  10271. special = false,
  10272. ch = "";
  10273. for (var i = 0; i < format.length; ++i) {
  10274. ch = format.charAt(i);
  10275. if (!special && ch == "\\") {
  10276. special = true;
  10277. } else if (special) {
  10278. special = false;
  10279. regex.push(String.escape(ch));
  10280. } else {
  10281. var obj = $f(ch, currentGroup);
  10282. currentGroup += obj.g;
  10283. regex.push(obj.s);
  10284. if (obj.g && obj.c) {
  10285. calc.push(obj.c);
  10286. }
  10287. }
  10288. }
  10289. Date.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$");
  10290. Date.parseFunctions[format] = new Function("input", "strict", xf(code, regexNum, calc.join('')));
  10291. }
  10292. }(),
  10293. // private
  10294. parseCodes : {
  10295. /*
  10296. * Notes:
  10297. * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
  10298. * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
  10299. * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
  10300. */
  10301. d: {
  10302. g:1,
  10303. c:"d = parseInt(results[{0}], 10);\n",
  10304. s:"(\\d{2})" // day of month with leading zeroes (01 - 31)
  10305. },
  10306. j: {
  10307. g:1,
  10308. c:"d = parseInt(results[{0}], 10);\n",
  10309. s:"(\\d{1,2})" // day of month without leading zeroes (1 - 31)
  10310. },
  10311. D: function() {
  10312. for (var a = [], i = 0; i < 7; a.push(Date.getShortDayName(i)), ++i); // get localised short day names
  10313. return {
  10314. g:0,
  10315. c:null,
  10316. s:"(?:" + a.join("|") +")"
  10317. }
  10318. },
  10319. l: function() {
  10320. return {
  10321. g:0,
  10322. c:null,
  10323. s:"(?:" + Date.dayNames.join("|") + ")"
  10324. }
  10325. },
  10326. N: {
  10327. g:0,
  10328. c:null,
  10329. s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
  10330. },
  10331. S: {
  10332. g:0,
  10333. c:null,
  10334. s:"(?:st|nd|rd|th)"
  10335. },
  10336. w: {
  10337. g:0,
  10338. c:null,
  10339. s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
  10340. },
  10341. z: {
  10342. g:1,
  10343. c:"z = parseInt(results[{0}], 10);\n",
  10344. s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
  10345. },
  10346. W: {
  10347. g:0,
  10348. c:null,
  10349. s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
  10350. },
  10351. F: function() {
  10352. return {
  10353. g:1,
  10354. c:"m = parseInt(Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
  10355. s:"(" + Date.monthNames.join("|") + ")"
  10356. }
  10357. },
  10358. M: function() {
  10359. for (var a = [], i = 0; i < 12; a.push(Date.getShortMonthName(i)), ++i); // get localised short month names
  10360. return Ext.applyIf({
  10361. s:"(" + a.join("|") + ")"
  10362. }, $f("F"));
  10363. },
  10364. m: {
  10365. g:1,
  10366. c:"m = parseInt(results[{0}], 10) - 1;\n",
  10367. s:"(\\d{2})" // month number with leading zeros (01 - 12)
  10368. },
  10369. n: {
  10370. g:1,
  10371. c:"m = parseInt(results[{0}], 10) - 1;\n",
  10372. s:"(\\d{1,2})" // month number without leading zeros (1 - 12)
  10373. },
  10374. t: {
  10375. g:0,
  10376. c:null,
  10377. s:"(?:\\d{2})" // no. of days in the month (28 - 31)
  10378. },
  10379. L: {
  10380. g:0,
  10381. c:null,
  10382. s:"(?:1|0)"
  10383. },
  10384. o: function() {
  10385. return $f("Y");
  10386. },
  10387. Y: {
  10388. g:1,
  10389. c:"y = parseInt(results[{0}], 10);\n",
  10390. s:"(\\d{4})" // 4-digit year
  10391. },
  10392. y: {
  10393. g:1,
  10394. c:"var ty = parseInt(results[{0}], 10);\n"
  10395. + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
  10396. s:"(\\d{1,2})"
  10397. },
  10398. a: {
  10399. g:1,
  10400. c:"if (results[{0}] == 'am') {\n"
  10401. + "if (!h || h == 12) { h = 0; }\n"
  10402. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  10403. s:"(am|pm)"
  10404. },
  10405. A: {
  10406. g:1,
  10407. c:"if (results[{0}] == 'AM') {\n"
  10408. + "if (!h || h == 12) { h = 0; }\n"
  10409. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  10410. s:"(AM|PM)"
  10411. },
  10412. g: function() {
  10413. return $f("G");
  10414. },
  10415. G: {
  10416. g:1,
  10417. c:"h = parseInt(results[{0}], 10);\n",
  10418. s:"(\\d{1,2})" // 24-hr format of an hour without leading zeroes (0 - 23)
  10419. },
  10420. h: function() {
  10421. return $f("H");
  10422. },
  10423. H: {
  10424. g:1,
  10425. c:"h = parseInt(results[{0}], 10);\n",
  10426. s:"(\\d{2})" // 24-hr format of an hour with leading zeroes (00 - 23)
  10427. },
  10428. i: {
  10429. g:1,
  10430. c:"i = parseInt(results[{0}], 10);\n",
  10431. s:"(\\d{2})" // minutes with leading zeros (00 - 59)
  10432. },
  10433. s: {
  10434. g:1,
  10435. c:"s = parseInt(results[{0}], 10);\n",
  10436. s:"(\\d{2})" // seconds with leading zeros (00 - 59)
  10437. },
  10438. u: {
  10439. g:1,
  10440. c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
  10441. s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  10442. },
  10443. O: {
  10444. g:1,
  10445. c:[
  10446. "o = results[{0}];",
  10447. "var sn = o.substring(0,1),", // get + / - sign
  10448. "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  10449. "mn = o.substring(3,5) % 60;", // get minutes
  10450. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  10451. ].join("\n"),
  10452. s: "([+\-]\\d{4})" // GMT offset in hrs and mins
  10453. },
  10454. P: {
  10455. g:1,
  10456. c:[
  10457. "o = results[{0}];",
  10458. "var sn = o.substring(0,1),", // get + / - sign
  10459. "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  10460. "mn = o.substring(4,6) % 60;", // get minutes
  10461. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  10462. ].join("\n"),
  10463. s: "([+\-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
  10464. },
  10465. T: {
  10466. g:0,
  10467. c:null,
  10468. s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
  10469. },
  10470. Z: {
  10471. g:1,
  10472. c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
  10473. + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
  10474. s:"([+\-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
  10475. },
  10476. c: function() {
  10477. var calc = [],
  10478. arr = [
  10479. $f("Y", 1), // year
  10480. $f("m", 2), // month
  10481. $f("d", 3), // day
  10482. $f("h", 4), // hour
  10483. $f("i", 5), // minute
  10484. $f("s", 6), // second
  10485. {c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  10486. {c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
  10487. "if(results[8]) {", // timezone specified
  10488. "if(results[8] == 'Z'){",
  10489. "zz = 0;", // UTC
  10490. "}else if (results[8].indexOf(':') > -1){",
  10491. $f("P", 8).c, // timezone offset with colon separator
  10492. "}else{",
  10493. $f("O", 8).c, // timezone offset without colon separator
  10494. "}",
  10495. "}"
  10496. ].join('\n')}
  10497. ];
  10498. for (var i = 0, l = arr.length; i < l; ++i) {
  10499. calc.push(arr[i].c);
  10500. }
  10501. return {
  10502. g:1,
  10503. c:calc.join(""),
  10504. s:[
  10505. arr[0].s, // year (required)
  10506. "(?:", "-", arr[1].s, // month (optional)
  10507. "(?:", "-", arr[2].s, // day (optional)
  10508. "(?:",
  10509. "(?:T| )?", // time delimiter -- either a "T" or a single blank space
  10510. arr[3].s, ":", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
  10511. "(?::", arr[5].s, ")?", // seconds (optional)
  10512. "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
  10513. "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
  10514. ")?",
  10515. ")?",
  10516. ")?"
  10517. ].join("")
  10518. }
  10519. },
  10520. U: {
  10521. g:1,
  10522. c:"u = parseInt(results[{0}], 10);\n",
  10523. s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
  10524. }
  10525. }
  10526. });
  10527. }());
  10528. Ext.apply(Date.prototype, {
  10529. // private
  10530. dateFormat : function(format) {
  10531. if (Date.formatFunctions[format] == null) {
  10532. Date.createFormat(format);
  10533. }
  10534. return Date.formatFunctions[format].call(this);
  10535. },
  10536. /**
  10537. * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
  10538. *
  10539. * Note: The date string returned by the javascript Date object's toString() method varies
  10540. * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
  10541. * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
  10542. * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
  10543. * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
  10544. * from the GMT offset portion of the date string.
  10545. * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
  10546. */
  10547. getTimezone : function() {
  10548. // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
  10549. //
  10550. // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
  10551. // Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
  10552. // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
  10553. // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
  10554. // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
  10555. //
  10556. // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
  10557. // step 1: (?:\((.*)\) -- find timezone in parentheses
  10558. // step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
  10559. // step 3: remove all non uppercase characters found in step 1 and 2
  10560. return this.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
  10561. },
  10562. /**
  10563. * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
  10564. * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
  10565. * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
  10566. */
  10567. getGMTOffset : function(colon) {
  10568. return (this.getTimezoneOffset() > 0 ? "-" : "+")
  10569. + String.leftPad(Math.floor(Math.abs(this.getTimezoneOffset()) / 60), 2, "0")
  10570. + (colon ? ":" : "")
  10571. + String.leftPad(Math.abs(this.getTimezoneOffset() % 60), 2, "0");
  10572. },
  10573. /**
  10574. * Get the numeric day number of the year, adjusted for leap year.
  10575. * @return {Number} 0 to 364 (365 in leap years).
  10576. */
  10577. getDayOfYear: function() {
  10578. var num = 0,
  10579. d = this.clone(),
  10580. m = this.getMonth(),
  10581. i;
  10582. for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
  10583. num += d.getDaysInMonth();
  10584. }
  10585. return num + this.getDate() - 1;
  10586. },
  10587. /**
  10588. * Get the numeric ISO-8601 week number of the year.
  10589. * (equivalent to the format specifier 'W', but without a leading zero).
  10590. * @return {Number} 1 to 53
  10591. */
  10592. getWeekOfYear : function() {
  10593. // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
  10594. var ms1d = 864e5, // milliseconds in a day
  10595. ms7d = 7 * ms1d; // milliseconds in a week
  10596. return function() { // return a closure so constants get calculated only once
  10597. var DC3 = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate() + 3) / ms1d, // an Absolute Day Number
  10598. AWN = Math.floor(DC3 / 7), // an Absolute Week Number
  10599. Wyr = new Date(AWN * ms7d).getUTCFullYear();
  10600. return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
  10601. }
  10602. }(),
  10603. /**
  10604. * Checks if the current date falls within a leap year.
  10605. * @return {Boolean} True if the current date falls within a leap year, false otherwise.
  10606. */
  10607. isLeapYear : function() {
  10608. var year = this.getFullYear();
  10609. return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
  10610. },
  10611. /**
  10612. * Get the first day of the current month, adjusted for leap year. The returned value
  10613. * is the numeric day index within the week (0-6) which can be used in conjunction with
  10614. * the {@link #monthNames} array to retrieve the textual day name.
  10615. * Example:
  10616. * <pre><code>
  10617. var dt = new Date('1/10/2007');
  10618. document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
  10619. </code></pre>
  10620. * @return {Number} The day number (0-6).
  10621. */
  10622. getFirstDayOfMonth : function() {
  10623. var day = (this.getDay() - (this.getDate() - 1)) % 7;
  10624. return (day < 0) ? (day + 7) : day;
  10625. },
  10626. /**
  10627. * Get the last day of the current month, adjusted for leap year. The returned value
  10628. * is the numeric day index within the week (0-6) which can be used in conjunction with
  10629. * the {@link #monthNames} array to retrieve the textual day name.
  10630. * Example:
  10631. * <pre><code>
  10632. var dt = new Date('1/10/2007');
  10633. document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
  10634. </code></pre>
  10635. * @return {Number} The day number (0-6).
  10636. */
  10637. getLastDayOfMonth : function() {
  10638. return this.getLastDateOfMonth().getDay();
  10639. },
  10640. /**
  10641. * Get the date of the first day of the month in which this date resides.
  10642. * @return {Date}
  10643. */
  10644. getFirstDateOfMonth : function() {
  10645. return new Date(this.getFullYear(), this.getMonth(), 1);
  10646. },
  10647. /**
  10648. * Get the date of the last day of the month in which this date resides.
  10649. * @return {Date}
  10650. */
  10651. getLastDateOfMonth : function() {
  10652. return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
  10653. },
  10654. /**
  10655. * Get the number of days in the current month, adjusted for leap year.
  10656. * @return {Number} The number of days in the month.
  10657. */
  10658. getDaysInMonth: function() {
  10659. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  10660. return function() { // return a closure for efficiency
  10661. var m = this.getMonth();
  10662. return m == 1 && this.isLeapYear() ? 29 : daysInMonth[m];
  10663. }
  10664. }(),
  10665. /**
  10666. * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
  10667. * @return {String} 'st, 'nd', 'rd' or 'th'.
  10668. */
  10669. getSuffix : function() {
  10670. switch (this.getDate()) {
  10671. case 1:
  10672. case 21:
  10673. case 31:
  10674. return "st";
  10675. case 2:
  10676. case 22:
  10677. return "nd";
  10678. case 3:
  10679. case 23:
  10680. return "rd";
  10681. default:
  10682. return "th";
  10683. }
  10684. },
  10685. /**
  10686. * Creates and returns a new Date instance with the exact same date value as the called instance.
  10687. * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
  10688. * variable will also be changed. When the intention is to create a new variable that will not
  10689. * modify the original instance, you should create a clone.
  10690. *
  10691. * Example of correctly cloning a date:
  10692. * <pre><code>
  10693. //wrong way:
  10694. var orig = new Date('10/1/2006');
  10695. var copy = orig;
  10696. copy.setDate(5);
  10697. document.write(orig); //returns 'Thu Oct 05 2006'!
  10698. //correct way:
  10699. var orig = new Date('10/1/2006');
  10700. var copy = orig.clone();
  10701. copy.setDate(5);
  10702. document.write(orig); //returns 'Thu Oct 01 2006'
  10703. </code></pre>
  10704. * @return {Date} The new Date instance.
  10705. */
  10706. clone : function() {
  10707. return new Date(this.getTime());
  10708. },
  10709. /**
  10710. * Checks if the current date is affected by Daylight Saving Time (DST).
  10711. * @return {Boolean} True if the current date is affected by DST.
  10712. */
  10713. isDST : function() {
  10714. // adapted from http://extjs.com/forum/showthread.php?p=247172#post247172
  10715. // courtesy of @geoffrey.mcgill
  10716. return new Date(this.getFullYear(), 0, 1).getTimezoneOffset() != this.getTimezoneOffset();
  10717. },
  10718. /**
  10719. * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
  10720. * automatically adjusting for Daylight Saving Time (DST) where applicable.
  10721. * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
  10722. * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
  10723. * @return {Date} this or the clone.
  10724. */
  10725. clearTime : function(clone) {
  10726. if (clone) {
  10727. return this.clone().clearTime();
  10728. }
  10729. // get current date before clearing time
  10730. var d = this.getDate();
  10731. // clear time
  10732. this.setHours(0);
  10733. this.setMinutes(0);
  10734. this.setSeconds(0);
  10735. this.setMilliseconds(0);
  10736. if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
  10737. // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
  10738. // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
  10739. // increment hour until cloned date == current date
  10740. for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr));
  10741. this.setDate(d);
  10742. this.setHours(c.getHours());
  10743. }
  10744. return this;
  10745. },
  10746. /**
  10747. * Provides a convenient method for performing basic date arithmetic. This method
  10748. * does not modify the Date instance being called - it creates and returns
  10749. * a new Date instance containing the resulting date value.
  10750. *
  10751. * Examples:
  10752. * <pre><code>
  10753. // Basic usage:
  10754. var dt = new Date('10/29/2006').add(Date.DAY, 5);
  10755. document.write(dt); //returns 'Fri Nov 03 2006 00:00:00'
  10756. // Negative values will be subtracted:
  10757. var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
  10758. document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
  10759. // You can even chain several calls together in one line:
  10760. var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
  10761. document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
  10762. </code></pre>
  10763. *
  10764. * @param {String} interval A valid date interval enum value.
  10765. * @param {Number} value The amount to add to the current date.
  10766. * @return {Date} The new Date instance.
  10767. */
  10768. add : function(interval, value) {
  10769. var d = this.clone();
  10770. if (!interval || value === 0) return d;
  10771. switch(interval.toLowerCase()) {
  10772. case Date.MILLI:
  10773. d.setMilliseconds(this.getMilliseconds() + value);
  10774. break;
  10775. case Date.SECOND:
  10776. d.setSeconds(this.getSeconds() + value);
  10777. break;
  10778. case Date.MINUTE:
  10779. d.setMinutes(this.getMinutes() + value);
  10780. break;
  10781. case Date.HOUR:
  10782. d.setHours(this.getHours() + value);
  10783. break;
  10784. case Date.DAY:
  10785. d.setDate(this.getDate() + value);
  10786. break;
  10787. case Date.MONTH:
  10788. var day = this.getDate();
  10789. if (day > 28) {
  10790. day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
  10791. }
  10792. d.setDate(day);
  10793. d.setMonth(this.getMonth() + value);
  10794. break;
  10795. case Date.YEAR:
  10796. d.setFullYear(this.getFullYear() + value);
  10797. break;
  10798. }
  10799. return d;
  10800. },
  10801. /**
  10802. * Checks if this date falls on or between the given start and end dates.
  10803. * @param {Date} start Start date
  10804. * @param {Date} end End date
  10805. * @return {Boolean} true if this date falls on or between the given start and end dates.
  10806. */
  10807. between : function(start, end) {
  10808. var t = this.getTime();
  10809. return start.getTime() <= t && t <= end.getTime();
  10810. }
  10811. });
  10812. /**
  10813. * Formats a date given the supplied format string.
  10814. * @param {String} format The format string.
  10815. * @return {String} The formatted date.
  10816. * @method format
  10817. */
  10818. Date.prototype.format = Date.prototype.dateFormat;
  10819. // private
  10820. if (Ext.isSafari && (navigator.userAgent.match(/WebKit\/(\d+)/)[1] || NaN) < 420) {
  10821. Ext.apply(Date.prototype, {
  10822. _xMonth : Date.prototype.setMonth,
  10823. _xDate : Date.prototype.setDate,
  10824. // Bug in Safari 1.3, 2.0 (WebKit build < 420)
  10825. // Date.setMonth does not work consistently if iMonth is not 0-11
  10826. setMonth : function(num) {
  10827. if (num <= -1) {
  10828. var n = Math.ceil(-num),
  10829. back_year = Math.ceil(n / 12),
  10830. month = (n % 12) ? 12 - n % 12 : 0;
  10831. this.setFullYear(this.getFullYear() - back_year);
  10832. return this._xMonth(month);
  10833. } else {
  10834. return this._xMonth(num);
  10835. }
  10836. },
  10837. // Bug in setDate() method (resolved in WebKit build 419.3, so to be safe we target Webkit builds < 420)
  10838. // The parameter for Date.setDate() is converted to a signed byte integer in Safari
  10839. // http://brianary.blogspot.com/2006/03/safari-date-bug.html
  10840. setDate : function(d) {
  10841. // use setTime() to workaround setDate() bug
  10842. // subtract current day of month in milliseconds, then add desired day of month in milliseconds
  10843. return this.setTime(this.getTime() - (this.getDate() - d) * 864e5);
  10844. }
  10845. });
  10846. }
  10847. /* Some basic Date tests... (requires Firebug)
  10848. Date.parseDate('', 'c'); // call Date.parseDate() once to force computation of regex string so we can console.log() it
  10849. console.log('Insane Regex for "c" format: %o', Date.parseCodes.c.s); // view the insane regex for the "c" format specifier
  10850. // standard tests
  10851. console.group('Standard Date.parseDate() Tests');
  10852. console.log('Date.parseDate("2009-01-05T11:38:56", "c") = %o', Date.parseDate("2009-01-05T11:38:56", "c")); // assumes browser's timezone setting
  10853. console.log('Date.parseDate("2009-02-04T12:37:55.001000", "c") = %o', Date.parseDate("2009-02-04T12:37:55.001000", "c")); // assumes browser's timezone setting
  10854. console.log('Date.parseDate("2009-03-03T13:36:54,101000Z", "c") = %o', Date.parseDate("2009-03-03T13:36:54,101000Z", "c")); // UTC
  10855. console.log('Date.parseDate("2009-04-02T14:35:53.901000-0530", "c") = %o', Date.parseDate("2009-04-02T14:35:53.901000-0530", "c")); // GMT-0530
  10856. console.log('Date.parseDate("2009-05-01T15:34:52,9876000+08:00", "c") = %o', Date.parseDate("2009-05-01T15:34:52,987600+08:00", "c")); // GMT+08:00
  10857. console.groupEnd();
  10858. // ISO-8601 format as specified in http://www.w3.org/TR/NOTE-datetime
  10859. // -- accepts ALL 6 levels of date-time granularity
  10860. console.group('ISO-8601 Granularity Test (see http://www.w3.org/TR/NOTE-datetime)');
  10861. console.log('Date.parseDate("1997", "c") = %o', Date.parseDate("1997", "c")); // YYYY (e.g. 1997)
  10862. console.log('Date.parseDate("1997-07", "c") = %o', Date.parseDate("1997-07", "c")); // YYYY-MM (e.g. 1997-07)
  10863. console.log('Date.parseDate("1997-07-16", "c") = %o', Date.parseDate("1997-07-16", "c")); // YYYY-MM-DD (e.g. 1997-07-16)
  10864. console.log('Date.parseDate("1997-07-16T19:20+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20+01:00", "c")); // YYYY-MM-DDThh:mmTZD (e.g. 1997-07-16T19:20+01:00)
  10865. console.log('Date.parseDate("1997-07-16T19:20:30+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20:30+01:00", "c")); // YYYY-MM-DDThh:mm:ssTZD (e.g. 1997-07-16T19:20:30+01:00)
  10866. console.log('Date.parseDate("1997-07-16T19:20:30.45+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20:30.45+01:00", "c")); // YYYY-MM-DDThh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
  10867. console.log('Date.parseDate("1997-07-16 19:20:30.45+01:00", "c") = %o', Date.parseDate("1997-07-16 19:20:30.45+01:00", "c")); // YYYY-MM-DD hh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
  10868. console.log('Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)= %o', Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)); // strict date parsing with invalid month value
  10869. console.groupEnd();
  10870. //*/
  10871. /**
  10872. * @class Ext.util.MixedCollection
  10873. * @extends Ext.util.Observable
  10874. * A Collection class that maintains both numeric indexes and keys and exposes events.
  10875. * @constructor
  10876. * @param {Boolean} allowFunctions Specify <tt>true</tt> if the {@link #addAll}
  10877. * function should add function references to the collection. Defaults to
  10878. * <tt>false</tt>.
  10879. * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
  10880. * and return the key value for that item. This is used when available to look up the key on items that
  10881. * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
  10882. * equivalent to providing an implementation for the {@link #getKey} method.
  10883. */
  10884. Ext.util.MixedCollection = function(allowFunctions, keyFn){
  10885. this.items = [];
  10886. this.map = {};
  10887. this.keys = [];
  10888. this.length = 0;
  10889. this.addEvents(
  10890. /**
  10891. * @event clear
  10892. * Fires when the collection is cleared.
  10893. */
  10894. 'clear',
  10895. /**
  10896. * @event add
  10897. * Fires when an item is added to the collection.
  10898. * @param {Number} index The index at which the item was added.
  10899. * @param {Object} o The item added.
  10900. * @param {String} key The key associated with the added item.
  10901. */
  10902. 'add',
  10903. /**
  10904. * @event replace
  10905. * Fires when an item is replaced in the collection.
  10906. * @param {String} key he key associated with the new added.
  10907. * @param {Object} old The item being replaced.
  10908. * @param {Object} new The new item.
  10909. */
  10910. 'replace',
  10911. /**
  10912. * @event remove
  10913. * Fires when an item is removed from the collection.
  10914. * @param {Object} o The item being removed.
  10915. * @param {String} key (optional) The key associated with the removed item.
  10916. */
  10917. 'remove',
  10918. 'sort'
  10919. );
  10920. this.allowFunctions = allowFunctions === true;
  10921. if(keyFn){
  10922. this.getKey = keyFn;
  10923. }
  10924. Ext.util.MixedCollection.superclass.constructor.call(this);
  10925. };
  10926. Ext.extend(Ext.util.MixedCollection, Ext.util.Observable, {
  10927. /**
  10928. * @cfg {Boolean} allowFunctions Specify <tt>true</tt> if the {@link #addAll}
  10929. * function should add function references to the collection. Defaults to
  10930. * <tt>false</tt>.
  10931. */
  10932. allowFunctions : false,
  10933. /**
  10934. * Adds an item to the collection. Fires the {@link #add} event when complete.
  10935. * @param {String} key <p>The key to associate with the item, or the new item.</p>
  10936. * <p>If a {@link #getKey} implementation was specified for this MixedCollection,
  10937. * or if the key of the stored items is in a property called <tt><b>id</b></tt>,
  10938. * the MixedCollection will be able to <i>derive</i> the key for the new item.
  10939. * In this case just pass the new item in this parameter.</p>
  10940. * @param {Object} o The item to add.
  10941. * @return {Object} The item added.
  10942. */
  10943. add : function(key, o){
  10944. if(arguments.length == 1){
  10945. o = arguments[0];
  10946. key = this.getKey(o);
  10947. }
  10948. if(typeof key != 'undefined' && key !== null){
  10949. var old = this.map[key];
  10950. if(typeof old != 'undefined'){
  10951. return this.replace(key, o);
  10952. }
  10953. this.map[key] = o;
  10954. }
  10955. this.length++;
  10956. this.items.push(o);
  10957. this.keys.push(key);
  10958. this.fireEvent('add', this.length-1, o, key);
  10959. return o;
  10960. },
  10961. /**
  10962. * MixedCollection has a generic way to fetch keys if you implement getKey. The default implementation
  10963. * simply returns <b><code>item.id</code></b> but you can provide your own implementation
  10964. * to return a different value as in the following examples:<pre><code>
  10965. // normal way
  10966. var mc = new Ext.util.MixedCollection();
  10967. mc.add(someEl.dom.id, someEl);
  10968. mc.add(otherEl.dom.id, otherEl);
  10969. //and so on
  10970. // using getKey
  10971. var mc = new Ext.util.MixedCollection();
  10972. mc.getKey = function(el){
  10973. return el.dom.id;
  10974. };
  10975. mc.add(someEl);
  10976. mc.add(otherEl);
  10977. // or via the constructor
  10978. var mc = new Ext.util.MixedCollection(false, function(el){
  10979. return el.dom.id;
  10980. });
  10981. mc.add(someEl);
  10982. mc.add(otherEl);
  10983. * </code></pre>
  10984. * @param {Object} item The item for which to find the key.
  10985. * @return {Object} The key for the passed item.
  10986. */
  10987. getKey : function(o){
  10988. return o.id;
  10989. },
  10990. /**
  10991. * Replaces an item in the collection. Fires the {@link #replace} event when complete.
  10992. * @param {String} key <p>The key associated with the item to replace, or the replacement item.</p>
  10993. * <p>If you supplied a {@link #getKey} implementation for this MixedCollection, or if the key
  10994. * of your stored items is in a property called <tt><b>id</b></tt>, then the MixedCollection
  10995. * will be able to <i>derive</i> the key of the replacement item. If you want to replace an item
  10996. * with one having the same key value, then just pass the replacement item in this parameter.</p>
  10997. * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate
  10998. * with that key.
  10999. * @return {Object} The new item.
  11000. */
  11001. replace : function(key, o){
  11002. if(arguments.length == 1){
  11003. o = arguments[0];
  11004. key = this.getKey(o);
  11005. }
  11006. var old = this.map[key];
  11007. if(typeof key == 'undefined' || key === null || typeof old == 'undefined'){
  11008. return this.add(key, o);
  11009. }
  11010. var index = this.indexOfKey(key);
  11011. this.items[index] = o;
  11012. this.map[key] = o;
  11013. this.fireEvent('replace', key, old, o);
  11014. return o;
  11015. },
  11016. /**
  11017. * Adds all elements of an Array or an Object to the collection.
  11018. * @param {Object/Array} objs An Object containing properties which will be added
  11019. * to the collection, or an Array of values, each of which are added to the collection.
  11020. * Functions references will be added to the collection if <code>{@link #allowFunctions}</code>
  11021. * has been set to <tt>true</tt>.
  11022. */
  11023. addAll : function(objs){
  11024. if(arguments.length > 1 || Ext.isArray(objs)){
  11025. var args = arguments.length > 1 ? arguments : objs;
  11026. for(var i = 0, len = args.length; i < len; i++){
  11027. this.add(args[i]);
  11028. }
  11029. }else{
  11030. for(var key in objs){
  11031. if(this.allowFunctions || typeof objs[key] != 'function'){
  11032. this.add(key, objs[key]);
  11033. }
  11034. }
  11035. }
  11036. },
  11037. /**
  11038. * Executes the specified function once for every item in the collection, passing the following arguments:
  11039. * <div class="mdetail-params"><ul>
  11040. * <li><b>item</b> : Mixed<p class="sub-desc">The collection item</p></li>
  11041. * <li><b>index</b> : Number<p class="sub-desc">The item's index</p></li>
  11042. * <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
  11043. * </ul></div>
  11044. * The function should return a boolean value. Returning false from the function will stop the iteration.
  11045. * @param {Function} fn The function to execute for each item.
  11046. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current item in the iteration.
  11047. */
  11048. each : function(fn, scope){
  11049. var items = [].concat(this.items); // each safe for removal
  11050. for(var i = 0, len = items.length; i < len; i++){
  11051. if(fn.call(scope || items[i], items[i], i, len) === false){
  11052. break;
  11053. }
  11054. }
  11055. },
  11056. /**
  11057. * Executes the specified function once for every key in the collection, passing each
  11058. * key, and its associated item as the first two parameters.
  11059. * @param {Function} fn The function to execute for each item.
  11060. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  11061. */
  11062. eachKey : function(fn, scope){
  11063. for(var i = 0, len = this.keys.length; i < len; i++){
  11064. fn.call(scope || window, this.keys[i], this.items[i], i, len);
  11065. }
  11066. },
  11067. /**
  11068. * Returns the first item in the collection which elicits a true return value from the
  11069. * passed selection function.
  11070. * @param {Function} fn The selection function to execute for each item.
  11071. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  11072. * @return {Object} The first item in the collection which returned true from the selection function.
  11073. */
  11074. find : function(fn, scope){
  11075. for(var i = 0, len = this.items.length; i < len; i++){
  11076. if(fn.call(scope || window, this.items[i], this.keys[i])){
  11077. return this.items[i];
  11078. }
  11079. }
  11080. return null;
  11081. },
  11082. /**
  11083. * Inserts an item at the specified index in the collection. Fires the {@link #add} event when complete.
  11084. * @param {Number} index The index to insert the item at.
  11085. * @param {String} key The key to associate with the new item, or the item itself.
  11086. * @param {Object} o (optional) If the second parameter was a key, the new item.
  11087. * @return {Object} The item inserted.
  11088. */
  11089. insert : function(index, key, o){
  11090. if(arguments.length == 2){
  11091. o = arguments[1];
  11092. key = this.getKey(o);
  11093. }
  11094. if(this.containsKey(key)){
  11095. this.suspendEvents();
  11096. this.removeKey(key);
  11097. this.resumeEvents();
  11098. }
  11099. if(index >= this.length){
  11100. return this.add(key, o);
  11101. }
  11102. this.length++;
  11103. this.items.splice(index, 0, o);
  11104. if(typeof key != 'undefined' && key !== null){
  11105. this.map[key] = o;
  11106. }
  11107. this.keys.splice(index, 0, key);
  11108. this.fireEvent('add', index, o, key);
  11109. return o;
  11110. },
  11111. /**
  11112. * Remove an item from the collection.
  11113. * @param {Object} o The item to remove.
  11114. * @return {Object} The item removed or false if no item was removed.
  11115. */
  11116. remove : function(o){
  11117. return this.removeAt(this.indexOf(o));
  11118. },
  11119. /**
  11120. * Remove an item from a specified index in the collection. Fires the {@link #remove} event when complete.
  11121. * @param {Number} index The index within the collection of the item to remove.
  11122. * @return {Object} The item removed or false if no item was removed.
  11123. */
  11124. removeAt : function(index){
  11125. if(index < this.length && index >= 0){
  11126. this.length--;
  11127. var o = this.items[index];
  11128. this.items.splice(index, 1);
  11129. var key = this.keys[index];
  11130. if(typeof key != 'undefined'){
  11131. delete this.map[key];
  11132. }
  11133. this.keys.splice(index, 1);
  11134. this.fireEvent('remove', o, key);
  11135. return o;
  11136. }
  11137. return false;
  11138. },
  11139. /**
  11140. * Removed an item associated with the passed key fom the collection.
  11141. * @param {String} key The key of the item to remove.
  11142. * @return {Object} The item removed or false if no item was removed.
  11143. */
  11144. removeKey : function(key){
  11145. return this.removeAt(this.indexOfKey(key));
  11146. },
  11147. /**
  11148. * Returns the number of items in the collection.
  11149. * @return {Number} the number of items in the collection.
  11150. */
  11151. getCount : function(){
  11152. return this.length;
  11153. },
  11154. /**
  11155. * Returns index within the collection of the passed Object.
  11156. * @param {Object} o The item to find the index of.
  11157. * @return {Number} index of the item. Returns -1 if not found.
  11158. */
  11159. indexOf : function(o){
  11160. return this.items.indexOf(o);
  11161. },
  11162. /**
  11163. * Returns index within the collection of the passed key.
  11164. * @param {String} key The key to find the index of.
  11165. * @return {Number} index of the key.
  11166. */
  11167. indexOfKey : function(key){
  11168. return this.keys.indexOf(key);
  11169. },
  11170. /**
  11171. * Returns the item associated with the passed key OR index.
  11172. * Key has priority over index. This is the equivalent
  11173. * of calling {@link #key} first, then if nothing matched calling {@link #itemAt}.
  11174. * @param {String/Number} key The key or index of the item.
  11175. * @return {Object} If the item is found, returns the item. If the item was not found, returns <tt>undefined</tt>.
  11176. * If an item was found, but is a Class, returns <tt>null</tt>.
  11177. */
  11178. item : function(key){
  11179. var mk = this.map[key],
  11180. item = mk !== undefined ? mk : (typeof key == 'number') ? this.items[key] : undefined;
  11181. return !Ext.isFunction(item) || this.allowFunctions ? item : null; // for prototype!
  11182. },
  11183. /**
  11184. * Returns the item at the specified index.
  11185. * @param {Number} index The index of the item.
  11186. * @return {Object} The item at the specified index.
  11187. */
  11188. itemAt : function(index){
  11189. return this.items[index];
  11190. },
  11191. /**
  11192. * Returns the item associated with the passed key.
  11193. * @param {String/Number} key The key of the item.
  11194. * @return {Object} The item associated with the passed key.
  11195. */
  11196. key : function(key){
  11197. return this.map[key];
  11198. },
  11199. /**
  11200. * Returns true if the collection contains the passed Object as an item.
  11201. * @param {Object} o The Object to look for in the collection.
  11202. * @return {Boolean} True if the collection contains the Object as an item.
  11203. */
  11204. contains : function(o){
  11205. return this.indexOf(o) != -1;
  11206. },
  11207. /**
  11208. * Returns true if the collection contains the passed Object as a key.
  11209. * @param {String} key The key to look for in the collection.
  11210. * @return {Boolean} True if the collection contains the Object as a key.
  11211. */
  11212. containsKey : function(key){
  11213. return typeof this.map[key] != 'undefined';
  11214. },
  11215. /**
  11216. * Removes all items from the collection. Fires the {@link #clear} event when complete.
  11217. */
  11218. clear : function(){
  11219. this.length = 0;
  11220. this.items = [];
  11221. this.keys = [];
  11222. this.map = {};
  11223. this.fireEvent('clear');
  11224. },
  11225. /**
  11226. * Returns the first item in the collection.
  11227. * @return {Object} the first item in the collection..
  11228. */
  11229. first : function(){
  11230. return this.items[0];
  11231. },
  11232. /**
  11233. * Returns the last item in the collection.
  11234. * @return {Object} the last item in the collection..
  11235. */
  11236. last : function(){
  11237. return this.items[this.length-1];
  11238. },
  11239. /**
  11240. * @private
  11241. * Performs the actual sorting based on a direction and a sorting function. Internally,
  11242. * this creates a temporary array of all items in the MixedCollection, sorts it and then writes
  11243. * the sorted array data back into this.items and this.keys
  11244. * @param {String} property Property to sort by ('key', 'value', or 'index')
  11245. * @param {String} dir (optional) Direction to sort 'ASC' or 'DESC'. Defaults to 'ASC'.
  11246. * @param {Function} fn (optional) Comparison function that defines the sort order.
  11247. * Defaults to sorting by numeric value.
  11248. */
  11249. _sort : function(property, dir, fn){
  11250. var i, len,
  11251. dsc = String(dir).toUpperCase() == 'DESC' ? -1 : 1,
  11252. //this is a temporary array used to apply the sorting function
  11253. c = [],
  11254. keys = this.keys,
  11255. items = this.items;
  11256. //default to a simple sorter function if one is not provided
  11257. fn = fn || function(a, b) {
  11258. return a - b;
  11259. };
  11260. //copy all the items into a temporary array, which we will sort
  11261. for(i = 0, len = items.length; i < len; i++){
  11262. c[c.length] = {
  11263. key : keys[i],
  11264. value: items[i],
  11265. index: i
  11266. };
  11267. }
  11268. //sort the temporary array
  11269. c.sort(function(a, b){
  11270. var v = fn(a[property], b[property]) * dsc;
  11271. if(v === 0){
  11272. v = (a.index < b.index ? -1 : 1);
  11273. }
  11274. return v;
  11275. });
  11276. //copy the temporary array back into the main this.items and this.keys objects
  11277. for(i = 0, len = c.length; i < len; i++){
  11278. items[i] = c[i].value;
  11279. keys[i] = c[i].key;
  11280. }
  11281. this.fireEvent('sort', this);
  11282. },
  11283. /**
  11284. * Sorts this collection by <b>item</b> value with the passed comparison function.
  11285. * @param {String} direction (optional) 'ASC' or 'DESC'. Defaults to 'ASC'.
  11286. * @param {Function} fn (optional) Comparison function that defines the sort order.
  11287. * Defaults to sorting by numeric value.
  11288. */
  11289. sort : function(dir, fn){
  11290. this._sort('value', dir, fn);
  11291. },
  11292. /**
  11293. * Reorders each of the items based on a mapping from old index to new index. Internally this
  11294. * just translates into a sort. The 'sort' event is fired whenever reordering has occured.
  11295. * @param {Object} mapping Mapping from old item index to new item index
  11296. */
  11297. reorder: function(mapping) {
  11298. this.suspendEvents();
  11299. var items = this.items,
  11300. index = 0,
  11301. length = items.length,
  11302. order = [],
  11303. remaining = [];
  11304. //object of {oldPosition: newPosition} reversed to {newPosition: oldPosition}
  11305. for (oldIndex in mapping) {
  11306. order[mapping[oldIndex]] = items[oldIndex];
  11307. }
  11308. for (index = 0; index < length; index++) {
  11309. if (mapping[index] == undefined) {
  11310. remaining.push(items[index]);
  11311. }
  11312. }
  11313. for (index = 0; index < length; index++) {
  11314. if (order[index] == undefined) {
  11315. order[index] = remaining.shift();
  11316. }
  11317. }
  11318. this.clear();
  11319. this.addAll(order);
  11320. this.resumeEvents();
  11321. this.fireEvent('sort', this);
  11322. },
  11323. /**
  11324. * Sorts this collection by <b>key</b>s.
  11325. * @param {String} direction (optional) 'ASC' or 'DESC'. Defaults to 'ASC'.
  11326. * @param {Function} fn (optional) Comparison function that defines the sort order.
  11327. * Defaults to sorting by case insensitive string.
  11328. */
  11329. keySort : function(dir, fn){
  11330. this._sort('key', dir, fn || function(a, b){
  11331. var v1 = String(a).toUpperCase(), v2 = String(b).toUpperCase();
  11332. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  11333. });
  11334. },
  11335. /**
  11336. * Returns a range of items in this collection
  11337. * @param {Number} startIndex (optional) The starting index. Defaults to 0.
  11338. * @param {Number} endIndex (optional) The ending index. Defaults to the last item.
  11339. * @return {Array} An array of items
  11340. */
  11341. getRange : function(start, end){
  11342. var items = this.items;
  11343. if(items.length < 1){
  11344. return [];
  11345. }
  11346. start = start || 0;
  11347. end = Math.min(typeof end == 'undefined' ? this.length-1 : end, this.length-1);
  11348. var i, r = [];
  11349. if(start <= end){
  11350. for(i = start; i <= end; i++) {
  11351. r[r.length] = items[i];
  11352. }
  11353. }else{
  11354. for(i = start; i >= end; i--) {
  11355. r[r.length] = items[i];
  11356. }
  11357. }
  11358. return r;
  11359. },
  11360. /**
  11361. * Filter the <i>objects</i> in this collection by a specific property.
  11362. * Returns a new collection that has been filtered.
  11363. * @param {String} property A property on your objects
  11364. * @param {String/RegExp} value Either string that the property values
  11365. * should start with or a RegExp to test against the property
  11366. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
  11367. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison (defaults to False).
  11368. * @return {MixedCollection} The new filtered collection
  11369. */
  11370. filter : function(property, value, anyMatch, caseSensitive){
  11371. if(Ext.isEmpty(value, false)){
  11372. return this.clone();
  11373. }
  11374. value = this.createValueMatcher(value, anyMatch, caseSensitive);
  11375. return this.filterBy(function(o){
  11376. return o && value.test(o[property]);
  11377. });
  11378. },
  11379. /**
  11380. * Filter by a function. Returns a <i>new</i> collection that has been filtered.
  11381. * The passed function will be called with each object in the collection.
  11382. * If the function returns true, the value is included otherwise it is filtered.
  11383. * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
  11384. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this MixedCollection.
  11385. * @return {MixedCollection} The new filtered collection
  11386. */
  11387. filterBy : function(fn, scope){
  11388. var r = new Ext.util.MixedCollection();
  11389. r.getKey = this.getKey;
  11390. var k = this.keys, it = this.items;
  11391. for(var i = 0, len = it.length; i < len; i++){
  11392. if(fn.call(scope||this, it[i], k[i])){
  11393. r.add(k[i], it[i]);
  11394. }
  11395. }
  11396. return r;
  11397. },
  11398. /**
  11399. * Finds the index of the first matching object in this collection by a specific property/value.
  11400. * @param {String} property The name of a property on your objects.
  11401. * @param {String/RegExp} value A string that the property values
  11402. * should start with or a RegExp to test against the property.
  11403. * @param {Number} start (optional) The index to start searching at (defaults to 0).
  11404. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning.
  11405. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison.
  11406. * @return {Number} The matched index or -1
  11407. */
  11408. findIndex : function(property, value, start, anyMatch, caseSensitive){
  11409. if(Ext.isEmpty(value, false)){
  11410. return -1;
  11411. }
  11412. value = this.createValueMatcher(value, anyMatch, caseSensitive);
  11413. return this.findIndexBy(function(o){
  11414. return o && value.test(o[property]);
  11415. }, null, start);
  11416. },
  11417. /**
  11418. * Find the index of the first matching object in this collection by a function.
  11419. * If the function returns <i>true</i> it is considered a match.
  11420. * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key).
  11421. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this MixedCollection.
  11422. * @param {Number} start (optional) The index to start searching at (defaults to 0).
  11423. * @return {Number} The matched index or -1
  11424. */
  11425. findIndexBy : function(fn, scope, start){
  11426. var k = this.keys, it = this.items;
  11427. for(var i = (start||0), len = it.length; i < len; i++){
  11428. if(fn.call(scope||this, it[i], k[i])){
  11429. return i;
  11430. }
  11431. }
  11432. return -1;
  11433. },
  11434. /**
  11435. * Returns a regular expression based on the given value and matching options. This is used internally for finding and filtering,
  11436. * and by Ext.data.Store#filter
  11437. * @private
  11438. * @param {String} value The value to create the regex for. This is escaped using Ext.escapeRe
  11439. * @param {Boolean} anyMatch True to allow any match - no regex start/end line anchors will be added. Defaults to false
  11440. * @param {Boolean} caseSensitive True to make the regex case sensitive (adds 'i' switch to regex). Defaults to false.
  11441. * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
  11442. */
  11443. createValueMatcher : function(value, anyMatch, caseSensitive, exactMatch) {
  11444. if (!value.exec) { // not a regex
  11445. var er = Ext.escapeRe;
  11446. value = String(value);
  11447. if (anyMatch === true) {
  11448. value = er(value);
  11449. } else {
  11450. value = '^' + er(value);
  11451. if (exactMatch === true) {
  11452. value += '$';
  11453. }
  11454. }
  11455. value = new RegExp(value, caseSensitive ? '' : 'i');
  11456. }
  11457. return value;
  11458. },
  11459. /**
  11460. * Creates a shallow copy of this collection
  11461. * @return {MixedCollection}
  11462. */
  11463. clone : function(){
  11464. var r = new Ext.util.MixedCollection();
  11465. var k = this.keys, it = this.items;
  11466. for(var i = 0, len = it.length; i < len; i++){
  11467. r.add(k[i], it[i]);
  11468. }
  11469. r.getKey = this.getKey;
  11470. return r;
  11471. }
  11472. });
  11473. /**
  11474. * This method calls {@link #item item()}.
  11475. * Returns the item associated with the passed key OR index. Key has priority
  11476. * over index. This is the equivalent of calling {@link #key} first, then if
  11477. * nothing matched calling {@link #itemAt}.
  11478. * @param {String/Number} key The key or index of the item.
  11479. * @return {Object} If the item is found, returns the item. If the item was
  11480. * not found, returns <tt>undefined</tt>. If an item was found, but is a Class,
  11481. * returns <tt>null</tt>.
  11482. */
  11483. Ext.util.MixedCollection.prototype.get = Ext.util.MixedCollection.prototype.item;/**
  11484. * @class Ext.util.JSON
  11485. * Modified version of Douglas Crockford"s json.js that doesn"t
  11486. * mess with the Object prototype
  11487. * http://www.json.org/js.html
  11488. * @singleton
  11489. */
  11490. Ext.util.JSON = new (function(){
  11491. var useHasOwn = !!{}.hasOwnProperty,
  11492. isNative = function() {
  11493. var useNative = null;
  11494. return function() {
  11495. if (useNative === null) {
  11496. useNative = Ext.USE_NATIVE_JSON && window.JSON && JSON.toString() == '[object JSON]';
  11497. }
  11498. return useNative;
  11499. };
  11500. }(),
  11501. pad = function(n) {
  11502. return n < 10 ? "0" + n : n;
  11503. },
  11504. doDecode = function(json){
  11505. return eval("(" + json + ')');
  11506. },
  11507. doEncode = function(o){
  11508. if(!Ext.isDefined(o) || o === null){
  11509. return "null";
  11510. }else if(Ext.isArray(o)){
  11511. return encodeArray(o);
  11512. }else if(Ext.isDate(o)){
  11513. return Ext.util.JSON.encodeDate(o);
  11514. }else if(Ext.isString(o)){
  11515. return encodeString(o);
  11516. }else if(typeof o == "number"){
  11517. //don't use isNumber here, since finite checks happen inside isNumber
  11518. return isFinite(o) ? String(o) : "null";
  11519. }else if(Ext.isBoolean(o)){
  11520. return String(o);
  11521. }else {
  11522. var a = ["{"], b, i, v;
  11523. for (i in o) {
  11524. // don't encode DOM objects
  11525. if(!o.getElementsByTagName){
  11526. if(!useHasOwn || o.hasOwnProperty(i)) {
  11527. v = o[i];
  11528. switch (typeof v) {
  11529. case "undefined":
  11530. case "function":
  11531. case "unknown":
  11532. break;
  11533. default:
  11534. if(b){
  11535. a.push(',');
  11536. }
  11537. a.push(doEncode(i), ":",
  11538. v === null ? "null" : doEncode(v));
  11539. b = true;
  11540. }
  11541. }
  11542. }
  11543. }
  11544. a.push("}");
  11545. return a.join("");
  11546. }
  11547. },
  11548. m = {
  11549. "\b": '\\b',
  11550. "\t": '\\t',
  11551. "\n": '\\n',
  11552. "\f": '\\f',
  11553. "\r": '\\r',
  11554. '"' : '\\"',
  11555. "\\": '\\\\'
  11556. },
  11557. encodeString = function(s){
  11558. if (/["\\\x00-\x1f]/.test(s)) {
  11559. return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
  11560. var c = m[b];
  11561. if(c){
  11562. return c;
  11563. }
  11564. c = b.charCodeAt();
  11565. return "\\u00" +
  11566. Math.floor(c / 16).toString(16) +
  11567. (c % 16).toString(16);
  11568. }) + '"';
  11569. }
  11570. return '"' + s + '"';
  11571. },
  11572. encodeArray = function(o){
  11573. var a = ["["], b, i, l = o.length, v;
  11574. for (i = 0; i < l; i += 1) {
  11575. v = o[i];
  11576. switch (typeof v) {
  11577. case "undefined":
  11578. case "function":
  11579. case "unknown":
  11580. break;
  11581. default:
  11582. if (b) {
  11583. a.push(',');
  11584. }
  11585. a.push(v === null ? "null" : Ext.util.JSON.encode(v));
  11586. b = true;
  11587. }
  11588. }
  11589. a.push("]");
  11590. return a.join("");
  11591. };
  11592. /**
  11593. * <p>Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal expression.
  11594. * <b>The returned value includes enclosing double quotation marks.</b></p>
  11595. * <p>The default return format is "yyyy-mm-ddThh:mm:ss".</p>
  11596. * <p>To override this:</p><pre><code>
  11597. Ext.util.JSON.encodeDate = function(d) {
  11598. return d.format('"Y-m-d"');
  11599. };
  11600. </code></pre>
  11601. * @param {Date} d The Date to encode
  11602. * @return {String} The string literal to use in a JSON string.
  11603. */
  11604. this.encodeDate = function(o){
  11605. return '"' + o.getFullYear() + "-" +
  11606. pad(o.getMonth() + 1) + "-" +
  11607. pad(o.getDate()) + "T" +
  11608. pad(o.getHours()) + ":" +
  11609. pad(o.getMinutes()) + ":" +
  11610. pad(o.getSeconds()) + '"';
  11611. };
  11612. /**
  11613. * Encodes an Object, Array or other value
  11614. * @param {Mixed} o The variable to encode
  11615. * @return {String} The JSON string
  11616. */
  11617. this.encode = function() {
  11618. var ec;
  11619. return function(o) {
  11620. if (!ec) {
  11621. // setup encoding function on first access
  11622. ec = isNative() ? JSON.stringify : doEncode;
  11623. }
  11624. return ec(o);
  11625. };
  11626. }();
  11627. /**
  11628. * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError unless the safe option is set.
  11629. * @param {String} json The JSON string
  11630. * @return {Object} The resulting object
  11631. */
  11632. this.decode = function() {
  11633. var dc;
  11634. return function(json) {
  11635. if (!dc) {
  11636. // setup decoding function on first access
  11637. dc = isNative() ? JSON.parse : doDecode;
  11638. }
  11639. return dc(json);
  11640. };
  11641. }();
  11642. })();
  11643. /**
  11644. * Shorthand for {@link Ext.util.JSON#encode}
  11645. * @param {Mixed} o The variable to encode
  11646. * @return {String} The JSON string
  11647. * @member Ext
  11648. * @method encode
  11649. */
  11650. Ext.encode = Ext.util.JSON.encode;
  11651. /**
  11652. * Shorthand for {@link Ext.util.JSON#decode}
  11653. * @param {String} json The JSON string
  11654. * @param {Boolean} safe (optional) Whether to return null or throw an exception if the JSON is invalid.
  11655. * @return {Object} The resulting object
  11656. * @member Ext
  11657. * @method decode
  11658. */
  11659. Ext.decode = Ext.util.JSON.decode;
  11660. /**
  11661. * @class Ext.util.Format
  11662. * Reusable data formatting functions
  11663. * @singleton
  11664. */
  11665. Ext.util.Format = function(){
  11666. var trimRe = /^\s+|\s+$/g,
  11667. stripTagsRE = /<\/?[^>]+>/gi,
  11668. stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  11669. nl2brRe = /\r?\n/g;
  11670. return {
  11671. /**
  11672. * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
  11673. * @param {String} value The string to truncate
  11674. * @param {Number} length The maximum length to allow before truncating
  11675. * @param {Boolean} word True to try to find a common work break
  11676. * @return {String} The converted text
  11677. */
  11678. ellipsis : function(value, len, word){
  11679. if(value && value.length > len){
  11680. if(word){
  11681. var vs = value.substr(0, len - 2),
  11682. index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
  11683. if(index == -1 || index < (len - 15)){
  11684. return value.substr(0, len - 3) + "...";
  11685. }else{
  11686. return vs.substr(0, index) + "...";
  11687. }
  11688. } else{
  11689. return value.substr(0, len - 3) + "...";
  11690. }
  11691. }
  11692. return value;
  11693. },
  11694. /**
  11695. * Checks a reference and converts it to empty string if it is undefined
  11696. * @param {Mixed} value Reference to check
  11697. * @return {Mixed} Empty string if converted, otherwise the original value
  11698. */
  11699. undef : function(value){
  11700. return value !== undefined ? value : "";
  11701. },
  11702. /**
  11703. * Checks a reference and converts it to the default value if it's empty
  11704. * @param {Mixed} value Reference to check
  11705. * @param {String} defaultValue The value to insert of it's undefined (defaults to "")
  11706. * @return {String}
  11707. */
  11708. defaultValue : function(value, defaultValue){
  11709. return value !== undefined && value !== '' ? value : defaultValue;
  11710. },
  11711. /**
  11712. * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
  11713. * @param {String} value The string to encode
  11714. * @return {String} The encoded text
  11715. */
  11716. htmlEncode : function(value){
  11717. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
  11718. },
  11719. /**
  11720. * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
  11721. * @param {String} value The string to decode
  11722. * @return {String} The decoded text
  11723. */
  11724. htmlDecode : function(value){
  11725. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  11726. },
  11727. /**
  11728. * Trims any whitespace from either side of a string
  11729. * @param {String} value The text to trim
  11730. * @return {String} The trimmed text
  11731. */
  11732. trim : function(value){
  11733. return String(value).replace(trimRe, "");
  11734. },
  11735. /**
  11736. * Returns a substring from within an original string
  11737. * @param {String} value The original text
  11738. * @param {Number} start The start index of the substring
  11739. * @param {Number} length The length of the substring
  11740. * @return {String} The substring
  11741. */
  11742. substr : function(value, start, length){
  11743. return String(value).substr(start, length);
  11744. },
  11745. /**
  11746. * Converts a string to all lower case letters
  11747. * @param {String} value The text to convert
  11748. * @return {String} The converted text
  11749. */
  11750. lowercase : function(value){
  11751. return String(value).toLowerCase();
  11752. },
  11753. /**
  11754. * Converts a string to all upper case letters
  11755. * @param {String} value The text to convert
  11756. * @return {String} The converted text
  11757. */
  11758. uppercase : function(value){
  11759. return String(value).toUpperCase();
  11760. },
  11761. /**
  11762. * Converts the first character only of a string to upper case
  11763. * @param {String} value The text to convert
  11764. * @return {String} The converted text
  11765. */
  11766. capitalize : function(value){
  11767. return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
  11768. },
  11769. // private
  11770. call : function(value, fn){
  11771. if(arguments.length > 2){
  11772. var args = Array.prototype.slice.call(arguments, 2);
  11773. args.unshift(value);
  11774. return eval(fn).apply(window, args);
  11775. }else{
  11776. return eval(fn).call(window, value);
  11777. }
  11778. },
  11779. /**
  11780. * Format a number as US currency
  11781. * @param {Number/String} value The numeric value to format
  11782. * @return {String} The formatted currency string
  11783. */
  11784. usMoney : function(v){
  11785. v = (Math.round((v-0)*100))/100;
  11786. v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
  11787. v = String(v);
  11788. var ps = v.split('.'),
  11789. whole = ps[0],
  11790. sub = ps[1] ? '.'+ ps[1] : '.00',
  11791. r = /(\d+)(\d{3})/;
  11792. while (r.test(whole)) {
  11793. whole = whole.replace(r, '$1' + ',' + '$2');
  11794. }
  11795. v = whole + sub;
  11796. if(v.charAt(0) == '-'){
  11797. return '-$' + v.substr(1);
  11798. }
  11799. return "$" + v;
  11800. },
  11801. /**
  11802. * Parse a value into a formatted date using the specified format pattern.
  11803. * @param {String/Date} value The value to format (Strings must conform to the format expected by the javascript Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method)
  11804. * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
  11805. * @return {String} The formatted date string
  11806. */
  11807. date : function(v, format){
  11808. if(!v){
  11809. return "";
  11810. }
  11811. if(!Ext.isDate(v)){
  11812. v = new Date(Date.parse(v));
  11813. }
  11814. return v.dateFormat(format || "m/d/Y");
  11815. },
  11816. /**
  11817. * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
  11818. * @param {String} format Any valid date format string
  11819. * @return {Function} The date formatting function
  11820. */
  11821. dateRenderer : function(format){
  11822. return function(v){
  11823. return Ext.util.Format.date(v, format);
  11824. };
  11825. },
  11826. /**
  11827. * Strips all HTML tags
  11828. * @param {Mixed} value The text from which to strip tags
  11829. * @return {String} The stripped text
  11830. */
  11831. stripTags : function(v){
  11832. return !v ? v : String(v).replace(stripTagsRE, "");
  11833. },
  11834. /**
  11835. * Strips all script tags
  11836. * @param {Mixed} value The text from which to strip script tags
  11837. * @return {String} The stripped text
  11838. */
  11839. stripScripts : function(v){
  11840. return !v ? v : String(v).replace(stripScriptsRe, "");
  11841. },
  11842. /**
  11843. * Simple format for a file size (xxx bytes, xxx KB, xxx MB)
  11844. * @param {Number/String} size The numeric value to format
  11845. * @return {String} The formatted file size
  11846. */
  11847. fileSize : function(size){
  11848. if(size < 1024) {
  11849. return size + " bytes";
  11850. } else if(size < 1048576) {
  11851. return (Math.round(((size*10) / 1024))/10) + " KB";
  11852. } else {
  11853. return (Math.round(((size*10) / 1048576))/10) + " MB";
  11854. }
  11855. },
  11856. /**
  11857. * It does simple math for use in a template, for example:<pre><code>
  11858. * var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
  11859. * </code></pre>
  11860. * @return {Function} A function that operates on the passed value.
  11861. */
  11862. math : function(){
  11863. var fns = {};
  11864. return function(v, a){
  11865. if(!fns[a]){
  11866. fns[a] = new Function('v', 'return v ' + a + ';');
  11867. }
  11868. return fns[a](v);
  11869. }
  11870. }(),
  11871. /**
  11872. * Rounds the passed number to the required decimal precision.
  11873. * @param {Number/String} value The numeric value to round.
  11874. * @param {Number} precision The number of decimal places to which to round the first parameter's value.
  11875. * @return {Number} The rounded value.
  11876. */
  11877. round : function(value, precision) {
  11878. var result = Number(value);
  11879. if (typeof precision == 'number') {
  11880. precision = Math.pow(10, precision);
  11881. result = Math.round(value * precision) / precision;
  11882. }
  11883. return result;
  11884. },
  11885. /**
  11886. * Formats the number according to the format string.
  11887. * <div style="margin-left:40px">examples (123456.789):
  11888. * <div style="margin-left:10px">
  11889. * 0 - (123456) show only digits, no precision<br>
  11890. * 0.00 - (123456.78) show only digits, 2 precision<br>
  11891. * 0.0000 - (123456.7890) show only digits, 4 precision<br>
  11892. * 0,000 - (123,456) show comma and digits, no precision<br>
  11893. * 0,000.00 - (123,456.78) show comma and digits, 2 precision<br>
  11894. * 0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision<br>
  11895. * To reverse the grouping (,) and decimal (.) for international numbers, add /i to the end.
  11896. * For example: 0.000,00/i
  11897. * </div></div>
  11898. * @param {Number} v The number to format.
  11899. * @param {String} format The way you would like to format this text.
  11900. * @return {String} The formatted number.
  11901. */
  11902. number: function(v, format) {
  11903. if(!format){
  11904. return v;
  11905. }
  11906. v = Ext.num(v, NaN);
  11907. if (isNaN(v)){
  11908. return '';
  11909. }
  11910. var comma = ',',
  11911. dec = '.',
  11912. i18n = false,
  11913. neg = v < 0;
  11914. v = Math.abs(v);
  11915. if(format.substr(format.length - 2) == '/i'){
  11916. format = format.substr(0, format.length - 2);
  11917. i18n = true;
  11918. comma = '.';
  11919. dec = ',';
  11920. }
  11921. var hasComma = format.indexOf(comma) != -1,
  11922. psplit = (i18n ? format.replace(/[^\d\,]/g, '') : format.replace(/[^\d\.]/g, '')).split(dec);
  11923. if(1 < psplit.length){
  11924. v = v.toFixed(psplit[1].length);
  11925. }else if(2 < psplit.length){
  11926. throw ('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);
  11927. }else{
  11928. v = v.toFixed(0);
  11929. }
  11930. var fnum = v.toString();
  11931. psplit = fnum.split('.');
  11932. if (hasComma) {
  11933. var cnum = psplit[0], parr = [], j = cnum.length, m = Math.floor(j / 3), n = cnum.length % 3 || 3;
  11934. for (var i = 0; i < j; i += n) {
  11935. if (i != 0) {
  11936. n = 3;
  11937. }
  11938. parr[parr.length] = cnum.substr(i, n);
  11939. m -= 1;
  11940. }
  11941. fnum = parr.join(comma);
  11942. if (psplit[1]) {
  11943. fnum += dec + psplit[1];
  11944. }
  11945. } else {
  11946. if (psplit[1]) {
  11947. fnum = psplit[0] + dec + psplit[1];
  11948. }
  11949. }
  11950. return (neg ? '-' : '') + format.replace(/[\d,?\.?]+/, fnum);
  11951. },
  11952. /**
  11953. * Returns a number rendering function that can be reused to apply a number format multiple times efficiently
  11954. * @param {String} format Any valid number format string for {@link #number}
  11955. * @return {Function} The number formatting function
  11956. */
  11957. numberRenderer : function(format){
  11958. return function(v){
  11959. return Ext.util.Format.number(v, format);
  11960. };
  11961. },
  11962. /**
  11963. * Selectively do a plural form of a word based on a numeric value. For example, in a template,
  11964. * {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments"
  11965. * if the value is 0 or greater than 1.
  11966. * @param {Number} value The value to compare against
  11967. * @param {String} singular The singular form of the word
  11968. * @param {String} plural (optional) The plural form of the word (defaults to the singular with an "s")
  11969. */
  11970. plural : function(v, s, p){
  11971. return v +' ' + (v == 1 ? s : (p ? p : s+'s'));
  11972. },
  11973. /**
  11974. * Converts newline characters to the HTML tag &lt;br/>
  11975. * @param {String} The string value to format.
  11976. * @return {String} The string with embedded &lt;br/> tags in place of newlines.
  11977. */
  11978. nl2br : function(v){
  11979. return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');
  11980. }
  11981. }
  11982. }();
  11983. /**
  11984. * @class Ext.XTemplate
  11985. * @extends Ext.Template
  11986. * <p>A template class that supports advanced functionality like:<div class="mdetail-params"><ul>
  11987. * <li>Autofilling arrays using templates and sub-templates</li>
  11988. * <li>Conditional processing with basic comparison operators</li>
  11989. * <li>Basic math function support</li>
  11990. * <li>Execute arbitrary inline code with special built-in template variables</li>
  11991. * <li>Custom member functions</li>
  11992. * <li>Many special tags and built-in operators that aren't defined as part of
  11993. * the API, but are supported in the templates that can be created</li>
  11994. * </ul></div></p>
  11995. * <p>XTemplate provides the templating mechanism built into:<div class="mdetail-params"><ul>
  11996. * <li>{@link Ext.DataView}</li>
  11997. * <li>{@link Ext.ListView}</li>
  11998. * <li>{@link Ext.form.ComboBox}</li>
  11999. * <li>{@link Ext.grid.TemplateColumn}</li>
  12000. * <li>{@link Ext.grid.GroupingView}</li>
  12001. * <li>{@link Ext.menu.Item}</li>
  12002. * <li>{@link Ext.layout.MenuLayout}</li>
  12003. * <li>{@link Ext.ColorPalette}</li>
  12004. * </ul></div></p>
  12005. *
  12006. * <p>For example usage {@link #XTemplate see the constructor}.</p>
  12007. *
  12008. * @constructor
  12009. * The {@link Ext.Template#Template Ext.Template constructor} describes
  12010. * the acceptable parameters to pass to the constructor. The following
  12011. * examples demonstrate all of the supported features.</p>
  12012. *
  12013. * <div class="mdetail-params"><ul>
  12014. *
  12015. * <li><b><u>Sample Data</u></b>
  12016. * <div class="sub-desc">
  12017. * <p>This is the data object used for reference in each code example:</p>
  12018. * <pre><code>
  12019. var data = {
  12020. name: 'Jack Slocum',
  12021. title: 'Lead Developer',
  12022. company: 'Ext JS, LLC',
  12023. email: 'jack@extjs.com',
  12024. address: '4 Red Bulls Drive',
  12025. city: 'Cleveland',
  12026. state: 'Ohio',
  12027. zip: '44102',
  12028. drinks: ['Red Bull', 'Coffee', 'Water'],
  12029. kids: [{
  12030. name: 'Sara Grace',
  12031. age:3
  12032. },{
  12033. name: 'Zachary',
  12034. age:2
  12035. },{
  12036. name: 'John James',
  12037. age:0
  12038. }]
  12039. };
  12040. * </code></pre>
  12041. * </div>
  12042. * </li>
  12043. *
  12044. *
  12045. * <li><b><u>Auto filling of arrays</u></b>
  12046. * <div class="sub-desc">
  12047. * <p>The <b><tt>tpl</tt></b> tag and the <b><tt>for</tt></b> operator are used
  12048. * to process the provided data object:
  12049. * <ul>
  12050. * <li>If the value specified in <tt>for</tt> is an array, it will auto-fill,
  12051. * repeating the template block inside the <tt>tpl</tt> tag for each item in the
  12052. * array.</li>
  12053. * <li>If <tt>for="."</tt> is specified, the data object provided is examined.</li>
  12054. * <li>While processing an array, the special variable <tt>{#}</tt>
  12055. * will provide the current array index + 1 (starts at 1, not 0).</li>
  12056. * </ul>
  12057. * </p>
  12058. * <pre><code>
  12059. &lt;tpl <b>for</b>=".">...&lt;/tpl> // loop through array at root node
  12060. &lt;tpl <b>for</b>="foo">...&lt;/tpl> // loop through array at foo node
  12061. &lt;tpl <b>for</b>="foo.bar">...&lt;/tpl> // loop through array at foo.bar node
  12062. * </code></pre>
  12063. * Using the sample data above:
  12064. * <pre><code>
  12065. var tpl = new Ext.XTemplate(
  12066. '&lt;p>Kids: ',
  12067. '&lt;tpl <b>for</b>=".">', // process the data.kids node
  12068. '&lt;p>{#}. {name}&lt;/p>', // use current array index to autonumber
  12069. '&lt;/tpl>&lt;/p>'
  12070. );
  12071. tpl.overwrite(panel.body, data.kids); // pass the kids property of the data object
  12072. * </code></pre>
  12073. * <p>An example illustrating how the <b><tt>for</tt></b> property can be leveraged
  12074. * to access specified members of the provided data object to populate the template:</p>
  12075. * <pre><code>
  12076. var tpl = new Ext.XTemplate(
  12077. '&lt;p>Name: {name}&lt;/p>',
  12078. '&lt;p>Title: {title}&lt;/p>',
  12079. '&lt;p>Company: {company}&lt;/p>',
  12080. '&lt;p>Kids: ',
  12081. '&lt;tpl <b>for="kids"</b>>', // interrogate the kids property within the data
  12082. '&lt;p>{name}&lt;/p>',
  12083. '&lt;/tpl>&lt;/p>'
  12084. );
  12085. tpl.overwrite(panel.body, data); // pass the root node of the data object
  12086. * </code></pre>
  12087. * <p>Flat arrays that contain values (and not objects) can be auto-rendered
  12088. * using the special <b><tt>{.}</tt></b> variable inside a loop. This variable
  12089. * will represent the value of the array at the current index:</p>
  12090. * <pre><code>
  12091. var tpl = new Ext.XTemplate(
  12092. '&lt;p>{name}\&#39;s favorite beverages:&lt;/p>',
  12093. '&lt;tpl for="drinks">',
  12094. '&lt;div> - {.}&lt;/div>',
  12095. '&lt;/tpl>'
  12096. );
  12097. tpl.overwrite(panel.body, data);
  12098. * </code></pre>
  12099. * <p>When processing a sub-template, for example while looping through a child array,
  12100. * you can access the parent object's members via the <b><tt>parent</tt></b> object:</p>
  12101. * <pre><code>
  12102. var tpl = new Ext.XTemplate(
  12103. '&lt;p>Name: {name}&lt;/p>',
  12104. '&lt;p>Kids: ',
  12105. '&lt;tpl for="kids">',
  12106. '&lt;tpl if="age > 1">',
  12107. '&lt;p>{name}&lt;/p>',
  12108. '&lt;p>Dad: {<b>parent</b>.name}&lt;/p>',
  12109. '&lt;/tpl>',
  12110. '&lt;/tpl>&lt;/p>'
  12111. );
  12112. tpl.overwrite(panel.body, data);
  12113. * </code></pre>
  12114. * </div>
  12115. * </li>
  12116. *
  12117. *
  12118. * <li><b><u>Conditional processing with basic comparison operators</u></b>
  12119. * <div class="sub-desc">
  12120. * <p>The <b><tt>tpl</tt></b> tag and the <b><tt>if</tt></b> operator are used
  12121. * to provide conditional checks for deciding whether or not to render specific
  12122. * parts of the template. Notes:<div class="sub-desc"><ul>
  12123. * <li>Double quotes must be encoded if used within the conditional</li>
  12124. * <li>There is no <tt>else</tt> operator &mdash; if needed, two opposite
  12125. * <tt>if</tt> statements should be used.</li>
  12126. * </ul></div>
  12127. * <pre><code>
  12128. &lt;tpl if="age &gt; 1 &amp;&amp; age &lt; 10">Child&lt;/tpl>
  12129. &lt;tpl if="age >= 10 && age < 18">Teenager&lt;/tpl>
  12130. &lt;tpl <b>if</b>="this.isGirl(name)">...&lt;/tpl>
  12131. &lt;tpl <b>if</b>="id==\'download\'">...&lt;/tpl>
  12132. &lt;tpl <b>if</b>="needsIcon">&lt;img src="{icon}" class="{iconCls}"/>&lt;/tpl>
  12133. // no good:
  12134. &lt;tpl if="name == "Jack"">Hello&lt;/tpl>
  12135. // encode &#34; if it is part of the condition, e.g.
  12136. &lt;tpl if="name == &#38;quot;Jack&#38;quot;">Hello&lt;/tpl>
  12137. * </code></pre>
  12138. * Using the sample data above:
  12139. * <pre><code>
  12140. var tpl = new Ext.XTemplate(
  12141. '&lt;p>Name: {name}&lt;/p>',
  12142. '&lt;p>Kids: ',
  12143. '&lt;tpl for="kids">',
  12144. '&lt;tpl if="age > 1">',
  12145. '&lt;p>{name}&lt;/p>',
  12146. '&lt;/tpl>',
  12147. '&lt;/tpl>&lt;/p>'
  12148. );
  12149. tpl.overwrite(panel.body, data);
  12150. * </code></pre>
  12151. * </div>
  12152. * </li>
  12153. *
  12154. *
  12155. * <li><b><u>Basic math support</u></b>
  12156. * <div class="sub-desc">
  12157. * <p>The following basic math operators may be applied directly on numeric
  12158. * data values:</p><pre>
  12159. * + - * /
  12160. * </pre>
  12161. * For example:
  12162. * <pre><code>
  12163. var tpl = new Ext.XTemplate(
  12164. '&lt;p>Name: {name}&lt;/p>',
  12165. '&lt;p>Kids: ',
  12166. '&lt;tpl for="kids">',
  12167. '&lt;tpl if="age &amp;gt; 1">', // <-- Note that the &gt; is encoded
  12168. '&lt;p>{#}: {name}&lt;/p>', // <-- Auto-number each item
  12169. '&lt;p>In 5 Years: {age+5}&lt;/p>', // <-- Basic math
  12170. '&lt;p>Dad: {parent.name}&lt;/p>',
  12171. '&lt;/tpl>',
  12172. '&lt;/tpl>&lt;/p>'
  12173. );
  12174. tpl.overwrite(panel.body, data);
  12175. </code></pre>
  12176. * </div>
  12177. * </li>
  12178. *
  12179. *
  12180. * <li><b><u>Execute arbitrary inline code with special built-in template variables</u></b>
  12181. * <div class="sub-desc">
  12182. * <p>Anything between <code>{[ ... ]}</code> is considered code to be executed
  12183. * in the scope of the template. There are some special variables available in that code:
  12184. * <ul>
  12185. * <li><b><tt>values</tt></b>: The values in the current scope. If you are using
  12186. * scope changing sub-templates, you can change what <tt>values</tt> is.</li>
  12187. * <li><b><tt>parent</tt></b>: The scope (values) of the ancestor template.</li>
  12188. * <li><b><tt>xindex</tt></b>: If you are in a looping template, the index of the
  12189. * loop you are in (1-based).</li>
  12190. * <li><b><tt>xcount</tt></b>: If you are in a looping template, the total length
  12191. * of the array you are looping.</li>
  12192. * <li><b><tt>fm</tt></b>: An alias for <tt>Ext.util.Format</tt>.</li>
  12193. * </ul>
  12194. * This example demonstrates basic row striping using an inline code block and the
  12195. * <tt>xindex</tt> variable:</p>
  12196. * <pre><code>
  12197. var tpl = new Ext.XTemplate(
  12198. '&lt;p>Name: {name}&lt;/p>',
  12199. '&lt;p>Company: {[values.company.toUpperCase() + ", " + values.title]}&lt;/p>',
  12200. '&lt;p>Kids: ',
  12201. '&lt;tpl for="kids">',
  12202. '&lt;div class="{[xindex % 2 === 0 ? "even" : "odd"]}">',
  12203. '{name}',
  12204. '&lt;/div>',
  12205. '&lt;/tpl>&lt;/p>'
  12206. );
  12207. tpl.overwrite(panel.body, data);
  12208. * </code></pre>
  12209. * </div>
  12210. * </li>
  12211. *
  12212. * <li><b><u>Template member functions</u></b>
  12213. * <div class="sub-desc">
  12214. * <p>One or more member functions can be specified in a configuration
  12215. * object passed into the XTemplate constructor for more complex processing:</p>
  12216. * <pre><code>
  12217. var tpl = new Ext.XTemplate(
  12218. '&lt;p>Name: {name}&lt;/p>',
  12219. '&lt;p>Kids: ',
  12220. '&lt;tpl for="kids">',
  12221. '&lt;tpl if="this.isGirl(name)">',
  12222. '&lt;p>Girl: {name} - {age}&lt;/p>',
  12223. '&lt;/tpl>',
  12224. // use opposite if statement to simulate 'else' processing:
  12225. '&lt;tpl if="this.isGirl(name) == false">',
  12226. '&lt;p>Boy: {name} - {age}&lt;/p>',
  12227. '&lt;/tpl>',
  12228. '&lt;tpl if="this.isBaby(age)">',
  12229. '&lt;p>{name} is a baby!&lt;/p>',
  12230. '&lt;/tpl>',
  12231. '&lt;/tpl>&lt;/p>',
  12232. {
  12233. // XTemplate configuration:
  12234. compiled: true,
  12235. disableFormats: true,
  12236. // member functions:
  12237. isGirl: function(name){
  12238. return name == 'Sara Grace';
  12239. },
  12240. isBaby: function(age){
  12241. return age < 1;
  12242. }
  12243. }
  12244. );
  12245. tpl.overwrite(panel.body, data);
  12246. * </code></pre>
  12247. * </div>
  12248. * </li>
  12249. *
  12250. * </ul></div>
  12251. *
  12252. * @param {Mixed} config
  12253. */
  12254. Ext.XTemplate = function(){
  12255. Ext.XTemplate.superclass.constructor.apply(this, arguments);
  12256. var me = this,
  12257. s = me.html,
  12258. re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
  12259. nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
  12260. ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
  12261. execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
  12262. m,
  12263. id = 0,
  12264. tpls = [],
  12265. VALUES = 'values',
  12266. PARENT = 'parent',
  12267. XINDEX = 'xindex',
  12268. XCOUNT = 'xcount',
  12269. RETURN = 'return ',
  12270. WITHVALUES = 'with(values){ ';
  12271. s = ['<tpl>', s, '</tpl>'].join('');
  12272. while((m = s.match(re))){
  12273. var m2 = m[0].match(nameRe),
  12274. m3 = m[0].match(ifRe),
  12275. m4 = m[0].match(execRe),
  12276. exp = null,
  12277. fn = null,
  12278. exec = null,
  12279. name = m2 && m2[1] ? m2[1] : '';
  12280. if (m3) {
  12281. exp = m3 && m3[1] ? m3[1] : null;
  12282. if(exp){
  12283. fn = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + RETURN +(Ext.util.Format.htmlDecode(exp))+'; }');
  12284. }
  12285. }
  12286. if (m4) {
  12287. exp = m4 && m4[1] ? m4[1] : null;
  12288. if(exp){
  12289. exec = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES +(Ext.util.Format.htmlDecode(exp))+'; }');
  12290. }
  12291. }
  12292. if(name){
  12293. switch(name){
  12294. case '.': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + VALUES + '; }'); break;
  12295. case '..': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + PARENT + '; }'); break;
  12296. default: name = new Function(VALUES, PARENT, WITHVALUES + RETURN + name + '; }');
  12297. }
  12298. }
  12299. tpls.push({
  12300. id: id,
  12301. target: name,
  12302. exec: exec,
  12303. test: fn,
  12304. body: m[1]||''
  12305. });
  12306. s = s.replace(m[0], '{xtpl'+ id + '}');
  12307. ++id;
  12308. }
  12309. Ext.each(tpls, function(t) {
  12310. me.compileTpl(t);
  12311. });
  12312. me.master = tpls[tpls.length-1];
  12313. me.tpls = tpls;
  12314. };
  12315. Ext.extend(Ext.XTemplate, Ext.Template, {
  12316. // private
  12317. re : /\{([\w-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\\]\s?[\d\.\+\-\*\\\(\)]+)?\}/g,
  12318. // private
  12319. codeRe : /\{\[((?:\\\]|.|\n)*?)\]\}/g,
  12320. // private
  12321. applySubTemplate : function(id, values, parent, xindex, xcount){
  12322. var me = this,
  12323. len,
  12324. t = me.tpls[id],
  12325. vs,
  12326. buf = [];
  12327. if ((t.test && !t.test.call(me, values, parent, xindex, xcount)) ||
  12328. (t.exec && t.exec.call(me, values, parent, xindex, xcount))) {
  12329. return '';
  12330. }
  12331. vs = t.target ? t.target.call(me, values, parent) : values;
  12332. len = vs.length;
  12333. parent = t.target ? values : parent;
  12334. if(t.target && Ext.isArray(vs)){
  12335. Ext.each(vs, function(v, i) {
  12336. buf[buf.length] = t.compiled.call(me, v, parent, i+1, len);
  12337. });
  12338. return buf.join('');
  12339. }
  12340. return t.compiled.call(me, vs, parent, xindex, xcount);
  12341. },
  12342. // private
  12343. compileTpl : function(tpl){
  12344. var fm = Ext.util.Format,
  12345. useF = this.disableFormats !== true,
  12346. sep = Ext.isGecko ? "+" : ",",
  12347. body;
  12348. function fn(m, name, format, args, math){
  12349. if(name.substr(0, 4) == 'xtpl'){
  12350. return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent, xindex, xcount)'+sep+"'";
  12351. }
  12352. var v;
  12353. if(name === '.'){
  12354. v = 'values';
  12355. }else if(name === '#'){
  12356. v = 'xindex';
  12357. }else if(name.indexOf('.') != -1){
  12358. v = name;
  12359. }else{
  12360. v = "values['" + name + "']";
  12361. }
  12362. if(math){
  12363. v = '(' + v + math + ')';
  12364. }
  12365. if (format && useF) {
  12366. args = args ? ',' + args : "";
  12367. if(format.substr(0, 5) != "this."){
  12368. format = "fm." + format + '(';
  12369. }else{
  12370. format = 'this.call("'+ format.substr(5) + '", ';
  12371. args = ", values";
  12372. }
  12373. } else {
  12374. args= ''; format = "("+v+" === undefined ? '' : ";
  12375. }
  12376. return "'"+ sep + format + v + args + ")"+sep+"'";
  12377. }
  12378. function codeFn(m, code){
  12379. // Single quotes get escaped when the template is compiled, however we want to undo this when running code.
  12380. return "'" + sep + '(' + code.replace(/\\'/g, "'") + ')' + sep + "'";
  12381. }
  12382. // branched to use + in gecko and [].join() in others
  12383. if(Ext.isGecko){
  12384. body = "tpl.compiled = function(values, parent, xindex, xcount){ return '" +
  12385. tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn) +
  12386. "';};";
  12387. }else{
  12388. body = ["tpl.compiled = function(values, parent, xindex, xcount){ return ['"];
  12389. body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn));
  12390. body.push("'].join('');};");
  12391. body = body.join('');
  12392. }
  12393. eval(body);
  12394. return this;
  12395. },
  12396. /**
  12397. * Returns an HTML fragment of this template with the specified values applied.
  12398. * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  12399. * @return {String} The HTML fragment
  12400. */
  12401. applyTemplate : function(values){
  12402. return this.master.compiled.call(this, values, {}, 1, 1);
  12403. },
  12404. /**
  12405. * Compile the template to a function for optimized performance. Recommended if the template will be used frequently.
  12406. * @return {Function} The compiled function
  12407. */
  12408. compile : function(){return this;}
  12409. /**
  12410. * @property re
  12411. * @hide
  12412. */
  12413. /**
  12414. * @property disableFormats
  12415. * @hide
  12416. */
  12417. /**
  12418. * @method set
  12419. * @hide
  12420. */
  12421. });
  12422. /**
  12423. * Alias for {@link #applyTemplate}
  12424. * Returns an HTML fragment of this template with the specified values applied.
  12425. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  12426. * @return {String} The HTML fragment
  12427. * @member Ext.XTemplate
  12428. * @method apply
  12429. */
  12430. Ext.XTemplate.prototype.apply = Ext.XTemplate.prototype.applyTemplate;
  12431. /**
  12432. * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
  12433. * @param {String/HTMLElement} el A DOM element or its id
  12434. * @return {Ext.Template} The created template
  12435. * @static
  12436. */
  12437. Ext.XTemplate.from = function(el){
  12438. el = Ext.getDom(el);
  12439. return new Ext.XTemplate(el.value || el.innerHTML);
  12440. };/**
  12441. * @class Ext.util.CSS
  12442. * Utility class for manipulating CSS rules
  12443. * @singleton
  12444. */
  12445. Ext.util.CSS = function(){
  12446. var rules = null;
  12447. var doc = document;
  12448. var camelRe = /(-[a-z])/gi;
  12449. var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
  12450. return {
  12451. /**
  12452. * Creates a stylesheet from a text blob of rules.
  12453. * These rules will be wrapped in a STYLE tag and appended to the HEAD of the document.
  12454. * @param {String} cssText The text containing the css rules
  12455. * @param {String} id An id to add to the stylesheet for later removal
  12456. * @return {StyleSheet}
  12457. */
  12458. createStyleSheet : function(cssText, id){
  12459. var ss;
  12460. var head = doc.getElementsByTagName("head")[0];
  12461. var rules = doc.createElement("style");
  12462. rules.setAttribute("type", "text/css");
  12463. if(id){
  12464. rules.setAttribute("id", id);
  12465. }
  12466. if(Ext.isIE){
  12467. head.appendChild(rules);
  12468. ss = rules.styleSheet;
  12469. ss.cssText = cssText;
  12470. }else{
  12471. try{
  12472. rules.appendChild(doc.createTextNode(cssText));
  12473. }catch(e){
  12474. rules.cssText = cssText;
  12475. }
  12476. head.appendChild(rules);
  12477. ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
  12478. }
  12479. this.cacheStyleSheet(ss);
  12480. return ss;
  12481. },
  12482. /**
  12483. * Removes a style or link tag by id
  12484. * @param {String} id The id of the tag
  12485. */
  12486. removeStyleSheet : function(id){
  12487. var existing = doc.getElementById(id);
  12488. if(existing){
  12489. existing.parentNode.removeChild(existing);
  12490. }
  12491. },
  12492. /**
  12493. * Dynamically swaps an existing stylesheet reference for a new one
  12494. * @param {String} id The id of an existing link tag to remove
  12495. * @param {String} url The href of the new stylesheet to include
  12496. */
  12497. swapStyleSheet : function(id, url){
  12498. this.removeStyleSheet(id);
  12499. var ss = doc.createElement("link");
  12500. ss.setAttribute("rel", "stylesheet");
  12501. ss.setAttribute("type", "text/css");
  12502. ss.setAttribute("id", id);
  12503. ss.setAttribute("href", url);
  12504. doc.getElementsByTagName("head")[0].appendChild(ss);
  12505. },
  12506. /**
  12507. * Refresh the rule cache if you have dynamically added stylesheets
  12508. * @return {Object} An object (hash) of rules indexed by selector
  12509. */
  12510. refreshCache : function(){
  12511. return this.getRules(true);
  12512. },
  12513. // private
  12514. cacheStyleSheet : function(ss){
  12515. if(!rules){
  12516. rules = {};
  12517. }
  12518. try{// try catch for cross domain access issue
  12519. var ssRules = ss.cssRules || ss.rules;
  12520. for(var j = ssRules.length-1; j >= 0; --j){
  12521. rules[ssRules[j].selectorText.toLowerCase()] = ssRules[j];
  12522. }
  12523. }catch(e){}
  12524. },
  12525. /**
  12526. * Gets all css rules for the document
  12527. * @param {Boolean} refreshCache true to refresh the internal cache
  12528. * @return {Object} An object (hash) of rules indexed by selector
  12529. */
  12530. getRules : function(refreshCache){
  12531. if(rules === null || refreshCache){
  12532. rules = {};
  12533. var ds = doc.styleSheets;
  12534. for(var i =0, len = ds.length; i < len; i++){
  12535. try{
  12536. this.cacheStyleSheet(ds[i]);
  12537. }catch(e){}
  12538. }
  12539. }
  12540. return rules;
  12541. },
  12542. /**
  12543. * Gets an an individual CSS rule by selector(s)
  12544. * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
  12545. * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
  12546. * @return {CSSRule} The CSS rule or null if one is not found
  12547. */
  12548. getRule : function(selector, refreshCache){
  12549. var rs = this.getRules(refreshCache);
  12550. if(!Ext.isArray(selector)){
  12551. return rs[selector.toLowerCase()];
  12552. }
  12553. for(var i = 0; i < selector.length; i++){
  12554. if(rs[selector[i]]){
  12555. return rs[selector[i].toLowerCase()];
  12556. }
  12557. }
  12558. return null;
  12559. },
  12560. /**
  12561. * Updates a rule property
  12562. * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
  12563. * @param {String} property The css property
  12564. * @param {String} value The new value for the property
  12565. * @return {Boolean} true If a rule was found and updated
  12566. */
  12567. updateRule : function(selector, property, value){
  12568. if(!Ext.isArray(selector)){
  12569. var rule = this.getRule(selector);
  12570. if(rule){
  12571. rule.style[property.replace(camelRe, camelFn)] = value;
  12572. return true;
  12573. }
  12574. }else{
  12575. for(var i = 0; i < selector.length; i++){
  12576. if(this.updateRule(selector[i], property, value)){
  12577. return true;
  12578. }
  12579. }
  12580. }
  12581. return false;
  12582. }
  12583. };
  12584. }();/**
  12585. @class Ext.util.ClickRepeater
  12586. @extends Ext.util.Observable
  12587. A wrapper class which can be applied to any element. Fires a "click" event while the
  12588. mouse is pressed. The interval between firings may be specified in the config but
  12589. defaults to 20 milliseconds.
  12590. Optionally, a CSS class may be applied to the element during the time it is pressed.
  12591. @cfg {Mixed} el The element to act as a button.
  12592. @cfg {Number} delay The initial delay before the repeating event begins firing.
  12593. Similar to an autorepeat key delay.
  12594. @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
  12595. @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
  12596. @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
  12597. "interval" and "delay" are ignored.
  12598. @cfg {Boolean} preventDefault True to prevent the default click event
  12599. @cfg {Boolean} stopDefault True to stop the default click event
  12600. @history
  12601. 2007-02-02 jvs Original code contributed by Nige "Animal" White
  12602. 2007-02-02 jvs Renamed to ClickRepeater
  12603. 2007-02-03 jvs Modifications for FF Mac and Safari
  12604. @constructor
  12605. @param {Mixed} el The element to listen on
  12606. @param {Object} config
  12607. */
  12608. Ext.util.ClickRepeater = function(el, config)
  12609. {
  12610. this.el = Ext.get(el);
  12611. this.el.unselectable();
  12612. Ext.apply(this, config);
  12613. this.addEvents(
  12614. /**
  12615. * @event mousedown
  12616. * Fires when the mouse button is depressed.
  12617. * @param {Ext.util.ClickRepeater} this
  12618. */
  12619. "mousedown",
  12620. /**
  12621. * @event click
  12622. * Fires on a specified interval during the time the element is pressed.
  12623. * @param {Ext.util.ClickRepeater} this
  12624. */
  12625. "click",
  12626. /**
  12627. * @event mouseup
  12628. * Fires when the mouse key is released.
  12629. * @param {Ext.util.ClickRepeater} this
  12630. */
  12631. "mouseup"
  12632. );
  12633. if(!this.disabled){
  12634. this.disabled = true;
  12635. this.enable();
  12636. }
  12637. // allow inline handler
  12638. if(this.handler){
  12639. this.on("click", this.handler, this.scope || this);
  12640. }
  12641. Ext.util.ClickRepeater.superclass.constructor.call(this);
  12642. };
  12643. Ext.extend(Ext.util.ClickRepeater, Ext.util.Observable, {
  12644. interval : 20,
  12645. delay: 250,
  12646. preventDefault : true,
  12647. stopDefault : false,
  12648. timer : 0,
  12649. /**
  12650. * Enables the repeater and allows events to fire.
  12651. */
  12652. enable: function(){
  12653. if(this.disabled){
  12654. this.el.on('mousedown', this.handleMouseDown, this);
  12655. if (Ext.isIE){
  12656. this.el.on('dblclick', this.handleDblClick, this);
  12657. }
  12658. if(this.preventDefault || this.stopDefault){
  12659. this.el.on('click', this.eventOptions, this);
  12660. }
  12661. }
  12662. this.disabled = false;
  12663. },
  12664. /**
  12665. * Disables the repeater and stops events from firing.
  12666. */
  12667. disable: function(/* private */ force){
  12668. if(force || !this.disabled){
  12669. clearTimeout(this.timer);
  12670. if(this.pressClass){
  12671. this.el.removeClass(this.pressClass);
  12672. }
  12673. Ext.getDoc().un('mouseup', this.handleMouseUp, this);
  12674. this.el.removeAllListeners();
  12675. }
  12676. this.disabled = true;
  12677. },
  12678. /**
  12679. * Convenience function for setting disabled/enabled by boolean.
  12680. * @param {Boolean} disabled
  12681. */
  12682. setDisabled: function(disabled){
  12683. this[disabled ? 'disable' : 'enable']();
  12684. },
  12685. eventOptions: function(e){
  12686. if(this.preventDefault){
  12687. e.preventDefault();
  12688. }
  12689. if(this.stopDefault){
  12690. e.stopEvent();
  12691. }
  12692. },
  12693. // private
  12694. destroy : function() {
  12695. this.disable(true);
  12696. Ext.destroy(this.el);
  12697. this.purgeListeners();
  12698. },
  12699. handleDblClick : function(){
  12700. clearTimeout(this.timer);
  12701. this.el.blur();
  12702. this.fireEvent("mousedown", this);
  12703. this.fireEvent("click", this);
  12704. },
  12705. // private
  12706. handleMouseDown : function(){
  12707. clearTimeout(this.timer);
  12708. this.el.blur();
  12709. if(this.pressClass){
  12710. this.el.addClass(this.pressClass);
  12711. }
  12712. this.mousedownTime = new Date();
  12713. Ext.getDoc().on("mouseup", this.handleMouseUp, this);
  12714. this.el.on("mouseout", this.handleMouseOut, this);
  12715. this.fireEvent("mousedown", this);
  12716. this.fireEvent("click", this);
  12717. // Do not honor delay or interval if acceleration wanted.
  12718. if (this.accelerate) {
  12719. this.delay = 400;
  12720. }
  12721. this.timer = this.click.defer(this.delay || this.interval, this);
  12722. },
  12723. // private
  12724. click : function(){
  12725. this.fireEvent("click", this);
  12726. this.timer = this.click.defer(this.accelerate ?
  12727. this.easeOutExpo(this.mousedownTime.getElapsed(),
  12728. 400,
  12729. -390,
  12730. 12000) :
  12731. this.interval, this);
  12732. },
  12733. easeOutExpo : function (t, b, c, d) {
  12734. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  12735. },
  12736. // private
  12737. handleMouseOut : function(){
  12738. clearTimeout(this.timer);
  12739. if(this.pressClass){
  12740. this.el.removeClass(this.pressClass);
  12741. }
  12742. this.el.on("mouseover", this.handleMouseReturn, this);
  12743. },
  12744. // private
  12745. handleMouseReturn : function(){
  12746. this.el.un("mouseover", this.handleMouseReturn, this);
  12747. if(this.pressClass){
  12748. this.el.addClass(this.pressClass);
  12749. }
  12750. this.click();
  12751. },
  12752. // private
  12753. handleMouseUp : function(){
  12754. clearTimeout(this.timer);
  12755. this.el.un("mouseover", this.handleMouseReturn, this);
  12756. this.el.un("mouseout", this.handleMouseOut, this);
  12757. Ext.getDoc().un("mouseup", this.handleMouseUp, this);
  12758. this.el.removeClass(this.pressClass);
  12759. this.fireEvent("mouseup", this);
  12760. }
  12761. });/**
  12762. * @class Ext.KeyNav
  12763. * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
  12764. * navigation keys to function calls that will get called when the keys are pressed, providing an easy
  12765. * way to implement custom navigation schemes for any UI component.</p>
  12766. * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
  12767. * pageUp, pageDown, del, home, end. Usage:</p>
  12768. <pre><code>
  12769. var nav = new Ext.KeyNav("my-element", {
  12770. "left" : function(e){
  12771. this.moveLeft(e.ctrlKey);
  12772. },
  12773. "right" : function(e){
  12774. this.moveRight(e.ctrlKey);
  12775. },
  12776. "enter" : function(e){
  12777. this.save();
  12778. },
  12779. scope : this
  12780. });
  12781. </code></pre>
  12782. * @constructor
  12783. * @param {Mixed} el The element to bind to
  12784. * @param {Object} config The config
  12785. */
  12786. Ext.KeyNav = function(el, config){
  12787. this.el = Ext.get(el);
  12788. Ext.apply(this, config);
  12789. if(!this.disabled){
  12790. this.disabled = true;
  12791. this.enable();
  12792. }
  12793. };
  12794. Ext.KeyNav.prototype = {
  12795. /**
  12796. * @cfg {Boolean} disabled
  12797. * True to disable this KeyNav instance (defaults to false)
  12798. */
  12799. disabled : false,
  12800. /**
  12801. * @cfg {String} defaultEventAction
  12802. * The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
  12803. * {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
  12804. * {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
  12805. */
  12806. defaultEventAction: "stopEvent",
  12807. /**
  12808. * @cfg {Boolean} forceKeyDown
  12809. * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
  12810. * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
  12811. * handle keydown instead of keypress.
  12812. */
  12813. forceKeyDown : false,
  12814. // private
  12815. relay : function(e){
  12816. var k = e.getKey();
  12817. var h = this.keyToHandler[k];
  12818. if(h && this[h]){
  12819. if(this.doRelay(e, this[h], h) !== true){
  12820. e[this.defaultEventAction]();
  12821. }
  12822. }
  12823. },
  12824. // private
  12825. doRelay : function(e, h, hname){
  12826. return h.call(this.scope || this, e);
  12827. },
  12828. // possible handlers
  12829. enter : false,
  12830. left : false,
  12831. right : false,
  12832. up : false,
  12833. down : false,
  12834. tab : false,
  12835. esc : false,
  12836. pageUp : false,
  12837. pageDown : false,
  12838. del : false,
  12839. home : false,
  12840. end : false,
  12841. // quick lookup hash
  12842. keyToHandler : {
  12843. 37 : "left",
  12844. 39 : "right",
  12845. 38 : "up",
  12846. 40 : "down",
  12847. 33 : "pageUp",
  12848. 34 : "pageDown",
  12849. 46 : "del",
  12850. 36 : "home",
  12851. 35 : "end",
  12852. 13 : "enter",
  12853. 27 : "esc",
  12854. 9 : "tab"
  12855. },
  12856. stopKeyUp: function(e) {
  12857. var k = e.getKey();
  12858. if (k >= 37 && k <= 40) {
  12859. // *** bugfix - safari 2.x fires 2 keyup events on cursor keys
  12860. // *** (note: this bugfix sacrifices the "keyup" event originating from keyNav elements in Safari 2)
  12861. e.stopEvent();
  12862. }
  12863. },
  12864. /**
  12865. * Destroy this KeyNav (this is the same as calling disable).
  12866. */
  12867. destroy: function(){
  12868. this.disable();
  12869. },
  12870. /**
  12871. * Enable this KeyNav
  12872. */
  12873. enable: function() {
  12874. if (this.disabled) {
  12875. if (Ext.isSafari2) {
  12876. // call stopKeyUp() on "keyup" event
  12877. this.el.on('keyup', this.stopKeyUp, this);
  12878. }
  12879. this.el.on(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
  12880. this.disabled = false;
  12881. }
  12882. },
  12883. /**
  12884. * Disable this KeyNav
  12885. */
  12886. disable: function() {
  12887. if (!this.disabled) {
  12888. if (Ext.isSafari2) {
  12889. // remove "keyup" event handler
  12890. this.el.un('keyup', this.stopKeyUp, this);
  12891. }
  12892. this.el.un(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
  12893. this.disabled = true;
  12894. }
  12895. },
  12896. /**
  12897. * Convenience function for setting disabled/enabled by boolean.
  12898. * @param {Boolean} disabled
  12899. */
  12900. setDisabled : function(disabled){
  12901. this[disabled ? "disable" : "enable"]();
  12902. },
  12903. // private
  12904. isKeydown: function(){
  12905. return this.forceKeyDown || Ext.EventManager.useKeydown;
  12906. }
  12907. };
  12908. /**
  12909. * @class Ext.KeyMap
  12910. * Handles mapping keys to actions for an element. One key map can be used for multiple actions.
  12911. * The constructor accepts the same config object as defined by {@link #addBinding}.
  12912. * If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
  12913. * combination it will call the function with this signature (if the match is a multi-key
  12914. * combination the callback will still be called only once): (String key, Ext.EventObject e)
  12915. * A KeyMap can also handle a string representation of keys.<br />
  12916. * Usage:
  12917. <pre><code>
  12918. // map one key by key code
  12919. var map = new Ext.KeyMap("my-element", {
  12920. key: 13, // or Ext.EventObject.ENTER
  12921. fn: myHandler,
  12922. scope: myObject
  12923. });
  12924. // map multiple keys to one action by string
  12925. var map = new Ext.KeyMap("my-element", {
  12926. key: "a\r\n\t",
  12927. fn: myHandler,
  12928. scope: myObject
  12929. });
  12930. // map multiple keys to multiple actions by strings and array of codes
  12931. var map = new Ext.KeyMap("my-element", [
  12932. {
  12933. key: [10,13],
  12934. fn: function(){ alert("Return was pressed"); }
  12935. }, {
  12936. key: "abc",
  12937. fn: function(){ alert('a, b or c was pressed'); }
  12938. }, {
  12939. key: "\t",
  12940. ctrl:true,
  12941. shift:true,
  12942. fn: function(){ alert('Control + shift + tab was pressed.'); }
  12943. }
  12944. ]);
  12945. </code></pre>
  12946. * <b>Note: A KeyMap starts enabled</b>
  12947. * @constructor
  12948. * @param {Mixed} el The element to bind to
  12949. * @param {Object} config The config (see {@link #addBinding})
  12950. * @param {String} eventName (optional) The event to bind to (defaults to "keydown")
  12951. */
  12952. Ext.KeyMap = function(el, config, eventName){
  12953. this.el = Ext.get(el);
  12954. this.eventName = eventName || "keydown";
  12955. this.bindings = [];
  12956. if(config){
  12957. this.addBinding(config);
  12958. }
  12959. this.enable();
  12960. };
  12961. Ext.KeyMap.prototype = {
  12962. /**
  12963. * True to stop the event from bubbling and prevent the default browser action if the
  12964. * key was handled by the KeyMap (defaults to false)
  12965. * @type Boolean
  12966. */
  12967. stopEvent : false,
  12968. /**
  12969. * Add a new binding to this KeyMap. The following config object properties are supported:
  12970. * <pre>
  12971. Property Type Description
  12972. ---------- --------------- ----------------------------------------------------------------------
  12973. key String/Array A single keycode or an array of keycodes to handle
  12974. shift Boolean True to handle key only when shift is pressed, False to handle the key only when shift is not pressed (defaults to undefined)
  12975. ctrl Boolean True to handle key only when ctrl is pressed, False to handle the key only when ctrl is not pressed (defaults to undefined)
  12976. alt Boolean True to handle key only when alt is pressed, False to handle the key only when alt is not pressed (defaults to undefined)
  12977. handler Function The function to call when KeyMap finds the expected key combination
  12978. fn Function Alias of handler (for backwards-compatibility)
  12979. scope Object The scope of the callback function
  12980. stopEvent Boolean True to stop the event from bubbling and prevent the default browser action if the key was handled by the KeyMap (defaults to false)
  12981. </pre>
  12982. *
  12983. * Usage:
  12984. * <pre><code>
  12985. // Create a KeyMap
  12986. var map = new Ext.KeyMap(document, {
  12987. key: Ext.EventObject.ENTER,
  12988. fn: handleKey,
  12989. scope: this
  12990. });
  12991. //Add a new binding to the existing KeyMap later
  12992. map.addBinding({
  12993. key: 'abc',
  12994. shift: true,
  12995. fn: handleKey,
  12996. scope: this
  12997. });
  12998. </code></pre>
  12999. * @param {Object/Array} config A single KeyMap config or an array of configs
  13000. */
  13001. addBinding : function(config){
  13002. if(Ext.isArray(config)){
  13003. Ext.each(config, function(c){
  13004. this.addBinding(c);
  13005. }, this);
  13006. return;
  13007. }
  13008. var keyCode = config.key,
  13009. fn = config.fn || config.handler,
  13010. scope = config.scope;
  13011. if (config.stopEvent) {
  13012. this.stopEvent = config.stopEvent;
  13013. }
  13014. if(typeof keyCode == "string"){
  13015. var ks = [];
  13016. var keyString = keyCode.toUpperCase();
  13017. for(var j = 0, len = keyString.length; j < len; j++){
  13018. ks.push(keyString.charCodeAt(j));
  13019. }
  13020. keyCode = ks;
  13021. }
  13022. var keyArray = Ext.isArray(keyCode);
  13023. var handler = function(e){
  13024. if(this.checkModifiers(config, e)){
  13025. var k = e.getKey();
  13026. if(keyArray){
  13027. for(var i = 0, len = keyCode.length; i < len; i++){
  13028. if(keyCode[i] == k){
  13029. if(this.stopEvent){
  13030. e.stopEvent();
  13031. }
  13032. fn.call(scope || window, k, e);
  13033. return;
  13034. }
  13035. }
  13036. }else{
  13037. if(k == keyCode){
  13038. if(this.stopEvent){
  13039. e.stopEvent();
  13040. }
  13041. fn.call(scope || window, k, e);
  13042. }
  13043. }
  13044. }
  13045. };
  13046. this.bindings.push(handler);
  13047. },
  13048. // private
  13049. checkModifiers: function(config, e){
  13050. var val, key, keys = ['shift', 'ctrl', 'alt'];
  13051. for (var i = 0, len = keys.length; i < len; ++i){
  13052. key = keys[i];
  13053. val = config[key];
  13054. if(!(val === undefined || (val === e[key + 'Key']))){
  13055. return false;
  13056. }
  13057. }
  13058. return true;
  13059. },
  13060. /**
  13061. * Shorthand for adding a single key listener
  13062. * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
  13063. * following options:
  13064. * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
  13065. * @param {Function} fn The function to call
  13066. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  13067. */
  13068. on : function(key, fn, scope){
  13069. var keyCode, shift, ctrl, alt;
  13070. if(typeof key == "object" && !Ext.isArray(key)){
  13071. keyCode = key.key;
  13072. shift = key.shift;
  13073. ctrl = key.ctrl;
  13074. alt = key.alt;
  13075. }else{
  13076. keyCode = key;
  13077. }
  13078. this.addBinding({
  13079. key: keyCode,
  13080. shift: shift,
  13081. ctrl: ctrl,
  13082. alt: alt,
  13083. fn: fn,
  13084. scope: scope
  13085. });
  13086. },
  13087. // private
  13088. handleKeyDown : function(e){
  13089. if(this.enabled){ //just in case
  13090. var b = this.bindings;
  13091. for(var i = 0, len = b.length; i < len; i++){
  13092. b[i].call(this, e);
  13093. }
  13094. }
  13095. },
  13096. /**
  13097. * Returns true if this KeyMap is enabled
  13098. * @return {Boolean}
  13099. */
  13100. isEnabled : function(){
  13101. return this.enabled;
  13102. },
  13103. /**
  13104. * Enables this KeyMap
  13105. */
  13106. enable: function(){
  13107. if(!this.enabled){
  13108. this.el.on(this.eventName, this.handleKeyDown, this);
  13109. this.enabled = true;
  13110. }
  13111. },
  13112. /**
  13113. * Disable this KeyMap
  13114. */
  13115. disable: function(){
  13116. if(this.enabled){
  13117. this.el.removeListener(this.eventName, this.handleKeyDown, this);
  13118. this.enabled = false;
  13119. }
  13120. },
  13121. /**
  13122. * Convenience function for setting disabled/enabled by boolean.
  13123. * @param {Boolean} disabled
  13124. */
  13125. setDisabled : function(disabled){
  13126. this[disabled ? "disable" : "enable"]();
  13127. }
  13128. };/**
  13129. * @class Ext.util.TextMetrics
  13130. * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
  13131. * wide, in pixels, a given block of text will be. Note that when measuring text, it should be plain text and
  13132. * should not contain any HTML, otherwise it may not be measured correctly.
  13133. * @singleton
  13134. */
  13135. Ext.util.TextMetrics = function(){
  13136. var shared;
  13137. return {
  13138. /**
  13139. * Measures the size of the specified text
  13140. * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
  13141. * that can affect the size of the rendered text
  13142. * @param {String} text The text to measure
  13143. * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
  13144. * in order to accurately measure the text height
  13145. * @return {Object} An object containing the text's size {width: (width), height: (height)}
  13146. */
  13147. measure : function(el, text, fixedWidth){
  13148. if(!shared){
  13149. shared = Ext.util.TextMetrics.Instance(el, fixedWidth);
  13150. }
  13151. shared.bind(el);
  13152. shared.setFixedWidth(fixedWidth || 'auto');
  13153. return shared.getSize(text);
  13154. },
  13155. /**
  13156. * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
  13157. * the overhead of multiple calls to initialize the style properties on each measurement.
  13158. * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
  13159. * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
  13160. * in order to accurately measure the text height
  13161. * @return {Ext.util.TextMetrics.Instance} instance The new instance
  13162. */
  13163. createInstance : function(el, fixedWidth){
  13164. return Ext.util.TextMetrics.Instance(el, fixedWidth);
  13165. }
  13166. };
  13167. }();
  13168. Ext.util.TextMetrics.Instance = function(bindTo, fixedWidth){
  13169. var ml = new Ext.Element(document.createElement('div'));
  13170. document.body.appendChild(ml.dom);
  13171. ml.position('absolute');
  13172. ml.setLeftTop(-1000, -1000);
  13173. ml.hide();
  13174. if(fixedWidth){
  13175. ml.setWidth(fixedWidth);
  13176. }
  13177. var instance = {
  13178. /**
  13179. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  13180. * Returns the size of the specified text based on the internal element's style and width properties
  13181. * @param {String} text The text to measure
  13182. * @return {Object} An object containing the text's size {width: (width), height: (height)}
  13183. */
  13184. getSize : function(text){
  13185. ml.update(text);
  13186. var s = ml.getSize();
  13187. ml.update('');
  13188. return s;
  13189. },
  13190. /**
  13191. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  13192. * Binds this TextMetrics instance to an element from which to copy existing CSS styles
  13193. * that can affect the size of the rendered text
  13194. * @param {String/HTMLElement} el The element, dom node or id
  13195. */
  13196. bind : function(el){
  13197. ml.setStyle(
  13198. Ext.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing')
  13199. );
  13200. },
  13201. /**
  13202. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  13203. * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
  13204. * to set a fixed width in order to accurately measure the text height.
  13205. * @param {Number} width The width to set on the element
  13206. */
  13207. setFixedWidth : function(width){
  13208. ml.setWidth(width);
  13209. },
  13210. /**
  13211. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  13212. * Returns the measured width of the specified text
  13213. * @param {String} text The text to measure
  13214. * @return {Number} width The width in pixels
  13215. */
  13216. getWidth : function(text){
  13217. ml.dom.style.width = 'auto';
  13218. return this.getSize(text).width;
  13219. },
  13220. /**
  13221. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  13222. * Returns the measured height of the specified text. For multiline text, be sure to call
  13223. * {@link #setFixedWidth} if necessary.
  13224. * @param {String} text The text to measure
  13225. * @return {Number} height The height in pixels
  13226. */
  13227. getHeight : function(text){
  13228. return this.getSize(text).height;
  13229. }
  13230. };
  13231. instance.bind(bindTo);
  13232. return instance;
  13233. };
  13234. Ext.Element.addMethods({
  13235. /**
  13236. * Returns the width in pixels of the passed text, or the width of the text in this Element.
  13237. * @param {String} text The text to measure. Defaults to the innerHTML of the element.
  13238. * @param {Number} min (Optional) The minumum value to return.
  13239. * @param {Number} max (Optional) The maximum value to return.
  13240. * @return {Number} The text width in pixels.
  13241. * @member Ext.Element getTextWidth
  13242. */
  13243. getTextWidth : function(text, min, max){
  13244. return (Ext.util.TextMetrics.measure(this.dom, Ext.value(text, this.dom.innerHTML, true)).width).constrain(min || 0, max || 1000000);
  13245. }
  13246. });
  13247. /**
  13248. * @class Ext.util.Cookies
  13249. * Utility class for managing and interacting with cookies.
  13250. * @singleton
  13251. */
  13252. Ext.util.Cookies = {
  13253. /**
  13254. * Create a cookie with the specified name and value. Additional settings
  13255. * for the cookie may be optionally specified (for example: expiration,
  13256. * access restriction, SSL).
  13257. * @param {String} name The name of the cookie to set.
  13258. * @param {Mixed} value The value to set for the cookie.
  13259. * @param {Object} expires (Optional) Specify an expiration date the
  13260. * cookie is to persist until. Note that the specified Date object will
  13261. * be converted to Greenwich Mean Time (GMT).
  13262. * @param {String} path (Optional) Setting a path on the cookie restricts
  13263. * access to pages that match that path. Defaults to all pages (<tt>'/'</tt>).
  13264. * @param {String} domain (Optional) Setting a domain restricts access to
  13265. * pages on a given domain (typically used to allow cookie access across
  13266. * subdomains). For example, "extjs.com" will create a cookie that can be
  13267. * accessed from any subdomain of extjs.com, including www.extjs.com,
  13268. * support.extjs.com, etc.
  13269. * @param {Boolean} secure (Optional) Specify true to indicate that the cookie
  13270. * should only be accessible via SSL on a page using the HTTPS protocol.
  13271. * Defaults to <tt>false</tt>. Note that this will only work if the page
  13272. * calling this code uses the HTTPS protocol, otherwise the cookie will be
  13273. * created with default options.
  13274. */
  13275. set : function(name, value){
  13276. var argv = arguments;
  13277. var argc = arguments.length;
  13278. var expires = (argc > 2) ? argv[2] : null;
  13279. var path = (argc > 3) ? argv[3] : '/';
  13280. var domain = (argc > 4) ? argv[4] : null;
  13281. var secure = (argc > 5) ? argv[5] : false;
  13282. document.cookie = name + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");
  13283. },
  13284. /**
  13285. * Retrieves cookies that are accessible by the current page. If a cookie
  13286. * does not exist, <code>get()</code> returns <tt>null</tt>. The following
  13287. * example retrieves the cookie called "valid" and stores the String value
  13288. * in the variable <tt>validStatus</tt>.
  13289. * <pre><code>
  13290. * var validStatus = Ext.util.Cookies.get("valid");
  13291. * </code></pre>
  13292. * @param {String} name The name of the cookie to get
  13293. * @return {Mixed} Returns the cookie value for the specified name;
  13294. * null if the cookie name does not exist.
  13295. */
  13296. get : function(name){
  13297. var arg = name + "=";
  13298. var alen = arg.length;
  13299. var clen = document.cookie.length;
  13300. var i = 0;
  13301. var j = 0;
  13302. while(i < clen){
  13303. j = i + alen;
  13304. if(document.cookie.substring(i, j) == arg){
  13305. return Ext.util.Cookies.getCookieVal(j);
  13306. }
  13307. i = document.cookie.indexOf(" ", i) + 1;
  13308. if(i === 0){
  13309. break;
  13310. }
  13311. }
  13312. return null;
  13313. },
  13314. /**
  13315. * Removes a cookie with the provided name from the browser
  13316. * if found by setting its expiration date to sometime in the past.
  13317. * @param {String} name The name of the cookie to remove
  13318. */
  13319. clear : function(name){
  13320. if(Ext.util.Cookies.get(name)){
  13321. document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  13322. }
  13323. },
  13324. /**
  13325. * @private
  13326. */
  13327. getCookieVal : function(offset){
  13328. var endstr = document.cookie.indexOf(";", offset);
  13329. if(endstr == -1){
  13330. endstr = document.cookie.length;
  13331. }
  13332. return unescape(document.cookie.substring(offset, endstr));
  13333. }
  13334. };/**
  13335. * Framework-wide error-handler. Developers can override this method to provide
  13336. * custom exception-handling. Framework errors will often extend from the base
  13337. * Ext.Error class.
  13338. * @param {Object/Error} e The thrown exception object.
  13339. */
  13340. Ext.handleError = function(e) {
  13341. throw e;
  13342. };
  13343. /**
  13344. * @class Ext.Error
  13345. * @extends Error
  13346. * <p>A base error class. Future implementations are intended to provide more
  13347. * robust error handling throughout the framework (<b>in the debug build only</b>)
  13348. * to check for common errors and problems. The messages issued by this class
  13349. * will aid error checking. Error checks will be automatically removed in the
  13350. * production build so that performance is not negatively impacted.</p>
  13351. * <p>Some sample messages currently implemented:</p><pre>
  13352. "DataProxy attempted to execute an API-action but found an undefined
  13353. url / function. Please review your Proxy url/api-configuration."
  13354. * </pre><pre>
  13355. "Could not locate your "root" property in your server response.
  13356. Please review your JsonReader config to ensure the config-property
  13357. "root" matches the property your server-response. See the JsonReader
  13358. docs for additional assistance."
  13359. * </pre>
  13360. * <p>An example of the code used for generating error messages:</p><pre><code>
  13361. try {
  13362. generateError({
  13363. foo: 'bar'
  13364. });
  13365. }
  13366. catch (e) {
  13367. console.error(e);
  13368. }
  13369. function generateError(data) {
  13370. throw new Ext.Error('foo-error', data);
  13371. }
  13372. * </code></pre>
  13373. * @param {String} message
  13374. */
  13375. Ext.Error = function(message) {
  13376. // Try to read the message from Ext.Error.lang
  13377. this.message = (this.lang[message]) ? this.lang[message] : message;
  13378. };
  13379. Ext.Error.prototype = new Error();
  13380. Ext.apply(Ext.Error.prototype, {
  13381. // protected. Extensions place their error-strings here.
  13382. lang: {},
  13383. name: 'Ext.Error',
  13384. /**
  13385. * getName
  13386. * @return {String}
  13387. */
  13388. getName : function() {
  13389. return this.name;
  13390. },
  13391. /**
  13392. * getMessage
  13393. * @return {String}
  13394. */
  13395. getMessage : function() {
  13396. return this.message;
  13397. },
  13398. /**
  13399. * toJson
  13400. * @return {String}
  13401. */
  13402. toJson : function() {
  13403. return Ext.encode(this);
  13404. }
  13405. });