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
94 if (head == undefined) {
95 head = Ext.get(document.getElementsByTagName("head")[0]);
103 * Returns the current HTML document object as an {@link Ext.core.Element}.
104 * @return Ext.core.Element The document
107 return Ext.get(document);
111 * This is shorthand reference to {@link Ext.ComponentManager#get}.
112 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
113 * @param {String} id The component {@link Ext.Component#id id}
114 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
117 getCmp: function(id) {
118 return Ext.ComponentManager.get(id);
122 * Returns the current orientation of the mobile device
123 * @return {String} Either 'portrait' or 'landscape'
125 getOrientation: function() {
126 return window.innerHeight > window.innerWidth ? 'portrait' : 'landscape';
130 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
131 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
132 * intended for arguments of type {@link Ext.core.Element} and {@link Ext.Component}, but any subclass of
133 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
134 * passed into this function in a single call as separate arguments.
135 * @param {Mixed} arg1 An {@link Ext.core.Element}, {@link Ext.Component}, or an Array of either of these to destroy
136 * @param {Mixed} arg2 (optional)
137 * @param {Mixed} etc... (optional)
139 destroy: function() {
140 var ln = arguments.length,
143 for (i = 0; i < ln; i++) {
146 if (Ext.isArray(arg)) {
147 this.destroy.apply(this, arg);
149 else if (Ext.isFunction(arg.destroy)) {
160 * Execute a callback function in a particular scope. If no function is passed the call is ignored.
161 * @param {Function} callback The callback to execute
162 * @param {Object} scope (optional) The scope to execute in
163 * @param {Array} args (optional) The arguments to pass to the function
164 * @param {Number} delay (optional) Pass a number to delay the call by a number of milliseconds.
166 callback: function(callback, scope, args, delay){
167 if(Ext.isFunction(callback)){
169 scope = scope || window;
171 Ext.defer(callback, delay, scope, args);
173 callback.apply(scope, args);
179 * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
180 * @param {String} value The string to encode
181 * @return {String} The encoded text
183 htmlEncode : function(value) {
184 return Ext.String.htmlEncode(value);
188 * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
189 * @param {String} value The string to decode
190 * @return {String} The decoded text
192 htmlDecode : function(value) {
193 return Ext.String.htmlDecode(value);
197 * Appends content to the query string of a URL, handling logic for whether to place
198 * a question mark or ampersand.
199 * @param {String} url The URL to append to.
200 * @param {String} s The content to append to the URL.
201 * @return (String) The resulting URL
203 urlAppend : function(url, s) {
204 if (!Ext.isEmpty(s)) {
205 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
212 Ext.ns = Ext.namespace;
215 window.undefined = window.undefined;
219 * Ext core utilities and functions.
223 var check = function(regex){
224 return regex.test(Ext.userAgent);
226 docMode = document.documentMode,
227 isOpera = check(/opera/),
228 isOpera10_5 = isOpera && check(/version\/10\.5/),
229 isChrome = check(/\bchrome\b/),
230 isWebKit = check(/webkit/),
231 isSafari = !isChrome && check(/safari/),
232 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
233 isSafari3 = isSafari && check(/version\/3/),
234 isSafari4 = isSafari && check(/version\/4/),
235 isIE = !isOpera && check(/msie/),
236 isIE7 = isIE && (check(/msie 7/) || docMode == 7),
237 isIE8 = isIE && (check(/msie 8/) && docMode != 7 && docMode != 9 || docMode == 8),
238 isIE9 = isIE && (check(/msie 9/) && docMode != 7 && docMode != 8 || docMode == 9),
239 isIE6 = isIE && check(/msie 6/),
240 isGecko = !isWebKit && check(/gecko/),
241 isGecko3 = isGecko && check(/rv:1\.9/),
242 isGecko4 = isGecko && check(/rv:2\.0/),
243 isFF3_0 = isGecko3 && check(/rv:1\.9\.0/),
244 isFF3_5 = isGecko3 && check(/rv:1\.9\.1/),
245 isFF3_6 = isGecko3 && check(/rv:1\.9\.2/),
246 isWindows = check(/windows|win32/),
247 isMac = check(/macintosh|mac os x/),
248 isLinux = check(/linux/),
250 webKitVersion = isWebKit && (/webkit\/(\d+\.\d+)/.exec(Ext.userAgent));
252 // remove css image flicker
254 document.execCommand("BackgroundImageCache", false, true);
257 Ext.setVersion('extjs', '4.0.1');
260 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
261 * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
264 SSL_SECURE_URL : Ext.isSecure && isIE ? 'javascript:""' : 'about:blank',
267 * True if the {@link Ext.fx.Anim} Class is available
273 * True to scope the reset CSS to be just applied to Ext components. Note that this wraps root containers
274 * with an additional element. Also remember that when you turn on this option, you have to use ext-all-scoped {
275 * unless you use the bootstrap.js to load your javascript, in which case it will be handled for you.
278 scopeResetCSS : Ext.buildSettings.scopeResetCSS,
281 * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
282 * Currently not optimized for performance.
285 enableNestedListenerRemoval : false,
288 * Indicates whether to use native browser parsing for JSON methods.
289 * This option is ignored if the browser does not support native JSON methods.
290 * <b>Note: Native JSON methods will not work with objects that have functions.
291 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
294 USE_NATIVE_JSON : false,
297 * Return the dom node for the passed String (id), dom node, or Ext.core.Element.
298 * Optional 'strict' flag is needed for IE since it can return 'name' and
299 * 'id' elements by using getElementById.
300 * Here are some examples:
302 // gets dom node based on id
303 var elDom = Ext.getDom('elId');
304 // gets dom node based on the dom node
305 var elDom1 = Ext.getDom(elDom);
307 // If we don't know if we are working with an
308 // Ext.core.Element or a dom node use Ext.getDom
310 var dom = Ext.getDom(el);
311 // do something with the dom node
314 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
315 * when this method is called to be successful.
317 * @return HTMLElement
319 getDom : function(el, strict) {
320 if (!el || !document) {
326 if (typeof el == 'string') {
327 var e = document.getElementById(el);
328 // IE returns elements with the 'name' and 'id' attribute.
329 // we do a strict check to return the element with only the id attribute
330 if (e && isIE && strict) {
331 if (el == e.getAttribute('id')) {
345 * Removes a DOM node from the document.
346 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
347 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval Ext.enableNestedListenerRemoval} is
348 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
349 * will be ignored if passed in.</p>
350 * @param {HTMLElement} node The node to remove
353 removeNode : isIE6 || isIE7 ? function() {
356 if(n && n.tagName != 'BODY'){
357 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
358 d = d || document.createElement('div');
361 delete Ext.cache[n.id];
365 if (n && n.parentNode && n.tagName != 'BODY') {
366 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
367 n.parentNode.removeChild(n);
368 delete Ext.cache[n.id];
373 * True if the detected browser is Opera.
379 * True if the detected browser is Opera 10.5x.
382 isOpera10_5 : isOpera10_5,
385 * True if the detected browser uses WebKit.
391 * True if the detected browser is Chrome.
397 * True if the detected browser is Safari.
403 * True if the detected browser is Safari 3.x.
406 isSafari3 : isSafari3,
409 * True if the detected browser is Safari 4.x.
412 isSafari4 : isSafari4,
415 * True if the detected browser is Safari 2.x.
418 isSafari2 : isSafari2,
421 * True if the detected browser is Internet Explorer.
427 * True if the detected browser is Internet Explorer 6.x.
433 * True if the detected browser is Internet Explorer 7.x.
439 * True if the detected browser is Internet Explorer 8.x.
445 * True if the detected browser is Internet Explorer 9.x.
451 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
457 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
463 * True if the detected browser uses a Gecko 2.0+ layout engine (e.g. Firefox 4.x).
469 * True if the detected browser uses FireFox 3.0
475 * True if the detected browser uses FireFox 3.5
481 * True if the detected browser uses FireFox 3.6
487 * True if the detected platform is Linux.
493 * True if the detected platform is Windows.
496 isWindows : isWindows,
499 * True if the detected platform is Mac OS.
505 * The current version of WebKit (-1 if the browser does not use WebKit).
508 webKitVersion: webKitVersion ? parseFloat(webKitVersion[1]) : -1,
511 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
512 * In older versions of IE, this defaults to "http://sencha.com/s.gif" and you should change this to a URL on your server.
513 * For other browsers it uses an inline data URL.
516 BLANK_IMAGE_URL : (isIE6 || isIE7) ? 'http:/' + '/www.sencha.com/s.gif' : 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
519 * <p>Utility method for returning a default value if the passed value is empty.</p>
520 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
523 * <li>an empty array</li>
524 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
526 * @param {Mixed} value The value to test
527 * @param {Mixed} defaultValue The value to return if the original value is empty
528 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
529 * @return {Mixed} value, if non-empty, else defaultValue
530 * @deprecated 4.0.0 Use {Ext#valueFrom} instead
532 value : function(v, defaultValue, allowBlank){
533 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
537 * Escapes the passed string for use in a regular expression
538 * @param {String} str
540 * @deprecated 4.0.0 Use {@link Ext.String#escapeRegex} instead
542 escapeRe : function(s) {
543 return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
547 * Applies event listeners to elements by selectors when the document is ready.
548 * The event name is specified with an <tt>@</tt> suffix.
551 // add a listener for click on all anchors in element with id foo
552 '#foo a@click' : function(e, t){
556 // add the same listener to multiple selectors (separated by comma BEFORE the @)
557 '#foo a, #bar span.some-class@mouseover' : function(){
562 * @param {Object} obj The list of behaviors to apply
564 addBehaviors : function(o){
566 Ext.onReady(function(){
570 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
575 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
578 cache[s] = Ext.select(s);
580 cache[s].on(parts[1], o[b]);
588 * Utility method for getting the width of the browser scrollbar. This can differ depending on
589 * operating system settings, such as the theme or font size.
590 * @param {Boolean} force (optional) true to force a recalculation of the value.
591 * @return {Number} The width of the scrollbar.
593 getScrollBarWidth: function(force){
598 if(force === true || scrollWidth === null){
600 // When IE9 positions an element offscreen via offsets, the offsetWidth is
601 // inaccurately reported. For IE9 only, we render on screen before removing.
602 var cssClass = Ext.isIE9 ? '' : Ext.baseCSSPrefix + 'hide-offsets';
603 // Append our div, do our calculation and then remove it
604 var div = Ext.getBody().createChild('<div class="' + cssClass + '" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
605 child = div.child('div', true);
606 var w1 = child.offsetWidth;
607 div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
608 var w2 = child.offsetWidth;
610 // Need to add 2 to ensure we leave enough space
611 scrollWidth = w1 - w2 + 2;
617 * Copies a set of named properties fom the source object to the destination object.
618 * <p>example:<pre><code>
619 ImageComponent = Ext.extend(Ext.Component, {
620 initComponent: function() {
621 this.autoEl = { tag: 'img' };
622 MyComponent.superclass.initComponent.apply(this, arguments);
623 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
627 * Important note: To borrow class prototype methods, use {@link Ext.Base#borrow} instead.
628 * @param {Object} dest The destination object.
629 * @param {Object} source The source object.
630 * @param {Array/String} names Either an Array of property names, or a comma-delimited list
631 * of property names to copy.
632 * @param {Boolean} usePrototypeKeys (Optional) Defaults to false. Pass true to copy keys off of the prototype as well as the instance.
633 * @return {Object} The modified object.
635 copyTo : function(dest, source, names, usePrototypeKeys){
636 if(typeof names == 'string'){
637 names = names.split(/[,;\s]/);
639 Ext.each(names, function(name){
640 if(usePrototypeKeys || source.hasOwnProperty(name)){
641 dest[name] = source[name];
648 * Attempts to destroy and then remove a set of named properties of the passed object.
649 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
650 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
651 * @param {Mixed} etc... More property names to destroy and remove.
653 destroyMembers : function(o, arg1, arg2, etc){
654 for (var i = 1, a = arguments, len = a.length; i < len; i++) {
655 Ext.destroy(o[a[i]]);
661 * Logs a message. If a console is present it will be used. On Opera, the method
662 * "opera.postError" is called. In other cases, the message is logged to an array
663 * "Ext.log.out". An attached debugger can watch this array and view the log. The
664 * log buffer is limited to a maximum of "Ext.log.max" entries (defaults to 100).
666 * If additional parameters are passed, they are joined and appended to the message.
668 * This method does nothing in a release build.
670 * @param {String|Object} message The message to log or an options object with any
671 * of the following properties:
673 * - `msg`: The message to log (required).
674 * - `level`: One of: "error", "warn", "info" or "log" (the default is "log").
675 * - `dump`: An object to dump to the log as part of the message.
676 * - `stack`: True to include a stack trace in the log.
679 log : function (message) {
682 con = Ext.global.console,
689 if (!Ext.isString(message)) {
691 message = options.msg || '';
692 level = options.level || level;
694 stack = options.stack;
696 if (dump && !(con && con.dir)) {
699 // Cannot use Ext.encode since it can recurse endlessly (if we're lucky)
700 // ...and the data could be prettier!
701 Ext.Object.each(dump, function (name, value) {
702 if (typeof(value) === "function") {
706 if (!Ext.isDefined(value) || value === null ||
708 Ext.isString(value) || (typeof(value) == "number") ||
709 Ext.isBoolean(value)) {
710 member = Ext.encode(value);
711 } else if (Ext.isArray(value)) {
713 } else if (Ext.isObject(value)) {
716 member = 'undefined';
718 members.push(Ext.encode(name) + ': ' + member);
721 if (members.length) {
722 message += ' \nData: {\n ' + members.join(',\n ') + '\n}';
728 if (arguments.length > 1) {
729 message += Array.prototype.slice.call(arguments, 1).join('');
732 // Not obvious, but 'console' comes and goes when Firebug is turned on/off, so
733 // an early test may fail either direction if Firebug is toggled.
735 if (con) { // if (Firebug-like console)
746 if (stack && con.trace) {
747 // Firebug's console.error() includes a trace already...
748 if (!con.firebug || level != 'error') {
753 // w/o console, all messages are equal, so munge the level into the message:
754 if (level != 'log') {
755 message = level.toUpperCase() + ': ' + message;
759 opera.postError(message);
761 var out = log.out || (log.out = []),
762 max = log.max || (log.max = 100);
764 if (out.length >= max) {
765 // this formula allows out.max to change (via debugger), where the
766 // more obvious "max/4" would not quite be the same
767 out.splice(0, out.length - 3 * Math.floor(max / 4)); // keep newest 75%
774 // Mostly informational, but the Ext.Error notifier uses them:
775 var counters = log.counters ||
776 (log.counters = { error: 0, warn: 0, info: 0, log: 0 });
783 * Partitions the set into two sets: a true set and a false set.
788 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
794 return val.className == "class1"
797 // true are those paragraph elements with a className of "class1",
798 // false set are those that do not have that className.
800 * @param {Array|NodeList} arr The array to partition
801 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
802 * itself must be able to be evaluated for its truthfulness.
803 * @return {Array} [true<Array>,false<Array>]
804 * @deprecated 4.0.0 Will be removed in the next major version
806 partition : function(arr, truth){
808 Ext.each(arr, function(v, i, a) {
809 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
815 * Invokes a method on each item in an Array.
818 Ext.invoke(Ext.query("p"), "getAttribute", "id");
819 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
821 * @param {Array|NodeList} arr The Array of items to invoke the method on.
822 * @param {String} methodName The method name to invoke.
823 * @param {...*} args Arguments to send into the method invocation.
824 * @return {Array} The results of invoking the method on each item in the array.
825 * @deprecated 4.0.0 Will be removed in the next major version
827 invoke : function(arr, methodName){
829 args = Array.prototype.slice.call(arguments, 2);
830 Ext.each(arr, function(v,i) {
831 if (v && typeof v[methodName] == 'function') {
832 ret.push(v[methodName].apply(v, args));
841 * <p>Zips N sets together.</p>
844 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
851 return "$" + a + "" + b + "." + c
853 ); // ["$+12.43", "$-10.15", "$+22.96"]
855 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
856 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
857 * @return {Array} The zipped set.
858 * @deprecated 4.0.0 Will be removed in the next major version
861 var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
864 len = Ext.max(Ext.pluck(arrs, "length")),
867 for (var i = 0; i < len; i++) {
870 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
872 for (var j = 0, aLen = arrs.length; j < aLen; j++){
873 ret[i].push( arrs[j][i] );
881 * Turns an array into a sentence, joined by a specified connector - e.g.:
882 * Ext.toSentence(['Adama', 'Tigh', 'Roslin']); //'Adama, Tigh and Roslin'
883 * Ext.toSentence(['Adama', 'Tigh', 'Roslin'], 'or'); //'Adama, Tigh or Roslin'
884 * @param {Array} items The array to create a sentence from
885 * @param {String} connector The string to use to connect the last two words. Usually 'and' or 'or' - defaults to 'and'.
886 * @return {String} The sentence string
887 * @deprecated 4.0.0 Will be removed in the next major version
889 toSentence: function(items, connector) {
890 var length = items.length;
895 var head = items.slice(0, length - 1),
896 tail = items[length - 1];
898 return Ext.util.Format.format("{0} {1} {2}", head.join(", "), connector || 'and', tail);
903 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
904 * you may want to set this to true.
913 * @param {Object} config
916 Ext.application = function(config) {
917 Ext.require('Ext.app.Application');
919 Ext.onReady(function() {
920 Ext.create('Ext.app.Application', config);