3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">/**
13 Ext.ns("Ext.grid", "Ext.list", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
14 "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
15 <div id="prop-Ext-ux"></div>/**
16 * Namespace alloted for extensions to the framework.
21 Ext.apply(Ext, function(){
27 <div id="prop-Ext-emptyFn"></div>/**
28 * A reusable empty function
32 emptyFn : function(){},
34 <div id="prop-Ext-BLANK_IMAGE_URL"></div>/**
35 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
36 * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
37 * For other browsers it uses an inline data URL.
40 BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 || Ext.isAir ?
41 'http:/' + '/extjs.com/s.gif' :
42 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
44 extendX : function(supr, fn){
45 return Ext.extend(supr, fn(supr.prototype));
48 <div id="method-Ext-getDoc"></div>/**
49 * Returns the current HTML document object as an {@link Ext.Element}.
50 * @return Ext.Element The document
53 return Ext.get(document);
56 <div id="method-Ext-num"></div>/**
57 * Utility method for validating that a value is numeric, returning the specified default value if it is not.
58 * @param {Mixed} value Should be a number, but any type will be handled appropriately
59 * @param {Number} defaultValue The value to return if the original value is non-numeric
60 * @return {Number} Value, if numeric, else defaultValue
62 num : function(v, defaultValue){
63 v = Number(Ext.isEmpty(v) || Ext.isBoolean(v) ? NaN : v);
64 return isNaN(v) ? defaultValue : v;
67 <div id="method-Ext-value"></div>/**
68 * <p>Utility method for returning a default value if the passed value is empty.</p>
69 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
72 * <li>an empty array</li>
73 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
75 * @param {Mixed} value The value to test
76 * @param {Mixed} defaultValue The value to return if the original value is empty
77 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
78 * @return {Mixed} value, if non-empty, else defaultValue
80 value : function(v, defaultValue, allowBlank){
81 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
84 <div id="method-Ext-escapeRe"></div>/**
85 * Escapes the passed string for use in a regular expression
89 escapeRe : function(s) {
90 return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
93 sequence : function(o, name, fn, scope){
94 o[name] = o[name].createSequence(fn, scope);
97 <div id="method-Ext-addBehaviors"></div>/**
98 * Applies event listeners to elements by selectors when the document is ready.
99 * The event name is specified with an <tt>@</tt> suffix.
102 // add a listener for click on all anchors in element with id foo
103 '#foo a@click' : function(e, t){
107 // add the same listener to multiple selectors (separated by comma BEFORE the @)
108 '#foo a, #bar span.some-class@mouseover' : function(){
113 * @param {Object} obj The list of behaviors to apply
115 addBehaviors : function(o){
117 Ext.onReady(function(){
121 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
126 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
129 cache[s] = Ext.select(s);
131 cache[s].on(parts[1], o[b]);
138 <div id="method-Ext-getScrollBarWidth"></div>/**
139 * Utility method for getting the width of the browser scrollbar. This can differ depending on
140 * operating system settings, such as the theme or font size.
141 * @param {Boolean} force (optional) true to force a recalculation of the value.
142 * @return {Number} The width of the scrollbar.
144 getScrollBarWidth: function(force){
149 if(force === true || scrollWidth === null){
150 // Append our div, do our calculation and then remove it
151 var div = Ext.getBody().createChild('<div class="x-hide-offsets" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
152 child = div.child('div', true);
153 var w1 = child.offsetWidth;
154 div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
155 var w2 = child.offsetWidth;
157 // Need to add 2 to ensure we leave enough space
158 scrollWidth = w1 - w2 + 2;
165 combine : function(){
166 var as = arguments, l = as.length, r = [];
167 for(var i = 0; i < l; i++){
171 }else if(a.length !== undefined && !a.substr){
172 r = r.concat(Array.prototype.slice.call(a, 0));
180 <div id="method-Ext-copyTo"></div>/**
181 * Copies a set of named properties fom the source object to the destination object.
182 * <p>example:<pre><code>
183 ImageComponent = Ext.extend(Ext.BoxComponent, {
184 initComponent: function() {
185 this.autoEl = { tag: 'img' };
186 MyComponent.superclass.initComponent.apply(this, arguments);
187 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
191 * @param {Object} The destination object.
192 * @param {Object} The source object.
193 * @param {Array/String} Either an Array of property names, or a comma-delimited list
194 * of property names to copy.
195 * @return {Object} The modified object.
197 copyTo : function(dest, source, names){
198 if(Ext.isString(names)){
199 names = names.split(/[,;\s]/);
201 Ext.each(names, function(name){
202 if(source.hasOwnProperty(name)){
203 dest[name] = source[name];
209 <div id="method-Ext-destroy"></div>/**
210 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
211 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
212 * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
213 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
214 * passed into this function in a single call as separate arguments.
215 * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
216 * @param {Mixed} arg2 (optional)
217 * @param {Mixed} etc... (optional)
219 destroy : function(){
220 Ext.each(arguments, function(arg){
222 if(Ext.isArray(arg)){
223 this.destroy.apply(this, arg);
224 }else if(Ext.isFunction(arg.destroy)){
233 <div id="method-Ext-destroyMembers"></div>/**
234 * Attempts to destroy and then remove a set of named properties of the passed object.
235 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
236 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
237 * @param {Mixed} etc... More property names to destroy and remove.
239 destroyMembers : function(o, arg1, arg2, etc){
240 for(var i = 1, a = arguments, len = a.length; i < len; i++) {
241 Ext.destroy(o[a[i]]);
246 <div id="method-Ext-clean"></div>/**
247 * Creates a copy of the passed Array with falsy values removed.
248 * @param {Array/NodeList} arr The Array from which to remove falsy values.
249 * @return {Array} The new, compressed Array.
251 clean : function(arr){
253 Ext.each(arr, function(v){
261 <div id="method-Ext-unique"></div>/**
262 * Creates a copy of the passed Array, filtered to contain only unique values.
263 * @param {Array} arr The Array to filter
264 * @return {Array} The new Array containing unique values.
266 unique : function(arr){
270 Ext.each(arr, function(v) {
279 <div id="method-Ext-flatten"></div>/**
280 * Recursively flattens into 1-d Array. Injects Arrays inline.
281 * @param {Array} arr The array to flatten
282 * @return {Array} The new, flattened array.
284 flatten : function(arr){
286 function rFlatten(a) {
287 Ext.each(a, function(v) {
296 return rFlatten(arr);
299 <div id="method-Ext-min"></div>/**
300 * Returns the minimum value in the Array.
301 * @param {Array|NodeList} arr The Array from which to select the minimum value.
302 * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
303 * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
304 * @return {Object} The minimum value in the Array.
306 min : function(arr, comp){
308 comp = comp || function(a,b){ return a < b ? -1 : 1; };
309 Ext.each(arr, function(v) {
310 ret = comp(ret, v) == -1 ? ret : v;
315 <div id="method-Ext-max"></div>/**
316 * Returns the maximum value in the Array
317 * @param {Array|NodeList} arr The Array from which to select the maximum value.
318 * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
319 * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
320 * @return {Object} The maximum value in the Array.
322 max : function(arr, comp){
324 comp = comp || function(a,b){ return a > b ? 1 : -1; };
325 Ext.each(arr, function(v) {
326 ret = comp(ret, v) == 1 ? ret : v;
331 <div id="method-Ext-mean"></div>/**
332 * Calculates the mean of the Array
333 * @param {Array} arr The Array to calculate the mean value of.
334 * @return {Number} The mean.
336 mean : function(arr){
337 return Ext.sum(arr) / arr.length;
340 <div id="method-Ext-sum"></div>/**
341 * Calculates the sum of the Array
342 * @param {Array} arr The Array to calculate the sum value of.
343 * @return {Number} The sum.
347 Ext.each(arr, function(v) {
353 <div id="method-Ext-partition"></div>/**
354 * Partitions the set into two sets: a true set and a false set.
359 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
365 return val.className == "class1"
368 // true are those paragraph elements with a className of "class1",
369 // false set are those that do not have that className.
371 * @param {Array|NodeList} arr The array to partition
372 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
373 * itself must be able to be evaluated for its truthfulness.
374 * @return {Array} [true<Array>,false<Array>]
376 partition : function(arr, truth){
378 Ext.each(arr, function(v, i, a) {
379 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
384 <div id="method-Ext-invoke"></div>/**
385 * Invokes a method on each item in an Array.
388 Ext.invoke(Ext.query("p"), "getAttribute", "id");
389 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
391 * @param {Array|NodeList} arr The Array of items to invoke the method on.
392 * @param {String} methodName The method name to invoke.
393 * @param {Anything} ... Arguments to send into the method invocation.
394 * @return {Array} The results of invoking the method on each item in the array.
396 invoke : function(arr, methodName){
398 args = Array.prototype.slice.call(arguments, 2);
399 Ext.each(arr, function(v,i) {
400 if (v && Ext.isFunction(v[methodName])) {
401 ret.push(v[methodName].apply(v, args));
409 <div id="method-Ext-pluck"></div>/**
410 * Plucks the value of a property from each item in the Array
413 Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
415 * @param {Array|NodeList} arr The Array of items to pluck the value from.
416 * @param {String} prop The property name to pluck from each element.
417 * @return {Array} The value from each item in the Array.
419 pluck : function(arr, prop){
421 Ext.each(arr, function(v) {
427 <div id="method-Ext-zip"></div>/**
428 * <p>Zips N sets together.</p>
431 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
438 return "$" + a + "" + b + "." + c
440 ); // ["$+12.43", "$-10.15", "$+22.96"]
442 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
443 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
444 * @return {Array} The zipped set.
447 var parts = Ext.partition(arguments, function( val ){ return !Ext.isFunction(val); }),
450 len = Ext.max(Ext.pluck(arrs, "length")),
453 for (var i = 0; i < len; i++) {
456 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
458 for (var j = 0, aLen = arrs.length; j < aLen; j++){
459 ret[i].push( arrs[j][i] );
466 <div id="method-Ext-getCmp"></div>/**
467 * This is shorthand reference to {@link Ext.ComponentMgr#get}.
468 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
469 * @param {String} id The component {@link Ext.Component#id id}
470 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
473 getCmp : function(id){
474 return Ext.ComponentMgr.get(id);
477 <div id="prop-Ext-useShims"></div>/**
478 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
479 * you may want to set this to true.
482 useShims: E.isIE6 || (E.isMac && E.isGecko2),
484 // inpired by a similar function in mootools library
485 <div id="method-Ext-type"></div>/**
486 * Returns the type of object that is passed in. If the object passed in is null or undefined it
487 * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
488 * <li><b>string</b>: If the object passed is a string</li>
489 * <li><b>number</b>: If the object passed is a number</li>
490 * <li><b>boolean</b>: If the object passed is a boolean value</li>
491 * <li><b>date</b>: If the object passed is a Date object</li>
492 * <li><b>function</b>: If the object passed is a function reference</li>
493 * <li><b>object</b>: If the object passed is an object</li>
494 * <li><b>array</b>: If the object passed is an array</li>
495 * <li><b>regexp</b>: If the object passed is a regular expression</li>
496 * <li><b>element</b>: If the object passed is a DOM Element</li>
497 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
498 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
499 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
501 * @param {Mixed} object
505 if(o === undefined || o === null){
512 if(t == 'object' && o.nodeName) {
514 case 1: return 'element';
515 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
518 if(t == 'object' || t == 'function') {
519 switch(o.constructor) {
520 case Array: return 'array';
521 case RegExp: return 'regexp';
522 case Date: return 'date';
524 if(Ext.isNumber(o.length) && Ext.isFunction(o.item)) {
531 intercept : function(o, name, fn, scope){
532 o[name] = o[name].createInterceptor(fn, scope);
536 callback : function(cb, scope, args, delay){
537 if(Ext.isFunction(cb)){
539 cb.defer(delay, scope, args || []);
541 cb.apply(scope, args || []);
550 * These functions are available on every Function object (any JavaScript function).
552 Ext.apply(Function.prototype, {
553 <div id="method-Function-createSequence"></div>/**
554 * Create a combined function call sequence of the original function + the passed function.
555 * The resulting function returns the results of the original function.
556 * The passed fcn is called with the parameters of the original function. Example usage:
558 var sayHi = function(name){
559 alert('Hi, ' + name);
562 sayHi('Fred'); // alerts "Hi, Fred"
564 var sayGoodbye = sayHi.createSequence(function(name){
565 alert('Bye, ' + name);
568 sayGoodbye('Fred'); // both alerts show
570 * @param {Function} fcn The function to sequence
571 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
572 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
573 * @return {Function} The new function
575 createSequence : function(fcn, scope){
577 return !Ext.isFunction(fcn) ?
580 var retval = method.apply(this || window, arguments);
581 fcn.apply(scope || this || window, arguments);
590 * These functions are available as static methods on the JavaScript String object.
592 Ext.applyIf(String, {
594 <div id="method-String-escape"></div>/**
595 * Escapes the passed string for ' and \
596 * @param {String} string The string to escape
597 * @return {String} The escaped string
600 escape : function(string) {
601 return string.replace(/('|\\)/g, "\\$1");
604 <div id="method-String-leftPad"></div>/**
605 * Pads the left side of a string with a specified character. This is especially useful
606 * for normalizing number and date strings. Example usage:
608 var s = String.leftPad('123', 5, '0');
609 // s now contains the string: '00123'
611 * @param {String} string The original string
612 * @param {Number} size The total length of the output string
613 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
614 * @return {String} The padded string
617 leftPad : function (val, size, ch) {
618 var result = String(val);
622 while (result.length < size) {
623 result = ch + result;
629 <div id="method-String-toggle"></div>/**
630 * Utility function that allows you to easily switch a string between two alternating values. The passed value
631 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
632 * they are already different, the first value passed in is returned. Note that this method returns the new value
633 * but does not change the current string.
635 // alternate sort directions
636 sort = sort.toggle('ASC', 'DESC');
638 // instead of conditional logic:
639 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
641 * @param {String} value The value to compare to the current string
642 * @param {String} other The new value to use if the string already equals the first value passed in
643 * @return {String} The new value
645 String.prototype.toggle = function(value, other){
646 return this == value ? other : value;
649 <div id="method-String-trim"></div>/**
650 * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
653 alert('-' + s + '-'); //alerts "- foo bar -"
654 alert('-' + s.trim() + '-'); //alerts "-foo bar-"
656 * @return {String} The trimmed string
658 String.prototype.trim = function(){
659 var re = /^\s+|\s+$/g;
660 return function(){ return this.replace(re, ""); };
663 // here to prevent dependency on Date.js
664 <div id="method-Date-getElapsed"></div>/**
665 Returns the number of milliseconds between this date and date
666 @param {Date} date (optional) Defaults to now
667 @return {Number} The diff in milliseconds
668 @member Date getElapsed
670 Date.prototype.getElapsed = function(date) {
671 return Math.abs((date || new Date()).getTime()-this.getTime());
675 <div id="cls-Number"></div>/**
678 Ext.applyIf(Number.prototype, {
679 <div id="method-Number-constrain"></div>/**
680 * Checks whether or not the current number is within a desired range. If the number is already within the
681 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
682 * exceeded. Note that this method returns the constrained value but does not change the current number.
683 * @param {Number} min The minimum number in the range
684 * @param {Number} max The maximum number in the range
685 * @return {Number} The constrained value if outside the range, otherwise the current value
687 constrain : function(min, max){
688 return Math.min(Math.max(this, min), max);