2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
15
// @TODO: this needs to be created at build time from module metadata
17
_APPLY_TO_WHITE_LIST = {
26
if (typeof YUI === 'undefined' || !YUI) {
29
* The YUI global namespace object. If YUI is already defined, the
30
* existing YUI object will not be overwritten so that defined
31
* namespaces are preserved.
37
* @param o Optional configuration object. Options:
39
* <li>------------------------------------------------------------------------</li>
41
* <li>------------------------------------------------------------------------</li>
43
* Turn debug statements on or off</li>
44
* <li>useBrowserConsole:
45
* Log to the browser console if debug is on and the console is available</li>
47
* A hash of log sources that should be logged. If specified, only log messages from these sources will be logged.
51
* A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list.</li>
53
* If throwFail is set, Y.fail will generate or re-throw a JS error. Otherwise the failure is logged.
55
* The target window/frame</li>
57
* A list of modules that defines the YUI core (overrides the default)</li>
58
* <li>------------------------------------------------------------------------</li>
59
* <li>For event and get:</li>
60
* <li>------------------------------------------------------------------------</li>
62
* The default poll interval</li>
63
* <li>-------------------------------------------------------------------------</li>
64
* <li>For loader:</li>
65
* <li>-------------------------------------------------------------------------</li>
69
* The secure base dir (not implemented)</li>
71
* The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li>
73
* The root path to prepend to module names for the combo service. Ex: 2.5.2/build/</li>
76
* A filter to apply to result urls. This filter will modify the default
77
* path for all modules. The default path for the YUI library is the
78
* minified version of the files (e.g., event-min.js). The filter property
79
* can be a predefined filter or a custom filter. The valid predefined
83
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
84
* This option will automatically include the logger widget</dd>
86
* <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
88
* You can also define a custom filter, which must be an object literal
89
* containing a search expression and a replace string:
92
* 'searchExp': "-min\\.js",
93
* 'replaceStr': "-debug.js"
99
* Use the YUI combo service to reduce the number of http connections required to load your dependencies</li>
101
* A list of modules that should never be dynamically loaded</li>
103
* A list of modules that should always be loaded when required, even if already present on the page</li>
105
* Node or id for a node that should be used as the insertion point for new nodes</li>
107
* charset for dynamic nodes</li>
109
* number of milliseconds before a timeout occurs when dynamically loading nodes. in not set, there is no timeout</li>
111
* execution context for all callbacks</li>
113
* callback for the 'success' event</li>
115
* callback for the 'failure' event</li>
117
* callback for the 'timeout' event</li>
119
* callback executed each time a script or css file is loaded</li>
121
* A list of module definitions. See Loader.addModule for the supported module metadata</li>
129
// Allow instantiation without the new operator
130
if (!(Y instanceof YUI)) {
133
// set up the core environment
136
// bind the specified additional modules for this instance
144
// The prototype contains the functions that are required to allow the external
145
// modules to be registered and for the instance to be initialized.
149
* Initialize this YUI instance
150
* @param o config options
158
// find targeted window and @TODO create facades
159
var w = (o.win) ? (o.win.contentWindow) : o.win || window;
162
o.debug = ('debug' in o) ? o.debug : true;
163
o.useBrowserConsole = ('useBrowserConsole' in o) ? o.useBrowserConsole : true;
164
o.throwFail = ('throwFail' in o) ? o.throwFail : true;
166
// add a reference to o for anything that needs it
167
// before _setup is called.
171
// @todo expand the new module metadata
182
this.Env._yidx = ++YUI.Env._idx;
183
this.id = this.stamp(this);
184
_instances[this.id] = this;
187
this.constructor = YUI;
192
* Finishes the instance setup. Attaches whatever modules were defined
193
* when the yui modules was registered.
197
_setup: function(o) {
199
// @TODO eval the need to copy the config
200
this.config = this.merge(this.config);
204
* Executes a method on a YUI instance with
205
* the specified id if the specified method is whitelisted.
207
* @param id {string} the YUI instance id
208
* @param method {string} the name of the method to exectute.
210
* @param args {Array} the arguments to apply to the method
211
* @return {object} the return value from the applied method or null
213
applyTo: function(id, method, args) {
215
if (!(method in _APPLY_TO_WHITE_LIST)) {
216
this.fail(method + ': applyTo not allowed');
220
var instance = _instances[id];
224
var nest = method.split('.'), m = instance;
226
for (var i=0; i<nest.length; i=i+1) {
231
this.fail('applyTo not found: ' + method);
235
return m.apply(instance, args);
244
* @param name {string} module name
245
* @param fn {Function} entry point into the module that
246
* is used to bind module to the YUI instance
247
* @param version {string} version string
248
* @return {YUI} the YUI instance
250
* requires - features that should be present before loading
251
* optional - optional features that should be present if load optional defined
252
* use - features that should be attached automatically
255
* omit - features that should not be loaded if this module is present
257
add: function(name, fn, version, details) {
260
// @todo expand this to include version mapping
262
// @todo allow requires/supersedes
264
// @todo may want to restore the build property
266
// @todo fire moduleAvailable event
272
details: details || {}
275
YUI.Env.mods[name] = m;
277
return this; // chain support
280
_attach: function(r, fromLoader) {
282
var mods = YUI.Env.mods,
283
attached = this.Env._attached;
285
for (var i=0, l=r.length; i<l; i=i+1) {
286
var name = r[i], m = mods[name], mm;
287
if (!attached[name] && m) {
289
attached[name] = true;
291
var d = m.details, req = d.requires, use = d.use;
294
this._attach(this.Array(req));
303
this._attach(this.Array(use));
311
* Bind a module to a YUI instance
312
* @param modules* {string} 1-n modules to bind (uses arguments array)
313
* @param *callback {function} callback function executed when
314
* the instance has the required functionality. If included, it
315
* must be the last parameter.
318
* Implement versioning? loader can load different versions?
319
* Should sub-modules/plugins be normal modules, or do
320
* we add syntax for specifying these?
322
* YUI().use('dragdrop')
323
* YUI().use('dragdrop:2.4.0'); // specific version
324
* YUI().use('dragdrop:2.4.0-'); // at least this version
325
* YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
326
* YUI().use('*'); // use all available modules
327
* YUI().use('lang+dump+substitute'); // use lang and some plugins
328
* YUI().use('lang+*'); // use lang and all known plugins
331
* @return {YUI} the YUI instance
336
a=Array.prototype.slice.call(arguments, 0),
342
callback = a[a.length-1];
345
// The last argument supplied to use can be a load complete callback
346
if (typeof callback === 'function') {
348
Y.Env._callback = callback;
353
// YUI().use('*'); // bind everything available
354
if (firstArg === "*") {
356
for (var k in mods) {
357
if (mods.hasOwnProperty(k)) {
362
return Y.use.apply(Y, a);
367
// use loader to expand dependencies and sort the
368
// requirements if it is available.
371
loader = new Y.Loader(Y.config);
373
loader.ignoreRegistered = true;
374
loader.allowRollup = false;
380
var missing = [], r = [], f = function(name) {
382
// only attach a module once
387
var m = mods[name], j, req, use;
392
req = m.details.requires;
398
// make sure requirements are attached
400
if (Y.Lang.isString(req)) {
403
for (j = 0; j < req.length; j = j + 1) {
409
// add this module to full list of things to attach
414
// process each requirement and any additional requirements
415
// the module metadata specifies
416
for (var i=0, l=a.length; i<l; i=i+1) {
421
var onComplete = function(fromLoader) {
424
fromLoader = fromLoader || {
429
if (Y.Env._callback) {
431
var cb = Y.Env._callback;
432
Y.Env._callback = null;
437
Y.fire('yui:load', Y, fromLoader);
443
if (Y.Loader && missing.length) {
444
loader = new Y.Loader(Y.config);
445
loader.onSuccess = onComplete;
446
loader.onFailure = onComplete;
447
loader.onTimeout = onComplete;
448
loader.attaching = a;
449
loader.require(missing);
456
return Y; // chain support var yui = YUI().use('dragdrop');
461
* Returns the namespace specified and creates it if it doesn't exist
463
* YUI.namespace("property.package");
464
* YUI.namespace("YAHOO.property.package");
466
* Either of the above would create YAHOO.property, then
467
* YUI.property.package
469
* Be careful when naming packages. Reserved words may work in some browsers
470
* and not others. For instance, the following will fail in Safari:
472
* YUI.namespace("really.long.nested.namespace");
474
* This fails because "long" is a future reserved word in ECMAScript
477
* @param {string*} arguments 1-n namespaces to create
478
* @return {object} A reference to the last namespace object created
480
namespace: function() {
481
var a=arguments, o=null, i, j, d;
482
for (i=0; i<a.length; i=i+1) {
485
for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
486
o[d[j]] = o[d[j]] || {};
493
// this is replaced if the log module is included
499
* Report an error. The reporting mechanism is controled by
500
* the 'throwFail' configuration attribute. If throwFail is
501
* not specified, the message is written to the logger, otherwise
502
* a JS error is thrown
504
* @param msg {string} the failure message
505
* @param e {Error} Optional JS error that was caught. If supplied
506
* and throwFail is specified, this error will be re-thrown.
507
* @return {YUI} this YUI instance
509
fail: function(msg, e) {
510
if (this.config.throwFail) {
511
throw (e || new Error(msg));
514
instance.log(msg, "error"); // don't scrub this one
521
* Generate an id that is unique among all YUI instances
523
* @param pre {string} optional guid prefix
524
* @return {string} the guid
526
guid: function(pre) {
527
var e = this.Env, p = (pre) || e._pre;
528
return p +'-' + e._yidx + '-' + e._uidx++;
532
* Stamps an object with a guid. If the object already
533
* has one, a new one is not created
535
* @param o The object to stamp
536
* @return {string} The object's guid
544
var uid = (typeof o === 'string') ? o : o._yuid;
555
// Give the YUI global the same properties as an instance.
556
// This makes it so that the YUI global can be used like the YAHOO
557
// global was used prior to 3.x. More importantly, the YUI global
558
// provides global metadata, so env needs to be configured.
561
var Y = YUI, p = Y.prototype, i;
563
// inheritance utilities are not available yet
570
// set up the environment
578
* @submodule yui-base
580
// This is just a stub to for dependency processing
581
YUI.add("yui-base", null, "3.0.0pr2");
587
YUI.add("log", function(instance) {
590
* If the 'debug' config is true, a 'yui:log' event will be
591
* dispatched, which the logger widget and anything else
592
* can consume. If the 'useBrowserConsole' config is true, it will
593
* write to the browser console if available.
597
* @param {String} msg The message to log.
598
* @param {String} cat The log category for the message. Default
599
* categories are "info", "warn", "error", time".
600
* Custom categories can be used as well. (opt)
601
* @param {String} src The source of the the message (opt)
602
* @param {boolean} silent If true, the log event won't fire
603
* @return {YUI} YUI instance
605
instance.log = function(msg, cat, src, silent) {
607
var Y = instance, c = Y.config, es = Y.Env._eventstack,
608
// bail = (es && es.logging);
611
// suppress log message if the config is off or the event stack
612
// or the event call stack contains a consumer of the yui:log event
613
if (c.debug && !bail) {
615
// apply source filters
618
var exc = c.logExclude, inc = c.logInclude;
620
// console.log('checking src filter: ' + src + ', inc: ' + inc + ', exc: ' + exc);
622
if (inc && !(src in inc)) {
623
// console.log('bail: inc list found, but src is not in list: ' + src);
625
} else if (exc && (src in exc)) {
626
// console.log('bail: exc list found, and src is in it: ' + src);
633
if (c.useBrowserConsole) {
634
var m = (src) ? src + ': ' + msg : msg;
635
if (typeof console != 'undefined') {
636
var f = (cat && console[cat]) ? cat : 'log';
638
} else if (typeof opera != 'undefined') {
643
if (Y.fire && !bail && !silent) {
644
Y.fire('yui:log', msg, cat, src);
658
YUI.add("lang", function(Y) {
661
* Provides the language utilites and extensions used by the library
665
Y.Lang = Y.Lang || {};
669
ARRAY_TOSTRING = '[object Array]',
670
FUNCTION_TOSTRING = '[object Function]',
674
UNDEFINED = 'undefined',
675
OP = Object.prototype;
678
* Determines whether or not the provided object is an array.
679
* Testing typeof/instanceof/constructor of arrays across frame
680
* boundaries isn't possible in Safari unless you have a reference
681
* to the other frame to test against its Array prototype. To
682
* handle this case, we test well-known array properties instead.
684
* @TODO can we kill this cross frame hack?
687
* @param o The object to test
688
* @return {boolean} true if o is an array
690
L.isArray = function(o) {
691
return OP.toString.apply(o) === ARRAY_TOSTRING;
695
* Determines whether or not the provided object is a boolean
698
* @param o The object to test
699
* @return {boolean} true if o is a boolean
701
L.isBoolean = function(o) {
702
return typeof o === BOOLEAN;
706
* Determines whether or not the provided object is a function
707
* Note: Internet Explorer thinks certain functions are objects:
709
* var obj = document.createElement("object");
710
* Y.Lang.isFunction(obj.getAttribute) // reports false in IE
712
* var input = document.createElement("input"); // append to body
713
* Y.Lang.isFunction(input.focus) // reports false in IE
715
* You will have to implement additional tests if these functions
720
* @param o The object to test
721
* @return {boolean} true if o is a function
723
L.isFunction = function(o) {
724
return OP.toString.apply(o) === FUNCTION_TOSTRING;
728
* Determines whether or not the supplied object is a date instance
731
* @param o The object to test
732
* @return {boolean} true if o is a date
734
L.isDate = function(o) {
735
return o instanceof Date;
739
* Determines whether or not the provided object is null
742
* @param o The object to test
743
* @return {boolean} true if o is null
745
L.isNull = function(o) {
750
* Determines whether or not the provided object is a legal number
753
* @param o The object to test
754
* @return {boolean} true if o is a number
756
L.isNumber = function(o) {
757
return typeof o === 'number' && isFinite(o);
761
* Determines whether or not the provided object is of type object
765
* @param o The object to test
766
* @param failfn {boolean} fail if the input is a function
767
* @return {boolean} true if o is an object
769
L.isObject = function(o, failfn) {
770
return (o && (typeof o === OBJECT || (!failfn && L.isFunction(o)))) || false;
774
* Determines whether or not the provided object is a string
777
* @param o The object to test
778
* @return {boolean} true if o is a string
780
L.isString = function(o) {
781
return typeof o === STRING;
785
* Determines whether or not the provided object is undefined
786
* @method isUndefined
788
* @param o The object to test
789
* @return {boolean} true if o is undefined
791
L.isUndefined = function(o) {
792
return typeof o === UNDEFINED;
796
* Returns a string without any leading or trailing whitespace. If
797
* the input is not a string, the input will be returned untouched.
800
* @param s {string} the string to trim
801
* @return {string} the trimmed string
803
L.trim = function(s){
805
return s.replace(/^\s+|\s+$/g, "");
812
* A convenience method for detecting a legitimate non-null value.
813
* Returns false for null/undefined/NaN, true for other values,
814
* including 0/false/''
817
* @param o The item to test
818
* @return {boolean} true if it is not null/undefined/NaN || false
820
L.isValue = function(o) {
821
// return (o || o === false || o === 0 || o === ''); // Infinity fails
822
return (L.isObject(o) || L.isString(o) || L.isNumber(o) || L.isBoolean(o));
839
YUI.add("array", function(Y) {
841
var L = Y.Lang, Native = Array.prototype;
844
* Adds the following array utilities to the YUI instance
849
* Y.Array(o) returns an array:
850
* - Arrays are return unmodified unless the start position is specified.
851
* - "Array-like" collections (@see Array.test) are converted to arrays
852
* - For everything else, a new array is created with the input as the sole item
853
* - The start position is used if the input is or is like an array to return
854
* a subset of the collection.
856
* @TODO this will not automatically convert elements that are also collections
857
* such as forms and selects. Passing true as the third param will
858
* force a conversion.
862
* @param o the item to arrayify
863
* @param i {int} if an array or array-like, this is the start index
864
* @param al {boolean} if true, it forces the array-like fork. This
865
* can be used to avoid multiple array.test calls.
866
* @return {Array} the resulting array
868
Y.Array = function(o, i, al) {
869
var t = (al) ? 2 : Y.Array.test(o);
873
// // return (i) ? o.slice(i) : o;
875
// return Native.slice.call(o, i || 0);
881
return Native.slice.call(o, i || 0);
891
* Evaluates the input to determine if it is an array, array-like, or
892
* something else. This is used to handle the arguments collection
893
* available within functions, and HTMLElement collections
898
* @todo current implementation (intenionally) will not implicitly
899
* handle html elements that are array-like (forms, selects, etc).
901
* @return {int} a number indicating the results:
902
* 0: Not an array or an array-like collection
904
* 2: array-like collection.
906
A.test = function(o) {
908
if (L.isObject(o, true)) {
913
// indexed, but no tagName (element) or alert (window)
917
(!Y.Lang.isFunction(o.size) || o.size() > 1)) {
928
* Executes the supplied function on each item in the array.
930
* @param a {Array} the array to iterate
931
* @param f {Function} the function to execute on each item
932
* @param o Optional context object
934
* @return {YUI} the YUI instance
936
A.each = (Native.forEach) ?
938
Native.forEach.call(a, f, o || Y);
943
for (i = 0; i < l; i=i+1) {
944
f.call(o || Y, a[i], i, a);
950
* Executes the supplied function on each item in the array.
951
* Returning true from the processing function will stop the
952
* processing of the remaining
955
* @param a {Array} the array to iterate
956
* @param f {Function} the function to execute on each item
957
* @param o Optional context object
959
* @return {boolean} true if the
961
A.some = (Native.forEach) ?
963
Native.some.call(a, f, o || Y);
968
for (var i = 0; i < l; i=i+1) {
969
if (f.call(o, a[i], i, a)) {
977
* Returns an object using the first array as keys, and
978
* the second as values. If the second array is not
979
* provided the value is set to true for each.
982
* @param k {Array} keyset
983
* @param v {Array} optional valueset
984
* @return {object} the hash
986
A.hash = function(k, v) {
987
var o = {}, l = k.length, vl = v && v.length, i;
988
for (i=0; i<l; i=i+1) {
989
o[k[i]] = (vl && vl > i) ? v[i] : true;
997
* Returns the index of the first item in the array
998
* that contains the specified value, -1 if the
1000
* @TODO use native method if avail
1001
* @method Array.indexOf
1003
* @param a {Array} the array to search
1004
* @param val the value to search for
1005
* @return {int} the index of the item that contains the value or -1
1007
A.indexOf = function(a, val) {
1008
for (var i=0; i<a.length; i=i+1) {
1019
* YUI core utilities
1024
YUI.add("core", function(Y) {
1028
OP = Object.prototype,
1029
IEF = ["toString", "valueOf"],
1030
PROTO = 'prototype',
1033
* IE will not enumerate native functions in a derived object even if the
1034
* function was overridden. This is a workaround for specific functions
1035
* we care about on the Object prototype.
1037
* @param {Function} r the object to receive the augmentation
1038
* @param {Function} s the object that supplies the properties to augment
1039
* @param w a whitelist object (the keys are the valid items to reference)
1043
_iefix = (Y.UA && Y.UA.ie) ?
1045
for (var i=0, a=IEF; i<a.length; i=i+1) {
1046
var n = a[i], f = s[n];
1047
if (L.isFunction(f) && f != OP[n]) {
1048
if (!w || (n in w)) {
1057
* Returns a new object containing all of the properties of
1058
* all the supplied objects. The properties from later objects
1059
* will overwrite those in earlier objects. Passing in a
1060
* single object will create a shallow copy of it. For a deep
1063
* @param arguments {Object*} the objects to merge
1064
* @return {object} the new merged object
1066
Y.merge = function() {
1067
// var o={}, a=arguments;
1068
// for (var i=0, l=a.length; i<l; i=i+1) {
1069
//var a=arguments, o=Y.Object(a[0]);
1070
var a=arguments, o={};
1071
for (var i=0, l=a.length; i<l; i=i+1) {
1072
Y.mix(o, a[i], true);
1078
* Applies the supplier's properties to the receiver. By default
1079
* all prototype and static propertes on the supplier are applied
1080
* to the corresponding spot on the receiver. By default all
1081
* properties are applied, and a property that is already on the
1082
* reciever will not be overwritten. The default behavior can
1083
* be modified by supplying the appropriate parameters.
1085
* @TODO add constants for the modes
1088
* @param {Function} r the object to receive the augmentation
1089
* @param {Function} s the object that supplies the properties to augment
1090
* @param ov {boolean} if true, properties already on the receiver
1091
* will be overwritten if found on the supplier.
1092
* @param wl {string[]} a whitelist. If supplied, only properties in
1093
* this list will be applied to the receiver.
1094
* @param {int} mode what should be copies, and to where
1095
* default(0): object to object
1096
* 1: prototype to prototype (old augment)
1097
* 2: prototype to prototype and object props (new augment)
1098
* 3: prototype to object
1099
* 4: object to prototype
1100
* @param merge {boolean} merge objects instead of overwriting/ignoring
1101
* Used by Y.aggregate
1102
* @return {object} the augmented object
1103
* @TODO review for PR2
1105
Y.mix = function(r, s, ov, wl, mode, merge) {
1111
var w = (wl && wl.length) ? A.hash(wl) : null, m = merge,
1113
f = function(fr, fs, proto, iwl) {
1115
var arr = m && L.isArray(fr);
1119
if (fs.hasOwnProperty(i)) {
1121
// We never want to overwrite the prototype
1122
// if (PROTO === i) {
1123
if (PROTO === i || '_yuid' === i) {
1127
// @TODO deal with the hasownprop issue
1129
// check white list if it was supplied
1130
if (!w || iwl || (i in w)) {
1131
// if the receiver has this property, it is an object,
1132
// and merge is specified, merge the two objects.
1133
if (m && L.isObject(fr[i], true)) {
1134
// console.log('aggregate RECURSE: ' + i);
1135
// @TODO recursive or no?
1136
// Y.mix(fr[i], fs[i]); // not recursive
1137
f(fr[i], fs[i], proto, true); // recursive
1138
// otherwise apply the property only if overwrite
1139
// is specified or the receiver doesn't have one.
1140
// @TODO make sure the 'arr' check isn't desructive
1141
} else if (!arr && (ov || !(i in fr))) {
1142
// console.log('hash: ' + i);
1144
// if merge is specified and the receiver is an array,
1145
// append the array item
1147
// console.log('array: ' + i);
1148
// @TODO probably will need to remove dups
1158
var rp = r.prototype, sp = s.prototype;
1161
case 1: // proto to proto
1164
case 2: // object to object and proto to proto
1168
case 3: // proto to static
1171
case 4: // static to proto
1174
default: // object to object
1185
* YUI object utilities
1189
YUI.add("object", function(Y) {
1192
* Adds the following Object utilities to the YUI instance
1197
* Y.Object(o) returns a new object based upon the supplied object.
1200
* @param o the supplier object
1201
* @return {object} the new object
1203
Y.Object = function(o) {
1204
var F = function() {};
1209
var O = Y.Object, L = Y.Lang;
1212
* Determines whether or not the property was added
1213
* to the object instance. Returns false if the property is not present
1214
* in the object, or was inherited from the prototype.
1216
* @deprecated Safari 1.x support has been removed, so this is simply a
1217
* wrapper for the native implementation. Use the native implementation
1220
* @TODO Remove in PR2
1222
* @method Object.owns
1224
* @param o {any} The object being testing
1225
* @param p {string} the property to look for
1226
* @return {boolean} true if the object has the property on the instance
1228
O.owns = function(o, p) {
1229
return (o && o.hasOwnProperty) ? o.hasOwnProperty(p) : false;
1233
* Returns an array containing the object's keys
1234
* @method Object.keys
1236
* @param o an object
1237
* @return {string[]} the keys
1239
O.keys = function(o) {
1242
if (o.hasOwnProperty(i)) {
1251
* Executes a function on each item. The function
1252
* receives the value, the key, and the object
1253
* as paramters (in that order).
1254
* @method Object.each
1256
* @param o the object to iterate
1257
* @param f {function} the function to execute
1258
* @param c the execution context
1259
* @param proto {boolean} include proto
1260
* @return {YUI} the YUI instance
1262
O.each = function (o, f, c, proto) {
1266
if (proto || o.hasOwnProperty(i)) {
1267
f.call(s, o[i], i, o);
1274
* YUI user agent detection
1278
YUI.add("ua", function(Y) {
1281
* Browser/platform detection
1290
* Internet Explorer version number or 0. Example: 6
1298
* Opera version number or 0. Example: 9.2
1306
* Gecko engine revision number. Will evaluate to 1 if Gecko
1307
* is detected but the revision could not be found. Other browsers
1308
* will be 0. Example: 1.8
1310
* Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7
1311
* Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8
1312
* Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8
1313
* Firefox 3 alpha: 1.9a4 <-- Reports 1.9
1322
* AppleWebKit version. KHTML browsers that are not WebKit browsers
1323
* will evaluate to 1, other browsers 0. Example: 418.9.1
1325
* Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the
1326
* latest available for Mac OSX 10.3.
1327
* Safari 2.0.2: 416 <-- hasOwnProperty introduced
1328
* Safari 2.0.4: 418 <-- preventDefault fixed
1329
* Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
1330
* different versions of webkit
1331
* Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been
1332
* updated, but not updated
1333
* to the latest patch.
1334
* Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native SVG
1335
* and many major issues fixed).
1336
* Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic update
1337
* from 2.x via the 10.4.11 OS patch
1340
* http://developer.apple.com/internet/safari/uamatrix.html
1348
* The mobile property will be set to a string containing any relevant
1349
* user agent information when a modern mobile browser is detected.
1350
* Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
1351
* devices with the WebKit-based browser, and Opera Mini.
1359
var ua=navigator.userAgent, m;
1361
// Modern KHTML browsers should qualify as Safari X-Grade
1362
if ((/KHTML/).test(ua)) {
1365
// Modern WebKit browsers are at least X-Grade
1366
m=ua.match(/AppleWebKit\/([^\s]*)/);
1368
o.webkit=parseFloat(m[1]);
1370
// Mobile browser check
1371
if (/ Mobile\//.test(ua)) {
1372
o.mobile = "Apple"; // iPhone or iPod Touch
1374
m=ua.match(/NokiaN[^\/]*/);
1376
o.mobile = m[0]; // Nokia N-series, ex: NokiaN95
1382
if (!o.webkit) { // not webkit
1383
// @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
1384
m=ua.match(/Opera[\s\/]([^\s]*)/);
1386
o.opera=parseFloat(m[1]);
1387
m=ua.match(/Opera Mini[^;]*/);
1389
o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
1391
} else { // not opera or webkit
1392
m=ua.match(/MSIE\s([^;]*)/);
1394
o.ie=parseFloat(m[1]);
1395
} else { // not opera, webkit, or ie
1396
m=ua.match(/Gecko\/([^\s]*)/);
1398
o.gecko=1; // Gecko detected, look for revision
1399
m=ua.match(/rv:([^\s\)]*)/);
1401
o.gecko=parseFloat(m[1]);
1412
* YUI setTimeout/setInterval abstraction
1416
YUI.add("later", function(Y) {
1421
* Executes the supplied function in the context of the supplied
1422
* object 'when' milliseconds later. Executes the function a
1423
* single time unless periodic is set to true.
1426
* @param when {int} the number of milliseconds to wait until the fn
1428
* @param o the context object.
1429
* @param fn {Function|String} the function to execute or the name of
1430
* the method in the 'o' object to execute.
1431
* @param data [Array] data that is provided to the function. This accepts
1432
* either a single item or an array. If an array is provided, the
1433
* function is executed with one parameter for each array item. If
1434
* you need to pass a single array parameter, it needs to be wrapped in
1435
* an array [myarray].
1436
* @param periodic {boolean} if true, executes continuously at supplied
1437
* interval until canceled.
1438
* @return {object} a timer object. Call the cancel() method on this object to
1441
var later = function(when, o, fn, data, periodic) {
1444
var m=fn, d=data, f, r;
1446
if (L.isString(fn)) {
1451
Y.fail("method undefined");
1454
if (!L.isArray(d)) {
1462
r = (periodic) ? setInterval(f, when) : setTimeout(f, when);
1466
cancel: function() {
1467
if (this.interval) {
1487
var min = ['yui-base', 'log', 'lang', 'array', 'core'], core,
1493
// apply the minimal required functionality
1494
Y.use.apply(Y, min);
1503
core = ["object", "ua", "later"];
1510
Y.use.apply(Y, core);
1514
YUI.add("yui", M, "3.0.0pr2");
1517
// the following will be bound automatically when this code is loaded