4 The Ext namespace (global object) encapsulates all classes, singletons, and utility methods provided by Sencha's libraries.</p>
5 Most user interface Components are at a lower level of nesting in the namespace, but many common utility functions are provided
6 as direct properties of the Ext namespace.
8 Also many frequently used methods from other classes are provided as shortcuts within the Ext namespace.
9 For example {@link Ext#getCmp Ext.getCmp} aliases {@link Ext.ComponentManager#get Ext.ComponentManager.get}.
11 Many applications are initiated with {@link Ext#onReady Ext.onReady} which is called once the DOM is ready.
12 This ensures all scripts have been loaded, preventing dependency issues. For example
14 Ext.onReady(function(){
16 renderTo: document.body,
21 For more information about how to use the Ext classes, see
23 * <a href="http://www.sencha.com/learn/">The Learning Center</a>
24 * <a href="http://www.sencha.com/learn/Ext_FAQ">The FAQ</a>
25 * <a href="http://www.sencha.com/forum/">The forums</a>
31 userAgent: navigator.userAgent.toLowerCase(),
34 BLANK_IMAGE_URL : 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
35 isStrict: document.compatMode == "CSS1Compat",
36 windowId: 'ext-window',
37 documentId: 'ext-document',
40 * True when the document is fully initialized and ready for action
46 * True to automatically uncache orphaned Ext.core.Elements periodically (defaults to true)
49 enableGarbageCollector: true,
52 * True to automatically purge event listeners during garbageCollection (defaults to true).
55 enableListenerCollection: true,
58 * Generates unique ids. If the element already has an id, it is unchanged
59 * @param {Mixed} el (optional) The element to generate an id for
60 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
61 * @return {String} The generated Id.
63 id: function(el, prefix) {
64 el = Ext.getDom(el, true) || {};
65 if (el === document) {
66 el.id = this.documentId;
68 else if (el === window) {
69 el.id = this.windowId;
72 el.id = (prefix || "ext-gen") + (++Ext.idSeed);
78 * Returns the current document body as an {@link Ext.core.Element}.
79 * @return Ext.core.Element The document body
82 return Ext.get(document.body || false);
86 * Returns the current document head as an {@link Ext.core.Element}.
87 * @return Ext.core.Element The document head
93 if (head == undefined) {
94 head = Ext.get(document.getElementsByTagName("head")[0]);
102 * Returns the current HTML document object as an {@link Ext.core.Element}.
103 * @return Ext.core.Element The document
106 return Ext.get(document);
110 * This is shorthand reference to {@link Ext.ComponentManager#get}.
111 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
112 * @param {String} id The component {@link Ext.Component#id id}
113 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
116 getCmp: function(id) {
117 return Ext.ComponentManager.get(id);
121 * Returns the current orientation of the mobile device
122 * @return {String} Either 'portrait' or 'landscape'
124 getOrientation: function() {
125 return window.innerHeight > window.innerWidth ? 'portrait' : 'landscape';
129 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
130 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
131 * intended for arguments of type {@link Ext.core.Element} and {@link Ext.Component}, but any subclass of
132 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
133 * passed into this function in a single call as separate arguments.
134 * @param {Mixed} arg1 An {@link Ext.core.Element}, {@link Ext.Component}, or an Array of either of these to destroy
135 * @param {Mixed} arg2 (optional)
136 * @param {Mixed} etc... (optional)
138 destroy: function() {
139 var ln = arguments.length,
142 for (i = 0; i < ln; i++) {
145 if (Ext.isArray(arg)) {
146 this.destroy.apply(this, arg);
148 else if (Ext.isFunction(arg.destroy)) {
159 * Execute a callback function in a particular scope. If no function is passed the call is ignored.
160 * @param {Function} callback The callback to execute
161 * @param {Object} scope (optional) The scope to execute in
162 * @param {Array} args (optional) The arguments to pass to the function
163 * @param {Number} delay (optional) Pass a number to delay the call by a number of milliseconds.
165 callback: function(callback, scope, args, delay){
166 if(Ext.isFunction(callback)){
168 scope = scope || window;
170 Ext.defer(callback, delay, scope, args);
172 callback.apply(scope, args);
178 * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
179 * @param {String} value The string to encode
180 * @return {String} The encoded text
182 htmlEncode : function(value) {
183 return Ext.String.htmlEncode(value);
187 * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
188 * @param {String} value The string to decode
189 * @return {String} The decoded text
191 htmlDecode : function(value) {
192 return Ext.String.htmlDecode(value);
196 * Appends content to the query string of a URL, handling logic for whether to place
197 * a question mark or ampersand.
198 * @param {String} url The URL to append to.
199 * @param {String} s The content to append to the URL.
200 * @return (String) The resulting URL
202 urlAppend : function(url, s) {
203 if (!Ext.isEmpty(s)) {
204 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
211 Ext.ns = Ext.namespace;
214 window.undefined = window.undefined;
217 * Ext core utilities and functions.
221 var check = function(regex){
222 return regex.test(Ext.userAgent);
224 docMode = document.documentMode,
225 isOpera = check(/opera/),
226 isOpera10_5 = isOpera && check(/version\/10\.5/),
227 isChrome = check(/\bchrome\b/),
228 isWebKit = check(/webkit/),
229 isSafari = !isChrome && check(/safari/),
230 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
231 isSafari3 = isSafari && check(/version\/3/),
232 isSafari4 = isSafari && check(/version\/4/),
233 isIE = !isOpera && check(/msie/),
234 isIE7 = isIE && (check(/msie 7/) || docMode == 7),
235 isIE8 = isIE && (check(/msie 8/) && docMode != 7 && docMode != 9 || docMode == 8),
236 isIE9 = isIE && (check(/msie 9/) && docMode != 7 && docMode != 8 || docMode == 9),
237 isIE6 = isIE && check(/msie 6/),
238 isGecko = !isWebKit && check(/gecko/),
239 isGecko3 = isGecko && check(/rv:1\.9/),
240 isGecko4 = isGecko && check(/rv:2\.0/),
241 isFF3_0 = isGecko3 && check(/rv:1\.9\.0/),
242 isFF3_5 = isGecko3 && check(/rv:1\.9\.1/),
243 isFF3_6 = isGecko3 && check(/rv:1\.9\.2/),
244 isWindows = check(/windows|win32/),
245 isMac = check(/macintosh|mac os x/),
246 isLinux = check(/linux/),
249 // remove css image flicker
251 document.execCommand("BackgroundImageCache", false, true);
254 Ext.setVersion('extjs', '4.0.0');
257 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
258 * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
261 SSL_SECURE_URL : Ext.isSecure && isIE ? 'javascript:""' : 'about:blank',
264 * True if the {@link Ext.fx.Anim} Class is available
270 * True to scope the reset CSS to be just applied to Ext components. Note that this wraps root containers
271 * with an additional element. Also remember that when you turn on this option, you have to use ext-all-scoped {
272 * unless you use the bootstrap.js to load your javascript, in which case it will be handled for you.
275 scopeResetCSS : Ext.buildSettings.scopeResetCSS,
278 * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
279 * Currently not optimized for performance.
282 enableNestedListenerRemoval : false,
285 * Indicates whether to use native browser parsing for JSON methods.
286 * This option is ignored if the browser does not support native JSON methods.
287 * <b>Note: Native JSON methods will not work with objects that have functions.
288 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
291 USE_NATIVE_JSON : false,
294 * Return the dom node for the passed String (id), dom node, or Ext.core.Element.
295 * Optional 'strict' flag is needed for IE since it can return 'name' and
296 * 'id' elements by using getElementById.
297 * Here are some examples:
299 // gets dom node based on id
300 var elDom = Ext.getDom('elId');
301 // gets dom node based on the dom node
302 var elDom1 = Ext.getDom(elDom);
304 // If we don't know if we are working with an
305 // Ext.core.Element or a dom node use Ext.getDom
307 var dom = Ext.getDom(el);
308 // do something with the dom node
311 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
312 * when this method is called to be successful.
314 * @return HTMLElement
316 getDom : function(el, strict) {
317 if (!el || !document) {
323 if (typeof el == 'string') {
324 var e = document.getElementById(el);
325 // IE returns elements with the 'name' and 'id' attribute.
326 // we do a strict check to return the element with only the id attribute
327 if (e && isIE && strict) {
328 if (el == e.getAttribute('id')) {
342 * Removes a DOM node from the document.
343 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
344 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval Ext.enableNestedListenerRemoval} is
345 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
346 * will be ignored if passed in.</p>
347 * @param {HTMLElement} node The node to remove
349 removeNode : isIE6 || isIE7 ? function() {
352 if(n && n.tagName != 'BODY'){
353 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
354 d = d || document.createElement('div');
357 delete Ext.cache[n.id];
361 if (n && n.parentNode && n.tagName != 'BODY') {
362 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
363 n.parentNode.removeChild(n);
364 delete Ext.cache[n.id];
369 * True if the detected browser is Opera.
375 * True if the detected browser is Opera 10.5x.
378 isOpera10_5 : isOpera10_5,
381 * True if the detected browser uses WebKit.
387 * True if the detected browser is Chrome.
393 * True if the detected browser is Safari.
399 * True if the detected browser is Safari 3.x.
402 isSafari3 : isSafari3,
405 * True if the detected browser is Safari 4.x.
408 isSafari4 : isSafari4,
411 * True if the detected browser is Safari 2.x.
414 isSafari2 : isSafari2,
417 * True if the detected browser is Internet Explorer.
423 * True if the detected browser is Internet Explorer 6.x.
429 * True if the detected browser is Internet Explorer 7.x.
435 * True if the detected browser is Internet Explorer 8.x.
441 * True if the detected browser is Internet Explorer 9.x.
447 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
453 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
459 * True if the detected browser uses a Gecko 2.0+ layout engine (e.g. Firefox 4.x).
465 * True if the detected browser uses FireFox 3.0
471 * True if the detected browser uses FireFox 3.5
477 * True if the detected browser uses FireFox 3.6
483 * True if the detected platform is Linux.
489 * True if the detected platform is Windows.
492 isWindows : isWindows,
495 * True if the detected platform is Mac OS.
501 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
502 * In older versions of IE, this defaults to "http://sencha.com/s.gif" and you should change this to a URL on your server.
503 * For other browsers it uses an inline data URL.
506 BLANK_IMAGE_URL : (isIE6 || isIE7) ? 'http:/' + '/www.sencha.com/s.gif' : 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
509 * <p>Utility method for returning a default value if the passed value is empty.</p>
510 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
513 * <li>an empty array</li>
514 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
516 * @param {Mixed} value The value to test
517 * @param {Mixed} defaultValue The value to return if the original value is empty
518 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
519 * @return {Mixed} value, if non-empty, else defaultValue
520 * @deprecated 4.0.0 Use {Ext#valueFrom} instead
522 value : function(v, defaultValue, allowBlank){
523 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
527 * Escapes the passed string for use in a regular expression
528 * @param {String} str
530 * @deprecated 4.0.0 Use {@link Ext.String#escapeRegex} instead
532 escapeRe : function(s) {
533 return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
537 * Applies event listeners to elements by selectors when the document is ready.
538 * The event name is specified with an <tt>@</tt> suffix.
541 // add a listener for click on all anchors in element with id foo
542 '#foo a@click' : function(e, t){
546 // add the same listener to multiple selectors (separated by comma BEFORE the @)
547 '#foo a, #bar span.some-class@mouseover' : function(){
552 * @param {Object} obj The list of behaviors to apply
554 addBehaviors : function(o){
556 Ext.onReady(function(){
560 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
565 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
568 cache[s] = Ext.select(s);
570 cache[s].on(parts[1], o[b]);
578 * Utility method for getting the width of the browser scrollbar. This can differ depending on
579 * operating system settings, such as the theme or font size.
580 * @param {Boolean} force (optional) true to force a recalculation of the value.
581 * @return {Number} The width of the scrollbar.
583 getScrollBarWidth: function(force){
588 if(force === true || scrollWidth === null){
590 // When IE9 positions an element offscreen via offsets, the offsetWidth is
591 // inaccurately reported. For IE9 only, we render on screen before removing.
592 var cssClass = Ext.isIE9 ? '' : Ext.baseCSSPrefix + 'hide-offsets';
593 // Append our div, do our calculation and then remove it
594 var div = Ext.getBody().createChild('<div class="' + cssClass + '" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
595 child = div.child('div', true);
596 var w1 = child.offsetWidth;
597 div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
598 var w2 = child.offsetWidth;
600 // Need to add 2 to ensure we leave enough space
601 scrollWidth = w1 - w2 + 2;
607 * Copies a set of named properties fom the source object to the destination object.
608 * <p>example:<pre><code>
609 ImageComponent = Ext.extend(Ext.Component, {
610 initComponent: function() {
611 this.autoEl = { tag: 'img' };
612 MyComponent.superclass.initComponent.apply(this, arguments);
613 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
617 * Important note: To borrow class prototype methods, use {@link Ext.Base#borrow} instead.
618 * @param {Object} dest The destination object.
619 * @param {Object} source The source object.
620 * @param {Array/String} names Either an Array of property names, or a comma-delimited list
621 * of property names to copy.
622 * @param {Boolean} usePrototypeKeys (Optional) Defaults to false. Pass true to copy keys off of the prototype as well as the instance.
623 * @return {Object} The modified object.
625 copyTo : function(dest, source, names, usePrototypeKeys){
626 if(typeof names == 'string'){
627 names = names.split(/[,;\s]/);
629 Ext.each(names, function(name){
630 if(usePrototypeKeys || source.hasOwnProperty(name)){
631 dest[name] = source[name];
638 * Attempts to destroy and then remove a set of named properties of the passed object.
639 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
640 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
641 * @param {Mixed} etc... More property names to destroy and remove.
643 destroyMembers : function(o, arg1, arg2, etc){
644 for (var i = 1, a = arguments, len = a.length; i < len; i++) {
645 Ext.destroy(o[a[i]]);
651 * Partitions the set into two sets: a true set and a false set.
656 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
662 return val.className == "class1"
665 // true are those paragraph elements with a className of "class1",
666 // false set are those that do not have that className.
668 * @param {Array|NodeList} arr The array to partition
669 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
670 * itself must be able to be evaluated for its truthfulness.
671 * @return {Array} [true<Array>,false<Array>]
672 * @deprecated 4.0.0 Will be removed in the next major version
674 partition : function(arr, truth){
676 Ext.each(arr, function(v, i, a) {
677 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
683 * Invokes a method on each item in an Array.
686 Ext.invoke(Ext.query("p"), "getAttribute", "id");
687 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
689 * @param {Array|NodeList} arr The Array of items to invoke the method on.
690 * @param {String} methodName The method name to invoke.
691 * @param {...*} args Arguments to send into the method invocation.
692 * @return {Array} The results of invoking the method on each item in the array.
693 * @deprecated 4.0.0 Will be removed in the next major version
695 invoke : function(arr, methodName){
697 args = Array.prototype.slice.call(arguments, 2);
698 Ext.each(arr, function(v,i) {
699 if (v && typeof v[methodName] == 'function') {
700 ret.push(v[methodName].apply(v, args));
709 * <p>Zips N sets together.</p>
712 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
719 return "$" + a + "" + b + "." + c
721 ); // ["$+12.43", "$-10.15", "$+22.96"]
723 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
724 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
725 * @return {Array} The zipped set.
726 * @deprecated 4.0.0 Will be removed in the next major version
729 var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
732 len = Ext.max(Ext.pluck(arrs, "length")),
735 for (var i = 0; i < len; i++) {
738 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
740 for (var j = 0, aLen = arrs.length; j < aLen; j++){
741 ret[i].push( arrs[j][i] );
749 * Turns an array into a sentence, joined by a specified connector - e.g.:
750 * Ext.toSentence(['Adama', 'Tigh', 'Roslin']); //'Adama, Tigh and Roslin'
751 * Ext.toSentence(['Adama', 'Tigh', 'Roslin'], 'or'); //'Adama, Tigh or Roslin'
752 * @param {Array} items The array to create a sentence from
753 * @param {String} connector The string to use to connect the last two words. Usually 'and' or 'or' - defaults to 'and'.
754 * @return {String} The sentence string
755 * @deprecated 4.0.0 Will be removed in the next major version
757 toSentence: function(items, connector) {
758 var length = items.length;
763 var head = items.slice(0, length - 1),
764 tail = items[length - 1];
766 return Ext.util.Format.format("{0} {1} {2}", head.join(", "), connector || 'and', tail);
771 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
772 * you may want to set this to true.
782 * @param {Object} config
784 Ext.application = function(config) {
785 Ext.require('Ext.app.Application');
787 Ext.onReady(function() {
788 Ext.create('Ext.app.Application', config);