|
1 /* |
|
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
3 Code licensed under the BSD License: |
|
4 http://developer.yahoo.net/yui/license.txt |
|
5 version: 3.0.0 |
|
6 build: 1549 |
|
7 */ |
|
8 (function() { |
|
9 |
|
10 var _instances = {}, |
|
11 _startTime = new Date().getTime(), |
|
12 p, |
|
13 i, |
|
14 |
|
15 add = function () { |
|
16 if (window.addEventListener) { |
|
17 return function(el, type, fn, capture) { |
|
18 el.addEventListener(type, fn, (!!capture)); |
|
19 }; |
|
20 } else if (window.attachEvent) { |
|
21 return function(el, type, fn) { |
|
22 el.attachEvent("on" + type, fn); |
|
23 }; |
|
24 } else { |
|
25 return function(){}; |
|
26 } |
|
27 }(), |
|
28 |
|
29 remove = function() { |
|
30 if (window.removeEventListener) { |
|
31 return function (el, type, fn, capture) { |
|
32 el.removeEventListener(type, fn, !!capture); |
|
33 }; |
|
34 } else if (window.detachEvent) { |
|
35 return function (el, type, fn) { |
|
36 el.detachEvent("on" + type, fn); |
|
37 }; |
|
38 } else { |
|
39 return function(){}; |
|
40 } |
|
41 }(), |
|
42 |
|
43 globalListener = function() { |
|
44 YUI.Env.windowLoaded = true; |
|
45 YUI.Env.DOMReady = true; |
|
46 remove(window, 'load', globalListener); |
|
47 }, |
|
48 |
|
49 // @TODO: this needs to be created at build time from module metadata |
|
50 |
|
51 _APPLY_TO_WHITE_LIST = { |
|
52 'io.xdrReady': 1, |
|
53 'io.start': 1, |
|
54 'io.success': 1, |
|
55 'io.failure': 1 |
|
56 }, |
|
57 |
|
58 SLICE = Array.prototype.slice; |
|
59 |
|
60 // reduce to one or the other |
|
61 if (typeof YUI === 'undefined' || !YUI) { |
|
62 |
|
63 /** |
|
64 * The YUI global namespace object. If YUI is already defined, the |
|
65 * existing YUI object will not be overwritten so that defined |
|
66 * namespaces are preserved. |
|
67 * |
|
68 * @class YUI |
|
69 * @constructor |
|
70 * @global |
|
71 * @uses EventTarget |
|
72 * @param o* Up to five optional configuration objects. This object is stored |
|
73 * in YUI.config. See config for the list of supported properties. |
|
74 */ |
|
75 |
|
76 /*global YUI*/ |
|
77 // Make a function, disallow direct instantiation |
|
78 YUI = function(o1, o2, o3, o4, o5) { |
|
79 |
|
80 var Y = this, a = arguments, i, l = a.length; |
|
81 |
|
82 // Allow instantiation without the new operator |
|
83 if (!(Y instanceof YUI)) { |
|
84 return new YUI(o1, o2, o3, o4, o5); |
|
85 } else { |
|
86 // set up the core environment |
|
87 Y._init(); |
|
88 |
|
89 for (i=0; i<l; i++) { |
|
90 Y._config(a[i]); |
|
91 } |
|
92 |
|
93 // bind the specified additional modules for this instance |
|
94 Y._setup(); |
|
95 |
|
96 return Y; |
|
97 } |
|
98 }; |
|
99 } |
|
100 |
|
101 // The prototype contains the functions that are required to allow the external |
|
102 // modules to be registered and for the instance to be initialized. |
|
103 YUI.prototype = { |
|
104 |
|
105 _config: function(o) { |
|
106 |
|
107 o = o || {}; |
|
108 |
|
109 var c = this.config, i, j, m, mods; |
|
110 |
|
111 mods = c.modules; |
|
112 for (i in o) { |
|
113 if (mods && i == 'modules') { |
|
114 m = o[i]; |
|
115 for (j in m) { |
|
116 if (m.hasOwnProperty(j)) { |
|
117 mods[j] = m[j]; |
|
118 } |
|
119 } |
|
120 } else if (i == 'win') { |
|
121 c[i] = o[i].contentWindow || o[i]; |
|
122 c.doc = c[i].document; |
|
123 } else { |
|
124 c[i] = o[i]; |
|
125 } |
|
126 } |
|
127 }, |
|
128 |
|
129 /** |
|
130 * Initialize this YUI instance |
|
131 * @param o config options |
|
132 * @private |
|
133 */ |
|
134 _init: function(o) { |
|
135 |
|
136 // find targeted window/frame |
|
137 // @TODO create facades |
|
138 var v = '3.0.0', Y = this; |
|
139 |
|
140 if (v.indexOf('@') > -1) { |
|
141 v = 'test'; |
|
142 } |
|
143 |
|
144 Y.version = v; |
|
145 |
|
146 Y.Env = { |
|
147 // @todo expand the new module metadata |
|
148 mods: {}, |
|
149 cdn: 'http://yui.yahooapis.com/' + v + '/build/', |
|
150 bootstrapped: false, |
|
151 _idx: 0, |
|
152 _used: {}, |
|
153 _attached: {}, |
|
154 _yidx: 0, |
|
155 _uidx: 0, |
|
156 _loaded: {} |
|
157 }; |
|
158 |
|
159 Y.Env._loaded[v] = {}; |
|
160 |
|
161 if (YUI.Env) { |
|
162 Y.Env._yidx = (++YUI.Env._yidx); |
|
163 Y.Env._guidp = ('yui_' + v + '-' + Y.Env._yidx + '-' + _startTime).replace(/\./g, '_'); |
|
164 Y.id = Y.stamp(Y); |
|
165 _instances[Y.id] = Y; |
|
166 } |
|
167 |
|
168 Y.constructor = YUI; |
|
169 |
|
170 // configuration defaults |
|
171 Y.config = { |
|
172 |
|
173 win: window || {}, |
|
174 doc: document, |
|
175 debug: true, |
|
176 useBrowserConsole: true, |
|
177 throwFail: true, |
|
178 |
|
179 base: function() { |
|
180 var b, nodes, i, match; |
|
181 |
|
182 // get from querystring |
|
183 nodes = document.getElementsByTagName('script'); |
|
184 |
|
185 for (i=0; i<nodes.length; i=i+1) { |
|
186 match = nodes[i].src.match(/^(.*)yui\/yui[\.\-].*js(\?.*)?$/); |
|
187 b = match && match[1]; |
|
188 if (b) { |
|
189 break; |
|
190 } |
|
191 } |
|
192 |
|
193 // use CDN default |
|
194 return b || this.Env.cdn; |
|
195 |
|
196 }(), |
|
197 |
|
198 loaderPath: 'loader/loader-min.js' |
|
199 }; |
|
200 |
|
201 }, |
|
202 |
|
203 /** |
|
204 * Finishes the instance setup. Attaches whatever modules were defined |
|
205 * when the yui modules was registered. |
|
206 * @method _setup |
|
207 * @private |
|
208 */ |
|
209 _setup: function(o) { |
|
210 this.use("yui-base"); |
|
211 }, |
|
212 |
|
213 /** |
|
214 * Executes a method on a YUI instance with |
|
215 * the specified id if the specified method is whitelisted. |
|
216 * @method applyTo |
|
217 * @param id {string} the YUI instance id |
|
218 * @param method {string} the name of the method to exectute. |
|
219 * Ex: 'Object.keys' |
|
220 * @param args {Array} the arguments to apply to the method |
|
221 * @return {object} the return value from the applied method or null |
|
222 */ |
|
223 applyTo: function(id, method, args) { |
|
224 |
|
225 if (!(method in _APPLY_TO_WHITE_LIST)) { |
|
226 this.error(method + ': applyTo not allowed'); |
|
227 return null; |
|
228 } |
|
229 |
|
230 var instance = _instances[id], nest, m, i; |
|
231 |
|
232 if (instance) { |
|
233 |
|
234 nest = method.split('.'); |
|
235 m = instance; |
|
236 |
|
237 for (i=0; i<nest.length; i=i+1) { |
|
238 |
|
239 m = m[nest[i]]; |
|
240 |
|
241 if (!m) { |
|
242 this.error('applyTo not found: ' + method); |
|
243 } |
|
244 } |
|
245 |
|
246 return m.apply(instance, args); |
|
247 } |
|
248 |
|
249 return null; |
|
250 }, |
|
251 |
|
252 /** |
|
253 * Register a module |
|
254 * @method add |
|
255 * @param name {string} module name |
|
256 * @param fn {Function} entry point into the module that |
|
257 * is used to bind module to the YUI instance |
|
258 * @param version {string} version string |
|
259 * @param details optional config data: |
|
260 * requires - features that should be present before loading |
|
261 * optional - optional features that should be present if load optional defined |
|
262 * use - features that should be attached automatically |
|
263 * skinnable - |
|
264 * rollup |
|
265 * omit - features that should not be loaded if this module is present |
|
266 * @return {YUI} the YUI instance |
|
267 * |
|
268 */ |
|
269 add: function(name, fn, version, details) { |
|
270 // this.log('Adding a new component ' + name); |
|
271 // @todo expand this to include version mapping |
|
272 // @todo may want to restore the build property |
|
273 // @todo fire moduleAvailable event |
|
274 |
|
275 YUI.Env.mods[name] = { |
|
276 name: name, |
|
277 fn: fn, |
|
278 version: version, |
|
279 details: details || {} |
|
280 }; |
|
281 |
|
282 return this; // chain support |
|
283 }, |
|
284 |
|
285 _attach: function(r, fromLoader) { |
|
286 |
|
287 var mods = YUI.Env.mods, |
|
288 attached = this.Env._attached, |
|
289 i, l = r.length, name, m, d, req, use; |
|
290 |
|
291 for (i=0; i<l; i=i+1) { |
|
292 |
|
293 name = r[i]; |
|
294 m = mods[name]; |
|
295 |
|
296 if (!attached[name] && m) { |
|
297 |
|
298 attached[name] = true; |
|
299 |
|
300 d = m.details; |
|
301 req = d.requires; |
|
302 use = d.use; |
|
303 |
|
304 if (req) { |
|
305 this._attach(this.Array(req)); |
|
306 } |
|
307 |
|
308 // this.log('attaching ' + name, 'info', 'yui'); |
|
309 |
|
310 if (m.fn) { |
|
311 m.fn(this); |
|
312 } |
|
313 |
|
314 if (use) { |
|
315 this._attach(this.Array(use)); |
|
316 } |
|
317 } |
|
318 } |
|
319 |
|
320 }, |
|
321 |
|
322 /** |
|
323 * Bind a module to a YUI instance |
|
324 * @param modules* {string} 1-n modules to bind (uses arguments array) |
|
325 * @param *callback {function} callback function executed when |
|
326 * the instance has the required functionality. If included, it |
|
327 * must be the last parameter. |
|
328 * |
|
329 * @TODO |
|
330 * Implement versioning? loader can load different versions? |
|
331 * Should sub-modules/plugins be normal modules, or do |
|
332 * we add syntax for specifying these? |
|
333 * |
|
334 * YUI().use('dragdrop') |
|
335 * YUI().use('dragdrop:2.4.0'); // specific version |
|
336 * YUI().use('dragdrop:2.4.0-'); // at least this version |
|
337 * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range |
|
338 * YUI().use('*'); // use all available modules |
|
339 * YUI().use('lang+dump+substitute'); // use lang and some plugins |
|
340 * YUI().use('lang+*'); // use lang and all known plugins |
|
341 * |
|
342 * |
|
343 * @return {YUI} the YUI instance |
|
344 */ |
|
345 use: function() { |
|
346 |
|
347 if (this._loading) { |
|
348 this._useQueue = this._useQueue || new this.Queue(); |
|
349 this._useQueue.add(SLICE.call(arguments, 0)); |
|
350 return this; |
|
351 } |
|
352 |
|
353 var Y = this, |
|
354 a=SLICE.call(arguments, 0), |
|
355 mods = YUI.Env.mods, |
|
356 used = Y.Env._used, |
|
357 loader, |
|
358 firstArg = a[0], |
|
359 dynamic = false, |
|
360 callback = a[a.length-1], |
|
361 k, i, l, missing = [], |
|
362 r = [], |
|
363 f = function(name) { |
|
364 |
|
365 // only attach a module once |
|
366 if (used[name]) { |
|
367 // Y.log(name + ' already used', 'info', 'yui'); |
|
368 return; |
|
369 } |
|
370 |
|
371 var m = mods[name], j, req, use; |
|
372 |
|
373 if (m) { |
|
374 |
|
375 // Y.log('USING ' + name, 'info', 'yui'); |
|
376 |
|
377 used[name] = true; |
|
378 |
|
379 req = m.details.requires; |
|
380 use = m.details.use; |
|
381 } else { |
|
382 |
|
383 // CSS files don't register themselves, see if it has been loaded |
|
384 if (!YUI.Env._loaded[Y.version][name]) { |
|
385 Y.log('module not found: ' + name, 'info', 'yui'); |
|
386 missing.push(name); |
|
387 } else { |
|
388 // probably css |
|
389 // Y.log('module not found BUT HAS BEEN LOADED: ' + name, 'info', 'yui'); |
|
390 used[name] = true; |
|
391 } |
|
392 } |
|
393 |
|
394 // make sure requirements are attached |
|
395 if (req) { |
|
396 if (Y.Lang.isString(req)) { |
|
397 f(req); |
|
398 } else { |
|
399 for (j = 0; j < req.length; j = j + 1) { |
|
400 // Y.log('using module\'s requirements: ' + name, 'info', 'yui'); |
|
401 f(req[j]); |
|
402 } |
|
403 } |
|
404 } |
|
405 |
|
406 // add this module to full list of things to attach |
|
407 // Y.log('adding to requires list: ' + name); |
|
408 r.push(name); |
|
409 |
|
410 }, |
|
411 |
|
412 onComplete = function(fromLoader) { |
|
413 |
|
414 // Y.log('Use complete'); |
|
415 |
|
416 fromLoader = fromLoader || { |
|
417 success: true, |
|
418 msg: 'not dynamic' |
|
419 }; |
|
420 |
|
421 if (Y.Env._callback) { |
|
422 |
|
423 var cb = Y.Env._callback; |
|
424 Y.Env._callback = null; |
|
425 cb(Y, fromLoader); |
|
426 } |
|
427 |
|
428 if (Y.fire) { |
|
429 Y.fire('yui:load', Y, fromLoader); |
|
430 } |
|
431 |
|
432 // process queued use requests as long until done |
|
433 // or dynamic load happens again. |
|
434 Y._loading = false; |
|
435 while (Y._useQueue && Y._useQueue.size() && !Y._loading) { |
|
436 Y.use.apply(Y, Y._useQueue.next()); |
|
437 } |
|
438 }; |
|
439 |
|
440 // Y.log(Y.id + ': use called: ' + a + ' :: ' + callback); |
|
441 |
|
442 // The last argument supplied to use can be a load complete callback |
|
443 if (typeof callback === 'function') { |
|
444 a.pop(); |
|
445 Y.Env._callback = callback; |
|
446 } else { |
|
447 callback = null; |
|
448 } |
|
449 |
|
450 // YUI().use('*'); // bind everything available |
|
451 if (firstArg === "*") { |
|
452 a = []; |
|
453 for (k in mods) { |
|
454 if (mods.hasOwnProperty(k)) { |
|
455 a.push(k); |
|
456 } |
|
457 } |
|
458 |
|
459 return Y.use.apply(Y, a); |
|
460 } |
|
461 |
|
462 // Y.log('loader before: ' + a.join(',')); |
|
463 |
|
464 // use loader to expand dependencies and sort the |
|
465 // requirements if it is available. |
|
466 if (Y.Loader) { |
|
467 dynamic = true; |
|
468 loader = new Y.Loader(Y.config); |
|
469 loader.require(a); |
|
470 loader.ignoreRegistered = true; |
|
471 loader.allowRollup = false; |
|
472 loader.calculate(); |
|
473 a = loader.sorted; |
|
474 } |
|
475 |
|
476 // Y.log('loader after: ' + a.join(',')); |
|
477 |
|
478 l = a.length; |
|
479 |
|
480 // process each requirement and any additional requirements |
|
481 // the module metadata specifies |
|
482 for (i=0; i<l; i=i+1) { |
|
483 f(a[i]); |
|
484 } |
|
485 |
|
486 // Y.log('all reqs: ' + r + ' --- missing: ' + missing + ', l: ' + l + ', ' + r[0]); |
|
487 |
|
488 // dynamic load |
|
489 if (Y.Loader && missing.length) { |
|
490 Y.log('Attempting to dynamically load the missing modules ' + missing, 'info', 'yui'); |
|
491 Y._loading = true; |
|
492 loader = new Y.Loader(Y.config); |
|
493 loader.onSuccess = onComplete; |
|
494 loader.onFailure = onComplete; |
|
495 loader.onTimeout = onComplete; |
|
496 loader.context = Y; |
|
497 loader.attaching = a; |
|
498 loader.require(missing); |
|
499 loader.insert(); |
|
500 } else if (Y.Get && missing.length && !Y.Env.bootstrapped) { |
|
501 Y.log('fetching loader: ' + Y.config.base + Y.config.loaderPath, 'info', 'yui'); |
|
502 Y._loading = true; |
|
503 |
|
504 a = Y.Array(arguments, 0, true); |
|
505 // a.unshift('loader'); |
|
506 |
|
507 Y.Get.script(Y.config.base + Y.config.loaderPath, { |
|
508 onEnd: function() { |
|
509 Y._loading = false; |
|
510 Y.Env.bootstrapped = true; |
|
511 Y._attach(['loader']); |
|
512 Y.use.apply(Y, a); |
|
513 } |
|
514 }); |
|
515 |
|
516 return Y; |
|
517 |
|
518 } else { |
|
519 Y._attach(r); |
|
520 onComplete(); |
|
521 } |
|
522 |
|
523 return Y; // chain support var yui = YUI().use('dragdrop'); |
|
524 }, |
|
525 |
|
526 |
|
527 /** |
|
528 * Returns the namespace specified and creates it if it doesn't exist |
|
529 * <pre> |
|
530 * YUI.namespace("property.package"); |
|
531 * YUI.namespace("YAHOO.property.package"); |
|
532 * </pre> |
|
533 * Either of the above would create YUI.property, then |
|
534 * YUI.property.package (YAHOO is scrubbed out, this is |
|
535 * to remain compatible with YUI2) |
|
536 * |
|
537 * Be careful when naming packages. Reserved words may work in some browsers |
|
538 * and not others. For instance, the following will fail in Safari: |
|
539 * <pre> |
|
540 * YUI.namespace("really.long.nested.namespace"); |
|
541 * </pre> |
|
542 * This fails because "long" is a future reserved word in ECMAScript |
|
543 * |
|
544 * @method namespace |
|
545 * @param {string*} arguments 1-n namespaces to create |
|
546 * @return {object} A reference to the last namespace object created |
|
547 */ |
|
548 namespace: function() { |
|
549 var a=arguments, o=null, i, j, d; |
|
550 for (i=0; i<a.length; i=i+1) { |
|
551 d = ("" + a[i]).split("."); |
|
552 o = this; |
|
553 for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) { |
|
554 o[d[j]] = o[d[j]] || {}; |
|
555 o = o[d[j]]; |
|
556 } |
|
557 } |
|
558 return o; |
|
559 }, |
|
560 |
|
561 // this is replaced if the log module is included |
|
562 log: function() { |
|
563 |
|
564 }, |
|
565 |
|
566 /** |
|
567 * Report an error. The reporting mechanism is controled by |
|
568 * the 'throwFail' configuration attribute. If throwFail is |
|
569 * not specified, the message is written to the Logger, otherwise |
|
570 * a JS error is thrown |
|
571 * @method error |
|
572 * @param msg {string} the error message |
|
573 * @param e {Error} Optional JS error that was caught. If supplied |
|
574 * and throwFail is specified, this error will be re-thrown. |
|
575 * @return {YUI} this YUI instance |
|
576 */ |
|
577 error: function(msg, e) { |
|
578 if (this.config.throwFail) { |
|
579 throw (e || new Error(msg)); |
|
580 } else { |
|
581 this.message(msg, "error"); // don't scrub this one |
|
582 } |
|
583 |
|
584 return this; |
|
585 }, |
|
586 |
|
587 /** |
|
588 * Generate an id that is unique among all YUI instances |
|
589 * @method guid |
|
590 * @param pre {string} optional guid prefix |
|
591 * @return {string} the guid |
|
592 */ |
|
593 guid: function(pre) { |
|
594 var id = this.Env._guidp + (++this.Env._uidx); |
|
595 return (pre) ? (pre + id) : id; |
|
596 }, |
|
597 |
|
598 /** |
|
599 * Returns a guid associated with an object. If the object |
|
600 * does not have one, a new one is created unless readOnly |
|
601 * is specified. |
|
602 * @method stamp |
|
603 * @param o The object to stamp |
|
604 * @param readOnly {boolean} if true, a valid guid will only |
|
605 * be returned if the object has one assigned to it. |
|
606 * @return {string} The object's guid or null |
|
607 */ |
|
608 stamp: function(o, readOnly) { |
|
609 |
|
610 if (!o) { |
|
611 return o; |
|
612 } |
|
613 |
|
614 var uid = (typeof o === 'string') ? o : o._yuid; |
|
615 |
|
616 if (!uid) { |
|
617 uid = this.guid(); |
|
618 if (!readOnly) { |
|
619 try { |
|
620 o._yuid = uid; |
|
621 } catch(e) { |
|
622 uid = null; |
|
623 } |
|
624 } |
|
625 } |
|
626 |
|
627 return uid; |
|
628 } |
|
629 }; |
|
630 |
|
631 // Give the YUI global the same properties as an instance. |
|
632 // This makes it so that the YUI global can be used like the YAHOO |
|
633 // global was used prior to 3.x. More importantly, the YUI global |
|
634 // provides global metadata, so env needs to be configured. |
|
635 // @TODO review |
|
636 |
|
637 p = YUI.prototype; |
|
638 |
|
639 // inheritance utilities are not available yet |
|
640 for (i in p) { |
|
641 // if (1) { // intenionally ignoring hasOwnProperty check |
|
642 YUI[i] = p[i]; |
|
643 // } |
|
644 } |
|
645 |
|
646 // set up the environment |
|
647 YUI._init(); |
|
648 |
|
649 // add a window load event at load time so we can capture |
|
650 // the case where it fires before dynamic loading is |
|
651 // complete. |
|
652 add(window, 'load', globalListener); |
|
653 |
|
654 YUI.Env.add = add; |
|
655 YUI.Env.remove = remove; |
|
656 |
|
657 /* |
|
658 * Subscribe to an event. The signature differs depending on the |
|
659 * type of event you are attaching to. |
|
660 * @method on |
|
661 * @param type {string|function|object} The type of the event. If |
|
662 * this is a function, this is dispatched to the aop system. If an |
|
663 * object, it is parsed for multiple subsription definitions |
|
664 * @param fn {Function} The callback |
|
665 * @param elspec {any} DOM element(s), selector string(s), and or |
|
666 * Node ref(s) to attach DOM related events to (only applies to |
|
667 * DOM events). |
|
668 * @param |
|
669 * @return the event target or a detach handle per 'chain' config |
|
670 */ |
|
671 |
|
672 })(); |
|
673 |
|
674 /** |
|
675 * The config object contains all of the configuration options for |
|
676 * the YUI instance. This object is supplied by the implementer |
|
677 * when instantiating a YUI instance. Some properties have default |
|
678 * values if they are not supplied by the implementer. |
|
679 * |
|
680 * @class config |
|
681 * @static |
|
682 */ |
|
683 |
|
684 /** |
|
685 * Turn debug statements on or off. |
|
686 * |
|
687 * @property debug |
|
688 * @type boolean |
|
689 * @default true |
|
690 */ |
|
691 |
|
692 /** |
|
693 * Log to the browser console if debug is on and the browser has a |
|
694 * supported console. |
|
695 * |
|
696 * @property useBrowserConsole |
|
697 * @type boolean |
|
698 * @default true |
|
699 */ |
|
700 |
|
701 /** |
|
702 * A hash of log sources that should be logged. If specified, only log messages from these sources will be logged. |
|
703 * |
|
704 * @property logInclude |
|
705 * @type object |
|
706 */ |
|
707 |
|
708 /** |
|
709 * A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list. |
|
710 * |
|
711 * @property logExclude |
|
712 * @type object |
|
713 */ |
|
714 |
|
715 /** |
|
716 * Set to true if the yui seed file was dynamically loaded in |
|
717 * order to bootstrap components relying on the window load event |
|
718 * and the 'domready' custom event. |
|
719 * |
|
720 * @property injected |
|
721 * @type object |
|
722 */ |
|
723 |
|
724 /** |
|
725 * If throwFail is set, Y.fail will generate or re-throw a JS Error. Otherwise the failure is logged. |
|
726 * |
|
727 * @property throwFail |
|
728 * @type boolean |
|
729 * @default true |
|
730 */ |
|
731 |
|
732 /** |
|
733 * The window/frame that this instance should operate in. |
|
734 * |
|
735 * @property win |
|
736 * @type Window |
|
737 * @default the window hosting YUI |
|
738 */ |
|
739 |
|
740 /** |
|
741 * The document associated with the 'win' configuration. |
|
742 * |
|
743 * @property doc |
|
744 * @type Document |
|
745 * @default the document hosting YUI |
|
746 */ |
|
747 |
|
748 /** |
|
749 * A list of modules that defines the YUI core (overrides the default). |
|
750 * |
|
751 * @property core |
|
752 * @type string[] |
|
753 */ |
|
754 |
|
755 /** |
|
756 * The default date format |
|
757 * |
|
758 * @property dateFormat |
|
759 * @type string |
|
760 */ |
|
761 |
|
762 /** |
|
763 * The default locale |
|
764 * |
|
765 * @property locale |
|
766 * @type string |
|
767 */ |
|
768 |
|
769 /** |
|
770 * The default interval when polling in milliseconds. |
|
771 * |
|
772 * @property pollInterval |
|
773 * @type int |
|
774 * @default 20 |
|
775 */ |
|
776 |
|
777 /** |
|
778 * The number of dynamic nodes to insert by default before |
|
779 * automatically removing them. This applies to script nodes |
|
780 * because remove the node will not make the evaluated script |
|
781 * unavailable. Dynamic CSS is not auto purged, because removing |
|
782 * a linked style sheet will also remove the style definitions. |
|
783 * |
|
784 * @property purgethreshold |
|
785 * @type int |
|
786 * @default 20 |
|
787 */ |
|
788 |
|
789 /** |
|
790 * The default interval when polling in milliseconds. |
|
791 * |
|
792 * @property windowResizeDelay |
|
793 * @type int |
|
794 * @default 40 |
|
795 */ |
|
796 |
|
797 /** |
|
798 * Base directory for dynamic loading |
|
799 * |
|
800 * @property base |
|
801 * @type string |
|
802 */ |
|
803 |
|
804 /** |
|
805 * The secure base dir (not implemented) |
|
806 * |
|
807 * For dynamic loading. |
|
808 * |
|
809 * @property secureBase |
|
810 * @type string |
|
811 */ |
|
812 |
|
813 /** |
|
814 * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo? |
|
815 * |
|
816 * For dynamic loading. |
|
817 * |
|
818 * @property comboBase |
|
819 * @type string |
|
820 */ |
|
821 |
|
822 /** |
|
823 * The root path to prepend to module names for the combo service. Ex: 3.0.0b1/build/ |
|
824 * |
|
825 * For dynamic loading. |
|
826 * |
|
827 * @property root |
|
828 * @type string |
|
829 */ |
|
830 |
|
831 /** |
|
832 * A filter to apply to result urls. This filter will modify the default |
|
833 * path for all modules. The default path for the YUI library is the |
|
834 * minified version of the files (e.g., event-min.js). The filter property |
|
835 * can be a predefined filter or a custom filter. The valid predefined |
|
836 * filters are: |
|
837 * <dl> |
|
838 * <dt>DEBUG</dt> |
|
839 * <dd>Selects the debug versions of the library (e.g., event-debug.js). |
|
840 * This option will automatically include the Logger widget</dd> |
|
841 * <dt>RAW</dt> |
|
842 * <dd>Selects the non-minified version of the library (e.g., event.js).</dd> |
|
843 * </dl> |
|
844 * You can also define a custom filter, which must be an object literal |
|
845 * containing a search expression and a replace string: |
|
846 * <pre> |
|
847 * myFilter: { |
|
848 * 'searchExp': "-min\\.js", |
|
849 * 'replaceStr': "-debug.js" |
|
850 * } |
|
851 * </pre> |
|
852 * |
|
853 * For dynamic loading. |
|
854 * |
|
855 * @property filter |
|
856 * @type string|object |
|
857 */ |
|
858 |
|
859 /** |
|
860 * Hash of per-component filter specification. If specified for a given component, |
|
861 * this overrides the filter config |
|
862 * |
|
863 * For dynamic loading. |
|
864 * |
|
865 * @property filters |
|
866 * @type object |
|
867 */ |
|
868 |
|
869 /** |
|
870 * Use the YUI combo service to reduce the number of http connections |
|
871 * required to load your dependencies. |
|
872 * |
|
873 * For dynamic loading. |
|
874 * |
|
875 * @property combine |
|
876 * @type boolean |
|
877 * @default true if 'base' is not supplied, false if it is. |
|
878 */ |
|
879 |
|
880 /** |
|
881 * A list of modules that should never be dynamically loaded |
|
882 * |
|
883 * @property ignore |
|
884 * @type string[] |
|
885 */ |
|
886 |
|
887 /** |
|
888 * A list of modules that should always be loaded when required, even if already |
|
889 * present on the page. |
|
890 * |
|
891 * @property force |
|
892 * @type string[] |
|
893 */ |
|
894 |
|
895 /** |
|
896 * Node or id for a node that should be used as the insertion point for new nodes |
|
897 * For dynamic loading. |
|
898 * |
|
899 * @property insertBefore |
|
900 * @type string |
|
901 */ |
|
902 |
|
903 /** |
|
904 * charset for dynamic nodes |
|
905 * |
|
906 * @property charset |
|
907 * @type string |
|
908 * @deprecated use jsAttributes cssAttributes |
|
909 */ |
|
910 |
|
911 /** |
|
912 * Object literal containing attributes to add to dynamically loaded script nodes. |
|
913 * |
|
914 * @property jsAttributes |
|
915 * @type string |
|
916 */ |
|
917 |
|
918 /** |
|
919 * Object literal containing attributes to add to dynamically loaded link nodes. |
|
920 * |
|
921 * @property cssAttributes |
|
922 * @type string |
|
923 */ |
|
924 |
|
925 /** |
|
926 * Number of milliseconds before a timeout occurs when dynamically |
|
927 * loading nodes. If not set, there is no timeout. |
|
928 * |
|
929 * @property timeout |
|
930 * @type int |
|
931 */ |
|
932 |
|
933 /** |
|
934 * Callback for the 'CSSComplete' event. When dynamically loading YUI |
|
935 * components with CSS, this property fires when the CSS is finished |
|
936 * loading but script loading is still ongoing. This provides an |
|
937 * opportunity to enhance the presentation of a loading page a little |
|
938 * bit before the entire loading process is done. |
|
939 * |
|
940 * @property onCSS |
|
941 * @type function |
|
942 */ |
|
943 |
|
944 /** |
|
945 * A list of module definitions to add to the list of YUI components. |
|
946 * These components can then be dynamically loaded side by side with |
|
947 * YUI via the use() method.See Loader.addModule for the supported |
|
948 * module metadata. |
|
949 * |
|
950 * @property modules |
|
951 * @type function |
|
952 */ |
|
953 |
|
954 /** |
|
955 * The loader 'path' attribute to the loader itself. This is combined |
|
956 * with the 'base' attribute to dynamically load the loader component |
|
957 * when boostrapping with the get utility alone. |
|
958 * |
|
959 * @property loaderPath |
|
960 * @default loader/loader-min.js |
|
961 */ |
|
962 YUI.add('yui-base', function(Y) { |
|
963 |
|
964 /* |
|
965 * YUI stub |
|
966 * @module yui |
|
967 * @submodule yui-base |
|
968 */ |
|
969 (function() { |
|
970 |
|
971 var INSTANCE = Y, |
|
972 LOGEVENT = 'yui:log', |
|
973 UNDEFINED = 'undefined', |
|
974 LEVELS = { debug: 1, info: 1, warn: 1, error: 1 }, |
|
975 _published; |
|
976 |
|
977 /** |
|
978 * If the 'debug' config is true, a 'yui:log' event will be |
|
979 * dispatched, which the Console widget and anything else |
|
980 * can consume. If the 'useBrowserConsole' config is true, it will |
|
981 * write to the browser console if available. YUI-specific log |
|
982 * messages will only be present in the -debug versions of the |
|
983 * JS files. The build system is supposed to remove log statements |
|
984 * from the raw and minified versions of the files. |
|
985 * |
|
986 * @method log |
|
987 * @for YUI |
|
988 * @param {String} msg The message to log. |
|
989 * @param {String} cat The log category for the message. Default |
|
990 * categories are "info", "warn", "error", time". |
|
991 * Custom categories can be used as well. (opt) |
|
992 * @param {String} src The source of the the message (opt) |
|
993 * @param {boolean} silent If true, the log event won't fire |
|
994 * @return {YUI} YUI instance |
|
995 */ |
|
996 INSTANCE.log = function(msg, cat, src, silent) { |
|
997 var Y = INSTANCE, c = Y.config, bail = false, excl, incl, m, f; |
|
998 // suppress log message if the config is off or the event stack |
|
999 // or the event call stack contains a consumer of the yui:log event |
|
1000 if (c.debug) { |
|
1001 // apply source filters |
|
1002 if (src) { |
|
1003 |
|
1004 excl = c.logExclude; |
|
1005 incl = c.logInclude; |
|
1006 |
|
1007 if (incl && !(src in incl)) { |
|
1008 bail = 1; |
|
1009 } else if (excl && (src in excl)) { |
|
1010 bail = 1; |
|
1011 } |
|
1012 } |
|
1013 |
|
1014 if (!bail) { |
|
1015 |
|
1016 if (c.useBrowserConsole) { |
|
1017 m = (src) ? src + ': ' + msg : msg; |
|
1018 if (typeof console != UNDEFINED && console.log) { |
|
1019 f = (cat && console[cat] && (cat in LEVELS)) ? cat : 'log'; |
|
1020 console[f](m); |
|
1021 } else if (typeof opera != UNDEFINED) { |
|
1022 opera.postError(m); |
|
1023 } |
|
1024 } |
|
1025 |
|
1026 if (Y.fire && !bail && !silent) { |
|
1027 if (!_published) { |
|
1028 Y.publish(LOGEVENT, { |
|
1029 broadcast: 2, |
|
1030 emitFacade: 1 |
|
1031 }); |
|
1032 |
|
1033 _published = 1; |
|
1034 |
|
1035 } |
|
1036 Y.fire(LOGEVENT, { |
|
1037 msg: msg, |
|
1038 cat: cat, |
|
1039 src: src |
|
1040 }); |
|
1041 } |
|
1042 } |
|
1043 } |
|
1044 |
|
1045 return Y; |
|
1046 }; |
|
1047 |
|
1048 /** |
|
1049 * Write a system message. This message will be preserved in the |
|
1050 * minified and raw versions of the YUI files, unlike log statements. |
|
1051 * @method message |
|
1052 * @for YUI |
|
1053 * @param {String} msg The message to log. |
|
1054 * @param {String} cat The log category for the message. Default |
|
1055 * categories are "info", "warn", "error", time". |
|
1056 * Custom categories can be used as well. (opt) |
|
1057 * @param {String} src The source of the the message (opt) |
|
1058 * @param {boolean} silent If true, the log event won't fire |
|
1059 * @return {YUI} YUI instance |
|
1060 */ |
|
1061 INSTANCE.message = function() { |
|
1062 return INSTANCE.log.apply(INSTANCE, arguments); |
|
1063 }; |
|
1064 |
|
1065 })(); |
|
1066 (function() { |
|
1067 /** |
|
1068 * Provides the language utilites and extensions used by the library |
|
1069 * @class Lang |
|
1070 * @static |
|
1071 */ |
|
1072 Y.Lang = Y.Lang || {}; |
|
1073 |
|
1074 var L = Y.Lang, |
|
1075 |
|
1076 ARRAY = 'array', |
|
1077 BOOLEAN = 'boolean', |
|
1078 DATE = 'date', |
|
1079 ERROR = 'error', |
|
1080 FUNCTION = 'function', |
|
1081 NUMBER = 'number', |
|
1082 NULL = 'null', |
|
1083 OBJECT = 'object', |
|
1084 REGEX = 'regexp', |
|
1085 STRING = 'string', |
|
1086 TOSTRING = Object.prototype.toString, |
|
1087 UNDEFINED = 'undefined', |
|
1088 |
|
1089 TYPES = { |
|
1090 'undefined' : UNDEFINED, |
|
1091 'number' : NUMBER, |
|
1092 'boolean' : BOOLEAN, |
|
1093 'string' : STRING, |
|
1094 '[object Function]' : FUNCTION, |
|
1095 '[object RegExp]' : REGEX, |
|
1096 '[object Array]' : ARRAY, |
|
1097 '[object Date]' : DATE, |
|
1098 '[object Error]' : ERROR |
|
1099 }, |
|
1100 |
|
1101 TRIMREGEX = /^\s+|\s+$/g, |
|
1102 EMPTYSTRING = ''; |
|
1103 |
|
1104 /** |
|
1105 * Determines whether or not the provided item is an array. |
|
1106 * Returns false for array-like collections such as the |
|
1107 * function arguments collection or HTMLElement collection |
|
1108 * will return false. You can use @see Array.test if you |
|
1109 * want to |
|
1110 * @method isArray |
|
1111 * @static |
|
1112 * @param o The object to test |
|
1113 * @return {boolean} true if o is an array |
|
1114 */ |
|
1115 L.isArray = function(o) { |
|
1116 return L.type(o) === ARRAY; |
|
1117 }; |
|
1118 |
|
1119 /** |
|
1120 * Determines whether or not the provided item is a boolean |
|
1121 * @method isBoolean |
|
1122 * @static |
|
1123 * @param o The object to test |
|
1124 * @return {boolean} true if o is a boolean |
|
1125 */ |
|
1126 L.isBoolean = function(o) { |
|
1127 return typeof o === BOOLEAN; |
|
1128 }; |
|
1129 |
|
1130 /** |
|
1131 * Determines whether or not the provided item is a function |
|
1132 * Note: Internet Explorer thinks certain functions are objects: |
|
1133 * |
|
1134 * var obj = document.createElement("object"); |
|
1135 * Y.Lang.isFunction(obj.getAttribute) // reports false in IE |
|
1136 * |
|
1137 * var input = document.createElement("input"); // append to body |
|
1138 * Y.Lang.isFunction(input.focus) // reports false in IE |
|
1139 * |
|
1140 * You will have to implement additional tests if these functions |
|
1141 * matter to you. |
|
1142 * |
|
1143 * @method isFunction |
|
1144 * @static |
|
1145 * @param o The object to test |
|
1146 * @return {boolean} true if o is a function |
|
1147 */ |
|
1148 L.isFunction = function(o) { |
|
1149 return L.type(o) === FUNCTION; |
|
1150 }; |
|
1151 |
|
1152 /** |
|
1153 * Determines whether or not the supplied item is a date instance |
|
1154 * @method isDate |
|
1155 * @static |
|
1156 * @param o The object to test |
|
1157 * @return {boolean} true if o is a date |
|
1158 */ |
|
1159 L.isDate = function(o) { |
|
1160 // return o instanceof Date; |
|
1161 return L.type(o) === DATE; |
|
1162 }; |
|
1163 |
|
1164 /** |
|
1165 * Determines whether or not the provided item is null |
|
1166 * @method isNull |
|
1167 * @static |
|
1168 * @param o The object to test |
|
1169 * @return {boolean} true if o is null |
|
1170 */ |
|
1171 L.isNull = function(o) { |
|
1172 return o === null; |
|
1173 }; |
|
1174 |
|
1175 /** |
|
1176 * Determines whether or not the provided item is a legal number |
|
1177 * @method isNumber |
|
1178 * @static |
|
1179 * @param o The object to test |
|
1180 * @return {boolean} true if o is a number |
|
1181 */ |
|
1182 L.isNumber = function(o) { |
|
1183 return typeof o === NUMBER && isFinite(o); |
|
1184 }; |
|
1185 |
|
1186 /** |
|
1187 * Determines whether or not the provided item is of type object |
|
1188 * or function |
|
1189 * @method isObject |
|
1190 * @static |
|
1191 * @param o The object to test |
|
1192 * @param failfn {boolean} fail if the input is a function |
|
1193 * @return {boolean} true if o is an object |
|
1194 */ |
|
1195 L.isObject = function(o, failfn) { |
|
1196 return (o && (typeof o === OBJECT || (!failfn && L.isFunction(o)))) || false; |
|
1197 }; |
|
1198 |
|
1199 /** |
|
1200 * Determines whether or not the provided item is a string |
|
1201 * @method isString |
|
1202 * @static |
|
1203 * @param o The object to test |
|
1204 * @return {boolean} true if o is a string |
|
1205 */ |
|
1206 L.isString = function(o) { |
|
1207 return typeof o === STRING; |
|
1208 }; |
|
1209 |
|
1210 /** |
|
1211 * Determines whether or not the provided item is undefined |
|
1212 * @method isUndefined |
|
1213 * @static |
|
1214 * @param o The object to test |
|
1215 * @return {boolean} true if o is undefined |
|
1216 */ |
|
1217 L.isUndefined = function(o) { |
|
1218 return typeof o === UNDEFINED; |
|
1219 }; |
|
1220 |
|
1221 /** |
|
1222 * Returns a string without any leading or trailing whitespace. If |
|
1223 * the input is not a string, the input will be returned untouched. |
|
1224 * @method trim |
|
1225 * @static |
|
1226 * @param s {string} the string to trim |
|
1227 * @return {string} the trimmed string |
|
1228 */ |
|
1229 L.trim = function(s){ |
|
1230 try { |
|
1231 return s.replace(TRIMREGEX, EMPTYSTRING); |
|
1232 } catch(e) { |
|
1233 return s; |
|
1234 } |
|
1235 }; |
|
1236 |
|
1237 /** |
|
1238 * A convenience method for detecting a legitimate non-null value. |
|
1239 * Returns false for null/undefined/NaN, true for other values, |
|
1240 * including 0/false/'' |
|
1241 * @method isValue |
|
1242 * @static |
|
1243 * @param o The item to test |
|
1244 * @return {boolean} true if it is not null/undefined/NaN || false |
|
1245 */ |
|
1246 L.isValue = function(o) { |
|
1247 var t = L.type(o); |
|
1248 switch (t) { |
|
1249 case NUMBER: |
|
1250 return isFinite(o); |
|
1251 case NULL: |
|
1252 case UNDEFINED: |
|
1253 return false; |
|
1254 default: |
|
1255 return !!(t); |
|
1256 } |
|
1257 }; |
|
1258 |
|
1259 /** |
|
1260 * Returns a string representing the type of the item passed in. |
|
1261 * @method type |
|
1262 * @param o the item to test |
|
1263 * @return {string} the detected type |
|
1264 */ |
|
1265 L.type = function (o) { |
|
1266 return TYPES[typeof o] || TYPES[TOSTRING.call(o)] || (o ? OBJECT : NULL); |
|
1267 }; |
|
1268 |
|
1269 })(); |
|
1270 |
|
1271 /* |
|
1272 * Provides information about the environment hosting YUI |
|
1273 * @module yui |
|
1274 * @submodule Array |
|
1275 */ |
|
1276 |
|
1277 (function() { |
|
1278 |
|
1279 var L = Y.Lang, Native = Array.prototype, |
|
1280 |
|
1281 /** |
|
1282 * Adds the following array utilities to the YUI instance. Additional |
|
1283 * array helpers can be found in the collection component. |
|
1284 * @class Array |
|
1285 */ |
|
1286 |
|
1287 /** |
|
1288 * Y.Array(o) returns an array: |
|
1289 * - Arrays are return unmodified unless the start position is specified. |
|
1290 * - "Array-like" collections (@see Array.test) are converted to arrays |
|
1291 * - For everything else, a new array is created with the input as the sole item |
|
1292 * - The start position is used if the input is or is like an array to return |
|
1293 * a subset of the collection. |
|
1294 * |
|
1295 * @TODO this will not automatically convert elements that are also collections |
|
1296 * such as forms and selects. Passing true as the third param will |
|
1297 * force a conversion. |
|
1298 * |
|
1299 * @method () |
|
1300 * @static |
|
1301 * @param o the item to arrayify |
|
1302 * @param i {int} if an array or array-like, this is the start index |
|
1303 * @param al {boolean} if true, it forces the array-like fork. This |
|
1304 * can be used to avoid multiple array.test calls. |
|
1305 * @return {Array} the resulting array |
|
1306 */ |
|
1307 YArray = function(o, startIdx, al) { |
|
1308 var t = (al) ? 2 : Y.Array.test(o), i, l, a; |
|
1309 |
|
1310 // switch (t) { |
|
1311 // case 1: |
|
1312 // // return (startIdx) ? o.slice(startIdx) : o; |
|
1313 // case 2: |
|
1314 // return Native.slice.call(o, startIdx || 0); |
|
1315 // default: |
|
1316 // return [o]; |
|
1317 // } |
|
1318 |
|
1319 if (t) { |
|
1320 try { |
|
1321 return Native.slice.call(o, startIdx || 0); |
|
1322 // IE errors when trying to slice element collections |
|
1323 } catch(e) { |
|
1324 a=[]; |
|
1325 for (i=0, l=o.length; i<l; i=i+1) { |
|
1326 a.push(o[i]); |
|
1327 } |
|
1328 return a; |
|
1329 } |
|
1330 } else { |
|
1331 return [o]; |
|
1332 } |
|
1333 |
|
1334 }; |
|
1335 |
|
1336 Y.Array = YArray; |
|
1337 |
|
1338 /** |
|
1339 * Evaluates the input to determine if it is an array, array-like, or |
|
1340 * something else. This is used to handle the arguments collection |
|
1341 * available within functions, and HTMLElement collections |
|
1342 * |
|
1343 * @method test |
|
1344 * @static |
|
1345 * |
|
1346 * @todo current implementation (intenionally) will not implicitly |
|
1347 * handle html elements that are array-like (forms, selects, etc). |
|
1348 * |
|
1349 * @return {int} a number indicating the results: |
|
1350 * 0: Not an array or an array-like collection |
|
1351 * 1: A real array. |
|
1352 * 2: array-like collection. |
|
1353 */ |
|
1354 YArray.test = function(o) { |
|
1355 var r = 0; |
|
1356 if (L.isObject(o)) { |
|
1357 if (L.isArray(o)) { |
|
1358 r = 1; |
|
1359 } else { |
|
1360 try { |
|
1361 // indexed, but no tagName (element) or alert (window) |
|
1362 if ("length" in o && !("tagName" in o) && !("alert" in o) && |
|
1363 (!Y.Lang.isFunction(o.size) || o.size() > 1)) { |
|
1364 r = 2; |
|
1365 } |
|
1366 |
|
1367 } catch(e) {} |
|
1368 } |
|
1369 } |
|
1370 return r; |
|
1371 }; |
|
1372 |
|
1373 /** |
|
1374 * Executes the supplied function on each item in the array. |
|
1375 * @method each |
|
1376 * @param a {Array} the array to iterate |
|
1377 * @param f {Function} the function to execute on each item |
|
1378 * @param o Optional context object |
|
1379 * @static |
|
1380 * @return {YUI} the YUI instance |
|
1381 */ |
|
1382 YArray.each = (Native.forEach) ? |
|
1383 function (a, f, o) { |
|
1384 Native.forEach.call(a || [], f, o || Y); |
|
1385 return Y; |
|
1386 } : |
|
1387 function (a, f, o) { |
|
1388 var l = (a && a.length) || 0, i; |
|
1389 for (i = 0; i < l; i=i+1) { |
|
1390 f.call(o || Y, a[i], i, a); |
|
1391 } |
|
1392 return Y; |
|
1393 }; |
|
1394 |
|
1395 /** |
|
1396 * Returns an object using the first array as keys, and |
|
1397 * the second as values. If the second array is not |
|
1398 * provided the value is set to true for each. |
|
1399 * @method hash |
|
1400 * @static |
|
1401 * @param k {Array} keyset |
|
1402 * @param v {Array} optional valueset |
|
1403 * @return {object} the hash |
|
1404 */ |
|
1405 YArray.hash = function(k, v) { |
|
1406 var o = {}, l = k.length, vl = v && v.length, i; |
|
1407 for (i=0; i<l; i=i+1) { |
|
1408 o[k[i]] = (vl && vl > i) ? v[i] : true; |
|
1409 } |
|
1410 |
|
1411 return o; |
|
1412 }; |
|
1413 |
|
1414 /** |
|
1415 * Returns the index of the first item in the array |
|
1416 * that contains the specified value, -1 if the |
|
1417 * value isn't found. |
|
1418 * @method indexOf |
|
1419 * @static |
|
1420 * @param a {Array} the array to search |
|
1421 * @param val the value to search for |
|
1422 * @return {int} the index of the item that contains the value or -1 |
|
1423 */ |
|
1424 YArray.indexOf = (Native.indexOf) ? |
|
1425 function(a, val) { |
|
1426 return Native.indexOf.call(a, val); |
|
1427 } : |
|
1428 function(a, val) { |
|
1429 for (var i=0; i<a.length; i=i+1) { |
|
1430 if (a[i] === val) { |
|
1431 return i; |
|
1432 } |
|
1433 } |
|
1434 |
|
1435 return -1; |
|
1436 }; |
|
1437 |
|
1438 /** |
|
1439 * Numeric sort convenience function. |
|
1440 * Y.ArrayAssert.itemsAreEqual([1, 2, 3], [3, 1, 2].sort(Y.Array.numericSort)); |
|
1441 * @method numericSort |
|
1442 */ |
|
1443 YArray.numericSort = function(a, b) { |
|
1444 return (a - b); |
|
1445 }; |
|
1446 |
|
1447 /** |
|
1448 * Executes the supplied function on each item in the array. |
|
1449 * Returning true from the processing function will stop the |
|
1450 * processing of the remaining |
|
1451 * items. |
|
1452 * @method some |
|
1453 * @param a {Array} the array to iterate |
|
1454 * @param f {Function} the function to execute on each item |
|
1455 * @param o Optional context object |
|
1456 * @static |
|
1457 * @return {boolean} true if the function returns true on |
|
1458 * any of the items in the array |
|
1459 */ |
|
1460 YArray.some = (Native.some) ? |
|
1461 function (a, f, o) { |
|
1462 return Native.some.call(a, f, o); |
|
1463 } : |
|
1464 function (a, f, o) { |
|
1465 var l = a.length, i; |
|
1466 for (i=0; i<l; i=i+1) { |
|
1467 if (f.call(o, a[i], i, a)) { |
|
1468 return true; |
|
1469 } |
|
1470 } |
|
1471 return false; |
|
1472 }; |
|
1473 |
|
1474 })(); |
|
1475 (function() { |
|
1476 |
|
1477 var L = Y.Lang, |
|
1478 DELIMITER = '__', |
|
1479 // FROZEN = { |
|
1480 // 'prototype': 1, |
|
1481 // '_yuid': 1 |
|
1482 // }, |
|
1483 |
|
1484 /* |
|
1485 * IE will not enumerate native functions in a derived object even if the |
|
1486 * function was overridden. This is a workaround for specific functions |
|
1487 * we care about on the Object prototype. |
|
1488 * @property _iefix |
|
1489 * @for YUI |
|
1490 * @param {Function} r the object to receive the augmentation |
|
1491 * @param {Function} s the object that supplies the properties to augment |
|
1492 * @private |
|
1493 */ |
|
1494 _iefix = function(r, s) { |
|
1495 var fn = s.toString; |
|
1496 if (L.isFunction(fn) && fn != Object.prototype.toString) { |
|
1497 r.toString = fn; |
|
1498 } |
|
1499 }; |
|
1500 |
|
1501 |
|
1502 /** |
|
1503 * Returns a new object containing all of the properties of |
|
1504 * all the supplied objects. The properties from later objects |
|
1505 * will overwrite those in earlier objects. Passing in a |
|
1506 * single object will create a shallow copy of it. For a deep |
|
1507 * copy, use clone. |
|
1508 * @method merge |
|
1509 * @for YUI |
|
1510 * @param arguments {Object*} the objects to merge |
|
1511 * @return {object} the new merged object |
|
1512 */ |
|
1513 Y.merge = function() { |
|
1514 var a = arguments, o = {}, i, l = a.length; |
|
1515 for (i=0; i<l; i=i+1) { |
|
1516 Y.mix(o, a[i], true); |
|
1517 } |
|
1518 return o; |
|
1519 }; |
|
1520 |
|
1521 /** |
|
1522 * Applies the supplier's properties to the receiver. By default |
|
1523 * all prototype and static propertes on the supplier are applied |
|
1524 * to the corresponding spot on the receiver. By default all |
|
1525 * properties are applied, and a property that is already on the |
|
1526 * reciever will not be overwritten. The default behavior can |
|
1527 * be modified by supplying the appropriate parameters. |
|
1528 * |
|
1529 * @TODO add constants for the modes |
|
1530 * |
|
1531 * @method mix |
|
1532 * @param {Function} r the object to receive the augmentation |
|
1533 * @param {Function} s the object that supplies the properties to augment |
|
1534 * @param ov {boolean} if true, properties already on the receiver |
|
1535 * will be overwritten if found on the supplier. |
|
1536 * @param wl {string[]} a whitelist. If supplied, only properties in |
|
1537 * this list will be applied to the receiver. |
|
1538 * @param {int} mode what should be copies, and to where |
|
1539 * default(0): object to object |
|
1540 * 1: prototype to prototype (old augment) |
|
1541 * 2: prototype to prototype and object props (new augment) |
|
1542 * 3: prototype to object |
|
1543 * 4: object to prototype |
|
1544 * @param merge {boolean} merge objects instead of overwriting/ignoring |
|
1545 * Used by Y.aggregate |
|
1546 * @return {object} the augmented object |
|
1547 */ |
|
1548 Y.mix = function(r, s, ov, wl, mode, merge) { |
|
1549 |
|
1550 if (!s||!r) { |
|
1551 return r || Y; |
|
1552 } |
|
1553 |
|
1554 if (mode) { |
|
1555 switch (mode) { |
|
1556 case 1: // proto to proto |
|
1557 return Y.mix(r.prototype, s.prototype, ov, wl, 0, merge); |
|
1558 case 2: // object to object and proto to proto |
|
1559 Y.mix(r.prototype, s.prototype, ov, wl, 0, merge); |
|
1560 break; // pass through |
|
1561 case 3: // proto to static |
|
1562 return Y.mix(r, s.prototype, ov, wl, 0, merge); |
|
1563 case 4: // static to proto |
|
1564 return Y.mix(r.prototype, s, ov, wl, 0, merge); |
|
1565 default: // object to object is what happens below |
|
1566 } |
|
1567 } |
|
1568 |
|
1569 // Maybe don't even need this wl && wl.length check anymore?? |
|
1570 var arr = merge && L.isArray(r), i, l, p; |
|
1571 |
|
1572 if (wl && wl.length) { |
|
1573 for (i = 0, l = wl.length; i < l; ++i) { |
|
1574 p = wl[i]; |
|
1575 if (p in s) { |
|
1576 if (merge && L.isObject(r[p], true)) { |
|
1577 Y.mix(r[p], s[p]); |
|
1578 } else if (!arr && (ov || !(p in r))) { |
|
1579 r[p] = s[p]; |
|
1580 } else if (arr) { |
|
1581 r.push(s[p]); |
|
1582 } |
|
1583 } |
|
1584 } |
|
1585 } else { |
|
1586 for (i in s) { |
|
1587 // if (s.hasOwnProperty(i) && !(i in FROZEN)) { |
|
1588 // check white list if it was supplied |
|
1589 // if the receiver has this property, it is an object, |
|
1590 // and merge is specified, merge the two objects. |
|
1591 if (merge && L.isObject(r[i], true)) { |
|
1592 Y.mix(r[i], s[i]); // recursive |
|
1593 // otherwise apply the property only if overwrite |
|
1594 // is specified or the receiver doesn't have one. |
|
1595 } else if (!arr && (ov || !(i in r))) { |
|
1596 r[i] = s[i]; |
|
1597 // if merge is specified and the receiver is an array, |
|
1598 // append the array item |
|
1599 } else if (arr) { |
|
1600 r.push(s[i]); |
|
1601 } |
|
1602 // } |
|
1603 } |
|
1604 |
|
1605 if (Y.UA.ie) { |
|
1606 _iefix(r, s); |
|
1607 } |
|
1608 } |
|
1609 |
|
1610 return r; |
|
1611 }; |
|
1612 |
|
1613 /** |
|
1614 * Returns a wrapper for a function which caches the |
|
1615 * return value of that function, keyed off of the combined |
|
1616 * argument values. |
|
1617 * @function cached |
|
1618 * @param source {function} the function to memoize |
|
1619 * @param cache an optional cache seed |
|
1620 * @param refetch if supplied, this value is tested against the cached |
|
1621 * value. If the values are equal, the wrapped function is executed again. |
|
1622 * @return {Function} the wrapped function |
|
1623 */ |
|
1624 Y.cached = function(source, cache, refetch){ |
|
1625 cache = cache || {}; |
|
1626 |
|
1627 return function(arg1, arg2) { |
|
1628 |
|
1629 var k = (arg2) ? Array.prototype.join.call(arguments, DELIMITER) : arg1, |
|
1630 v = cache[k]; |
|
1631 |
|
1632 if (!(k in cache) || (refetch && cache[k] == refetch)) { |
|
1633 cache[k] = source.apply(source, arguments); |
|
1634 } |
|
1635 |
|
1636 return cache[k]; |
|
1637 }; |
|
1638 |
|
1639 }; |
|
1640 |
|
1641 })(); |
|
1642 |
|
1643 (function() { |
|
1644 |
|
1645 /** |
|
1646 * Adds the following Object utilities to the YUI instance |
|
1647 * @class Object |
|
1648 */ |
|
1649 |
|
1650 /** |
|
1651 * Y.Object(o) returns a new object based upon the supplied object. |
|
1652 * @TODO Use native Object.create() when available |
|
1653 * @method () |
|
1654 * @static |
|
1655 * @param o the supplier object |
|
1656 * @return {Object} the new object |
|
1657 */ |
|
1658 Y.Object = function(o) { |
|
1659 var F = function() {}; |
|
1660 F.prototype = o; |
|
1661 return new F(); |
|
1662 }; |
|
1663 |
|
1664 var O = Y.Object, |
|
1665 |
|
1666 UNDEFINED = undefined, |
|
1667 |
|
1668 /** |
|
1669 * Extracts the keys, values, or size from an object |
|
1670 * |
|
1671 * @method _extract |
|
1672 * @param o the object |
|
1673 * @param what what to extract (0: keys, 1: values, 2: size) |
|
1674 * @return {boolean|Array} the extracted info |
|
1675 * @static |
|
1676 * @private |
|
1677 */ |
|
1678 _extract = function(o, what) { |
|
1679 var count = (what === 2), out = (count) ? 0 : [], i; |
|
1680 |
|
1681 for (i in o) { |
|
1682 if (count) { |
|
1683 out++; |
|
1684 } else { |
|
1685 if (o.hasOwnProperty(i)) { |
|
1686 out.push((what) ? o[i] : i); |
|
1687 } |
|
1688 } |
|
1689 } |
|
1690 |
|
1691 return out; |
|
1692 }; |
|
1693 |
|
1694 /** |
|
1695 * Returns an array containing the object's keys |
|
1696 * @TODO use native Object.keys() if available |
|
1697 * @method keys |
|
1698 * @static |
|
1699 * @param o an object |
|
1700 * @return {string[]} the keys |
|
1701 */ |
|
1702 O.keys = function(o) { |
|
1703 return _extract(o); |
|
1704 }; |
|
1705 |
|
1706 /** |
|
1707 * Returns an array containing the object's values |
|
1708 * @TODO use native Object.values() if available |
|
1709 * @method values |
|
1710 * @static |
|
1711 * @param o an object |
|
1712 * @return {Array} the values |
|
1713 */ |
|
1714 O.values = function(o) { |
|
1715 return _extract(o, 1); |
|
1716 }; |
|
1717 |
|
1718 /** |
|
1719 * Returns the size of an object |
|
1720 * @TODO use native Object.size() if available |
|
1721 * @method size |
|
1722 * @static |
|
1723 * @param o an object |
|
1724 * @return {int} the size |
|
1725 */ |
|
1726 O.size = function(o) { |
|
1727 return _extract(o, 2); |
|
1728 }; |
|
1729 |
|
1730 /** |
|
1731 * Returns true if the object contains a given key |
|
1732 * @method hasKey |
|
1733 * @static |
|
1734 * @param o an object |
|
1735 * @param k the key to query |
|
1736 * @return {boolean} true if the object contains the key |
|
1737 */ |
|
1738 O.hasKey = function(o, k) { |
|
1739 // return (o.hasOwnProperty(k)); |
|
1740 return (k in o); |
|
1741 }; |
|
1742 |
|
1743 /** |
|
1744 * Returns true if the object contains a given value |
|
1745 * @method hasValue |
|
1746 * @static |
|
1747 * @param o an object |
|
1748 * @param v the value to query |
|
1749 * @return {boolean} true if the object contains the value |
|
1750 */ |
|
1751 O.hasValue = function(o, v) { |
|
1752 return (Y.Array.indexOf(O.values(o), v) > -1); |
|
1753 }; |
|
1754 |
|
1755 /** |
|
1756 * Determines whether or not the property was added |
|
1757 * to the object instance. Returns false if the property is not present |
|
1758 * in the object, or was inherited from the prototype. |
|
1759 * |
|
1760 * @deprecated Safari 1.x support has been removed, so this is simply a |
|
1761 * wrapper for the native implementation. Use the native implementation |
|
1762 * directly instead. |
|
1763 * |
|
1764 * @TODO Remove in B1 |
|
1765 * |
|
1766 * @method owns |
|
1767 * @static |
|
1768 * @param o {any} The object being testing |
|
1769 * @param p {string} the property to look for |
|
1770 * @return {boolean} true if the object has the property on the instance |
|
1771 */ |
|
1772 O.owns = function(o, k) { |
|
1773 return (o.hasOwnProperty(k)); |
|
1774 }; |
|
1775 |
|
1776 /** |
|
1777 * Executes a function on each item. The function |
|
1778 * receives the value, the key, and the object |
|
1779 * as paramters (in that order). |
|
1780 * @method each |
|
1781 * @static |
|
1782 * @param o the object to iterate |
|
1783 * @param f {function} the function to execute |
|
1784 * @param c the execution context |
|
1785 * @param proto {boolean} include proto |
|
1786 * @return {YUI} the YUI instance |
|
1787 */ |
|
1788 O.each = function (o, f, c, proto) { |
|
1789 var s = c || Y, i; |
|
1790 |
|
1791 for (i in o) { |
|
1792 if (proto || o.hasOwnProperty(i)) { |
|
1793 f.call(s, o[i], i, o); |
|
1794 } |
|
1795 } |
|
1796 return Y; |
|
1797 }; |
|
1798 |
|
1799 /** |
|
1800 * Retrieves the sub value at the provided path, |
|
1801 * from the value object provided. |
|
1802 * |
|
1803 * @method getValue |
|
1804 * @param o The object from which to extract the property value |
|
1805 * @param path {Array} A path array, specifying the object traversal path |
|
1806 * from which to obtain the sub value. |
|
1807 * @return {Any} The value stored in the path, undefined if not found. |
|
1808 * Returns the source object if an empty path is provided. |
|
1809 */ |
|
1810 O.getValue = function (o, path) { |
|
1811 var p=Y.Array(path), l=p.length, i; |
|
1812 |
|
1813 for (i=0; o !== UNDEFINED && i < l; i=i+1) { |
|
1814 o = o[p[i]]; |
|
1815 } |
|
1816 |
|
1817 return o; |
|
1818 }; |
|
1819 |
|
1820 /** |
|
1821 * Sets the sub-attribute value at the provided path on the |
|
1822 * value object. Returns the modified value object, or |
|
1823 * undefined if the path is invalid. |
|
1824 * |
|
1825 * @method setValue |
|
1826 * @param o The object on which to set the sub value. |
|
1827 * @param path {Array} A path array, specifying the object traversal path |
|
1828 * at which to set the sub value. |
|
1829 * @param val {Any} The new value for the sub-attribute. |
|
1830 * @return {Object} The modified object, with the new sub value set, or |
|
1831 * undefined, if the path was invalid. |
|
1832 */ |
|
1833 O.setValue = function(o, path, val) { |
|
1834 |
|
1835 var p=Y.Array(path), leafIdx=p.length-1, i, ref=o; |
|
1836 |
|
1837 if (leafIdx >= 0) { |
|
1838 for (i=0; ref !== UNDEFINED && i < leafIdx; i=i+1) { |
|
1839 ref = ref[p[i]]; |
|
1840 } |
|
1841 |
|
1842 if (ref !== UNDEFINED) { |
|
1843 ref[p[i]] = val; |
|
1844 } else { |
|
1845 return UNDEFINED; |
|
1846 } |
|
1847 } |
|
1848 |
|
1849 return o; |
|
1850 }; |
|
1851 |
|
1852 |
|
1853 })(); |
|
1854 |
|
1855 /* |
|
1856 * Provides information about the environment hosting YUI |
|
1857 * @module yui |
|
1858 * @submodule UA |
|
1859 */ |
|
1860 /** |
|
1861 * YUI user agent detection. |
|
1862 * Do not fork for a browser if it can be avoided. Use feature detection when |
|
1863 * you can. Use the user agent as a last resort. UA stores a version |
|
1864 * number for the browser engine, 0 otherwise. This value may or may not map |
|
1865 * to the version number of the browser using the engine. The value is |
|
1866 * presented as a float so that it can easily be used for boolean evaluation |
|
1867 * as well as for looking for a particular range of versions. Because of this, |
|
1868 * some of the granularity of the version info may be lost (e.g., Gecko 1.8.0.9 |
|
1869 * reports 1.8). |
|
1870 * @class UA |
|
1871 * @static |
|
1872 */ |
|
1873 Y.UA = function() { |
|
1874 |
|
1875 var numberfy = function(s) { |
|
1876 var c = 0; |
|
1877 return parseFloat(s.replace(/\./g, function() { |
|
1878 return (c++ == 1) ? '' : '.'; |
|
1879 })); |
|
1880 }, |
|
1881 |
|
1882 nav = navigator, |
|
1883 |
|
1884 o = { |
|
1885 |
|
1886 /** |
|
1887 * Internet Explorer version number or 0. Example: 6 |
|
1888 * @property ie |
|
1889 * @type float |
|
1890 * @static |
|
1891 */ |
|
1892 ie: 0, |
|
1893 |
|
1894 /** |
|
1895 * Opera version number or 0. Example: 9.2 |
|
1896 * @property opera |
|
1897 * @type float |
|
1898 * @static |
|
1899 */ |
|
1900 opera: 0, |
|
1901 |
|
1902 /** |
|
1903 * Gecko engine revision number. Will evaluate to 1 if Gecko |
|
1904 * is detected but the revision could not be found. Other browsers |
|
1905 * will be 0. Example: 1.8 |
|
1906 * <pre> |
|
1907 * Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7 |
|
1908 * Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8 |
|
1909 * Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8 |
|
1910 * Firefox 3 alpha: 1.9a4 <-- Reports 1.9 |
|
1911 * </pre> |
|
1912 * @property gecko |
|
1913 * @type float |
|
1914 * @static |
|
1915 */ |
|
1916 gecko: 0, |
|
1917 |
|
1918 /** |
|
1919 * AppleWebKit version. KHTML browsers that are not WebKit browsers |
|
1920 * will evaluate to 1, other browsers 0. Example: 418.9 |
|
1921 * <pre> |
|
1922 * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the |
|
1923 * latest available for Mac OSX 10.3. |
|
1924 * Safari 2.0.2: 416 <-- hasOwnProperty introduced |
|
1925 * Safari 2.0.4: 418 <-- preventDefault fixed |
|
1926 * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run |
|
1927 * different versions of webkit |
|
1928 * Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been |
|
1929 * updated, but not updated |
|
1930 * to the latest patch. |
|
1931 * Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native SVG |
|
1932 * and many major issues fixed). |
|
1933 * Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic update |
|
1934 * from 2.x via the 10.4.11 OS patch |
|
1935 * Webkit nightly 1/2008:525+ <-- Supports DOMContentLoaded event. |
|
1936 * yahoo.com user agent hack removed. |
|
1937 * </pre> |
|
1938 * http://en.wikipedia.org/wiki/Safari_(web_browser)#Version_history |
|
1939 * @property webkit |
|
1940 * @type float |
|
1941 * @static |
|
1942 */ |
|
1943 webkit: 0, |
|
1944 |
|
1945 /** |
|
1946 * The mobile property will be set to a string containing any relevant |
|
1947 * user agent information when a modern mobile browser is detected. |
|
1948 * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series |
|
1949 * devices with the WebKit-based browser, and Opera Mini. |
|
1950 * @property mobile |
|
1951 * @type string |
|
1952 * @static |
|
1953 */ |
|
1954 mobile: null, |
|
1955 |
|
1956 /** |
|
1957 * Adobe AIR version number or 0. Only populated if webkit is detected. |
|
1958 * Example: 1.0 |
|
1959 * @property air |
|
1960 * @type float |
|
1961 */ |
|
1962 air: 0, |
|
1963 |
|
1964 /** |
|
1965 * Google Caja version number or 0. |
|
1966 * @property caja |
|
1967 * @type float |
|
1968 */ |
|
1969 caja: nav.cajaVersion, |
|
1970 |
|
1971 /** |
|
1972 * Set to true if the page appears to be in SSL |
|
1973 * @property secure |
|
1974 * @type boolean |
|
1975 * @static |
|
1976 */ |
|
1977 secure: false, |
|
1978 |
|
1979 /** |
|
1980 * The operating system. Currently only detecting windows or macintosh |
|
1981 * @property os |
|
1982 * @type string |
|
1983 * @static |
|
1984 */ |
|
1985 os: null |
|
1986 |
|
1987 }, |
|
1988 |
|
1989 ua = nav && nav.userAgent, |
|
1990 |
|
1991 loc = Y.config.win.location, |
|
1992 |
|
1993 href = loc && loc.href, |
|
1994 |
|
1995 m; |
|
1996 |
|
1997 o.secure = href && (href.toLowerCase().indexOf("https") === 0); |
|
1998 |
|
1999 if (ua) { |
|
2000 |
|
2001 if ((/windows|win32/i).test(ua)) { |
|
2002 o.os = 'windows'; |
|
2003 } else if ((/macintosh/i).test(ua)) { |
|
2004 o.os = 'macintosh'; |
|
2005 } |
|
2006 |
|
2007 // Modern KHTML browsers should qualify as Safari X-Grade |
|
2008 if ((/KHTML/).test(ua)) { |
|
2009 o.webkit=1; |
|
2010 } |
|
2011 // Modern WebKit browsers are at least X-Grade |
|
2012 m=ua.match(/AppleWebKit\/([^\s]*)/); |
|
2013 if (m&&m[1]) { |
|
2014 o.webkit=numberfy(m[1]); |
|
2015 |
|
2016 // Mobile browser check |
|
2017 if (/ Mobile\//.test(ua)) { |
|
2018 o.mobile = "Apple"; // iPhone or iPod Touch |
|
2019 } else { |
|
2020 m=ua.match(/NokiaN[^\/]*|Android \d\.\d|webOS\/\d\.\d/); |
|
2021 if (m) { |
|
2022 o.mobile = m[0]; // Nokia N-series, Android, webOS, ex: NokiaN95 |
|
2023 } |
|
2024 } |
|
2025 |
|
2026 m=ua.match(/AdobeAIR\/([^\s]*)/); |
|
2027 if (m) { |
|
2028 o.air = m[0]; // Adobe AIR 1.0 or better |
|
2029 } |
|
2030 |
|
2031 } |
|
2032 |
|
2033 if (!o.webkit) { // not webkit |
|
2034 // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr) |
|
2035 m=ua.match(/Opera[\s\/]([^\s]*)/); |
|
2036 if (m&&m[1]) { |
|
2037 o.opera=numberfy(m[1]); |
|
2038 m=ua.match(/Opera Mini[^;]*/); |
|
2039 if (m) { |
|
2040 o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316 |
|
2041 } |
|
2042 } else { // not opera or webkit |
|
2043 m=ua.match(/MSIE\s([^;]*)/); |
|
2044 if (m&&m[1]) { |
|
2045 o.ie=numberfy(m[1]); |
|
2046 } else { // not opera, webkit, or ie |
|
2047 m=ua.match(/Gecko\/([^\s]*)/); |
|
2048 if (m) { |
|
2049 o.gecko=1; // Gecko detected, look for revision |
|
2050 m=ua.match(/rv:([^\s\)]*)/); |
|
2051 if (m&&m[1]) { |
|
2052 o.gecko=numberfy(m[1]); |
|
2053 } |
|
2054 } |
|
2055 } |
|
2056 } |
|
2057 } |
|
2058 } |
|
2059 |
|
2060 return o; |
|
2061 }(); |
|
2062 (function() { |
|
2063 var L = Y.Lang, |
|
2064 |
|
2065 /** |
|
2066 * Executes the supplied function in the context of the supplied |
|
2067 * object 'when' milliseconds later. Executes the function a |
|
2068 * single time unless periodic is set to true. |
|
2069 * @method later |
|
2070 * @for YUI |
|
2071 * @param when {int} the number of milliseconds to wait until the fn |
|
2072 * is executed. |
|
2073 * @param o the context object. |
|
2074 * @param fn {Function|String} the function to execute or the name of |
|
2075 * the method in the 'o' object to execute. |
|
2076 * @param data [Array] data that is provided to the function. This accepts |
|
2077 * either a single item or an array. If an array is provided, the |
|
2078 * function is executed with one parameter for each array item. If |
|
2079 * you need to pass a single array parameter, it needs to be wrapped in |
|
2080 * an array [myarray]. |
|
2081 * @param periodic {boolean} if true, executes continuously at supplied |
|
2082 * interval until canceled. |
|
2083 * @return {object} a timer object. Call the cancel() method on this object to |
|
2084 * stop the timer. |
|
2085 */ |
|
2086 later = function(when, o, fn, data, periodic) { |
|
2087 when = when || 0; |
|
2088 o = o || {}; |
|
2089 var m=fn, d=data, f, r; |
|
2090 |
|
2091 if (L.isString(fn)) { |
|
2092 m = o[fn]; |
|
2093 } |
|
2094 |
|
2095 if (!m) { |
|
2096 Y.error("method undefined"); |
|
2097 } |
|
2098 |
|
2099 if (!L.isArray(d)) { |
|
2100 d = [data]; |
|
2101 } |
|
2102 |
|
2103 f = function() { |
|
2104 m.apply(o, d); |
|
2105 }; |
|
2106 |
|
2107 r = (periodic) ? setInterval(f, when) : setTimeout(f, when); |
|
2108 |
|
2109 return { |
|
2110 id: r, |
|
2111 interval: periodic, |
|
2112 cancel: function() { |
|
2113 if (this.interval) { |
|
2114 clearInterval(r); |
|
2115 } else { |
|
2116 clearTimeout(r); |
|
2117 } |
|
2118 } |
|
2119 }; |
|
2120 }; |
|
2121 |
|
2122 Y.later = later; |
|
2123 L.later = later; |
|
2124 |
|
2125 })(); |
|
2126 (function() { |
|
2127 |
|
2128 var min = ['yui-base'], core, C = Y.config, LOADER='loader'; |
|
2129 |
|
2130 // apply the minimal required functionality |
|
2131 Y.use.apply(Y, min); |
|
2132 |
|
2133 Y.log(Y.id + ' initialized', 'info', 'yui'); |
|
2134 |
|
2135 if (C.core) { |
|
2136 core = C.core; |
|
2137 } else { |
|
2138 core = ['queue-base', 'get']; |
|
2139 if (YUI.Env.mods[LOADER]) { |
|
2140 core.push(LOADER); |
|
2141 } |
|
2142 } |
|
2143 |
|
2144 Y.use.apply(Y, core); |
|
2145 |
|
2146 })(); |
|
2147 |
|
2148 |
|
2149 |
|
2150 }, '3.0.0' ); |