2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
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.
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.
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.
38 * Set to true if the library will be dynamically loaded after window.onload.
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
57 * Forces the use of the supplied locale where applicable in the library
64 if (typeof YAHOO == "undefined" || !YAHOO) {
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.
76 * Returns the namespace specified and creates it if it doesn't exist
78 * YAHOO.namespace("property.package");
79 * YAHOO.namespace("YAHOO.property.package");
81 * Either of the above would create YAHOO.property, then
82 * YAHOO.property.package
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:
87 * YAHOO.namespace("really.long.nested.namespace");
89 * This fails because "long" is a future reserved word in ECMAScript
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').
102 * @param {String*} arguments 1-n namespaces to create
103 * @return {Object} A reference to the last namespace object created
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(".");
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]] || {};
122 * Uses YAHOO.widget.Logger to output a log message, if the widget is
127 * @param {String} msg The message to log.
128 * @param {String} cat The log category for the message. Default
129 * categories are "info", "warn", "error", time".
130 * Custom categories can be used as well. (opt)
131 * @param {String} src The source of the the message (opt)
132 * @return {Boolean} True if the log operation was successful.
134 YAHOO.log = function(msg, cat, src) {
135 var l=YAHOO.widget.Logger;
137 return l.log(msg, cat, src);
144 * Registers a module with the YAHOO object
147 * @param {String} name the name of the module (event, slider, etc)
148 * @param {Function} mainClass a reference to class in the module. This
149 * class will be tagged with the version info
150 * so that it will be possible to identify the
151 * version that is in use when multiple versions
153 * @param {Object} data metadata object for the module. Currently it
154 * is expected to contain a "version" property
155 * and a "build" property at minimum.
157 YAHOO.register = function(name, mainClass, data) {
158 var mods = YAHOO.env.modules, m, v, b, ls, i;
170 ls = YAHOO.env.listeners;
177 m.mainClass = mainClass;
179 // fire the module load listeners
180 for (i=0;i<ls.length;i=i+1) {
183 // label the main class
185 mainClass.VERSION = v;
188 YAHOO.log("mainClass is undefined for module " + name, "warn");
193 * YAHOO.env is used to keep track of what is known about the YUI library and
194 * the browsing environment
198 YAHOO.env = YAHOO.env || {
201 * Keeps the version info for all YUI modules that have reported themselves
208 * List of functions that should be executed every time a YUI module
210 * @property listeners
217 * Returns the version data for the specified module:
219 * <dt>name:</dt> <dd>The name of the module</dd>
220 * <dt>version:</dt> <dd>The version in use</dd>
221 * <dt>build:</dt> <dd>The build number in use</dd>
222 * <dt>versions:</dt> <dd>All versions that were registered</dd>
223 * <dt>builds:</dt> <dd>All builds that were registered.</dd>
224 * <dt>mainClass:</dt> <dd>An object that was was stamped with the
225 * current version and build. If
226 * mainClass.VERSION != version or mainClass.BUILD != build,
227 * multiple versions of pieces of the library have been
228 * loaded, potentially causing issues.</dd>
233 * @param {String} name the name of the module (event, slider, etc)
234 * @return {Object} The version info
236 YAHOO.env.getVersion = function(name) {
237 return YAHOO.env.modules[name] || null;
241 * Do not fork for a browser if it can be avoided. Use feature detection when
242 * you can. Use the user agent as a last resort. YAHOO.env.ua stores a version
243 * number for the browser engine, 0 otherwise. This value may or may not map
244 * to the version number of the browser using the engine. The value is
245 * presented as a float so that it can easily be used for boolean evaluation
246 * as well as for looking for a particular range of versions. Because of this,
247 * some of the granularity of the version info may be lost (e.g., Gecko 1.8.0.9
249 * @class YAHOO.env.ua
252 YAHOO.env.ua = function() {
254 var numberfy = function(s) {
256 return parseFloat(s.replace(/\./g, function() {
257 return (c++ == 1) ? '' : '.';
266 * Internet Explorer version number or 0. Example: 6
273 * Opera version number or 0. Example: 9.2
280 * Gecko engine revision number. Will evaluate to 1 if Gecko
281 * is detected but the revision could not be found. Other browsers
282 * will be 0. Example: 1.8
284 * Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7
285 * Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8
286 * Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8
287 * Firefox 3 alpha: 1.9a4 <-- Reports 1.9
295 * AppleWebKit version. KHTML browsers that are not WebKit browsers
296 * will evaluate to 1, other browsers 0. Example: 418.9.1
298 * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the
299 * latest available for Mac OSX 10.3.
300 * Safari 2.0.2: 416 <-- hasOwnProperty introduced
301 * Safari 2.0.4: 418 <-- preventDefault fixed
302 * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
303 * different versions of webkit
304 * Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been
305 * updated, but not updated
306 * to the latest patch.
307 * Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native SVG
308 * and many major issues fixed).
309 * 3.x yahoo.com, flickr:422 <-- Safari 3.x hacks the user agent
310 * string when hitting yahoo.com and
312 * Safari 3.0.4 (523.12):523.12 <-- First Tiger release - automatic update
313 * from 2.x via the 10.4.11 OS patch
314 * Webkit nightly 1/2008:525+ <-- Supports DOMContentLoaded event.
315 * yahoo.com user agent hack removed.
318 * http://developer.apple.com/internet/safari/uamatrix.html
325 * The mobile property will be set to a string containing any relevant
326 * user agent information when a modern mobile browser is detected.
327 * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
328 * devices with the WebKit-based browser, and Opera Mini.
335 * Adobe AIR version number or 0. Only populated if webkit is detected.
343 * Google Caja version number or 0.
347 caja: nav.cajaVersion,
350 * Set to true if the page appears to be in SSL
358 * The operating system. Currently only detecting windows or macintosh
367 ua = navigator && navigator.userAgent,
369 loc = window && window.location,
371 href = loc && loc.href,
375 o.secure = href && (href.toLowerCase().indexOf("https") === 0);
379 if ((/windows|win32/i).test(ua)) {
381 } else if ((/macintosh/i).test(ua)) {
385 // Modern KHTML browsers should qualify as Safari X-Grade
386 if ((/KHTML/).test(ua)) {
390 // Modern WebKit browsers are at least X-Grade
391 m=ua.match(/AppleWebKit\/([^\s]*)/);
393 o.webkit=numberfy(m[1]);
395 // Mobile browser check
396 if (/ Mobile\//.test(ua)) {
397 o.mobile = "Apple"; // iPhone or iPod Touch
399 m=ua.match(/NokiaN[^\/]*/);
401 o.mobile = m[0]; // Nokia N-series, ex: NokiaN95
405 m=ua.match(/AdobeAIR\/([^\s]*)/);
407 o.air = m[0]; // Adobe AIR 1.0 or better
412 if (!o.webkit) { // not webkit
413 // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
414 m=ua.match(/Opera[\s\/]([^\s]*)/);
416 o.opera=numberfy(m[1]);
417 m=ua.match(/Opera Mini[^;]*/);
419 o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
421 } else { // not opera or webkit
422 m=ua.match(/MSIE\s([^;]*)/);
425 } else { // not opera, webkit, or ie
426 m=ua.match(/Gecko\/([^\s]*)/);
428 o.gecko=1; // Gecko detected, look for revision
429 m=ua.match(/rv:([^\s\)]*)/);
431 o.gecko=numberfy(m[1]);
443 * Initializes the global by creating the default namespaces and applying
444 * any new configuration information that is detected. This is the setup
451 YAHOO.namespace("util", "widget", "example");
452 /*global YAHOO_config*/
453 if ("undefined" !== typeof YAHOO_config) {
454 var l=YAHOO_config.listener, ls=YAHOO.env.listeners,unique=true, i;
456 // if YAHOO is loaded multiple times we need to check to see if
457 // this is a new config object. If it is, add the new component
458 // load listener to the stack
459 for (i=0; i<ls.length; i++) {
473 * Provides the language utilites and extensions used by the library
476 YAHOO.lang = YAHOO.lang || {};
483 OP = Object.prototype,
484 ARRAY_TOSTRING = '[object Array]',
485 FUNCTION_TOSTRING = '[object Function]',
486 OBJECT_TOSTRING = '[object Object]',
489 // ADD = ["toString", "valueOf", "hasOwnProperty"],
490 ADD = ["toString", "valueOf"],
495 * Determines wheather or not the provided object is an array.
497 * @param {any} o The object being testing
498 * @return {boolean} the result
500 isArray: function(o) {
501 return OP.toString.apply(o) === ARRAY_TOSTRING;
505 * Determines whether or not the provided object is a boolean
507 * @param {any} o The object being testing
508 * @return {boolean} the result
510 isBoolean: function(o) {
511 return typeof o === 'boolean';
515 * Determines whether or not the provided object is a function.
516 * Note: Internet Explorer thinks certain functions are objects:
518 * var obj = document.createElement("object");
519 * YAHOO.lang.isFunction(obj.getAttribute) // reports false in IE
521 * var input = document.createElement("input"); // append to body
522 * YAHOO.lang.isFunction(input.focus) // reports false in IE
524 * You will have to implement additional tests if these functions
528 * @param {any} o The object being testing
529 * @return {boolean} the result
531 isFunction: function(o) {
532 return (typeof o === 'function') || OP.toString.apply(o) === FUNCTION_TOSTRING;
536 * Determines whether or not the provided object is null
538 * @param {any} o The object being testing
539 * @return {boolean} the result
541 isNull: function(o) {
546 * Determines whether or not the provided object is a legal number
548 * @param {any} o The object being testing
549 * @return {boolean} the result
551 isNumber: function(o) {
552 return typeof o === 'number' && isFinite(o);
556 * Determines whether or not the provided object is of type object
559 * @param {any} o The object being testing
560 * @return {boolean} the result
562 isObject: function(o) {
563 return (o && (typeof o === 'object' || L.isFunction(o))) || false;
567 * Determines whether or not the provided object is a string
569 * @param {any} o The object being testing
570 * @return {boolean} the result
572 isString: function(o) {
573 return typeof o === 'string';
577 * Determines whether or not the provided object is undefined
578 * @method isUndefined
579 * @param {any} o The object being testing
580 * @return {boolean} the result
582 isUndefined: function(o) {
583 return typeof o === 'undefined';
588 * IE will not enumerate native functions in a derived object even if the
589 * function was overridden. This is a workaround for specific functions
590 * we care about on the Object prototype.
591 * @property _IEEnumFix
592 * @param {Function} r the object to receive the augmentation
593 * @param {Function} s the object that supplies the properties to augment
597 _IEEnumFix: (YAHOO.env.ua.ie) ? function(r, s) {
599 for (i=0;i<ADD.length;i=i+1) {
604 if (L.isFunction(f) && f!=OP[fname]) {
611 * Utility to set up the prototype, constructor and superclass properties to
612 * support an inheritance strategy that can chain constructors and methods.
613 * Static members will not be inherited.
617 * @param {Function} subc the object to modify
618 * @param {Function} superc the object to inherit
619 * @param {Object} overrides additional properties/methods to add to the
620 * subclass prototype. These will override the
621 * matching items obtained from the superclass
624 extend: function(subc, superc, overrides) {
625 if (!superc||!subc) {
626 throw new Error("extend failed, please check that " +
627 "all dependencies are included.");
629 var F = function() {}, i;
630 F.prototype=superc.prototype;
631 subc.prototype=new F();
632 subc.prototype.constructor=subc;
633 subc.superclass=superc.prototype;
634 if (superc.prototype.constructor == OP.constructor) {
635 superc.prototype.constructor=superc;
639 for (i in overrides) {
640 if (L.hasOwnProperty(overrides, i)) {
641 subc.prototype[i]=overrides[i];
645 L._IEEnumFix(subc.prototype, overrides);
650 * Applies all properties in the supplier to the receiver if the
651 * receiver does not have these properties yet. Optionally, one or
652 * more methods/properties can be specified (as additional
653 * parameters). This option will overwrite the property if receiver
654 * has it already. If true is passed as the third parameter, all
655 * properties will be applied and _will_ overwrite properties in
658 * @method augmentObject
661 * @param {Function} r the object to receive the augmentation
662 * @param {Function} s the object that supplies the properties to augment
663 * @param {String*|boolean} arguments zero or more properties methods
664 * to augment the receiver with. If none specified, everything
665 * in the supplier will be used unless it would
666 * overwrite an existing property in the receiver. If true
667 * is specified as the third parameter, all properties will
668 * be applied and will overwrite an existing property in
671 augmentObject: function(r, s) {
673 throw new Error("Absorb failed, verify dependencies.");
675 var a=arguments, i, p, overrideList=a[2];
676 if (overrideList && overrideList!==true) { // only absorb the specified properties
677 for (i=2; i<a.length; i=i+1) {
680 } else { // take everything, overwriting only if the third parameter is true
682 if (overrideList || !(p in r)) {
692 * Same as YAHOO.lang.augmentObject, except it only applies prototype properties
693 * @see YAHOO.lang.augmentObject
694 * @method augmentProto
696 * @param {Function} r the object to receive the augmentation
697 * @param {Function} s the object that supplies the properties to augment
698 * @param {String*|boolean} arguments zero or more properties methods
699 * to augment the receiver with. If none specified, everything
700 * in the supplier will be used unless it would overwrite an existing
701 * property in the receiver. if true is specified as the third
702 * parameter, all properties will be applied and will overwrite an
703 * existing property in the receiver
705 augmentProto: function(r, s) {
707 throw new Error("Augment failed, verify dependencies.");
709 //var a=[].concat(arguments);
710 var a=[r.prototype,s.prototype], i;
711 for (i=2;i<arguments.length;i=i+1) {
712 a.push(arguments[i]);
714 L.augmentObject.apply(this, a);
719 * Returns a simple string representation of the object or array.
720 * Other types of objects will be returned unprocessed. Arrays
721 * are expected to be indexed. Use object notation for
722 * associative arrays.
725 * @param o {Object} The object to dump
726 * @param d {int} How deep to recurse child objects, default 3
727 * @return {String} the dump result
729 dump: function(o, d) {
730 var i,len,s=[],OBJ="{...}",FUN="f(){...}",
731 COMMA=', ', ARROW=' => ';
733 // Cast non-objects to string
734 // Skip dates because the std toString is what we want
735 // Skip HTMLElement-like objects because trying to dump
736 // an element will cause an unhandled exception in FF 2.x
737 if (!L.isObject(o)) {
739 } else if (o instanceof Date || ("nodeType" in o && "tagName" in o)) {
741 } else if (L.isFunction(o)) {
745 // dig into child objects the depth specifed. Default 3
746 d = (L.isNumber(d)) ? d : 3;
751 for (i=0,len=o.length;i<len;i=i+1) {
752 if (L.isObject(o[i])) {
753 s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);
763 // objects {k1 => v1, k2 => v2}
767 if (L.hasOwnProperty(o, i)) {
769 if (L.isObject(o[i])) {
770 s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);
787 * Does variable substitution on a string. It scans through the string
788 * looking for expressions enclosed in { } braces. If an expression
789 * is found, it is used a key on the object. If there is a space in
790 * the key, the first word is used for the key and the rest is provided
791 * to an optional function to be used to programatically determine the
792 * value (the extra information might be used for this decision). If
793 * the value for the key in the object, or what is returned from the
794 * function has a string value, number value, or object value, it is
795 * substituted for the bracket expression and it repeats. If this
796 * value is an object, it uses the Object's toString() if this has
797 * been overridden, otherwise it does a shallow dump of the key/value
801 * @param s {String} The string that will be modified.
802 * @param o {Object} An object containing the replacement values
803 * @param f {Function} An optional function that can be used to
804 * process each match. It receives the key,
805 * value, and any extra metadata included with
806 * the key inside of the braces.
807 * @return {String} the substituted string
809 substitute: function (s, o, f) {
810 var i, j, k, key, v, meta, saved=[], token,
811 DUMP='dump', SPACE=' ', LBRACE='{', RBRACE='}',
816 i = s.lastIndexOf(LBRACE);
820 j = s.indexOf(RBRACE, i);
825 //Extract key and meta info
826 token = s.substring(i + 1, j);
829 k = key.indexOf(SPACE);
831 meta = key.substring(k + 1);
832 key = key.substring(0, k);
838 // if a substitution function was provided, execute it
845 v = L.dump(v, parseInt(meta, 10));
849 // look for the keyword 'dump', if found force obj dump
850 dump = meta.indexOf(DUMP);
852 meta = meta.substring(4);
855 objstr = v.toString();
857 // use the toString if it is not the Object toString
858 // and the 'dump' meta info was not found
859 if (objstr === OBJECT_TOSTRING || dump > -1) {
860 v = L.dump(v, parseInt(meta, 10));
865 } else if (!L.isString(v) && !L.isNumber(v)) {
866 // This {block} has no replace string. Save it for later.
867 v = "~-" + saved.length + "-~";
868 saved[saved.length] = token;
873 s = s.substring(0, i) + v + s.substring(j + 1);
878 // restore saved {block}s
879 for (i=saved.length-1; i>=0; i=i-1) {
880 s = s.replace(new RegExp("~-" + i + "-~"), "{" + saved[i] + "}", "g");
888 * Returns a string without any leading or trailing whitespace. If
889 * the input is not a string, the input will be returned untouched.
892 * @param s {string} the string to trim
893 * @return {string} the trimmed string
897 return s.replace(/^\s+|\s+$/g, "");
904 * Returns a new object containing all of the properties of
905 * all the supplied objects. The properties from later objects
906 * will overwrite those in earlier objects.
909 * @param arguments {Object*} the objects to merge
910 * @return the new merged object
913 var o={}, a=arguments, l=a.length, i;
914 for (i=0; i<l; i=i+1) {
915 L.augmentObject(o, a[i], true);
921 * Executes the supplied function in the context of the supplied
922 * object 'when' milliseconds later. Executes the function a
923 * single time unless periodic is set to true.
926 * @param when {int} the number of milliseconds to wait until the fn
928 * @param o the context object
929 * @param fn {Function|String} the function to execute or the name of
930 * the method in the 'o' object to execute
931 * @param data [Array] data that is provided to the function. This accepts
932 * either a single item or an array. If an array is provided, the
933 * function is executed with one parameter for each array item. If
934 * you need to pass a single array parameter, it needs to be wrapped in
936 * @param periodic {boolean} if true, executes continuously at supplied
937 * interval until canceled
938 * @return a timer object. Call the cancel() method on this object to
941 later: function(when, o, fn, data, periodic) {
944 var m=fn, d=data, f, r;
946 if (L.isString(fn)) {
951 throw new TypeError("method undefined");
954 if (d && !L.isArray(d)) {
959 m.apply(o, d || NOTHING);
962 r = (periodic) ? setInterval(f, when) : setTimeout(f, when);
977 * A convenience method for detecting a legitimate non-null value.
978 * Returns false for null/undefined/NaN, true for other values,
979 * including 0/false/''
982 * @param o {any} the item to test
983 * @return {boolean} true if it is not null/undefined/NaN || false
985 isValue: function(o) {
986 // return (o || o === false || o === 0 || o === ''); // Infinity fails
987 return (L.isObject(o) || L.isString(o) || L.isNumber(o) || L.isBoolean(o));
993 * Determines whether or not the property was added
994 * to the object instance. Returns false if the property is not present
995 * in the object, or was inherited from the prototype.
996 * This abstraction is provided to enable hasOwnProperty for Safari 1.3.x.
997 * There is a discrepancy between YAHOO.lang.hasOwnProperty and
998 * Object.prototype.hasOwnProperty when the property is a primitive added to
999 * both the instance AND prototype with the same value:
1001 * var A = function() {};
1002 * A.prototype.foo = 'foo';
1005 * alert(a.hasOwnProperty('foo')); // true
1006 * alert(YAHOO.lang.hasOwnProperty(a, 'foo')); // false when using fallback
1008 * @method hasOwnProperty
1009 * @param {any} o The object being testing
1010 * @param prop {string} the name of the property to test
1011 * @return {boolean} the result
1013 L.hasOwnProperty = (OP.hasOwnProperty) ?
1015 return o && o.hasOwnProperty(prop);
1016 } : function(o, prop) {
1017 return !L.isUndefined(o[prop]) &&
1018 o.constructor.prototype[prop] !== o[prop];
1022 OB.augmentObject(L, OB, true);
1025 * An alias for <a href="YAHOO.lang.html">YAHOO.lang</a>
1026 * @class YAHOO.util.Lang
1028 YAHOO.util.Lang = L;
1031 * Same as YAHOO.lang.augmentObject, except it only applies prototype
1032 * properties. This is an alias for augmentProto.
1033 * @see YAHOO.lang.augmentObject
1036 * @param {Function} r the object to receive the augmentation
1037 * @param {Function} s the object that supplies the properties to augment
1038 * @param {String*|boolean} arguments zero or more properties methods to
1039 * augment the receiver with. If none specified, everything
1040 * in the supplier will be used unless it would
1041 * overwrite an existing property in the receiver. if true
1042 * is specified as the third parameter, all properties will
1043 * be applied and will overwrite an existing property in
1046 L.augment = L.augmentProto;
1049 * An alias for <a href="YAHOO.lang.html#augment">YAHOO.lang.augment</a>
1053 * @param {Function} r the object to receive the augmentation
1054 * @param {Function} s the object that supplies the properties to augment
1055 * @param {String*} arguments zero or more properties methods to
1056 * augment the receiver with. If none specified, everything
1057 * in the supplier will be used unless it would
1058 * overwrite an existing property in the receiver
1060 YAHOO.augment = L.augmentProto;
1063 * An alias for <a href="YAHOO.lang.html#extend">YAHOO.lang.extend</a>
1066 * @param {Function} subc the object to modify
1067 * @param {Function} superc the object to inherit
1068 * @param {Object} overrides additional properties/methods to add to the
1069 * subclass prototype. These will override the
1070 * matching items obtained from the superclass if present.
1072 YAHOO.extend = L.extend;
1075 YAHOO.register("yahoo", YAHOO, {version: "2.8.0r4", build: "2449"});
1077 * Provides a mechanism to fetch remote resources and
1078 * insert them into a document
1084 * Fetches and inserts one or more script or link nodes into the document
1085 * @namespace YAHOO.util
1086 * @class YAHOO.util.Get
1088 YAHOO.util.Get = function() {
1091 * hash of queues to manage multiple requests
1098 * queue index used to generate transaction ids
1106 * node index used to generate unique node ids
1115 // sandboxFrame=null,
1118 * interal property used to prevent multiple simultaneous purge
1131 * Generates an HTML element, this is not appended to a document
1133 * @param type {string} the type of element
1134 * @param attr {string} the attributes
1135 * @param win {Window} optional window to create the element in
1136 * @return {HTMLElement} the generated node
1139 var _node = function(type, attr, win) {
1140 var w = win || window, d=w.document, n=d.createElement(type);
1142 for (var i in attr) {
1143 if (attr[i] && YAHOO.lang.hasOwnProperty(attr, i)) {
1144 n.setAttribute(i, attr[i]);
1152 * Generates a link node
1154 * @param url {string} the url for the css file
1155 * @param win {Window} optional window to create the node in
1156 * @return {HTMLElement} the generated node
1159 var _linkNode = function(url, win, attributes) {
1162 id: "yui__dyn_" + (nidx++),
1169 lang.augmentObject(o, attributes);
1172 return _node("link", o, win);
1176 * Generates a script node
1177 * @method _scriptNode
1178 * @param url {string} the url for the script file
1179 * @param win {Window} optional window to create the node in
1180 * @return {HTMLElement} the generated node
1183 var _scriptNode = function(url, win, attributes) {
1185 id: "yui__dyn_" + (nidx++),
1186 type: "text/javascript",
1191 lang.augmentObject(o, attributes);
1194 return _node("script", o, win);
1198 * Returns the data payload for callback functions
1199 * @method _returnData
1202 var _returnData = function(q, msg) {
1215 var _get = function(nId, tId) {
1216 var q = queues[tId],
1217 n = (lang.isString(nId)) ? q.win.document.getElementById(nId) : nId;
1219 _fail(tId, "target node not found: " + nId);
1226 * The request failed, execute fail handler with whatever
1227 * was accomplished. There isn't a failure case at the
1228 * moment unless you count aborted transactions
1230 * @param id {string} the id of the request
1233 var _fail = function(id, msg) {
1235 // execute failure callback
1237 var sc=q.scope || q.win;
1238 q.onFailure.call(sc, _returnData(q, msg));
1243 * The request is complete, so executing the requester's callback
1245 * @param id {string} the id of the request
1248 var _finish = function(id) {
1253 var msg = "transaction " + id + " was aborted";
1258 // execute success callback
1260 var sc=q.scope || q.win;
1261 q.onSuccess.call(sc, _returnData(q));
1268 * @param id {string} the id of the request
1271 var _timeout = function(id) {
1274 var sc=q.scope || q;
1275 q.onTimeout.call(sc, _returnData(q));
1280 * Loads the next item for a given request
1282 * @param id {string} the id of the request
1283 * @param loaded {string} the url that was just loaded, if any
1286 var _next = function(id, loaded) {
1290 // Y.log('cancel timer');
1295 var msg = "transaction " + id + " was aborted";
1306 // This is the first pass: make sure the url is an array
1307 q.url = (lang.isString(q.url)) ? [q.url] : q.url;
1309 q.varName = (lang.isString(q.varName)) ? [q.varName] : q.varName;
1313 var w=q.win, d=w.document, h=d.getElementsByTagName("head")[0], n;
1315 if (q.url.length === 0) {
1316 // Safari 2.x workaround - There is no way to know when
1317 // a script is ready in versions of Safari prior to 3.x.
1318 // Adding an extra node reduces the problem, but doesn't
1319 // eliminate it completely because the browser executes
1320 // them asynchronously.
1321 if (q.type === "script" && ua.webkit && ua.webkit < 420 &&
1322 !q.finalpass && !q.varName) {
1323 // Add another script node. This does not guarantee that the
1324 // scripts will execute in order, but it does appear to fix the
1325 // problem on fast connections more effectively than using an
1326 // arbitrary timeout. It is possible that the browser does
1327 // block subsequent script execution in this case for a limited
1329 var extra = _scriptNode(null, q.win, q.attributes);
1330 extra.innerHTML='YAHOO.util.Get._finalize("' + id + '");';
1331 q.nodes.push(extra); h.appendChild(extra);
1343 // if the url is undefined, this is probably a trailing comma problem in IE
1351 // Y.log('create timer');
1352 q.timer = lang.later(q.timeout, q, _timeout, id);
1355 if (q.type === "script") {
1356 n = _scriptNode(url, w, q.attributes);
1358 n = _linkNode(url, w, q.attributes);
1361 // track this node's load progress
1362 _track(q.type, n, id, url, w, q.url.length);
1364 // add the node to the queue so we can return it to the user supplied callback
1367 // add it to the head or insert it before 'insertBefore'
1368 if (q.insertBefore) {
1369 var s = _get(q.insertBefore, id);
1371 s.parentNode.insertBefore(n, s);
1378 // FireFox does not support the onload event for link nodes, so there is
1379 // no way to make the css requests synchronous. This means that the css
1380 // rules in multiple files could be applied out of order in this browser
1381 // if a later request returns before an earlier one. Safari too.
1382 if ((ua.webkit || ua.gecko) && q.type === "css") {
1388 * Removes processed queues and corresponding nodes
1389 * @method _autoPurge
1392 var _autoPurge = function() {
1399 for (var i in queues) {
1401 if (q.autopurge && q.finished) {
1411 * Removes the nodes for the specified queue
1415 var _purge = function(tId) {
1418 var q = queues[tId],
1422 h = d.getElementsByTagName("head")[0],
1425 if (q.insertBefore) {
1426 sib = _get(q.insertBefore, tId);
1432 for (i=0; i<l; i=i+1) {
1434 if (node.clearAttributes) {
1435 node.clearAttributes();
1437 for (attr in node) {
1442 h.removeChild(node);
1450 * Saves the state for the request and begins loading
1451 * the requested urls
1453 * @param type {string} the type of node to insert
1454 * @param url {string} the url to load
1455 * @param opts the hash of options for this request
1458 var _queue = function(type, url, opts) {
1460 var id = "q" + (qidx++);
1463 if (qidx % YAHOO.util.Get.PURGE_THRESH === 0) {
1467 queues[id] = lang.merge(opts, {
1477 q.win = q.win || window;
1478 q.scope = q.scope || q.win;
1479 q.autopurge = ("autopurge" in q) ? q.autopurge :
1480 (type === "script") ? true : false;
1483 q.attributes = q.attributes || {};
1484 q.attributes.charset = opts.charset;
1487 lang.later(0, q, _next, id);
1495 * Detects when a node has been loaded. In the case of
1496 * script nodes, this does not guarantee that contained
1497 * script is ready to use.
1499 * @param type {string} the type of node to track
1500 * @param n {HTMLElement} the node to track
1501 * @param id {string} the id of the request
1502 * @param url {string} the url that is being loaded
1503 * @param win {Window} the targeted window
1504 * @param qlength the number of remaining items in the queue,
1505 * including this one
1506 * @param trackfn {Function} function to execute when finished
1507 * the default is _next
1510 var _track = function(type, n, id, url, win, qlength, trackfn) {
1511 var f = trackfn || _next;
1513 // IE supports the readystatechange event for script and css nodes
1515 n.onreadystatechange = function() {
1516 var rs = this.readyState;
1517 if ("loaded" === rs || "complete" === rs) {
1518 n.onreadystatechange = null;
1523 // webkit prior to 3.x is problemmatic
1524 } else if (ua.webkit) {
1526 if (type === "script") {
1528 // Safari 3.x supports the load event for script nodes (DOM2)
1529 if (ua.webkit >= 420) {
1531 n.addEventListener("load", function() {
1535 // Nothing can be done with Safari < 3.x except to pause and hope
1536 // for the best, particularly after last script is inserted. The
1537 // scripts will always execute in the order they arrive, not
1538 // necessarily the order in which they were inserted. To support
1539 // script nodes with complete reliability in these browsers, script
1540 // nodes either need to invoke a function in the window once they
1541 // are loaded or the implementer needs to provide a well-known
1542 // property that the utility can poll for.
1544 // Poll for the existence of the named variable, if it
1548 var freq=YAHOO.util.Get.POLL_FREQ;
1549 q.maxattempts = YAHOO.util.Get.TIMEOUT/freq;
1551 q._cache = q.varName[0].split(".");
1552 q.timer = lang.later(freq, q, function(o) {
1553 var a=this._cache, l=a.length, w=this.win, i;
1554 for (i=0; i<l; i=i+1) {
1557 // if we have exausted our attempts, give up
1559 if (this.attempts++ > this.maxattempts) {
1560 var msg = "Over retry limit, giving up";
1575 lang.later(YAHOO.util.Get.POLL_FREQ, null, f, [id, url]);
1580 // FireFox and Opera support onload (but not DOM2 in FF) handlers for
1581 // script nodes. Opera, but not FF, supports the onload event for link
1584 n.onload = function() {
1593 * The default poll freqency in ms, when needed
1594 * @property POLL_FREQ
1602 * The number of request required before an automatic purge.
1603 * property PURGE_THRESH
1611 * The length time to poll for varName when loading a script in
1612 * Safari 2.x before the transaction fails.
1621 * Called by the the helper for detecting script load in Safari
1623 * @param id {string} the transaction id
1626 _finalize: function(id) {
1627 lang.later(0, null, _finish, id);
1631 * Abort a transaction
1633 * @param {string|object} either the tId or the object returned from
1636 abort: function(o) {
1637 var id = (lang.isString(o)) ? o : o.tId;
1645 * Fetches and inserts one or more script nodes into the head
1646 * of the current document or the document in a specified window.
1650 * @param url {string|string[]} the url or urls to the script(s)
1651 * @param opts {object} Options:
1653 * <dt>onSuccess</dt>
1655 * callback to execute when the script(s) are finished loading
1656 * The callback receives an object back with the following
1660 * <dd>the window the script(s) were inserted into</dd>
1662 * <dd>the data object passed in when the request was made</dd>
1664 * <dd>An array containing references to the nodes that were
1667 * <dd>A function that, when executed, will remove the nodes
1668 * that were inserted</dd>
1672 * <dt>onFailure</dt>
1674 * callback to execute when the script load operation fails
1675 * The callback receives an object back with the following
1679 * <dd>the window the script(s) were inserted into</dd>
1681 * <dd>the data object passed in when the request was made</dd>
1683 * <dd>An array containing references to the nodes that were
1684 * inserted successfully</dd>
1686 * <dd>A function that, when executed, will remove any nodes
1687 * that were inserted</dd>
1691 * <dt>onTimeout</dt>
1693 * callback to execute when a timeout occurs.
1694 * The callback receives an object back with the following
1698 * <dd>the window the script(s) were inserted into</dd>
1700 * <dd>the data object passed in when the request was made</dd>
1702 * <dd>An array containing references to the nodes that were
1705 * <dd>A function that, when executed, will remove the nodes
1706 * that were inserted</dd>
1711 * <dd>the execution context for the callbacks</dd>
1713 * <dd>a window other than the one the utility occupies</dd>
1714 * <dt>autopurge</dt>
1716 * setting to true will let the utilities cleanup routine purge
1717 * the script once loaded
1721 * data that is supplied to the callback when the script(s) are
1726 * variable that should be available when a script is finished
1727 * loading. Used to help Safari 2.x and below with script load
1728 * detection. The type of this property should match what was
1729 * passed into the url parameter: if loading a single url, a
1730 * string can be supplied. If loading multiple scripts, you
1731 * must supply an array that contains the variable name for
1734 * <dt>insertBefore</dt>
1735 * <dd>node or node id that will become the new node's nextSibling</dd>
1738 * <dd>Node charset, deprecated, use 'attributes'</dd>
1739 * <dt>attributes</dt>
1740 * <dd>A hash of attributes to apply to dynamic nodes.</dd>
1742 * <dd>Number of milliseconds to wait before aborting and firing the timeout event</dd>
1744 * // assumes yahoo, dom, and event are already on the page
1745 * YAHOO.util.Get.script(
1746 * ["http://yui.yahooapis.com/2.7.0/build/dragdrop/dragdrop-min.js",
1747 * "http://yui.yahooapis.com/2.7.0/build/animation/animation-min.js"], {
1748 * onSuccess: function(o) {
1749 * new YAHOO.util.DDProxy("dd1"); // also new o.reference("dd1"); would work
1750 * this.log("won't cause error because YAHOO is the scope");
1751 * this.log(o.nodes.length === 2) // true
1752 * // o.purge(); // optionally remove the script nodes immediately
1753 * },
1754 * onFailure: function(o) {
1755 * },
1756 * data: "foo",
1757 * timeout: 10000, // 10 second timeout
1758 * scope: YAHOO,
1759 * // win: otherframe // target another window/frame
1760 * autopurge: true // allow the utility to choose when to remove the nodes
1761 * });
1763 * @return {tId: string} an object containing info about the transaction
1765 script: function(url, opts) { return _queue("script", url, opts); },
1768 * Fetches and inserts one or more css link nodes into the
1769 * head of the current document or the document in a specified
1773 * @param url {string} the url or urls to the css file(s)
1774 * @param opts Options:
1776 * <dt>onSuccess</dt>
1778 * callback to execute when the css file(s) are finished loading
1779 * The callback receives an object back with the following
1782 * <dd>the window the link nodes(s) were inserted into</dd>
1784 * <dd>the data object passed in when the request was made</dd>
1786 * <dd>An array containing references to the nodes that were
1789 * <dd>A function that, when executed, will remove the nodes
1790 * that were inserted</dd>
1795 * <dd>the execution context for the callbacks</dd>
1797 * <dd>a window other than the one the utility occupies</dd>
1800 * data that is supplied to the callbacks when the nodes(s) are
1803 * <dt>insertBefore</dt>
1804 * <dd>node or node id that will become the new node's nextSibling</dd>
1806 * <dd>Node charset, deprecated, use 'attributes'</dd>
1807 * <dt>attributes</dt>
1808 * <dd>A hash of attributes to apply to dynamic nodes.</dd>
1811 * YAHOO.util.Get.css("http://yui.yahooapis.com/2.7.0/build/menu/assets/skins/sam/menu.css");
1814 * YAHOO.util.Get.css(["http://yui.yahooapis.com/2.7.0/build/menu/assets/skins/sam/menu.css",
1816 * @return {tId: string} an object containing info about the transaction
1818 css: function(url, opts) {
1819 return _queue("css", url, opts);
1824 YAHOO.register("get", YAHOO.util.Get, {version: "2.8.0r4", build: "2449"});
1826 * Provides dynamic loading for the YUI library. It includes the dependency
1827 * info for the library, and will automatically pull in dependencies for
1828 * the modules requested. It supports rollup files (such as utilities.js
1829 * and yahoo-dom-event.js), and will automatically use these when
1830 * appropriate in order to minimize the number of http connections
1831 * required to load all of the dependencies.
1834 * @namespace YAHOO.util
1838 * YUILoader provides dynamic loading for YUI.
1839 * @class YAHOO.util.YUILoader
1841 * version management, automatic sandboxing
1845 var Y=YAHOO, util=Y.util, lang=Y.lang, env=Y.env,
1846 PROV = "_provides", SUPER = "_supersedes",
1847 REQ = "expanded", AFTER = "_after";
1851 dupsAllowed: {'yahoo': true, 'get': true},
1854 * The library metadata for the current release The is the default
1855 * value for YAHOO.util.YUILoader.moduleInfo
1861 // 'root': '2.5.2/build/',
1862 // 'base': 'http://yui.yahooapis.com/2.5.2/build/',
1864 'root': '2.8.0r4/build/',
1865 'base': 'http://yui.yahooapis.com/2.8.0r4/build/',
1867 'comboBase': 'http://yui.yahooapis.com/combo?',
1870 'defaultSkin': 'sam',
1871 'base': 'assets/skins/',
1873 'after': ['reset', 'fonts', 'grids', 'base'],
1877 dupsAllowed: ['yahoo', 'get'],
1883 'path': 'animation/animation-min.js',
1884 'requires': ['dom', 'event']
1889 'path': 'autocomplete/autocomplete-min.js',
1890 'requires': ['dom', 'event', 'datasource'],
1891 'optional': ['connection', 'animation'],
1897 'path': 'base/base-min.css',
1898 'after': ['reset', 'fonts', 'grids']
1903 'path': 'button/button-min.js',
1904 'requires': ['element'],
1905 'optional': ['menu'],
1911 'path': 'calendar/calendar-min.js',
1912 'requires': ['event', 'dom'],
1913 supersedes: ['datemeth'],
1919 'path': 'carousel/carousel-min.js',
1920 'requires': ['element'],
1921 'optional': ['animation'],
1927 'path': 'charts/charts-min.js',
1928 'requires': ['element', 'json', 'datasource', 'swf']
1933 'path': 'colorpicker/colorpicker-min.js',
1934 'requires': ['slider', 'element'],
1935 'optional': ['animation'],
1941 'path': 'connection/connection-min.js',
1942 'requires': ['event'],
1943 'supersedes': ['connectioncore']
1948 'path': 'connection/connection_core-min.js',
1949 'requires': ['event'],
1955 'path': 'container/container-min.js',
1956 'requires': ['dom', 'event'],
1957 // button is also optional, but this creates a circular
1958 // dependency when loadOptional is specified. button
1959 // optionally includes menu, menu requires container.
1960 'optional': ['dragdrop', 'animation', 'connection'],
1961 'supersedes': ['containercore'],
1967 'path': 'container/container_core-min.js',
1968 'requires': ['dom', 'event'],
1974 'path': 'cookie/cookie-min.js',
1975 'requires': ['yahoo']
1980 'path': 'datasource/datasource-min.js',
1981 'requires': ['event'],
1982 'optional': ['connection']
1987 'path': 'datatable/datatable-min.js',
1988 'requires': ['element', 'datasource'],
1989 'optional': ['calendar', 'dragdrop', 'paginator'],
1995 'path': 'datemath/datemath-min.js',
1996 'requires': ['yahoo']
2001 'path': 'dom/dom-min.js',
2002 'requires': ['yahoo']
2007 'path': 'dragdrop/dragdrop-min.js',
2008 'requires': ['dom', 'event']
2013 'path': 'editor/editor-min.js',
2014 'requires': ['menu', 'element', 'button'],
2015 'optional': ['animation', 'dragdrop'],
2016 'supersedes': ['simpleeditor'],
2022 'path': 'element/element-min.js',
2023 'requires': ['dom', 'event'],
2024 'optional': ['event-mouseenter', 'event-delegate']
2027 'element-delegate': {
2029 'path': 'element-delegate/element-delegate-min.js',
2030 'requires': ['element']
2035 'path': 'event/event-min.js',
2036 'requires': ['yahoo']
2041 'path': 'event-simulate/event-simulate-min.js',
2042 'requires': ['event']
2047 'path': 'event-delegate/event-delegate-min.js',
2048 'requires': ['event'],
2049 'optional': ['selector']
2052 'event-mouseenter': {
2054 'path': 'event-mouseenter/event-mouseenter-min.js',
2055 'requires': ['dom', 'event']
2060 'path': 'fonts/fonts-min.css'
2065 'path': 'get/get-min.js',
2066 'requires': ['yahoo']
2071 'path': 'grids/grids-min.css',
2072 'requires': ['fonts'],
2073 'optional': ['reset']
2078 'path': 'history/history-min.js',
2079 'requires': ['event']
2084 'path': 'imagecropper/imagecropper-min.js',
2085 'requires': ['dragdrop', 'element', 'resize'],
2091 'path': 'imageloader/imageloader-min.js',
2092 'requires': ['event', 'dom']
2097 'path': 'json/json-min.js',
2098 'requires': ['yahoo']
2103 'path': 'layout/layout-min.js',
2104 'requires': ['element'],
2105 'optional': ['animation', 'dragdrop', 'resize', 'selector'],
2111 'path': 'logger/logger-min.js',
2112 'requires': ['event', 'dom'],
2113 'optional': ['dragdrop'],
2119 'path': 'menu/menu-min.js',
2120 'requires': ['containercore'],
2126 'path': 'paginator/paginator-min.js',
2127 'requires': ['element'],
2133 'path': 'profiler/profiler-min.js',
2134 'requires': ['yahoo']
2140 'path': 'profilerviewer/profilerviewer-min.js',
2141 'requires': ['profiler', 'yuiloader', 'element'],
2147 'path': 'progressbar/progressbar-min.js',
2148 'requires': ['element'],
2149 'optional': ['animation'],
2155 'path': 'reset/reset-min.css'
2158 'reset-fonts-grids': {
2160 'path': 'reset-fonts-grids/reset-fonts-grids.css',
2161 'supersedes': ['reset', 'fonts', 'grids', 'reset-fonts'],
2167 'path': 'reset-fonts/reset-fonts.css',
2168 'supersedes': ['reset', 'fonts'],
2174 'path': 'resize/resize-min.js',
2175 'requires': ['dragdrop', 'element'],
2176 'optional': ['animation'],
2182 'path': 'selector/selector-min.js',
2183 'requires': ['yahoo', 'dom']
2188 'path': 'editor/simpleeditor-min.js',
2189 'requires': ['element'],
2190 'optional': ['containercore', 'menu', 'button', 'animation', 'dragdrop'],
2197 'path': 'slider/slider-min.js',
2198 'requires': ['dragdrop'],
2199 'optional': ['animation'],
2205 'path': 'storage/storage-min.js',
2206 'requires': ['yahoo', 'event', 'cookie'],
2207 'optional': ['swfstore']
2212 'path': 'stylesheet/stylesheet-min.js',
2213 'requires': ['yahoo']
2218 'path': 'swf/swf-min.js',
2219 'requires': ['element'],
2220 'supersedes': ['swfdetect']
2225 'path': 'swfdetect/swfdetect-min.js',
2226 'requires': ['yahoo']
2231 'path': 'swfstore/swfstore-min.js',
2232 'requires': ['element', 'cookie', 'swf']
2237 'path': 'tabview/tabview-min.js',
2238 'requires': ['element'],
2239 'optional': ['connection'],
2245 'path': 'treeview/treeview-min.js',
2246 'requires': ['event', 'dom'],
2247 'optional': ['json', 'animation', 'calendar'],
2253 'path': 'uploader/uploader-min.js',
2254 'requires': ['element']
2259 'path': 'utilities/utilities.js',
2260 'supersedes': ['yahoo', 'event', 'dragdrop', 'animation', 'dom', 'connection', 'element', 'yahoo-dom-event', 'get', 'yuiloader', 'yuiloader-dom-event'],
2266 'path': 'yahoo/yahoo-min.js'
2269 'yahoo-dom-event': {
2271 'path': 'yahoo-dom-event/yahoo-dom-event.js',
2272 'supersedes': ['yahoo', 'event', 'dom'],
2278 'path': 'yuiloader/yuiloader-min.js',
2279 'supersedes': ['yahoo', 'get']
2282 'yuiloader-dom-event': {
2284 'path': 'yuiloader-dom-event/yuiloader-dom-event.js',
2285 'supersedes': ['yahoo', 'dom', 'event', 'get', 'yuiloader', 'yahoo-dom-event'],
2291 'path': 'yuitest/yuitest-min.js',
2292 'requires': ['logger'],
2293 'optional': ['event-simulate'],
2301 appendArray: function(o, a) {
2303 for (var i=0; i<a.length; i=i+1) {
2309 keys: function(o, ordered) {
2312 if (lang.hasOwnProperty(o, i)) {
2323 appendArray: function(a1, a2) {
2324 Array.prototype.push.apply(a1, a2);
2326 for (var i=0; i<a2.length; i=i+1) {
2332 indexOf: function(a, val) {
2333 for (var i=0; i<a.length; i=i+1) {
2342 toObject: function(a) {
2344 for (var i=0; i<a.length; i=i+1) {
2352 * Returns a unique array. Does not maintain order, which is fine
2353 * for this application, and performs better than it would if it
2357 return YUI.ObjectUtil.keys(YUI.ArrayUtil.toObject(a));
2362 YAHOO.util.YUILoader = function(o) {
2365 * Internal callback to handle multiple internal insert() calls
2366 * so that css is inserted prior to js
2367 * @property _internalCallback
2370 this._internalCallback = null;
2373 * Use the YAHOO environment listener to detect script load. This
2374 * is only switched on for Safari 2.x and below.
2375 * @property _useYahooListener
2378 this._useYahooListener = false;
2381 * Callback that will be executed when the loader is finished
2386 this.onSuccess = null;
2389 * Callback that will be executed if there is a failure
2393 this.onFailure = Y.log;
2396 * Callback that will be executed each time a new module is loaded
2397 * @method onProgress
2400 this.onProgress = null;
2403 * Callback that will be executed if a timeout occurs
2407 this.onTimeout = null;
2410 * The execution scope for all callbacks
2417 * Data that is passed to all callbacks
2423 * Node reference or id where new nodes should be inserted before
2424 * @property insertBefore
2425 * @type string|HTMLElement
2427 this.insertBefore = null;
2430 * The charset attribute for inserted nodes
2435 this.charset = null;
2438 * The name of the variable in a sandbox or script node
2439 * (for external script support in Safari 2.x and earlier)
2440 * to reference when the load is complete. If this variable
2441 * is not available in the specified scripts, the operation will
2446 this.varName = null;
2449 * The base directory.
2452 * @default http://yui.yahooapis.com/[YUI VERSION]/build/
2454 this.base = YUI.info.base;
2457 * Base path for the combo service
2458 * @property comboBase
2460 * @default http://yui.yahooapis.com/combo?
2462 this.comboBase = YUI.info.comboBase;
2465 * If configured, YUI will use the the combo handler on the
2466 * Yahoo! CDN to pontentially reduce the number of http requests
2472 // this.combine = (o && !('base' in o));
2473 this.combine = false;
2477 * Root path to prepend to module path for the combo
2481 * @default [YUI VERSION]/build/
2483 this.root = YUI.info.root;
2486 * Timeout value in milliseconds. If set, this value will be used by
2487 * the get utility. the timeout event will fire if
2495 * A list of modules that should not be loaded, even if
2496 * they turn up in the dependency tree
2503 * A list of modules that should always be loaded, even
2504 * if they have already been inserted into the page.
2511 * Should we allow rollups
2512 * @property allowRollup
2516 this.allowRollup = true;
2519 * A filter to apply to result urls. This filter will modify the default
2520 * path for all modules. The default path for the YUI library is the
2521 * minified version of the files (e.g., event-min.js). The filter property
2522 * can be a predefined filter or a custom filter. The valid predefined
2526 * <dd>Selects the debug versions of the library (e.g., event-debug.js).
2527 * This option will automatically include the logger widget</dd>
2529 * <dd>Selects the non-minified version of the library (e.g., event.js).
2531 * You can also define a custom filter, which must be an object literal
2532 * containing a search expression and a replace string:
2535 * 'searchExp': "-min\\.js",
2536 * 'replaceStr': "-debug.js"
2540 * @type string|{searchExp: string, replaceStr: string}
2545 * The list of requested modules
2546 * @property required
2547 * @type {string: boolean}
2552 * The library metadata
2553 * @property moduleInfo
2555 this.moduleInfo = lang.merge(YUI.info.moduleInfo);
2558 * List of rollup files found in the library metadata
2561 this.rollups = null;
2564 * Whether or not to load optional dependencies for
2565 * the requested modules
2566 * @property loadOptional
2570 this.loadOptional = false;
2573 * All of the derived dependencies in sorted order, which
2574 * will be populated when either calculate() or insert()
2582 * Set when beginning to compute the dependency tree.
2583 * Composed of what YAHOO reports to be loaded combined
2584 * with what has been loaded by the tool
2586 * @type {string: boolean}
2591 * Flag to indicate the dependency tree needs to be recomputed
2592 * if insert is called again.
2600 * List of modules inserted by the utility
2601 * @property inserted
2602 * @type {string: boolean}
2607 * Provides the information used to skin the skinnable components.
2608 * The following skin definition would result in 'skin1' and 'skin2'
2609 * being loaded for calendar (if calendar was requested), and
2610 * 'sam' for all other skinnable components:
2615 * // The default skin, which is automatically applied if not
2616 * // overriden by a component-specific skin definition.
2617 * // Change this in to apply a different skin globally
2618 * defaultSkin: 'sam',
2620 * // This is combined with the loader base property to get
2621 * // the default root directory for a skin. ex:
2622 * // http://yui.yahooapis.com/2.3.0/build/assets/skins/sam/
2623 * base: 'assets/skins/',
2625 * // The name of the rollup css file for the skin
2628 * // The number of skinnable components requested that are
2629 * // required before using the rollup file rather than the
2630 * // individual component css files
2633 * // Any component-specific overrides can be specified here,
2634 * // making it possible to load different skins for different
2635 * // components. It is possible to load more than one skin
2636 * // for a given component as well.
2638 * calendar: ['skin1', 'skin2']
2647 env.listeners.push(function(m) {
2648 if (self._useYahooListener) {
2649 //Y.log("YAHOO listener: " + m.name);
2650 self.loadNext(m.name);
2654 this.skin = lang.merge(YUI.info.skin);
2660 Y.util.YUILoader.prototype = {
2664 'searchExp': "-min\\.js",
2668 'searchExp': "-min\\.js",
2669 'replaceStr': "-debug.js"
2673 SKIN_PREFIX: "skin-",
2675 _config: function(o) {
2677 // apply config values
2680 if (lang.hasOwnProperty(o, i)) {
2681 if (i == "require") {
2691 var f = this.filter;
2693 if (lang.isString(f)) {
2694 f = f.toUpperCase();
2696 // the logger must be available in order to use the debug
2697 // versions of the library
2698 if (f === "DEBUG") {
2699 this.require("logger");
2702 // hack to handle a a bug where LogWriter is being instantiated
2703 // at load time, and the loader has no way to sort above it
2705 if (!Y.widget.LogWriter) {
2706 Y.widget.LogWriter = function() {
2711 this.filter = this.FILTERS[f];
2716 /** Add a new module to the component metadata.
2718 * <dt>name:</dt> <dd>required, the component name</dd>
2719 * <dt>type:</dt> <dd>required, the component type (js or css)</dd>
2720 * <dt>path:</dt> <dd>required, the path to the script from "base"</dd>
2721 * <dt>requires:</dt> <dd>array of modules required by this component</dd>
2722 * <dt>optional:</dt> <dd>array of optional modules for this component</dd>
2723 * <dt>supersedes:</dt> <dd>array of the modules this component replaces</dd>
2724 * <dt>after:</dt> <dd>array of modules the components which, if present, should be sorted above this one</dd>
2725 * <dt>rollup:</dt> <dd>the number of superseded modules required for automatic rollup</dd>
2726 * <dt>fullpath:</dt> <dd>If fullpath is specified, this is used instead of the configured base + path</dd>
2727 * <dt>skinnable:</dt> <dd>flag to determine if skin assets should automatically be pulled in</dd>
2730 * @param o An object containing the module data
2731 * @return {boolean} true if the module was added, false if
2732 * the object passed in did not provide all required attributes
2734 addModule: function(o) {
2736 if (!o || !o.name || !o.type || (!o.path && !o.fullpath)) {
2740 o.ext = ('ext' in o) ? o.ext : true;
2741 o.requires = o.requires || [];
2743 this.moduleInfo[o.name] = o;
2750 * Add a requirement for one or more module
2752 * @param what {string[] | string*} the modules to load
2754 require: function(what) {
2755 var a = (typeof what === "string") ? arguments : what;
2757 YUI.ObjectUtil.appendArray(this.required, a);
2761 * Adds the skin def to the module info
2763 * @param skin {string} the name of the skin
2764 * @param mod {string} the name of the module
2765 * @return {string} the module name for the skin
2768 _addSkin: function(skin, mod) {
2770 // Add a module definition for the skin rollup css
2771 var name = this.formatSkin(skin), info = this.moduleInfo,
2772 sinf = this.skin, ext = info[mod] && info[mod].ext;
2774 // Y.log('ext? ' + mod + ": " + ext);
2776 // Y.log('adding skin ' + name);
2780 'path': sinf.base + skin + '/' + sinf.path,
2781 //'supersedes': '*',
2782 'after': sinf.after,
2783 'rollup': sinf.rollup,
2788 // Add a module definition for the module-specific skin css
2790 name = this.formatSkin(skin, mod);
2792 var mdef = info[mod], pkg = mdef.pkg || mod;
2793 // Y.log('adding skin ' + name);
2797 'after': sinf.after,
2798 'path': pkg + '/' + sinf.base + skin + '/' + mod + '.css',
2808 * Returns an object containing properties for all modules required
2809 * in order to load the requested module
2810 * @method getRequires
2811 * @param mod The module definition from moduleInfo
2813 getRequires: function(mod) {
2818 if (!this.dirty && mod.expanded) {
2819 return mod.expanded;
2822 mod.requires=mod.requires || [];
2823 var i, d=[], r=mod.requires, o=mod.optional, info=this.moduleInfo, m;
2824 for (i=0; i<r.length; i=i+1) {
2827 YUI.ArrayUtil.appendArray(d, this.getRequires(m));
2829 // add existing skins for skinnable modules as well. The only
2830 // way to do this is go through the list of required items (this
2831 // assumes that _skin is called before getRequires is called on
2833 // if (m.skinnable) {
2834 // var req=this.required, l=req.length;
2835 // for (var j=0; j<l; j=j+1) {
2836 // // YAHOO.log('checking ' + r[j]);
2837 // if (req[j].indexOf(r[j]) > -1) {
2838 // // YAHOO.log('adding ' + r[j]);
2845 if (o && this.loadOptional) {
2846 for (i=0; i<o.length; i=i+1) {
2848 YUI.ArrayUtil.appendArray(d, this.getRequires(info[o[i]]));
2852 mod.expanded = YUI.ArrayUtil.uniq(d);
2854 return mod.expanded;
2859 * Returns an object literal of the modules the supplied module satisfies
2860 * @method getProvides
2861 * @param name{string} The name of the module
2862 * @param notMe {string} don't add this module name, only include superseded modules
2863 * @return what this module provides
2865 getProvides: function(name, notMe) {
2866 var addMe = !(notMe), ckey = (addMe) ? PROV : SUPER,
2867 m = this.moduleInfo[name], o = {};
2874 // Y.log('cached: ' + name + ' ' + ckey + ' ' + lang.dump(this.moduleInfo[name][ckey], 0));
2878 var s = m.supersedes, done={}, me = this;
2880 // use worker to break cycles
2881 var add = function(mm) {
2883 // Y.log(name + ' provides worker trying: ' + mm);
2885 // we always want the return value normal behavior
2886 // (provides) for superseded modules.
2887 lang.augmentObject(o, me.getProvides(mm));
2891 // Y.log(name + ' provides worker skipping done: ' + mm);
2895 // calculate superseded modules
2897 for (var i=0; i<s.length; i=i+1) {
2905 m[PROV] = lang.merge(o);
2906 m[PROV][name] = true;
2908 // Y.log(name + " supersedes " + lang.dump(m[SUPER], 0));
2909 // Y.log(name + " provides " + lang.dump(m[PROV], 0));
2916 * Calculates the dependency tree, the result is stored in the sorted
2919 * @param o optional options object
2921 calculate: function(o) {
2922 if (o || this.dirty) {
2926 // this._skin(); // deprecated
2927 if (this.allowRollup) {
2933 // Y.log("after calculate: " + lang.dump(this.required));
2940 * Investigates the current YUI configuration on the page. By default,
2941 * modules already detected will not be loaded again unless a force
2942 * option is encountered. Called by calculate()
2946 _setup: function() {
2948 var info = this.moduleInfo, name, i, j;
2950 // Create skin modules
2951 for (name in info) {
2953 if (lang.hasOwnProperty(info, name)) {
2955 if (m && m.skinnable) {
2956 // Y.log("skinning: " + name);
2957 var o=this.skin.overrides, smod;
2959 for (i=0; i<o[name].length; i=i+1) {
2960 smod = this._addSkin(o[name][i], name);
2963 smod = this._addSkin(this.skin.defaultSkin, name);
2966 m.requires.push(smod);
2972 var l = lang.merge(this.inserted); // shallow clone
2974 if (!this._sandbox) {
2975 l = lang.merge(l, env.modules);
2978 // Y.log("Already loaded stuff: " + lang.dump(l, 0));
2980 // add the ignore list to the list of loaded packages
2982 YUI.ObjectUtil.appendArray(l, this.ignore);
2985 // remove modules on the force list from the loaded list
2987 for (i=0; i<this.force.length; i=i+1) {
2988 if (this.force[i] in l) {
2989 delete l[this.force[i]];
2994 // expand the list to include superseded modules
2996 // Y.log("expanding: " + j);
2997 if (lang.hasOwnProperty(l, j)) {
2998 lang.augmentObject(l, this.getProvides(j));
3002 // Y.log("loaded expanded: " + lang.dump(l, 0));
3010 * Inspects the required modules list looking for additional
3011 * dependencies. Expands the required list to include all
3012 * required modules. Called by calculate()
3016 _explode: function() {
3018 var r=this.required, i, mod;
3021 if (lang.hasOwnProperty(r, i)) {
3022 mod = this.moduleInfo[i];
3025 var req = this.getRequires(mod);
3028 YUI.ObjectUtil.appendArray(r, req);
3036 * Sets up the requirements for the skin assets if any of the
3037 * requested modules are skinnable
3040 * @deprecated skin modules are generated for all skinnable
3041 * components during _setup(), and the components
3042 * are configured to require the skin.
3049 * Returns the skin module name for the specified skin name. If a
3050 * module name is supplied, the returned skin module name is
3051 * specific to the module passed in.
3052 * @method formatSkin
3053 * @param skin {string} the name of the skin
3054 * @param mod {string} optional: the name of a module to skin
3055 * @return {string} the full skin module name
3057 formatSkin: function(skin, mod) {
3058 var s = this.SKIN_PREFIX + skin;
3067 * Reverses <code>formatSkin</code>, providing the skin name and
3068 * module name if the string matches the pattern for skins.
3070 * @param mod {string} the module name to parse
3071 * @return {skin: string, module: string} the parsed skin name
3072 * and module name, or null if the supplied string does not match
3075 parseSkin: function(mod) {
3077 if (mod.indexOf(this.SKIN_PREFIX) === 0) {
3078 var a = mod.split("-");
3079 return {skin: a[1], module: a[2]};
3086 * Look for rollup packages to determine if all of the modules a
3087 * rollup supersedes are required. If so, include the rollup to
3088 * help reduce the total number of connections required. Called
3093 _rollup: function() {
3094 var i, j, m, s, rollups={}, r=this.required, roll,
3095 info = this.moduleInfo;
3097 // find and cache rollup modules
3098 if (this.dirty || !this.rollups) {
3100 if (lang.hasOwnProperty(info, i)) {
3102 //if (m && m.rollup && m.supersedes) {
3103 if (m && m.rollup) {
3109 this.rollups = rollups;
3112 // make as many passes as needed to pick up rollup rollups
3116 // go through the rollup candidates
3117 for (i in rollups) {
3119 // there can be only one
3120 if (!r[i] && !this.loaded[i]) {
3121 m =info[i]; s = m.supersedes; roll=false;
3127 var skin = (m.ext) ? false : this.parseSkin(i), c = 0;
3129 // Y.log('skin? ' + i + ": " + skin);
3132 if (lang.hasOwnProperty(r, j)) {
3133 if (i !== j && this.parseSkin(j)) {
3135 roll = (c >= m.rollup);
3137 // Y.log("skin rollup " + lang.dump(r));
3146 // check the threshold
3147 for (j=0;j<s.length;j=j+1) {
3149 // if the superseded module is loaded, we can't load the rollup
3150 if (this.loaded[s[j]] && (!YUI.dupsAllowed[s[j]])) {
3153 // increment the counter if this module is required. if we are
3154 // beyond the rollup threshold, we will use the rollup module
3155 } else if (r[s[j]]) {
3157 roll = (c >= m.rollup);
3159 // Y.log("over thresh " + c + ", " + lang.dump(r));
3167 // Y.log("rollup: " + i + ", " + lang.dump(this, 1));
3172 // expand the rollup's dependencies
3173 this.getRequires(m);
3178 // if we made it here w/o rolling up something, we are done
3186 * Remove superceded modules and loaded modules. Called by
3187 * calculate() after we have the mega list of all dependencies
3191 _reduce: function() {
3193 var i, j, s, m, r=this.required;
3196 // remove if already loaded
3197 if (i in this.loaded) {
3200 // remove anything this module supersedes
3203 var skinDef = this.parseSkin(i);
3206 //YAHOO.log("skin found in reduce: " + skinDef.skin + ", " + skinDef.module);
3207 // the skin rollup will not have a module name
3208 if (!skinDef.module) {
3209 var skin_pre = this.SKIN_PREFIX + skinDef.skin;
3210 //YAHOO.log("skin_pre: " + skin_pre);
3213 if (lang.hasOwnProperty(r, j)) {
3214 m = this.moduleInfo[j];
3215 var ext = m && m.ext;
3216 if (!ext && j !== i && j.indexOf(skin_pre) > -1) {
3217 // Y.log ("removing component skin: " + j);
3225 m = this.moduleInfo[i];
3226 s = m && m.supersedes;
3228 for (j=0; j<s.length; j=j+1) {
3239 _onFailure: function(msg) {
3240 YAHOO.log('Failure', 'info', 'loader');
3242 var f = this.onFailure;
3244 f.call(this.scope, {
3245 msg: 'failure: ' + msg,
3252 _onTimeout: function() {
3253 YAHOO.log('Timeout', 'info', 'loader');
3254 var f = this.onTimeout;
3256 f.call(this.scope, {
3265 * Sorts the dependency tree. The last step of calculate()
3270 // create an indexed list
3271 var s=[], info=this.moduleInfo, loaded=this.loaded,
3272 checkOptional=!this.loadOptional, me = this;
3274 // returns true if b is not loaded, and is required
3275 // directly or by means of modules it supersedes.
3276 var requires = function(aa, bb) {
3280 if (loaded[bb] || !mm) {
3288 optional = mm.optional;
3291 // check if this module requires the other directly
3292 if (rr && YUI.ArrayUtil.indexOf(rr, bb) > -1) {
3296 // check if this module should be sorted after the other
3297 if (after && YUI.ArrayUtil.indexOf(after, bb) > -1) {
3301 // if loadOptional is not specified, optional dependencies still
3302 // must be sorted correctly when present.
3303 if (checkOptional && optional && YUI.ArrayUtil.indexOf(optional, bb) > -1) {
3307 // check if this module requires one the other supersedes
3308 var ss=info[bb] && info[bb].supersedes;
3310 for (ii=0; ii<ss.length; ii=ii+1) {
3311 if (requires(aa, ss[ii])) {
3317 // var ss=me.getProvides(bb, true);
3320 // if (requires(aa, ii)) {
3326 // external css files should be sorted below yui css
3327 if (mm.ext && mm.type == 'css' && !other.ext && other.type == 'css') {
3334 // get the required items out of the obj into an array so we
3336 for (var i in this.required) {
3337 if (lang.hasOwnProperty(this.required, i)) {
3342 // pointer to the first unsorted item
3345 // keep going until we make a pass without moving anything
3348 var l=s.length, a, b, j, k, moved=false;
3350 // start the loop after items that are already sorted
3351 for (j=p; j<l; j=j+1) {
3353 // check the next module on the list to see if its
3354 // dependencies have been met
3357 // check everything below current item and move if we
3358 // find a requirement for the current item
3359 for (k=j+1; k<l; k=k+1) {
3360 if (requires(a, s[k])) {
3362 // extract the dependency so we can move it up
3365 // insert the dependency above the item that
3367 s.splice(j, 0, b[0]);
3374 // jump out of loop if we moved something
3377 // this item is sorted, move our pointer and keep going
3383 // when we make it here and moved is false, we are
3394 toString: function() {
3398 filter: this.filter,
3399 required: this.required,
3400 loaded: this.loaded,
3401 inserted: this.inserted
3407 _combine: function() {
3409 this._combining = [];
3414 js = this.comboBase,
3415 css = this.comboBase,
3417 startLen = js.length,
3418 i, m, type = this.loadType;
3420 YAHOO.log('type ' + type);
3422 for (i=0; i<len; i=i+1) {
3424 m = this.moduleInfo[s[i]];
3426 if (m && !m.ext && (!type || type === m.type)) {
3428 target = this.root + m.path;
3434 if (m.type == 'js') {
3440 // YAHOO.log(target);
3441 this._combining.push(s[i]);
3445 if (this._combining.length) {
3447 YAHOO.log('Attempting to combine: ' + this._combining, "info", "loader");
3449 var callback=function(o) {
3450 // YAHOO.log('Combo complete: ' + o.data, "info", "loader");
3451 // this._combineComplete = true;
3453 var c=this._combining, len=c.length, i, m;
3454 for (i=0; i<len; i=i+1) {
3455 this.inserted[c[i]] = true;
3458 this.loadNext(o.data);
3461 loadScript = function() {
3462 // YAHOO.log('combining js: ' + js);
3463 if (js.length > startLen) {
3464 YAHOO.util.Get.script(self._filter(js), {
3465 data: self._loading,
3466 onSuccess: callback,
3467 onFailure: self._onFailure,
3468 onTimeout: self._onTimeout,
3469 insertBefore: self.insertBefore,
3470 charset: self.charset,
3471 timeout: self.timeout,
3477 // load the css first
3478 // YAHOO.log('combining css: ' + css);
3479 if (css.length > startLen) {
3480 YAHOO.util.Get.css(this._filter(css), {
3481 data: this._loading,
3482 onSuccess: loadScript,
3483 onFailure: this._onFailure,
3484 onTimeout: this._onTimeout,
3485 insertBefore: this.insertBefore,
3486 charset: this.charset,
3487 timeout: this.timeout,
3497 // this._combineComplete = true;
3498 this.loadNext(this._loading);
3503 * inserts the requested modules and their dependencies.
3504 * <code>type</code> can be "js" or "css". Both script and
3505 * css are inserted if type is not provided.
3507 * @param o optional options object
3508 * @param type {string} the type of dependency to insert
3510 insert: function(o, type) {
3512 // Y.log("insert: " + lang.dump(o, 1) + ", " + type);
3514 // Y.log("insert: " + this.toString() + ", " + type);
3517 // build the dependency list
3521 // set a flag to indicate the load has started
3522 this._loading = true;
3524 // flag to indicate we are done with the combo service
3525 // and any additional files will need to be loaded
3527 // this._combineComplete = false;
3529 // keep the loadType (js, css or undefined) cached
3530 this.loadType = type;
3533 return this._combine();
3537 // Y.log("trying to load css first");
3539 this._internalCallback = function() {
3540 self._internalCallback = null;
3541 self.insert(null, "js");
3543 this.insert(null, "css");
3554 * Interns the script for the requested modules. The callback is
3555 * provided a reference to the sandboxed YAHOO object. This only
3556 * applies to the script: css can not be sandboxed; css will be
3557 * loaded into the page normally if specified.
3559 * @param callback {Function} the callback to exectued when the load is
3562 sandbox: function(o, type) {
3564 // YAHOO.log("sandbox: " + lang.dump(o, 1) + ", " + type);
3566 // YAHOO.log("sandbox: " + this.toString() + ", " + type);
3571 if (!this.onSuccess) {
3572 throw new Error("You must supply an onSuccess handler for your sandbox");
3575 this._sandbox = true;
3579 // take care of any css first (this can't be sandboxed)
3580 if (!type || type !== "js") {
3581 this._internalCallback = function() {
3582 self._internalCallback = null;
3583 self.sandbox(null, "js");
3585 this.insert(null, "css");
3589 // get the connection manager if not on the page
3590 if (!util.Connect) {
3591 // get a new loader instance to load connection.
3592 var ld = new YAHOO.util.YUILoader();
3595 filter: this.filter,
3596 require: "connection",
3597 insertBefore: this.insertBefore,
3598 charset: this.charset,
3599 onSuccess: function() {
3600 this.sandbox(null, "js");
3607 this._scriptText = [];
3608 this._loadCount = 0;
3609 this._stopCount = this.sorted.length;
3614 var s=this.sorted, l=s.length, i, m, url;
3616 for (i=0; i<l; i=i+1) {
3617 m = this.moduleInfo[s[i]];
3619 // undefined modules cause a failure
3621 this._onFailure("undefined module " + m);
3622 for (var j=0;j<this._xhr.length;j=j+1) {
3623 this._xhr[j].abort();
3628 // css files should be done
3629 if (m.type !== "js") {
3635 url = (url) ? this._filter(url) : this._url(m.path);
3637 // YAHOO.log("xhr request: " + url + ", " + i);
3641 success: function(o) {
3643 var idx=o.argument[0], name=o.argument[2];
3645 // store the response in the position it was requested
3646 this._scriptText[idx] = o.responseText;
3648 // YAHOO.log("received: " + o.responseText.substr(0, 100) + ", " + idx);
3650 if (this.onProgress) {
3651 this.onProgress.call(this.scope, {
3653 scriptText: o.responseText,
3659 // only generate the sandbox once everything is loaded
3662 if (this._loadCount >= this._stopCount) {
3664 // the variable to find
3665 var v = this.varName || "YAHOO";
3667 // wrap the contents of the requested modules in an anonymous function
3668 var t = "(function() {\n";
3670 // return the locally scoped reference.
3671 var b = "\nreturn " + v + ";\n})();";
3673 var ref = eval(t + this._scriptText.join("\n") + b);
3675 this._pushEvents(ref);
3678 this.onSuccess.call(this.scope, {
3683 this._onFailure.call(this.varName + " reference failure");
3688 failure: function(o) {
3689 this.onFailure.call(this.scope, {
3698 // module index, module name, sandbox name
3699 argument: [i, url, s[i]]
3703 this._xhr.push(util.Connect.asyncRequest('GET', url, xhrData));
3708 * Executed every time a module is loaded, and if we are in a load
3709 * cycle, we attempt to load the next script. Public so that it
3710 * is possible to call this if using a method other than
3711 * YAHOO.register to determine when scripts are fully loaded
3713 * @param mname {string} optional the name of the module that has
3714 * been loaded (which is usually why it is time to load the next
3717 loadNext: function(mname) {
3719 // It is possible that this function is executed due to something
3720 // else one the page loading a YUI module. Only react when we
3721 // are actively loading something
3722 if (!this._loading) {
3729 // if the module that was just loaded isn't what we were expecting,
3731 if (mname !== this._loading) {
3735 // YAHOO.log("loadNext executing, just loaded " + mname);
3737 // The global handler that is called when each module is loaded
3738 // will pass that module name to this function. Storing this
3739 // data to avoid loading the same module multiple times
3740 this.inserted[mname] = true;
3742 if (this.onProgress) {
3743 this.onProgress.call(this.scope, {
3748 //var o = this.getProvides(mname);
3749 //this.inserted = lang.merge(this.inserted, o);
3752 var s=this.sorted, len=s.length, i, m;
3754 for (i=0; i<len; i=i+1) {
3756 // This.inserted keeps track of what the loader has loaded
3757 if (s[i] in this.inserted) {
3758 // YAHOO.log(s[i] + " alread loaded ");
3762 // Because rollups will cause multiple load notifications
3763 // from YAHOO, loadNext may be called multiple times for
3764 // the same module when loading a rollup. We can safely
3765 // skip the subsequent requests
3766 if (s[i] === this._loading) {
3767 // YAHOO.log("still loading " + s[i] + ", waiting");
3771 // log("inserting " + s[i]);
3772 m = this.moduleInfo[s[i]];
3775 this.onFailure.call(this.scope, {
3776 msg: "undefined module " + m,
3782 // The load type is stored to offer the possibility to load
3783 // the css separately from the script.
3784 if (!this.loadType || this.loadType === m.type) {
3785 this._loading = s[i];
3786 //YAHOO.log("attempting to load " + s[i] + ", " + this.base);
3788 var fn=(m.type === "css") ? util.Get.css : util.Get.script,
3792 self.loadNext(o.data);
3795 url = (url) ? this._filter(url) : this._url(m.path);
3797 // safari 2.x or lower, script, and part of YUI
3798 if (env.ua.webkit && env.ua.webkit < 420 && m.type === "js" &&
3800 //YUI.info.moduleInfo[s[i]]) {
3801 //YAHOO.log("using YAHOO env " + s[i] + ", " + m.varName);
3803 this._useYahooListener = true;
3809 onFailure: this._onFailure,
3810 onTimeout: this._onTimeout,
3811 insertBefore: this.insertBefore,
3812 charset: this.charset,
3813 timeout: this.timeout,
3823 this._loading = null;
3825 // internal callback for loading css first
3826 if (this._internalCallback) {
3827 var f = this._internalCallback;
3828 this._internalCallback = null;
3830 } else if (this.onSuccess) {
3832 this.onSuccess.call(this.scope, {
3840 * In IE, the onAvailable/onDOMReady events need help when Event is
3841 * loaded dynamically
3842 * @method _pushEvents
3843 * @param {Function} optional function reference
3846 _pushEvents: function(ref) {
3847 var r = ref || YAHOO;
3848 if (r.util && r.util.Event) {
3849 r.util.Event._load();
3856 * @return {string} the filtered string
3859 _filter: function(str) {
3860 var f = this.filter;
3861 return (f) ? str.replace(new RegExp(f.searchExp, 'g'), f.replaceStr) : str;
3865 * Generates the full url for a module
3867 * @param path {string} the path fragment
3868 * @return {string} the full url
3871 _url: function(path) {
3872 return this._filter((this.base || "") + path);
3879 YAHOO.register("yuiloader", YAHOO.util.YUILoader, {version: "2.8.0r4", build: "2449"});