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