]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui/build/yahoo/yahoo.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / yui / build / yahoo / yahoo.js
1 /*
2 Copyright (c) 2011, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 2.9.0
6 */
7 /**
8  * The YAHOO object is the single global object used by YUI Library.  It
9  * contains utility function for setting up namespaces, inheritance, and
10  * logging.  YAHOO.util, YAHOO.widget, and YAHOO.example are namespaces
11  * created automatically for and used by the library.
12  * @module yahoo
13  * @title  YAHOO Global
14  */
15
16 /**
17  * YAHOO_config is not included as part of the library.  Instead it is an
18  * object that can be defined by the implementer immediately before
19  * including the YUI library.  The properties included in this object
20  * will be used to configure global properties needed as soon as the
21  * library begins to load.
22  * @class YAHOO_config
23  * @static
24  */
25
26 /**
27  * A reference to a function that will be executed every time a YAHOO module
28  * is loaded.  As parameter, this function will receive the version
29  * information for the module. See <a href="YAHOO.env.html#getVersion">
30  * YAHOO.env.getVersion</a> for the description of the version data structure.
31  * @property listener
32  * @type Function
33  * @static
34  * @default undefined
35  */
36
37 /**
38  * Set to true if the library will be dynamically loaded after window.onload.
39  * Defaults to false
40  * @property injecting
41  * @type boolean
42  * @static
43  * @default undefined
44  */
45
46 /**
47  * Instructs the yuiloader component to dynamically load yui components and
48  * their dependencies.  See the yuiloader documentation for more information
49  * about dynamic loading
50  * @property load
51  * @static
52  * @default undefined
53  * @see yuiloader
54  */
55
56 /**
57  * Forces the use of the supplied locale where applicable in the library
58  * @property locale
59  * @type string
60  * @static
61  * @default undefined
62  */
63
64 if (typeof YAHOO == "undefined" || !YAHOO) {
65     /**
66      * The YAHOO global namespace object.  If YAHOO is already defined, the
67      * existing YAHOO object will not be overwritten so that defined
68      * namespaces are preserved.
69      * @class YAHOO
70      * @static
71      */
72     var YAHOO = {};
73 }
74
75 /**
76  * Returns the namespace specified and creates it if it doesn't exist
77  * <pre>
78  * YAHOO.namespace("property.package");
79  * YAHOO.namespace("YAHOO.property.package");
80  * </pre>
81  * Either of the above would create YAHOO.property, then
82  * YAHOO.property.package
83  *
84  * Be careful when naming packages. Reserved words may work in some browsers
85  * and not others. For instance, the following will fail in Safari:
86  * <pre>
87  * YAHOO.namespace("really.long.nested.namespace");
88  * </pre>
89  * This fails because "long" is a future reserved word in ECMAScript
90  *
91  * For implementation code that uses YUI, do not create your components
92  * in the namespaces defined by YUI (
93  * <code>YAHOO.util</code>,
94  * <code>YAHOO.widget</code>,
95  * <code>YAHOO.lang</code>,
96  * <code>YAHOO.tool</code>,
97  * <code>YAHOO.example</code>,
98  * <code>YAHOO.env</code>) -- create your own namespace (e.g., 'companyname').
99  *
100  * @method namespace
101  * @static
102  * @param  {String*} arguments 1-n namespaces to create
103  * @return {Object}  A reference to the last namespace object created
104  */
105 YAHOO.namespace = function() {
106     var a=arguments, o=null, i, j, d;
107     for (i=0; i<a.length; i=i+1) {
108         d=(""+a[i]).split(".");
109         o=YAHOO;
110
111         // YAHOO is implied, so it is ignored if it is included
112         for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
113             o[d[j]]=o[d[j]] || {};
114             o=o[d[j]];
115         }
116     }
117
118     return o;
119 };
120
121 /**
122  * Uses YAHOO.widget.Logger to output a log message, if the widget is
123  * available.
124  * Note: LogReader adds the message, category, and source to the DOM as HTML.
125  *
126  * @method log
127  * @static
128  * @param  {HTML}  msg  The message to log.
129  * @param  {HTML}  cat  The log category for the message.  Default
130  *                        categories are "info", "warn", "error", time".
131  *                        Custom categories can be used as well. (opt)
132  * @param  {HTML}  src  The source of the the message (opt)
133  * @return {Boolean}      True if the log operation was successful.
134  */
135 YAHOO.log = function(msg, cat, src) {
136     var l=YAHOO.widget.Logger;
137     if(l && l.log) {
138         return l.log(msg, cat, src);
139     } else {
140         return false;
141     }
142 };
143
144 /**
145  * Registers a module with the YAHOO object
146  * @method register
147  * @static
148  * @param {String}   name    the name of the module (event, slider, etc)
149  * @param {Function} mainClass a reference to class in the module.  This
150  *                             class will be tagged with the version info
151  *                             so that it will be possible to identify the
152  *                             version that is in use when multiple versions
153  *                             have loaded
154  * @param {Object}   data      metadata object for the module.  Currently it
155  *                             is expected to contain a "version" property
156  *                             and a "build" property at minimum.
157  */
158 YAHOO.register = function(name, mainClass, data) {
159     var mods = YAHOO.env.modules, m, v, b, ls, i;
160
161     if (!mods[name]) {
162         mods[name] = {
163             versions:[],
164             builds:[]
165         };
166     }
167
168     m  = mods[name];
169     v  = data.version;
170     b  = data.build;
171     ls = YAHOO.env.listeners;
172
173     m.name = name;
174     m.version = v;
175     m.build = b;
176     m.versions.push(v);
177     m.builds.push(b);
178     m.mainClass = mainClass;
179
180     // fire the module load listeners
181     for (i=0;i<ls.length;i=i+1) {
182         ls[i](m);
183     }
184     // label the main class
185     if (mainClass) {
186         mainClass.VERSION = v;
187         mainClass.BUILD = b;
188     } else {
189         YAHOO.log("mainClass is undefined for module " + name, "warn");
190     }
191 };
192
193 /**
194  * YAHOO.env is used to keep track of what is known about the YUI library and
195  * the browsing environment
196  * @class YAHOO.env
197  * @static
198  */
199 YAHOO.env = YAHOO.env || {
200
201     /**
202      * Keeps the version info for all YUI modules that have reported themselves
203      * @property modules
204      * @type Object[]
205      */
206     modules: [],
207
208     /**
209      * List of functions that should be executed every time a YUI module
210      * reports itself.
211      * @property listeners
212      * @type Function[]
213      */
214     listeners: []
215 };
216
217 /**
218  * Returns the version data for the specified module:
219  *      <dl>
220  *      <dt>name:</dt>      <dd>The name of the module</dd>
221  *      <dt>version:</dt>   <dd>The version in use</dd>
222  *      <dt>build:</dt>     <dd>The build number in use</dd>
223  *      <dt>versions:</dt>  <dd>All versions that were registered</dd>
224  *      <dt>builds:</dt>    <dd>All builds that were registered.</dd>
225  *      <dt>mainClass:</dt> <dd>An object that was was stamped with the
226  *                 current version and build. If
227  *                 mainClass.VERSION != version or mainClass.BUILD != build,
228  *                 multiple versions of pieces of the library have been
229  *                 loaded, potentially causing issues.</dd>
230  *       </dl>
231  *
232  * @method getVersion
233  * @static
234  * @param {String}  name the name of the module (event, slider, etc)
235  * @return {Object} The version info
236  */
237 YAHOO.env.getVersion = function(name) {
238     return YAHOO.env.modules[name] || null;
239 };
240
241 /**
242  * Do not fork for a browser if it can be avoided.  Use feature detection when
243  * you can.  Use the user agent as a last resort.  YAHOO.env.ua stores a version
244  * number for the browser engine, 0 otherwise.  This value may or may not map
245  * to the version number of the browser using the engine.  The value is
246  * presented as a float so that it can easily be used for boolean evaluation
247  * as well as for looking for a particular range of versions.  Because of this,
248  * some of the granularity of the version info may be lost (e.g., Gecko 1.8.0.9
249  * reports 1.8).
250  * @class YAHOO.env.ua
251  * @static
252  */
253
254 /**
255  * parses a user agent string (or looks for one in navigator to parse if
256  * not supplied).
257  * @method parseUA
258  * @since 2.9.0
259  * @static
260  */
261 YAHOO.env.parseUA = function(agent) {
262
263         var numberify = function(s) {
264             var c = 0;
265             return parseFloat(s.replace(/\./g, function() {
266                 return (c++ == 1) ? '' : '.';
267             }));
268         },
269
270         nav = navigator,
271
272         o = {
273
274         /**
275          * Internet Explorer version number or 0.  Example: 6
276          * @property ie
277          * @type float
278          * @static
279          */
280         ie: 0,
281
282         /**
283          * Opera version number or 0.  Example: 9.2
284          * @property opera
285          * @type float
286          * @static
287          */
288         opera: 0,
289
290         /**
291          * Gecko engine revision number.  Will evaluate to 1 if Gecko
292          * is detected but the revision could not be found. Other browsers
293          * will be 0.  Example: 1.8
294          * <pre>
295          * Firefox 1.0.0.4: 1.7.8   <-- Reports 1.7
296          * Firefox 1.5.0.9: 1.8.0.9 <-- 1.8
297          * Firefox 2.0.0.3: 1.8.1.3 <-- 1.81
298          * Firefox 3.0   <-- 1.9
299          * Firefox 3.5   <-- 1.91
300          * </pre>
301          * @property gecko
302          * @type float
303          * @static
304          */
305         gecko: 0,
306
307         /**
308          * AppleWebKit version.  KHTML browsers that are not WebKit browsers
309          * will evaluate to 1, other browsers 0.  Example: 418.9
310          * <pre>
311          * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the
312          *                                   latest available for Mac OSX 10.3.
313          * Safari 2.0.2:         416     <-- hasOwnProperty introduced
314          * Safari 2.0.4:         418     <-- preventDefault fixed
315          * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
316          *                                   different versions of webkit
317          * Safari 2.0.4 (419.3): 419     <-- Tiger installations that have been
318          *                                   updated, but not updated
319          *                                   to the latest patch.
320          * Webkit 212 nightly:   522+    <-- Safari 3.0 precursor (with native
321          * SVG and many major issues fixed).
322          * Safari 3.0.4 (523.12) 523.12  <-- First Tiger release - automatic
323          * update from 2.x via the 10.4.11 OS patch.
324          * Webkit nightly 1/2008:525+    <-- Supports DOMContentLoaded event.
325          *                                   yahoo.com user agent hack removed.
326          * </pre>
327          * http://en.wikipedia.org/wiki/Safari_version_history
328          * @property webkit
329          * @type float
330          * @static
331          */
332         webkit: 0,
333
334         /**
335          * Chrome will be detected as webkit, but this property will also
336          * be populated with the Chrome version number
337          * @property chrome
338          * @type float
339          * @static
340          */
341         chrome: 0,
342
343         /**
344          * The mobile property will be set to a string containing any relevant
345          * user agent information when a modern mobile browser is detected.
346          * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
347          * devices with the WebKit-based browser, and Opera Mini.
348          * @property mobile
349          * @type string
350          * @static
351          */
352         mobile: null,
353
354         /**
355          * Adobe AIR version number or 0.  Only populated if webkit is detected.
356          * Example: 1.0
357          * @property air
358          * @type float
359          */
360         air: 0,
361         /**
362          * Detects Apple iPad's OS version
363          * @property ipad
364          * @type float
365          * @static
366          */
367         ipad: 0,
368         /**
369          * Detects Apple iPhone's OS version
370          * @property iphone
371          * @type float
372          * @static
373          */
374         iphone: 0,
375         /**
376          * Detects Apples iPod's OS version
377          * @property ipod
378          * @type float
379          * @static
380          */
381         ipod: 0,
382         /**
383          * General truthy check for iPad, iPhone or iPod
384          * @property ios
385          * @type float
386          * @static
387          */
388         ios: null,
389         /**
390          * Detects Googles Android OS version
391          * @property android
392          * @type float
393          * @static
394          */
395         android: 0,
396         /**
397          * Detects Palms WebOS version
398          * @property webos
399          * @type float
400          * @static
401          */
402         webos: 0,
403
404         /**
405          * Google Caja version number or 0.
406          * @property caja
407          * @type float
408          */
409         caja: nav && nav.cajaVersion,
410
411         /**
412          * Set to true if the page appears to be in SSL
413          * @property secure
414          * @type boolean
415          * @static
416          */
417         secure: false,
418
419         /**
420          * The operating system.  Currently only detecting windows or macintosh
421          * @property os
422          * @type string
423          * @static
424          */
425         os: null
426
427     },
428
429     ua = agent || (navigator && navigator.userAgent),
430
431     loc = window && window.location,
432
433     href = loc && loc.href,
434
435     m;
436
437     o.secure = href && (href.toLowerCase().indexOf("https") === 0);
438
439     if (ua) {
440
441         if ((/windows|win32/i).test(ua)) {
442             o.os = 'windows';
443         } else if ((/macintosh/i).test(ua)) {
444             o.os = 'macintosh';
445         } else if ((/rhino/i).test(ua)) {
446             o.os = 'rhino';
447         }
448
449         // Modern KHTML browsers should qualify as Safari X-Grade
450         if ((/KHTML/).test(ua)) {
451             o.webkit = 1;
452         }
453         // Modern WebKit browsers are at least X-Grade
454         m = ua.match(/AppleWebKit\/([^\s]*)/);
455         if (m && m[1]) {
456             o.webkit = numberify(m[1]);
457
458             // Mobile browser check
459             if (/ Mobile\//.test(ua)) {
460                 o.mobile = 'Apple'; // iPhone or iPod Touch
461
462                 m = ua.match(/OS ([^\s]*)/);
463                 if (m && m[1]) {
464                     m = numberify(m[1].replace('_', '.'));
465                 }
466                 o.ios = m;
467                 o.ipad = o.ipod = o.iphone = 0;
468
469                 m = ua.match(/iPad|iPod|iPhone/);
470                 if (m && m[0]) {
471                     o[m[0].toLowerCase()] = o.ios;
472                 }
473             } else {
474                 m = ua.match(/NokiaN[^\/]*|Android \d\.\d|webOS\/\d\.\d/);
475                 if (m) {
476                     // Nokia N-series, Android, webOS, ex: NokiaN95
477                     o.mobile = m[0];
478                 }
479                 if (/webOS/.test(ua)) {
480                     o.mobile = 'WebOS';
481                     m = ua.match(/webOS\/([^\s]*);/);
482                     if (m && m[1]) {
483                         o.webos = numberify(m[1]);
484                     }
485                 }
486                 if (/ Android/.test(ua)) {
487                     o.mobile = 'Android';
488                     m = ua.match(/Android ([^\s]*);/);
489                     if (m && m[1]) {
490                         o.android = numberify(m[1]);
491                     }
492
493                 }
494             }
495
496             m = ua.match(/Chrome\/([^\s]*)/);
497             if (m && m[1]) {
498                 o.chrome = numberify(m[1]); // Chrome
499             } else {
500                 m = ua.match(/AdobeAIR\/([^\s]*)/);
501                 if (m) {
502                     o.air = m[0]; // Adobe AIR 1.0 or better
503                 }
504             }
505         }
506
507         if (!o.webkit) { // not webkit
508 // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
509             m = ua.match(/Opera[\s\/]([^\s]*)/);
510             if (m && m[1]) {
511                 o.opera = numberify(m[1]);
512                 m = ua.match(/Version\/([^\s]*)/);
513                 if (m && m[1]) {
514                     o.opera = numberify(m[1]); // opera 10+
515                 }
516                 m = ua.match(/Opera Mini[^;]*/);
517                 if (m) {
518                     o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
519                 }
520             } else { // not opera or webkit
521                 m = ua.match(/MSIE\s([^;]*)/);
522                 if (m && m[1]) {
523                     o.ie = numberify(m[1]);
524                 } else { // not opera, webkit, or ie
525                     m = ua.match(/Gecko\/([^\s]*)/);
526                     if (m) {
527                         o.gecko = 1; // Gecko detected, look for revision
528                         m = ua.match(/rv:([^\s\)]*)/);
529                         if (m && m[1]) {
530                             o.gecko = numberify(m[1]);
531                         }
532                     }
533                 }
534             }
535         }
536     }
537
538     return o;
539 };
540
541 YAHOO.env.ua = YAHOO.env.parseUA();
542
543 /*
544  * Initializes the global by creating the default namespaces and applying
545  * any new configuration information that is detected.  This is the setup
546  * for env.
547  * @method init
548  * @static
549  * @private
550  */
551 (function() {
552     YAHOO.namespace("util", "widget", "example");
553     /*global YAHOO_config*/
554     if ("undefined" !== typeof YAHOO_config) {
555         var l=YAHOO_config.listener, ls=YAHOO.env.listeners,unique=true, i;
556         if (l) {
557             // if YAHOO is loaded multiple times we need to check to see if
558             // this is a new config object.  If it is, add the new component
559             // load listener to the stack
560             for (i=0; i<ls.length; i++) {
561                 if (ls[i] == l) {
562                     unique = false;
563                     break;
564                 }
565             }
566
567             if (unique) {
568                 ls.push(l);
569             }
570         }
571     }
572 })();
573 /**
574  * Provides the language utilites and extensions used by the library
575  * @class YAHOO.lang
576  */
577 YAHOO.lang = YAHOO.lang || {};
578
579 (function() {
580
581
582 var L = YAHOO.lang,
583
584     OP = Object.prototype,
585     ARRAY_TOSTRING = '[object Array]',
586     FUNCTION_TOSTRING = '[object Function]',
587     OBJECT_TOSTRING = '[object Object]',
588     NOTHING = [],
589
590     HTML_CHARS = {
591         '&': '&amp;',
592         '<': '&lt;',
593         '>': '&gt;',
594         '"': '&quot;',
595         "'": '&#x27;',
596         '/': '&#x2F;',
597         '`': '&#x60;'
598     },
599
600     // ADD = ["toString", "valueOf", "hasOwnProperty"],
601     ADD = ["toString", "valueOf"],
602
603     OB = {
604
605     /**
606      * Determines wheather or not the provided object is an array.
607      * @method isArray
608      * @param {any} o The object being testing
609      * @return {boolean} the result
610      */
611     isArray: function(o) {
612         return OP.toString.apply(o) === ARRAY_TOSTRING;
613     },
614
615     /**
616      * Determines whether or not the provided object is a boolean
617      * @method isBoolean
618      * @param {any} o The object being testing
619      * @return {boolean} the result
620      */
621     isBoolean: function(o) {
622         return typeof o === 'boolean';
623     },
624
625     /**
626      * Determines whether or not the provided object is a function.
627      * Note: Internet Explorer thinks certain functions are objects:
628      *
629      * var obj = document.createElement("object");
630      * YAHOO.lang.isFunction(obj.getAttribute) // reports false in IE
631      *
632      * var input = document.createElement("input"); // append to body
633      * YAHOO.lang.isFunction(input.focus) // reports false in IE
634      *
635      * You will have to implement additional tests if these functions
636      * matter to you.
637      *
638      * @method isFunction
639      * @param {any} o The object being testing
640      * @return {boolean} the result
641      */
642     isFunction: function(o) {
643         return (typeof o === 'function') || OP.toString.apply(o) === FUNCTION_TOSTRING;
644     },
645
646     /**
647      * Determines whether or not the provided object is null
648      * @method isNull
649      * @param {any} o The object being testing
650      * @return {boolean} the result
651      */
652     isNull: function(o) {
653         return o === null;
654     },
655
656     /**
657      * Determines whether or not the provided object is a legal number
658      * @method isNumber
659      * @param {any} o The object being testing
660      * @return {boolean} the result
661      */
662     isNumber: function(o) {
663         return typeof o === 'number' && isFinite(o);
664     },
665
666     /**
667      * Determines whether or not the provided object is of type object
668      * or function
669      * @method isObject
670      * @param {any} o The object being testing
671      * @return {boolean} the result
672      */
673     isObject: function(o) {
674 return (o && (typeof o === 'object' || L.isFunction(o))) || false;
675     },
676
677     /**
678      * Determines whether or not the provided object is a string
679      * @method isString
680      * @param {any} o The object being testing
681      * @return {boolean} the result
682      */
683     isString: function(o) {
684         return typeof o === 'string';
685     },
686
687     /**
688      * Determines whether or not the provided object is undefined
689      * @method isUndefined
690      * @param {any} o The object being testing
691      * @return {boolean} the result
692      */
693     isUndefined: function(o) {
694         return typeof o === 'undefined';
695     },
696
697
698     /**
699      * IE will not enumerate native functions in a derived object even if the
700      * function was overridden.  This is a workaround for specific functions
701      * we care about on the Object prototype.
702      * @property _IEEnumFix
703      * @param {Function} r  the object to receive the augmentation
704      * @param {Function} s  the object that supplies the properties to augment
705      * @static
706      * @private
707      */
708     _IEEnumFix: (YAHOO.env.ua.ie) ? function(r, s) {
709             var i, fname, f;
710             for (i=0;i<ADD.length;i=i+1) {
711
712                 fname = ADD[i];
713                 f = s[fname];
714
715                 if (L.isFunction(f) && f!=OP[fname]) {
716                     r[fname]=f;
717                 }
718             }
719     } : function(){},
720
721     /**
722      * <p>
723      * Returns a copy of the specified string with special HTML characters
724      * escaped. The following characters will be converted to their
725      * corresponding character entities:
726      * <code>&amp; &lt; &gt; &quot; &#x27; &#x2F; &#x60;</code>
727      * </p>
728      *
729      * <p>
730      * This implementation is based on the
731      * <a href="http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet">OWASP
732      * HTML escaping recommendations</a>. In addition to the characters
733      * in the OWASP recommendation, we also escape the <code>&#x60;</code>
734      * character, since IE interprets it as an attribute delimiter when used in
735      * innerHTML.
736      * </p>
737      *
738      * @method escapeHTML
739      * @param {String} html String to escape.
740      * @return {String} Escaped string.
741      * @static
742      * @since 2.9.0
743      */
744     escapeHTML: function (html) {
745         return html.replace(/[&<>"'\/`]/g, function (match) {
746             return HTML_CHARS[match];
747         });
748     },
749
750     /**
751      * Utility to set up the prototype, constructor and superclass properties to
752      * support an inheritance strategy that can chain constructors and methods.
753      * Static members will not be inherited.
754      *
755      * @method extend
756      * @static
757      * @param {Function} subc   the object to modify
758      * @param {Function} superc the object to inherit
759      * @param {Object} overrides  additional properties/methods to add to the
760      *                              subclass prototype.  These will override the
761      *                              matching items obtained from the superclass
762      *                              if present.
763      */
764     extend: function(subc, superc, overrides) {
765         if (!superc||!subc) {
766             throw new Error("extend failed, please check that " +
767                             "all dependencies are included.");
768         }
769         var F = function() {}, i;
770         F.prototype=superc.prototype;
771         subc.prototype=new F();
772         subc.prototype.constructor=subc;
773         subc.superclass=superc.prototype;
774         if (superc.prototype.constructor == OP.constructor) {
775             superc.prototype.constructor=superc;
776         }
777
778         if (overrides) {
779             for (i in overrides) {
780                 if (L.hasOwnProperty(overrides, i)) {
781                     subc.prototype[i]=overrides[i];
782                 }
783             }
784
785             L._IEEnumFix(subc.prototype, overrides);
786         }
787     },
788
789     /**
790      * Applies all properties in the supplier to the receiver if the
791      * receiver does not have these properties yet.  Optionally, one or
792      * more methods/properties can be specified (as additional
793      * parameters).  This option will overwrite the property if receiver
794      * has it already.  If true is passed as the third parameter, all
795      * properties will be applied and _will_ overwrite properties in
796      * the receiver.
797      *
798      * @method augmentObject
799      * @static
800      * @since 2.3.0
801      * @param {Function} r  the object to receive the augmentation
802      * @param {Function} s  the object that supplies the properties to augment
803      * @param {String*|boolean}  arguments zero or more properties methods
804      *        to augment the receiver with.  If none specified, everything
805      *        in the supplier will be used unless it would
806      *        overwrite an existing property in the receiver. If true
807      *        is specified as the third parameter, all properties will
808      *        be applied and will overwrite an existing property in
809      *        the receiver
810      */
811     augmentObject: function(r, s) {
812         if (!s||!r) {
813             throw new Error("Absorb failed, verify dependencies.");
814         }
815         var a=arguments, i, p, overrideList=a[2];
816         if (overrideList && overrideList!==true) { // only absorb the specified properties
817             for (i=2; i<a.length; i=i+1) {
818                 r[a[i]] = s[a[i]];
819             }
820         } else { // take everything, overwriting only if the third parameter is true
821             for (p in s) {
822                 if (overrideList || !(p in r)) {
823                     r[p] = s[p];
824                 }
825             }
826
827             L._IEEnumFix(r, s);
828         }
829
830         return r;
831     },
832
833     /**
834      * Same as YAHOO.lang.augmentObject, except it only applies prototype properties
835      * @see YAHOO.lang.augmentObject
836      * @method augmentProto
837      * @static
838      * @param {Function} r  the object to receive the augmentation
839      * @param {Function} s  the object that supplies the properties to augment
840      * @param {String*|boolean}  arguments zero or more properties methods
841      *        to augment the receiver with.  If none specified, everything
842      *        in the supplier will be used unless it would overwrite an existing
843      *        property in the receiver.  if true is specified as the third
844      *        parameter, all properties will be applied and will overwrite an
845      *        existing property in the receiver
846      */
847     augmentProto: function(r, s) {
848         if (!s||!r) {
849             throw new Error("Augment failed, verify dependencies.");
850         }
851         //var a=[].concat(arguments);
852         var a=[r.prototype,s.prototype], i;
853         for (i=2;i<arguments.length;i=i+1) {
854             a.push(arguments[i]);
855         }
856         L.augmentObject.apply(this, a);
857
858         return r;
859     },
860
861
862     /**
863      * Returns a simple string representation of the object or array.
864      * Other types of objects will be returned unprocessed.  Arrays
865      * are expected to be indexed.  Use object notation for
866      * associative arrays.
867      * @method dump
868      * @since 2.3.0
869      * @param o {Object} The object to dump
870      * @param d {int} How deep to recurse child objects, default 3
871      * @return {String} the dump result
872      */
873     dump: function(o, d) {
874         var i,len,s=[],OBJ="{...}",FUN="f(){...}",
875             COMMA=', ', ARROW=' => ';
876
877         // Cast non-objects to string
878         // Skip dates because the std toString is what we want
879         // Skip HTMLElement-like objects because trying to dump
880         // an element will cause an unhandled exception in FF 2.x
881         if (!L.isObject(o)) {
882             return o + "";
883         } else if (o instanceof Date || ("nodeType" in o && "tagName" in o)) {
884             return o;
885         } else if  (L.isFunction(o)) {
886             return FUN;
887         }
888
889         // dig into child objects the depth specifed. Default 3
890         d = (L.isNumber(d)) ? d : 3;
891
892         // arrays [1, 2, 3]
893         if (L.isArray(o)) {
894             s.push("[");
895             for (i=0,len=o.length;i<len;i=i+1) {
896                 if (L.isObject(o[i])) {
897                     s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);
898                 } else {
899                     s.push(o[i]);
900                 }
901                 s.push(COMMA);
902             }
903             if (s.length > 1) {
904                 s.pop();
905             }
906             s.push("]");
907         // objects {k1 => v1, k2 => v2}
908         } else {
909             s.push("{");
910             for (i in o) {
911                 if (L.hasOwnProperty(o, i)) {
912                     s.push(i + ARROW);
913                     if (L.isObject(o[i])) {
914                         s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);
915                     } else {
916                         s.push(o[i]);
917                     }
918                     s.push(COMMA);
919                 }
920             }
921             if (s.length > 1) {
922                 s.pop();
923             }
924             s.push("}");
925         }
926
927         return s.join("");
928     },
929
930     /**
931      * Does variable substitution on a string. It scans through the string
932      * looking for expressions enclosed in { } braces. If an expression
933      * is found, it is used a key on the object.  If there is a space in
934      * the key, the first word is used for the key and the rest is provided
935      * to an optional function to be used to programatically determine the
936      * value (the extra information might be used for this decision). If
937      * the value for the key in the object, or what is returned from the
938      * function has a string value, number value, or object value, it is
939      * substituted for the bracket expression and it repeats.  If this
940      * value is an object, it uses the Object's toString() if this has
941      * been overridden, otherwise it does a shallow dump of the key/value
942      * pairs.
943      *
944      * By specifying the recurse option, the string is rescanned after
945      * every replacement, allowing for nested template substitutions.
946      * The side effect of this option is that curly braces in the
947      * replacement content must be encoded.
948      *
949      * @method substitute
950      * @since 2.3.0
951      * @param s {String} The string that will be modified.
952      * @param o {Object} An object containing the replacement values
953      * @param f {Function} An optional function that can be used to
954      *                     process each match.  It receives the key,
955      *                     value, and any extra metadata included with
956      *                     the key inside of the braces.
957      * @param recurse {boolean} default true - if not false, the replaced
958      * string will be rescanned so that nested substitutions are possible.
959      * @return {String} the substituted string
960      */
961     substitute: function (s, o, f, recurse) {
962         var i, j, k, key, v, meta, saved=[], token, lidx=s.length,
963             DUMP='dump', SPACE=' ', LBRACE='{', RBRACE='}',
964             dump, objstr;
965
966         for (;;) {
967             i = s.lastIndexOf(LBRACE, lidx);
968             if (i < 0) {
969                 break;
970             }
971             j = s.indexOf(RBRACE, i);
972             if (i + 1 > j) {
973                 break;
974             }
975
976             //Extract key and meta info
977             token = s.substring(i + 1, j);
978             key = token;
979             meta = null;
980             k = key.indexOf(SPACE);
981             if (k > -1) {
982                 meta = key.substring(k + 1);
983                 key = key.substring(0, k);
984             }
985
986             // lookup the value
987             v = o[key];
988
989             // if a substitution function was provided, execute it
990             if (f) {
991                 v = f(key, v, meta);
992             }
993
994             if (L.isObject(v)) {
995                 if (L.isArray(v)) {
996                     v = L.dump(v, parseInt(meta, 10));
997                 } else {
998                     meta = meta || "";
999
1000                     // look for the keyword 'dump', if found force obj dump
1001                     dump = meta.indexOf(DUMP);
1002                     if (dump > -1) {
1003                         meta = meta.substring(4);
1004                     }
1005
1006                     objstr = v.toString();
1007
1008                     // use the toString if it is not the Object toString
1009                     // and the 'dump' meta info was not found
1010                     if (objstr === OBJECT_TOSTRING || dump > -1) {
1011                         v = L.dump(v, parseInt(meta, 10));
1012                     } else {
1013                         v = objstr;
1014                     }
1015                 }
1016             } else if (!L.isString(v) && !L.isNumber(v)) {
1017                 // This {block} has no replace string. Save it for later.
1018                 v = "~-" + saved.length + "-~";
1019                 saved[saved.length] = token;
1020
1021                 // break;
1022             }
1023
1024             s = s.substring(0, i) + v + s.substring(j + 1);
1025
1026             if (recurse === false) {
1027                 lidx = i-1;
1028             }
1029
1030         }
1031
1032         // restore saved {block}s
1033         for (i=saved.length-1; i>=0; i=i-1) {
1034             s = s.replace(new RegExp("~-" + i + "-~"), "{"  + saved[i] + "}", "g");
1035         }
1036
1037         return s;
1038     },
1039
1040
1041     /**
1042      * Returns a string without any leading or trailing whitespace.  If
1043      * the input is not a string, the input will be returned untouched.
1044      * @method trim
1045      * @since 2.3.0
1046      * @param s {string} the string to trim
1047      * @return {string} the trimmed string
1048      */
1049     trim: function(s){
1050         try {
1051             return s.replace(/^\s+|\s+$/g, "");
1052         } catch(e) {
1053             return s;
1054         }
1055     },
1056
1057     /**
1058      * Returns a new object containing all of the properties of
1059      * all the supplied objects.  The properties from later objects
1060      * will overwrite those in earlier objects.
1061      * @method merge
1062      * @since 2.3.0
1063      * @param arguments {Object*} the objects to merge
1064      * @return the new merged object
1065      */
1066     merge: function() {
1067         var o={}, a=arguments, l=a.length, i;
1068         for (i=0; i<l; i=i+1) {
1069             L.augmentObject(o, a[i], true);
1070         }
1071         return o;
1072     },
1073
1074     /**
1075      * Executes the supplied function in the context of the supplied
1076      * object 'when' milliseconds later.  Executes the function a
1077      * single time unless periodic is set to true.
1078      * @method later
1079      * @since 2.4.0
1080      * @param when {int} the number of milliseconds to wait until the fn
1081      * is executed
1082      * @param o the context object
1083      * @param fn {Function|String} the function to execute or the name of
1084      * the method in the 'o' object to execute
1085      * @param data [Array] data that is provided to the function.  This accepts
1086      * either a single item or an array.  If an array is provided, the
1087      * function is executed with one parameter for each array item.  If
1088      * you need to pass a single array parameter, it needs to be wrapped in
1089      * an array [myarray]
1090      * @param periodic {boolean} if true, executes continuously at supplied
1091      * interval until canceled
1092      * @return a timer object. Call the cancel() method on this object to
1093      * stop the timer.
1094      */
1095     later: function(when, o, fn, data, periodic) {
1096         when = when || 0;
1097         o = o || {};
1098         var m=fn, d=data, f, r;
1099
1100         if (L.isString(fn)) {
1101             m = o[fn];
1102         }
1103
1104         if (!m) {
1105             throw new TypeError("method undefined");
1106         }
1107
1108         if (!L.isUndefined(data) && !L.isArray(d)) {
1109             d = [data];
1110         }
1111
1112         f = function() {
1113             m.apply(o, d || NOTHING);
1114         };
1115
1116         r = (periodic) ? setInterval(f, when) : setTimeout(f, when);
1117
1118         return {
1119             interval: periodic,
1120             cancel: function() {
1121                 if (this.interval) {
1122                     clearInterval(r);
1123                 } else {
1124                     clearTimeout(r);
1125                 }
1126             }
1127         };
1128     },
1129
1130     /**
1131      * A convenience method for detecting a legitimate non-null value.
1132      * Returns false for null/undefined/NaN, true for other values,
1133      * including 0/false/''
1134      * @method isValue
1135      * @since 2.3.0
1136      * @param o {any} the item to test
1137      * @return {boolean} true if it is not null/undefined/NaN || false
1138      */
1139     isValue: function(o) {
1140         // return (o || o === false || o === 0 || o === ''); // Infinity fails
1141 return (L.isObject(o) || L.isString(o) || L.isNumber(o) || L.isBoolean(o));
1142     }
1143
1144 };
1145
1146 /**
1147  * Determines whether or not the property was added
1148  * to the object instance.  Returns false if the property is not present
1149  * in the object, or was inherited from the prototype.
1150  * This abstraction is provided to enable hasOwnProperty for Safari 1.3.x.
1151  * There is a discrepancy between YAHOO.lang.hasOwnProperty and
1152  * Object.prototype.hasOwnProperty when the property is a primitive added to
1153  * both the instance AND prototype with the same value:
1154  * <pre>
1155  * var A = function() {};
1156  * A.prototype.foo = 'foo';
1157  * var a = new A();
1158  * a.foo = 'foo';
1159  * alert(a.hasOwnProperty('foo')); // true
1160  * alert(YAHOO.lang.hasOwnProperty(a, 'foo')); // false when using fallback
1161  * </pre>
1162  * @method hasOwnProperty
1163  * @param {any} o The object being testing
1164  * @param prop {string} the name of the property to test
1165  * @return {boolean} the result
1166  */
1167 L.hasOwnProperty = (OP.hasOwnProperty) ?
1168     function(o, prop) {
1169         return o && o.hasOwnProperty && o.hasOwnProperty(prop);
1170     } : function(o, prop) {
1171         return !L.isUndefined(o[prop]) &&
1172                 o.constructor.prototype[prop] !== o[prop];
1173     };
1174
1175 // new lang wins
1176 OB.augmentObject(L, OB, true);
1177
1178 /*
1179  * An alias for <a href="YAHOO.lang.html">YAHOO.lang</a>
1180  * @class YAHOO.util.Lang
1181  */
1182 YAHOO.util.Lang = L;
1183
1184 /**
1185  * Same as YAHOO.lang.augmentObject, except it only applies prototype
1186  * properties.  This is an alias for augmentProto.
1187  * @see YAHOO.lang.augmentObject
1188  * @method augment
1189  * @static
1190  * @param {Function} r  the object to receive the augmentation
1191  * @param {Function} s  the object that supplies the properties to augment
1192  * @param {String*|boolean}  arguments zero or more properties methods to
1193  *        augment the receiver with.  If none specified, everything
1194  *        in the supplier will be used unless it would
1195  *        overwrite an existing property in the receiver.  if true
1196  *        is specified as the third parameter, all properties will
1197  *        be applied and will overwrite an existing property in
1198  *        the receiver
1199  */
1200 L.augment = L.augmentProto;
1201
1202 /**
1203  * An alias for <a href="YAHOO.lang.html#augment">YAHOO.lang.augment</a>
1204  * @for YAHOO
1205  * @method augment
1206  * @static
1207  * @param {Function} r  the object to receive the augmentation
1208  * @param {Function} s  the object that supplies the properties to augment
1209  * @param {String*}  arguments zero or more properties methods to
1210  *        augment the receiver with.  If none specified, everything
1211  *        in the supplier will be used unless it would
1212  *        overwrite an existing property in the receiver
1213  */
1214 YAHOO.augment = L.augmentProto;
1215
1216 /**
1217  * An alias for <a href="YAHOO.lang.html#extend">YAHOO.lang.extend</a>
1218  * @method extend
1219  * @static
1220  * @param {Function} subc   the object to modify
1221  * @param {Function} superc the object to inherit
1222  * @param {Object} overrides  additional properties/methods to add to the
1223  *        subclass prototype.  These will override the
1224  *        matching items obtained from the superclass if present.
1225  */
1226 YAHOO.extend = L.extend;
1227
1228 })();
1229 YAHOO.register("yahoo", YAHOO, {version: "2.9.0", build: "2800"});