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>
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>
128
// Allow var yui = YUI() instead of var yui = new YUI()
132
// set up the core environment
135
// bind the specified additional modules for this instance
143
// The prototype contains the functions that are required to allow the external
144
// modules to be registered and for the instance to be initialized.
148
* Initialize this YUI instance
149
* @param o config options
157
// find targeted window and @TODO create facades
158
var w = (o.win) ? (o.win.contentWindow) : o.win || window;
161
o.debug = ('debug' in o) ? o.debug : true;
162
o.useConsole = ('useConsole' in o) ? o.useConsole: true;
164
// @TODO default throwFail to true in PR2
165
// o.throwFail = ('throwFail' in o) ? o.debug : true;
167
// add a reference to o for anything that needs it
168
// before _setup is called.
172
// @todo expand the new module metadata
183
this.Env._yidx = ++YUI.Env._idx;
184
this.id = this.stamp(this);
185
_instances[this.id] = this;
188
this.constructor = YUI;
193
* Finishes the instance setup. Attaches whatever modules were defined
194
* when the yui modules was registered.
198
_setup: function(o) {
200
// @TODO eval the need to copy the config
201
this.config = this.merge(this.config);
205
* Executes a method on a YUI instance with
206
* the specified id if the specified method is whitelisted.
208
* @param id {string} the YUI instance id
209
* @param method {string} the name of the method to exectute.
211
* @param args {Array} the arguments to apply to the method
212
* @return {object} the return value from the applied method or null
214
applyTo: function(id, method, args) {
216
if (!(method in _APPLY_TO_WHITE_LIST)) {
217
this.fail(method + ': applyTo not allowed');
221
var instance = _instances[id];
225
var nest = method.split('.'), m = instance;
227
for (var i=0; i<nest.length; i=i+1) {
232
this.fail('applyTo not found: ' + method);
236
return m.apply(instance, args);
245
* @param name {string} module name
246
* @param namespace {string} name space for the module
247
* @param fn {Function} entry point into the module that
248
* is used to bind module to the YUI instance
249
* @param version {string} version string
250
* @return {YUI} the YUI instance
252
* requires - features that should be present before loading
253
* optional - optional features that should be present if load optional defined
254
* use - features that should be attached automatically
257
* omit - features that should not be loaded if this module is present
259
add: function(name, fn, version, details) {
262
// @todo expand this to include version mapping
264
// @todo allow requires/supersedes
266
// @todo may want to restore the build property
268
// @todo fire moduleAvailable event
274
details: details || {}
277
YUI.Env.mods[name] = m;
279
return this; // chain support
282
_attach: function(r, fromLoader) {
284
var mods = YUI.Env.mods,
285
attached = this.Env._attached;
287
for (var i=0, l=r.length; i<l; i=i+1) {
288
var name = r[i], m = mods[name], mm;
289
if (!attached[name] && m) {
291
attached[name] = true;
293
var d = m.details, req = d.requires, use = d.use;
296
this._attach(this.Array(req));
305
this._attach(this.Array(use));
313
* Bind a module to a YUI instance
314
* @param modules* {string} 1-n modules to bind (uses arguments array)
315
* @param *callback {function} callback function executed when
316
* the instance has the required functionality. If included, it
317
* must be the last parameter.
320
* Implement versioning? loader can load different versions?
321
* Should sub-modules/plugins be normal modules, or do
322
* we add syntax for specifying these?
324
* YUI().use('dragdrop')
325
* YUI().use('dragdrop:2.4.0'); // specific version
326
* YUI().use('dragdrop:2.4.0-'); // at least this version
327
* YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
328
* YUI().use('*'); // use all available modules
329
* YUI().use('lang+dump+substitute'); // use lang and some plugins
330
* YUI().use('lang+*'); // use lang and all known plugins
333
* @return {YUI} the YUI instance
338
a=Array.prototype.slice.call(arguments, 0),
344
callback = a[a.length-1];
347
// The last argument supplied to use can be a load complete callback
348
if (typeof callback === 'function') {
350
Y.Env._callback = callback;
355
// YUI().use('*'); // bind everything available
356
if (firstArg === "*") {
358
for (var k in mods) {
359
if (mods.hasOwnProperty(k)) {
364
return Y.use.apply(Y, a);
369
// use loader to optimize and sort the requirements if it
373
loader = new Y.Loader(Y.config);
375
loader.ignoreRegistered = true;
381
var missing = [], r = [], f = function(name) {
383
// only attach a module once
388
var m = mods[name], j, req, use;
393
req = m.details.requires;
399
// make sure requirements are attached
401
if (Y.Lang.isString(req)) {
404
for (j = 0; j < req.length; j = j + 1) {
410
// add this module to full list of things to attach
415
// process each requirement and any additional requirements
416
// the module metadata specifies
417
for (var i=0, l=a.length; i<l; i=i+1) {
422
var onComplete = function(fromLoader) {
425
fromLoader = fromLoader || {
430
if (Y.Env._callback) {
432
var cb = Y.Env._callback;
433
Y.Env._callback = null;
438
Y.fire('yui:load', Y, fromLoader);
444
if (Y.Loader && missing.length) {
445
loader = new Y.Loader(Y.config);
446
loader.onSuccess = onComplete;
447
loader.onFailure = onComplete;
448
loader.onTimeout = onComplete;
449
loader.attaching = a;
450
loader.require(missing);
457
return Y; // chain support var yui = YUI().use('dragdrop');
462
* Returns the namespace specified and creates it if it doesn't exist
464
* YUI.namespace("property.package");
465
* YUI.namespace("YUI.property.package");
467
* Either of the above would create YUI.property, then
468
* YUI.property.package
470
* Be careful when naming packages. Reserved words may work in some browsers
471
* and not others. For instance, the following will fail in Safari:
473
* YUI.namespace("really.long.nested.namespace");
475
* This fails because "long" is a future reserved word in ECMAScript
478
* @param {string*} arguments 1-n namespaces to create
479
* @return {object} A reference to the last namespace object created
481
namespace: function() {
482
var a=arguments, o=null, i, j, d;
483
for (i=0; i<a.length; i=i+1) {
486
for (j=(d[0] == "YUI") ? 1 : 0; j<d.length; j=j+1) {
487
o[d[j]] = o[d[j]] || {};
494
// this is replaced if the log module is included
500
* Report an error. The reporting mechanism is controled by
501
* the 'throwFail' configuration attribute. If throwFail is
502
* not specified, the message is written to the logger, otherwise
503
* a JS error is thrown
505
* @param msg {string} the failure message
506
* @param e {Error} Optional JS error that was caught. If supplied
507
* and throwFail is specified, this error will be re-thrown.
508
* @return {YUI} this YUI instance
510
fail: function(msg, e) {
512
instance.log(msg, "error"); // don't scrub this one
514
if (this.config.throwFail) {
515
throw e || new Error(msg);
522
* Generate an id that is unique among all YUI instances
524
* @param pre {string} optional guid prefix
525
* @return {string} the guid
527
guid: function(pre) {
528
var e = this.Env, p = (pre) || e._pre;
529
return p +'-' + e._yidx + '-' + e._uidx++;
533
* Stamps an object with a guid. If the object already
534
* has one, a new one is not created
536
* @param o The object to stamp
537
* @return {string} The object's guid
545
var uid = (typeof o === 'string') ? o : o._yuid;
556
// Give the YUI global the same properties as an instance.
557
// This makes it so that the YUI global can be used like the YAHOO
558
// global was used prior to 3.x. More importantly, the YUI global
559
// provides global metadata, so env needs to be configured.
562
var Y = YUI, p = Y.prototype, i;
564
// inheritance utilities are not available yet
566
if (true) { // hasOwnProperty not available yet and not needed
571
// set up the environment
579
* @submodule yui-base
581
// This is just a stub to for dependency processing
582
YUI.add("yui-base", null, "3.0.0pr1");
588
YUI.add("log", function(instance) {
591
* If the 'debug' config is true, a 'yui:log' event will be
592
* dispatched, which the logger widget and anything else
593
* can consume. If the 'useConsole' config is true, it will
594
* write to the browser console if available.
598
* @param {String} msg The message to log.
599
* @param {String} cat The log category for the message. Default
600
* categories are "info", "warn", "error", time".
601
* Custom categories can be used as well. (opt)
602
* @param {String} src The source of the the message (opt)
603
* @return {YUI} YUI instance
605
instance.log = function(msg, cat, src) {
607
var Y = instance, c = Y.config, es = Y.Env._eventstack,
608
bail = (es && es.logging);
610
// suppress log message if the config is off or the event stack
611
// or the event call stack contains a consumer of the yui:log event
612
if (c.debug && !bail) {
614
// apply source filters
617
var exc = c.logExclude, inc = c.logInclude;
619
// console.log('checking src filter: ' + src + ', inc: ' + inc + ', exc: ' + exc);
621
if (inc && !(src in inc)) {
622
// console.log('bail: inc list found, but src is not in list: ' + src);
624
} else if (exc && (src in exc)) {
625
// console.log('bail: exc list found, and src is in it: ' + src);
632
if (c.useConsole && typeof console != 'undefined') {
633
var f = (cat && console[cat]) ? cat : 'log',
634
m = (src) ? src + ': ' + msg : msg;
638
if (Y.fire && !bail) {
639
Y.fire('yui:log', msg, cat, src);
653
YUI.add("lang", function(Y) {
656
* Provides the language utilites and extensions used by the library
660
Y.Lang = Y.Lang || {};
662
var L = Y.Lang, SPLICE="splice", LENGTH="length";
665
* Determines whether or not the provided object is an array.
666
* Testing typeof/instanceof/constructor of arrays across frame
667
* boundaries isn't possible in Safari unless you have a reference
668
* to the other frame to test against its Array prototype. To
669
* handle this case, we test well-known array properties instead.
671
* @TODO can we kill this cross frame hack?
674
* @param o The object to test
675
* @return {boolean} true if o is an array
677
L.isArray = function(o) {
679
//return L.isNumber(o.length) && L.isFunction(o.splice);
680
return (o[SPLICE] && L.isNumber(o[LENGTH]));
686
* Determines whether or not the provided object is a boolean
689
* @param o The object to test
690
* @return {boolean} true if o is a boolean
692
L.isBoolean = function(o) {
693
return typeof o === 'boolean';
697
* Determines whether or not the provided object is a function
700
* @param o The object to test
701
* @return {boolean} true if o is a function
703
L.isFunction = function(o) {
704
return typeof o === 'function';
708
* Determines whether or not the supplied object is a date instance
711
* @param o The object to test
712
* @return {boolean} true if o is a date
714
L.isDate = function(o) {
715
return o instanceof Date;
719
* Determines whether or not the provided object is null
722
* @param o The object to test
723
* @return {boolean} true if o is null
725
L.isNull = function(o) {
730
* Determines whether or not the provided object is a legal number
733
* @param o The object to test
734
* @return {boolean} true if o is a number
736
L.isNumber = function(o) {
737
return typeof o === 'number' && isFinite(o);
741
* Determines whether or not the provided object is of type object
745
* @param o The object to test
746
* @param failfn {boolean} fail if the input is a function
747
* @return {boolean} true if o is an object
749
L.isObject = function(o, failfn) {
750
return (o && (typeof o === 'object' || (!failfn && L.isFunction(o)))) || false;
754
* Determines whether or not the provided object is a string
757
* @param o The object to test
758
* @return {boolean} true if o is a string
760
L.isString = function(o) {
761
return typeof o === 'string';
765
* Determines whether or not the provided object is undefined
766
* @method isUndefined
768
* @param o The object to test
769
* @return {boolean} true if o is undefined
771
L.isUndefined = function(o) {
772
return typeof o === 'undefined';
776
* Returns a string without any leading or trailing whitespace. If
777
* the input is not a string, the input will be returned untouched.
780
* @param s {string} the string to trim
781
* @return {string} the trimmed string
783
L.trim = function(s){
785
return s.replace(/^\s+|\s+$/g, "");
792
* A convenience method for detecting a legitimate non-null value.
793
* Returns false for null/undefined/NaN, true for other values,
794
* including 0/false/''
797
* @param o The item to test
798
* @return {boolean} true if it is not null/undefined/NaN || false
800
L.isValue = function(o) {
801
// return (o || o === false || o === 0 || o === ''); // Infinity fails
802
return (L.isObject(o) || L.isString(o) || L.isNumber(o) || L.isBoolean(o));
819
YUI.add("array", function(Y) {
821
var L = Y.Lang, Native = Array.prototype;
824
* Adds the following array utilities to the YUI instance
829
* Y.Array(o) returns an array:
830
* - Arrays are return unmodified unless the start position is specified.
831
* - "Array-like" collections (@see Array.test) are converted to arrays
832
* - For everything else, a new array is created with the input as the sole item
833
* - The start position is used if the input is or is like an array to return
834
* a subset of the collection.
836
* @TODO this will not automatically convert elements that are also collections
837
* such as forms and selects. Passing true as the third param will
838
* force a conversion.
842
* @param o the item to arrayify
843
* @param i {int} if an array or array-like, this is the start index
844
* @param al {boolean} if true, it forces the array-like fork. This
845
* can be used to avoid multiple array.test calls.
846
* @return {Array} the resulting array
848
Y.Array = function(o, i, al) {
849
var t = (al) ? 2 : Y.Array.test(o);
852
return (i) ? o.slice(o, i) : o;
854
return Native.slice.call(o, i || 0);
863
* Evaluates the input to determine if it is an array, array-like, or
864
* something else. This is used to handle the arguments collection
865
* available within functions, and HTMLElement collections
870
* @todo current implementation (intenionally) will not implicitly
871
* handle html elements that are array-like (forms, selects, etc).
873
* @return {int} a number indicating the results:
874
* 0: Not an array or an array-like collection
876
* 2: array-like collection.
878
A.test = function(o) {
880
if (L.isObject(o, true)) {
885
// indexed, but no tagName (element) or alert (window)
886
if ("length" in o && !("tagName" in o) && !("alert" in o)) {
897
* Executes the supplied function on each item in the array.
900
* @return {YUI} the YUI instance
902
A.each = (Native.forEach) ?
904
Native.forEach.call(a, f, o || Y);
909
for (i = 0; i < l; i=i+1) {
910
f.call(o || Y, a[i], i, a);
916
* Returns an object using the first array as keys, and
917
* the second as values. If the second array is not
918
* provided the value is set to true for each.
921
* @param k {Array} keyset
922
* @param v {Array} optional valueset
923
* @return {object} the hash
925
A.hash = function(k, v) {
926
var o = {}, l = k.length, vl = v && v.length, i;
927
for (i=0; i<l; i=i+1) {
928
o[k[i]] = (vl && vl > i) ? v[i] : true;
936
* Returns the index of the first item in the array
937
* that contains the specified value, -1 if the
939
* @TODO use native method if avail
940
* @method Array.indexOf
942
* @param a {Array} the array to search
943
* @param val the value to search for
944
* @return {int} the index of the item that contains the value or -1
946
A.indexOf = function(a, val) {
947
for (var i=0; i<a.length; i=i+1) {
963
YUI.add("core", function(Y) {
967
OP = Object.prototype,
968
IEF = ["toString", "valueOf"],
972
* IE will not enumerate native functions in a derived object even if the
973
* function was overridden. This is a workaround for specific functions
974
* we care about on the Object prototype.
976
* @param {Function} r the object to receive the augmentation
977
* @param {Function} s the object that supplies the properties to augment
978
* @param w a whitelist object (the keys are the valid items to reference)
982
_iefix = (Y.UA && Y.UA.ie) ?
984
for (var i=0, a=IEF; i<a.length; i=i+1) {
985
var n = a[i], f = s[n];
986
if (L.isFunction(f) && f != OP[n]) {
987
if (!w || (n in w)) {
996
* Returns a new object containing all of the properties of
997
* all the supplied objects. The properties from later objects
998
* will overwrite those in earlier objects. Passing in a
999
* single object will create a shallow copy of it. For a deep
1002
* @param arguments {Object*} the objects to merge
1003
* @return {object} the new merged object
1005
Y.merge = function() {
1006
// var o={}, a=arguments;
1007
// for (var i=0, l=a.length; i<l; i=i+1) {
1008
//var a=arguments, o=Y.Object(a[0]);
1009
var a=arguments, o={};
1010
for (var i=0, l=a.length; i<l; i=i+1) {
1011
Y.mix(o, a[i], true);
1017
* Applies the supplier's properties to the receiver. By default
1018
* all prototype and static propertes on the supplier are applied
1019
* to the corresponding spot on the receiver. By default all
1020
* properties are applied, and a property that is already on the
1021
* reciever will not be overwritten. The default behavior can
1022
* be modified by supplying the appropriate parameters.
1024
* @TODO add constants for the modes
1027
* @param {Function} r the object to receive the augmentation
1028
* @param {Function} s the object that supplies the properties to augment
1029
* @param ov {boolean} if true, properties already on the receiver
1030
* will be overwritten if found on the supplier.
1031
* @param wl {string[]} a whitelist. If supplied, only properties in
1032
* this list will be applied to the receiver.
1033
* @param {int} mode what should be copies, and to where
1034
* default(0): object to object
1035
* 1: prototype to prototype (old augment)
1036
* 2: prototype to prototype and object props (new augment)
1037
* 3: prototype to object
1038
* 4: object to prototype
1039
* @param merge {boolean} merge objects instead of overwriting/ignoring
1040
* Used by Y.aggregate
1041
* @return {object} the augmented object
1042
* @TODO review for PR2
1044
Y.mix = function(r, s, ov, wl, mode, merge) {
1050
var w = (wl && wl.length) ? A.hash(wl) : null, m = merge,
1052
f = function(fr, fs, proto, iwl) {
1054
var arr = m && L.isArray(fr);
1058
// We never want to overwrite the prototype
1059
// if (PROTO === i) {
1060
if (PROTO === i || '_yuid' === i) {
1064
// @TODO deal with the hasownprop issue
1066
// check white list if it was supplied
1067
if (!w || iwl || (i in w)) {
1068
// if the receiver has this property, it is an object,
1069
// and merge is specified, merge the two objects.
1070
if (m && L.isObject(fr[i], true)) {
1071
// console.log('aggregate RECURSE: ' + i);
1072
// @TODO recursive or no?
1073
// Y.mix(fr[i], fs[i]); // not recursive
1074
f(fr[i], fs[i], proto, true); // recursive
1075
// otherwise apply the property only if overwrite
1076
// is specified or the receiver doesn't have one.
1077
// @TODO make sure the 'arr' check isn't desructive
1078
} else if (!arr && (ov || !(i in fr))) {
1079
// console.log('hash: ' + i);
1081
// if merge is specified and the receiver is an array,
1082
// append the array item
1084
// console.log('array: ' + i);
1085
// @TODO probably will need to remove dups
1094
var rp = r.prototype, sp = s.prototype;
1097
case 1: // proto to proto
1100
case 2: // object to object and proto to proto
1104
case 3: // proto to static
1107
case 4: // static to proto
1110
default: // object to object
1121
* YUI object utilities
1125
YUI.add("object", function(Y) {
1128
* Adds the following Object utilities to the YUI instance
1133
* Y.Object(o) returns a new object based upon the supplied object.
1136
* @param o the supplier object
1137
* @return {object} the new object
1139
Y.Object = function(o) {
1140
var F = function() {};
1145
var O = Y.Object, L = Y.Lang;
1148
* Determines whether or not the property was added
1149
* to the object instance. Returns false if the property is not present
1150
* in the object, or was inherited from the prototype.
1152
* @deprecated Safari 1.x support has been removed, so this is simply a
1153
* wrapper for the native implementation. Use the native implementation
1156
* @TODO Remove in PR2
1158
* @method Object.owns
1160
* @param o {any} The object being testing
1161
* @param p {string} the property to look for
1162
* @return {boolean} true if the object has the property on the instance
1164
O.owns = function(o, p) {
1165
return (o && o.hasOwnProperty) ? o.hasOwnProperty(p) : false;
1169
* Returns an array containing the object's keys
1170
* @method Object.keys
1172
* @param o an object
1173
* @return {string[]} the keys
1175
O.keys = function(o) {
1178
if (o.hasOwnProperty(i)) {
1187
* Executes a function on each item. The function
1188
* receives the value, the key, and the object
1189
* as paramters (in that order).
1190
* @method Object.each
1192
* @param o the object to iterate
1193
* @param f {function} the function to execute
1194
* @param c the execution context
1195
* @param proto {boolean} include proto
1196
* @return {YUI} the YUI instance
1198
O.each = function (o, f, c, proto) {
1202
if (proto || o.hasOwnProperty(i)) {
1203
f.call(s, o[i], i, o);
1210
* YUI user agent detection
1214
YUI.add("ua", function(Y) {
1217
* Browser/platform detection
1226
* Internet Explorer version number or 0. Example: 6
1234
* Opera version number or 0. Example: 9.2
1242
* Gecko engine revision number. Will evaluate to 1 if Gecko
1243
* is detected but the revision could not be found. Other browsers
1244
* will be 0. Example: 1.8
1246
* Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7
1247
* Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8
1248
* Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8
1249
* Firefox 3 alpha: 1.9a4 <-- Reports 1.9
1258
* AppleWebKit version. KHTML browsers that are not WebKit browsers
1259
* will evaluate to 1, other browsers 0. Example: 418.9.1
1261
* Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the
1262
* latest available for Mac OSX 10.3.
1263
* Safari 2.0.2: 416 <-- hasOwnProperty introduced
1264
* Safari 2.0.4: 418 <-- preventDefault fixed
1265
* Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
1266
* different versions of webkit
1267
* Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been
1268
* updated, but not updated
1269
* to the latest patch.
1270
* Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native SVG
1271
* and many major issues fixed).
1272
* Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic update
1273
* from 2.x via the 10.4.11 OS patch
1276
* http://developer.apple.com/internet/safari/uamatrix.html
1284
* The mobile property will be set to a string containing any relevant
1285
* user agent information when a modern mobile browser is detected.
1286
* Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
1287
* devices with the WebKit-based browser, and Opera Mini.
1295
var ua=navigator.userAgent, m;
1297
// Modern KHTML browsers should qualify as Safari X-Grade
1298
if ((/KHTML/).test(ua)) {
1301
// Modern WebKit browsers are at least X-Grade
1302
m=ua.match(/AppleWebKit\/([^\s]*)/);
1304
o.webkit=parseFloat(m[1]);
1306
// Mobile browser check
1307
if (/ Mobile\//.test(ua)) {
1308
o.mobile = "Apple"; // iPhone or iPod Touch
1310
m=ua.match(/NokiaN[^\/]*/);
1312
o.mobile = m[0]; // Nokia N-series, ex: NokiaN95
1318
if (!o.webkit) { // not webkit
1319
// @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
1320
m=ua.match(/Opera[\s\/]([^\s]*)/);
1322
o.opera=parseFloat(m[1]);
1323
m=ua.match(/Opera Mini[^;]*/);
1325
o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
1327
} else { // not opera or webkit
1328
m=ua.match(/MSIE\s([^;]*)/);
1330
o.ie=parseFloat(m[1]);
1331
} else { // not opera, webkit, or ie
1332
m=ua.match(/Gecko\/([^\s]*)/);
1334
o.gecko=1; // Gecko detected, look for revision
1335
m=ua.match(/rv:([^\s\)]*)/);
1337
o.gecko=parseFloat(m[1]);
1348
* YUI setTimeout/setInterval abstraction
1352
YUI.add("later", function(Y) {
1357
* Executes the supplied function in the context of the supplied
1358
* object 'when' milliseconds later. Executes the function a
1359
* single time unless periodic is set to true.
1362
* @param when {int} the number of milliseconds to wait until the fn
1364
* @param o the context object.
1365
* @param fn {Function|String} the function to execute or the name of
1366
* the method in the 'o' object to execute.
1367
* @param data [Array] data that is provided to the function. This accepts
1368
* either a single item or an array. If an array is provided, the
1369
* function is executed with one parameter for each array item. If
1370
* you need to pass a single array parameter, it needs to be wrapped in
1371
* an array [myarray].
1372
* @param periodic {boolean} if true, executes continuously at supplied
1373
* interval until canceled.
1374
* @return {object} a timer object. Call the cancel() method on this object to
1377
var later = function(when, o, fn, data, periodic) {
1380
var m=fn, d=data, f, r;
1382
if (L.isString(fn)) {
1387
Y.fail("method undefined");
1390
if (!L.isArray(d)) {
1398
r = (periodic) ? setInterval(f, when) : setTimeout(f, when);
1402
cancel: function() {
1403
if (this.interval) {
1423
var min = ['yui-base', 'log', 'lang', 'array', 'core'], core,
1429
// apply the minimal required functionality
1430
Y.use.apply(Y, min);
1439
core = ["object", "ua", "later"];
1446
Y.use.apply(Y, core);
1450
YUI.add("yui", M, "3.0.0pr1");
1453
// the following will be bound automatically when this code is loaded