/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk
229.1.3 by Paul Hummer
Added forgotten library
1
/*
2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
5
version: 3.0.0pr1
6
*/
7
/**
8
 * YUI core
9
 * @module yui
10
 */
11
(function() {
12
13
    var _instances = {},
14
15
// @TODO: this needs to be created at build time from module metadata
16
17
        _APPLY_TO_WHITE_LIST = {
18
            'io.xdrReady': 1,
19
            'io.start': 1,
20
            'io.success': 1,
21
            'io.failure': 1,
22
            'io.abort': 1
23
        };
24
        
25
26
if (typeof YUI === 'undefined' || !YUI) {
27
28
    /**
29
     * The YUI global namespace object.  If YUI is already defined, the
30
     * existing YUI object will not be overwritten so that defined
31
     * namespaces are preserved.  
32
     *
33
     * @class YUI
34
     * @constructor
35
     * @global
36
     * @uses Event.Target
37
     * @param o Optional configuration object.  Options:
38
     * <ul>
39
     *  <li>------------------------------------------------------------------------</li>
40
     *  <li>Global:</li>
41
     *  <li>------------------------------------------------------------------------</li>
42
     *  <li>debug:
43
     *  Turn debug statements on or off</li>
44
     *  <li>useConsole:
45
     *  Log to the browser console if debug is on and the console is available</li>
46
     *  <li>logInclude:
47
     *  A hash of log sources that should be logged.  If specified, only log messages from these sources will be logged.
48
     *  
49
     *  </li>
50
     *  <li>logExclude:
51
     *  A hash of log sources that should be not be logged.  If specified, all sources are logged if not on this list.</li>
52
     *  <li>throwFail:
53
     *  If throwFail is set, Y.fail will generate or re-throw a JS error.  Otherwise the failure is logged.
54
     *  <li>win:
55
     *  The target window/frame</li>
56
     *  <li>core:
57
     *  A list of modules that defines the YUI core (overrides the default)</li>
58
     *  <li>------------------------------------------------------------------------</li>
59
     *  <li>For event and get:</li>
60
     *  <li>------------------------------------------------------------------------</li>
61
     *  <li>pollInterval:
62
     *  The default poll interval</li>
63
     *  <li>-------------------------------------------------------------------------</li>
64
     *  <li>For loader:</li>
65
     *  <li>-------------------------------------------------------------------------</li>
66
     *  <li>base:
67
     *  The base dir</li>
68
     *  <li>secureBase:
69
     *  The secure base dir (not implemented)</li>
70
     *  <li>comboBase:
71
     *  The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li>
72
     *  <li>root:
73
     *  The root path to prepend to module names for the combo service. Ex: 2.5.2/build/</li>
74
     *  <li>filter:
75
     *  
76
     * A filter to apply to result urls.  This filter will modify the default
77
     * path for all modules.  The default path for the YUI library is the
78
     * minified version of the files (e.g., event-min.js).  The filter property
79
     * can be a predefined filter or a custom filter.  The valid predefined 
80
     * filters are:
81
     * <dl>
82
     *  <dt>DEBUG</dt>
83
     *  <dd>Selects the debug versions of the library (e.g., event-debug.js).
84
     *      This option will automatically include the logger widget</dd>
85
     *  <dt>RAW</dt>
86
     *  <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
87
     * </dl>
88
     * You can also define a custom filter, which must be an object literal 
89
     * containing a search expression and a replace string:
90
     * <pre>
91
     *  myFilter: &#123; 
92
     *      'searchExp': "-min\\.js", 
93
     *      'replaceStr': "-debug.js"
94
     *  &#125;
95
     * </pre>
96
     *
97
     *  </li>
98
     *  <li>combine:
99
     *  Use the YUI combo service to reduce the number of http connections required to load your dependencies</li>
100
     *  <li>ignore:
101
     *  A list of modules that should never be dynamically loaded</li>
102
     *  <li>force:
103
     *  A list of modules that should always be loaded when required, even if already present on the page</li>
104
     *  <li>insertBefore:
105
     *  Node or id for a node that should be used as the insertion point for new nodes</li>
106
     *  <li>charset:
107
     *  charset for dynamic nodes</li>
108
     *  <li>timeout:
109
     *  number of milliseconds before a timeout occurs when dynamically loading nodes.  in not set, there is no timeout</li>
110
     *  <li>context:
111
     *  execution context for all callbacks</li>
112
     *  <li>onSuccess:
113
     *  callback for the 'success' event</li>
114
     *  <li>onFailure:
115
     *  callback for the 'failure' event</li>
116
     *  <li>onTimeout:
117
     *  callback for the 'timeout' event</li>
118
     *  <li>onProgress:
119
     *  callback executed each time a script or css file is loaded</li>
120
     *  <li>modules:
121
     *  A list of module definitions.  See Loader.addModule for the supported module metadata</li>
122
     * </ul>
123
     */
124
125
    /*global YUI*/
126
    YUI = function(o) {
127
        var Y = this;
128
        // Allow var yui = YUI() instead of var yui = new YUI()
129
        if (Y == window) {
130
            return new YUI(o);
131
        } else {
132
            // set up the core environment
133
            Y._init(o);
134
135
            // bind the specified additional modules for this instance
136
            Y._setup();
137
138
            return Y;
139
        }
140
    };
141
}
142
143
// The prototype contains the functions that are required to allow the external
144
// modules to be registered and for the instance to be initialized.
145
YUI.prototype = {
146
147
    /**
148
     * Initialize this YUI instance
149
     * @param o config options
150
     * @private
151
     */
152
    _init: function(o) {
153
        
154
155
        o = o || {};
156
157
        // find targeted window and @TODO create facades
158
        var w = (o.win) ? (o.win.contentWindow) : o.win  || window;
159
        o.win = w;
160
        o.doc = w.document;
161
        o.debug = ('debug' in o) ? o.debug : true;
162
        o.useConsole = ('useConsole' in o) ? o.useConsole: true;
163
164
        // @TODO default throwFail to true in PR2
165
        // o.throwFail = ('throwFail' in o) ? o.debug : true;
166
    
167
        // add a reference to o for anything that needs it
168
        // before _setup is called.
169
        this.config = o;
170
171
        this.Env = {
172
            // @todo expand the new module metadata
173
            mods: {},
174
            _idx: 0,
175
            _pre: 'yuid',
176
            _used: {},
177
            _attached: {},
178
            _yidx: 0,
179
            _uidx: 0
180
        };
181
182
        if (YUI.Env) {
183
            this.Env._yidx = ++YUI.Env._idx;
184
            this.id = this.stamp(this);
185
            _instances[this.id] = this;
186
        }
187
188
        this.constructor = YUI;
189
190
    },
191
    
192
    /**
193
     * Finishes the instance setup. Attaches whatever modules were defined
194
     * when the yui modules was registered.
195
     * @method _setup
196
     * @private
197
     */
198
    _setup: function(o) {
199
        this.use("yui");
200
        // @TODO eval the need to copy the config
201
        this.config = this.merge(this.config);
202
    },
203
204
    /**
205
     * Executes a method on a YUI instance with
206
     * the specified id if the specified method is whitelisted.
207
     * @method applyTo
208
     * @param id {string} the YUI instance id
209
     * @param method {string} the name of the method to exectute.
210
     * Ex: 'Object.keys'
211
     * @param args {Array} the arguments to apply to the method
212
     * @return {object} the return value from the applied method or null
213
     */
214
    applyTo: function(id, method, args) {
215
216
        if (!(method in _APPLY_TO_WHITE_LIST)) {
217
            this.fail(method + ': applyTo not allowed');
218
            return null;
219
        }
220
221
        var instance = _instances[id];
222
223
        if (instance) {
224
225
            var nest = method.split('.'), m = instance;
226
227
            for (var i=0; i<nest.length; i=i+1) {
228
229
                m = m[nest[i]];
230
231
                if (!m) {
232
                    this.fail('applyTo not found: ' + method);
233
                }
234
            }
235
236
            return m.apply(instance, args);
237
        }
238
239
        return null;
240
    }, 
241
242
    /**
243
     * Register a module
244
     * @method add
245
     * @param name {string} module name
246
     * @param namespace {string} name space for the module
247
     * @param fn {Function} entry point into the module that
248
     * is used to bind module to the YUI instance
249
     * @param version {string} version string
250
     * @return {YUI} the YUI instance
251
     *
252
     * requires   - features that should be present before loading
253
     * optional   - optional features that should be present if load optional defined
254
     * use  - features that should be attached automatically
255
     * skinnable  -
256
     * rollup
257
     * omit - features that should not be loaded if this module is present
258
     */
259
    add: function(name, fn, version, details) {
260
261
262
        // @todo expand this to include version mapping
263
        
264
        // @todo allow requires/supersedes
265
266
        // @todo may want to restore the build property
267
        
268
        // @todo fire moduleAvailable event
269
        
270
        var m = {
271
            name: name, 
272
            fn: fn,
273
            version: version,
274
            details: details || {}
275
        };
276
277
        YUI.Env.mods[name] = m;
278
279
        return this; // chain support
280
    },
281
282
    _attach: function(r, fromLoader) {
283
284
        var mods = YUI.Env.mods,
285
            attached = this.Env._attached;
286
287
        for (var i=0, l=r.length; i<l; i=i+1) {
288
            var name = r[i], m = mods[name], mm;
289
            if (!attached[name] && m) {
290
291
                attached[name] = true;
292
293
                var d = m.details, req = d.requires, use = d.use;
294
295
                if (req) {
296
                    this._attach(this.Array(req));
297
                }
298
299
300
                if (m.fn) {
301
                    m.fn(this);
302
                }
303
304
                if (use) {
305
                    this._attach(this.Array(use));
306
                }
307
            }
308
        }
309
310
    },
311
312
    /**
313
     * Bind a module to a YUI instance
314
     * @param modules* {string} 1-n modules to bind (uses arguments array)
315
     * @param *callback {function} callback function executed when 
316
     * the instance has the required functionality.  If included, it
317
     * must be the last parameter.
318
     *
319
     * @TODO 
320
     * Implement versioning?  loader can load different versions?
321
     * Should sub-modules/plugins be normal modules, or do
322
     * we add syntax for specifying these?
323
     *
324
     * YUI().use('dragdrop')
325
     * YUI().use('dragdrop:2.4.0'); // specific version
326
     * YUI().use('dragdrop:2.4.0-'); // at least this version
327
     * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
328
     * YUI().use('*'); // use all available modules
329
     * YUI().use('lang+dump+substitute'); // use lang and some plugins
330
     * YUI().use('lang+*'); // use lang and all known plugins
331
     *
332
     *
333
     * @return {YUI} the YUI instance
334
     */
335
    use: function() {
336
337
        var Y = this, 
338
            a=Array.prototype.slice.call(arguments, 0), 
339
            mods = YUI.Env.mods, 
340
            used = Y.Env._used,
341
            loader, 
342
            firstArg = a[0], 
343
            dynamic = false,
344
            callback = a[a.length-1];
345
346
347
        // The last argument supplied to use can be a load complete callback
348
        if (typeof callback === 'function') {
349
            a.pop();
350
            Y.Env._callback = callback;
351
        } else {
352
            callback = null;
353
        }
354
355
        // YUI().use('*'); // bind everything available
356
        if (firstArg === "*") {
357
            a = [];
358
            for (var k in mods) {
359
                if (mods.hasOwnProperty(k)) {
360
                    a.push(k);
361
                }
362
            }
363
364
            return Y.use.apply(Y, a);
365
366
        }
367
       
368
369
        // use loader to optimize and sort the requirements if it
370
        // is available.
371
        if (Y.Loader) {
372
            dynamic = true;
373
            loader = new Y.Loader(Y.config);
374
            loader.require(a);
375
            loader.ignoreRegistered = true;
376
            loader.calculate();
377
            a = loader.sorted;
378
        }
379
380
381
        var missing = [], r = [], f = function(name) {
382
383
            // only attach a module once
384
            if (used[name]) {
385
                return;
386
            }
387
388
            var m = mods[name], j, req, use;
389
390
            if (m) {
391
                used[name] = true;
392
393
                req = m.details.requires;
394
                use = m.details.use;
395
            } else {
396
                missing.push(name);
397
            }
398
399
            // make sure requirements are attached
400
            if (req) {
401
                if (Y.Lang.isString(req)) {
402
                    f(req);
403
                } else {
404
                    for (j = 0; j < req.length; j = j + 1) {
405
                        f(req[j]);
406
                    }
407
                }
408
            }
409
410
            // add this module to full list of things to attach
411
            r.push(name);
412
413
        };
414
415
        // process each requirement and any additional requirements 
416
        // the module metadata specifies
417
        for (var i=0, l=a.length; i<l; i=i+1) {
418
            f(a[i]);
419
        }
420
421
422
        var onComplete = function(fromLoader) {
423
424
425
            fromLoader = fromLoader || {
426
                success: true,
427
                msg: 'not dynamic'
428
            };
429
430
            if (Y.Env._callback) {
431
432
                var cb = Y.Env._callback;
433
                Y.Env._callback = null;
434
                cb(Y, fromLoader);
435
            }
436
437
            if (Y.fire) {
438
                Y.fire('yui:load', Y, fromLoader);
439
            }
440
        };
441
442
443
        // dynamic load
444
        if (Y.Loader && missing.length) {
445
            loader = new Y.Loader(Y.config);
446
            loader.onSuccess = onComplete;
447
            loader.onFailure = onComplete;
448
            loader.onTimeout = onComplete;
449
            loader.attaching = a;
450
            loader.require(missing);
451
            loader.insert();
452
        } else {
453
            Y._attach(r);
454
            onComplete();
455
        }
456
457
        return Y; // chain support var yui = YUI().use('dragdrop');
458
    },
459
460
461
    /**
462
     * Returns the namespace specified and creates it if it doesn't exist
463
     * <pre>
464
     * YUI.namespace("property.package");
465
     * YUI.namespace("YUI.property.package");
466
     * </pre>
467
     * Either of the above would create YUI.property, then
468
     * YUI.property.package
469
     *
470
     * Be careful when naming packages. Reserved words may work in some browsers
471
     * and not others. For instance, the following will fail in Safari:
472
     * <pre>
473
     * YUI.namespace("really.long.nested.namespace");
474
     * </pre>
475
     * This fails because "long" is a future reserved word in ECMAScript
476
     *
477
     * @method namespace
478
     * @param  {string*} arguments 1-n namespaces to create 
479
     * @return {object}  A reference to the last namespace object created
480
     */
481
    namespace: function() {
482
        var a=arguments, o=null, i, j, d;
483
        for (i=0; i<a.length; i=i+1) {
484
            d = a[i].split(".");
485
            o = this;
486
            for (j=(d[0] == "YUI") ? 1 : 0; j<d.length; j=j+1) {
487
                o[d[j]] = o[d[j]] || {};
488
                o = o[d[j]];
489
            }
490
        }
491
        return o;
492
    },
493
494
    // this is replaced if the log module is included
495
    log: function() {
496
497
    },
498
499
    /**
500
     * Report an error.  The reporting mechanism is controled by
501
     * the 'throwFail' configuration attribute.  If throwFail is
502
     * not specified, the message is written to the logger, otherwise
503
     * a JS error is thrown
504
     * @method fail
505
     * @param msg {string} the failure message
506
     * @param e {Error} Optional JS error that was caught.  If supplied
507
     * and throwFail is specified, this error will be re-thrown.
508
     * @return {YUI} this YUI instance
509
     */
510
    fail: function(msg, e) {
511
        var instance = this;
512
        instance.log(msg, "error"); // don't scrub this one
513
514
        if (this.config.throwFail) {
515
            throw e || new Error(msg);
516
        }
517
518
        return this;
519
    },
520
521
    /**
522
     * Generate an id that is unique among all YUI instances
523
     * @method guid
524
     * @param pre {string} optional guid prefix
525
     * @return {string} the guid
526
     */
527
    guid: function(pre) {
528
        var e = this.Env, p = (pre) || e._pre;
529
        return p +'-' + e._yidx + '-' + e._uidx++;
530
    },
531
532
    /**
533
     * Stamps an object with a guid.  If the object already
534
     * has one, a new one is not created
535
     * @method stamp
536
     * @param o The object to stamp
537
     * @return {string} The object's guid
538
     */
539
    stamp: function(o) {
540
541
        if (!o) {
542
            return o;
543
        }
544
545
        var uid = (typeof o === 'string') ? o : o._yuid;
546
547
        if (!uid) {
548
            uid = this.guid();
549
            o._yuid = uid;
550
        }
551
552
        return uid;
553
    }
554
};
555
556
// Give the YUI global the same properties as an instance.
557
// This makes it so that the YUI global can be used like the YAHOO
558
// global was used prior to 3.x.  More importantly, the YUI global
559
// provides global metadata, so env needs to be configured.
560
// @TODO review
561
562
    var Y = YUI, p = Y.prototype, i;
563
564
    // inheritance utilities are not available yet
565
    for (i in p) {
566
        if (true) { // hasOwnProperty not available yet and not needed
567
            Y[i] = p[i];
568
        }
569
    }
570
571
    // set up the environment
572
    Y._init();
573
574
575
})();
576
/**
577
 * YUI stub
578
 * @module yui
579
 * @submodule yui-base
580
 */
581
// This is just a stub to for dependency processing
582
YUI.add("yui-base", null, "3.0.0pr1");
583
/*
584
 * YUI console logger
585
 * @module yui
586
 * @submodule log
587
 */
588
YUI.add("log", function(instance) {
589
590
    /**
591
     * If the 'debug' config is true, a 'yui:log' event will be
592
     * dispatched, which the logger widget and anything else
593
     * can consume.  If the 'useConsole' config is true, it will
594
     * write to the browser console if available.
595
     *
596
     * @method log
597
     * @for YUI
598
     * @param  {String}  msg  The message to log.
599
     * @param  {String}  cat  The log category for the message.  Default
600
     *                        categories are "info", "warn", "error", time".
601
     *                        Custom categories can be used as well. (opt)
602
     * @param  {String}  src  The source of the the message (opt)
603
     * @return {YUI}      YUI instance
604
     */
605
    instance.log = function(msg, cat, src) {
606
607
        var Y = instance, c = Y.config, es = Y.Env._eventstack,
608
            bail = (es && es.logging);
609
610
        // suppress log message if the config is off or the event stack
611
        // or the event call stack contains a consumer of the yui:log event
612
        if (c.debug && !bail) {
613
614
            // apply source filters
615
            if (src) {
616
617
                var exc = c.logExclude, inc = c.logInclude;
618
619
                // console.log('checking src filter: ' + src + ', inc: ' + inc + ', exc: ' + exc);
620
621
                if (inc && !(src in inc)) {
622
                    // console.log('bail: inc list found, but src is not in list: ' + src);
623
                    bail = true;
624
                } else if (exc && (src in exc)) {
625
                    // console.log('bail: exc list found, and src is in it: ' + src);
626
                    bail = true;
627
                }
628
            }
629
630
            if (!bail) {
631
632
                if (c.useConsole && typeof console != 'undefined') {
633
                        var f = (cat && console[cat]) ? cat : 'log',
634
                            m = (src) ? src + ': ' + msg : msg;
635
                        console[f](m);
636
                }
637
638
                if (Y.fire && !bail) {
639
                    Y.fire('yui:log', msg, cat, src);
640
                }
641
            }
642
        }
643
644
        return Y;
645
    };
646
647
}, "3.0.0pr1");
648
/*
649
 * YUI lang utils
650
 * @module yui
651
 * @submodule lang
652
 */
653
YUI.add("lang", function(Y) {
654
655
    /**
656
     * Provides the language utilites and extensions used by the library
657
     * @class Lang
658
     * @static
659
     */
660
    Y.Lang = Y.Lang || {};
661
662
    var L = Y.Lang, SPLICE="splice", LENGTH="length";
663
664
    /**
665
     * Determines whether or not the provided object is an array.
666
     * Testing typeof/instanceof/constructor of arrays across frame 
667
     * boundaries isn't possible in Safari unless you have a reference
668
     * to the other frame to test against its Array prototype.  To
669
     * handle this case, we test well-known array properties instead.
670
     * properties.
671
     * @TODO can we kill this cross frame hack?
672
     * @method isArray
673
     * @static
674
     * @param o The object to test
675
     * @return {boolean} true if o is an array
676
     */
677
     L.isArray = function(o) { 
678
        if (o) {
679
           //return L.isNumber(o.length) && L.isFunction(o.splice);
680
           return (o[SPLICE] && L.isNumber(o[LENGTH]));
681
        }
682
        return false;
683
    };
684
685
    /**
686
     * Determines whether or not the provided object is a boolean
687
     * @method isBoolean
688
     * @static
689
     * @param o The object to test
690
     * @return {boolean} true if o is a boolean
691
     */
692
    L.isBoolean = function(o) {
693
        return typeof o === 'boolean';
694
    };
695
    
696
    /**
697
     * Determines whether or not the provided object is a function
698
     * @method isFunction
699
     * @static
700
     * @param o The object to test
701
     * @return {boolean} true if o is a function
702
     */
703
    L.isFunction = function(o) {
704
        return typeof o === 'function';
705
    };
706
        
707
    /**
708
     * Determines whether or not the supplied object is a date instance
709
     * @method isDate
710
     * @static
711
     * @param o The object to test
712
     * @return {boolean} true if o is a date
713
     */
714
    L.isDate = function(o) {
715
        return o instanceof Date;
716
    };
717
718
    /**
719
     * Determines whether or not the provided object is null
720
     * @method isNull
721
     * @static
722
     * @param o The object to test
723
     * @return {boolean} true if o is null
724
     */
725
    L.isNull = function(o) {
726
        return o === null;
727
    };
728
        
729
    /**
730
     * Determines whether or not the provided object is a legal number
731
     * @method isNumber
732
     * @static
733
     * @param o The object to test
734
     * @return {boolean} true if o is a number
735
     */
736
    L.isNumber = function(o) {
737
        return typeof o === 'number' && isFinite(o);
738
    };
739
      
740
    /**
741
     * Determines whether or not the provided object is of type object
742
     * or function
743
     * @method isObject
744
     * @static
745
     * @param o The object to test
746
     * @param failfn {boolean} fail if the input is a function
747
     * @return {boolean} true if o is an object
748
     */  
749
    L.isObject = function(o, failfn) {
750
return (o && (typeof o === 'object' || (!failfn && L.isFunction(o)))) || false;
751
    };
752
        
753
    /**
754
     * Determines whether or not the provided object is a string
755
     * @method isString
756
     * @static
757
     * @param o The object to test
758
     * @return {boolean} true if o is a string
759
     */
760
    L.isString = function(o) {
761
        return typeof o === 'string';
762
    };
763
        
764
    /**
765
     * Determines whether or not the provided object is undefined
766
     * @method isUndefined
767
     * @static
768
     * @param o The object to test
769
     * @return {boolean} true if o is undefined
770
     */
771
    L.isUndefined = function(o) {
772
        return typeof o === 'undefined';
773
    };
774
    
775
    /**
776
     * Returns a string without any leading or trailing whitespace.  If 
777
     * the input is not a string, the input will be returned untouched.
778
     * @method trim
779
     * @static
780
     * @param s {string} the string to trim
781
     * @return {string} the trimmed string
782
     */
783
    L.trim = function(s){
784
        try {
785
            return s.replace(/^\s+|\s+$/g, "");
786
        } catch(e) {
787
            return s;
788
        }
789
    };
790
791
    /**
792
     * A convenience method for detecting a legitimate non-null value.
793
     * Returns false for null/undefined/NaN, true for other values, 
794
     * including 0/false/''
795
     * @method isValue
796
     * @static
797
     * @param o The item to test
798
     * @return {boolean} true if it is not null/undefined/NaN || false
799
     */
800
    L.isValue = function(o) {
801
// return (o || o === false || o === 0 || o === ''); // Infinity fails
802
return (L.isObject(o) || L.isString(o) || L.isNumber(o) || L.isBoolean(o));
803
    };
804
805
}, "3.0.0pr1");
806
807
808
/*
809
 * Array utilities
810
 * @module yui
811
 * @submodule array
812
 */
813
814
/**
815
 * YUI core
816
 * @module yui
817
 */
818
819
YUI.add("array", function(Y) {
820
821
    var L = Y.Lang, Native = Array.prototype;
822
823
    /**
824
     * Adds the following array utilities to the YUI instance
825
     * @class YUI~array
826
     */
827
828
    /** 
829
     * Y.Array(o) returns an array:
830
     * - Arrays are return unmodified unless the start position is specified.
831
     * - "Array-like" collections (@see Array.test) are converted to arrays
832
     * - For everything else, a new array is created with the input as the sole item
833
     * - The start position is used if the input is or is like an array to return
834
     *   a subset of the collection.
835
     *
836
     *   @TODO this will not automatically convert elements that are also collections
837
     *   such as forms and selects.  Passing true as the third param will
838
     *   force a conversion.
839
     *
840
     * @method Array
841
     * @static
842
     *   @param o the item to arrayify
843
     *   @param i {int} if an array or array-like, this is the start index
844
     *   @param al {boolean} if true, it forces the array-like fork.  This
845
     *   can be used to avoid multiple array.test calls.
846
     *   @return {Array} the resulting array
847
     */
848
    Y.Array = function(o, i, al) {
849
        var t = (al) ? 2 : Y.Array.test(o);
850
        switch (t) {
851
            case 1:
852
                return (i) ? o.slice(o, i) : o;
853
            case 2:
854
                return Native.slice.call(o, i || 0);
855
            default:
856
                return [o];
857
        }
858
    };
859
860
    var A = Y.Array;
861
    
862
    /** 
863
     * Evaluates the input to determine if it is an array, array-like, or 
864
     * something else.  This is used to handle the arguments collection 
865
     * available within functions, and HTMLElement collections
866
     *
867
     * @method Array.test
868
     * @static
869
     *
870
     * @todo current implementation (intenionally) will not implicitly 
871
     * handle html elements that are array-like (forms, selects, etc).  
872
     *
873
     * @return {int} a number indicating the results:
874
     * 0: Not an array or an array-like collection
875
     * 1: A real array. 
876
     * 2: array-like collection.
877
     */
878
    A.test = function(o) {
879
        var r = 0;
880
        if (L.isObject(o, true)) {
881
            if (L.isArray(o)) {
882
                r = 1; 
883
            } else {
884
                try {
885
                    // indexed, but no tagName (element) or alert (window)
886
                    if ("length" in o && !("tagName" in o)  && !("alert" in o)) {
887
                        r = 2;
888
                    }
889
                        
890
                } catch(ex) {}
891
            }
892
        }
893
        return r;
894
    };
895
896
    /**
897
     * Executes the supplied function on each item in the array.
898
     * @method Array.each
899
     * @static
900
     * @return {YUI} the YUI instance
901
     */
902
    A.each = (Native.forEach) ?
903
        function (a, f, o) { 
904
            Native.forEach.call(a, f, o || Y);
905
            return Y;
906
        } :
907
        function (a, f, o) { 
908
            var l = a.length, i;
909
            for (i = 0; i < l; i=i+1) {
910
                f.call(o || Y, a[i], i, a);
911
            }
912
            return Y;
913
        };
914
915
    /**
916
     * Returns an object using the first array as keys, and
917
     * the second as values.  If the second array is not
918
     * provided the value is set to true for each.
919
     * @method Array.hash
920
     * @static
921
     * @param k {Array} keyset
922
     * @param v {Array} optional valueset
923
     * @return {object} the hash
924
     */
925
    A.hash = function(k, v) {
926
        var o = {}, l = k.length, vl = v && v.length, i;
927
        for (i=0; i<l; i=i+1) {
928
            o[k[i]] = (vl && vl > i) ? v[i] : true;
929
        }
930
931
        return o;
932
    };
933
934
935
    /**
936
     * Returns the index of the first item in the array
937
     * that contains the specified value, -1 if the
938
     * value isn't found.
939
     * @TODO use native method if avail
940
     * @method Array.indexOf
941
     * @static
942
     * @param a {Array} the array to search
943
     * @param val the value to search for
944
     * @return {int} the index of the item that contains the value or -1
945
     */
946
    A.indexOf = function(a, val) {
947
        for (var i=0; i<a.length; i=i+1) {
948
            if (a[i] === val) {
949
                return i;
950
            }
951
        }
952
953
        return -1;
954
    };
955
956
}, "3.0.0pr1");
957
/*
958
 * YUI core utilities
959
 * @module yui
960
 * @submodule core
961
 */
962
// requires lang
963
YUI.add("core", function(Y) {
964
965
    var L = Y.Lang, 
966
    A = Y.Array,
967
    OP = Object.prototype, 
968
    IEF = ["toString", "valueOf"], 
969
    PROTO = 'prototype',
970
971
    /**
972
     * IE will not enumerate native functions in a derived object even if the
973
     * function was overridden.  This is a workaround for specific functions 
974
     * we care about on the Object prototype. 
975
     * @property _iefix
976
     * @param {Function} r  the object to receive the augmentation
977
     * @param {Function} s  the object that supplies the properties to augment
978
     * @param w a whitelist object (the keys are the valid items to reference)
979
     * @private
980
     * @for YUI
981
     */
982
    _iefix = (Y.UA && Y.UA.ie) ?
983
        function(r, s, w) {
984
            for (var i=0, a=IEF; i<a.length; i=i+1) {
985
                var n = a[i], f = s[n];
986
                if (L.isFunction(f) && f != OP[n]) {
987
                    if (!w || (n in w)) {
988
                        r[n]=f;
989
                    }
990
                }
991
            }
992
        } : function() {};
993
   
994
995
    /**
996
     * Returns a new object containing all of the properties of
997
     * all the supplied objects.  The properties from later objects
998
     * will overwrite those in earlier objects.  Passing in a
999
     * single object will create a shallow copy of it.  For a deep
1000
     * copy, use clone.
1001
     * @method merge
1002
     * @param arguments {Object*} the objects to merge
1003
     * @return {object} the new merged object
1004
     */
1005
    Y.merge = function() {
1006
        // var o={}, a=arguments;
1007
        // for (var i=0, l=a.length; i<l; i=i+1) {
1008
        //var a=arguments, o=Y.Object(a[0]);
1009
        var a=arguments, o={};
1010
        for (var i=0, l=a.length; i<l; i=i+1) {
1011
            Y.mix(o, a[i], true);
1012
        }
1013
        return o;
1014
    };
1015
       
1016
    /**
1017
     * Applies the supplier's properties to the receiver.  By default
1018
     * all prototype and static propertes on the supplier are applied
1019
     * to the corresponding spot on the receiver.  By default all
1020
     * properties are applied, and a property that is already on the
1021
     * reciever will not be overwritten.  The default behavior can
1022
     * be modified by supplying the appropriate parameters.
1023
     *
1024
     * @TODO add constants for the modes
1025
     *
1026
     * @method mix
1027
     * @param {Function} r  the object to receive the augmentation
1028
     * @param {Function} s  the object that supplies the properties to augment
1029
     * @param ov {boolean} if true, properties already on the receiver
1030
     * will be overwritten if found on the supplier.
1031
     * @param wl {string[]} a whitelist.  If supplied, only properties in 
1032
     * this list will be applied to the receiver.
1033
     * @param {int} mode what should be copies, and to where
1034
     *        default(0): object to object
1035
     *        1: prototype to prototype (old augment)
1036
     *        2: prototype to prototype and object props (new augment)
1037
     *        3: prototype to object
1038
     *        4: object to prototype
1039
     * @param merge {boolean} merge objects instead of overwriting/ignoring
1040
     * Used by Y.aggregate
1041
     * @return {object} the augmented object
1042
     * @TODO review for PR2
1043
     */
1044
    Y.mix = function(r, s, ov, wl, mode, merge) {
1045
1046
        if (!s||!r) {
1047
            return Y;
1048
        }
1049
1050
        var w = (wl && wl.length) ? A.hash(wl) : null, m = merge,
1051
1052
            f = function(fr, fs, proto, iwl) {
1053
1054
                var arr = m && L.isArray(fr);
1055
1056
                for (var i in fs) { 
1057
1058
                    // We never want to overwrite the prototype
1059
                    // if (PROTO === i) {
1060
                    if (PROTO === i || '_yuid' === i) {
1061
                        continue;
1062
                    }
1063
1064
                    // @TODO deal with the hasownprop issue
1065
1066
                    // check white list if it was supplied
1067
                    if (!w || iwl || (i in w)) {
1068
                        // if the receiver has this property, it is an object,
1069
                        // and merge is specified, merge the two objects.
1070
                        if (m && L.isObject(fr[i], true)) {
1071
                            // console.log('aggregate RECURSE: ' + i);
1072
                            // @TODO recursive or no?
1073
                            // Y.mix(fr[i], fs[i]); // not recursive
1074
                            f(fr[i], fs[i], proto, true); // recursive
1075
                        // otherwise apply the property only if overwrite
1076
                        // is specified or the receiver doesn't have one.
1077
                        // @TODO make sure the 'arr' check isn't desructive
1078
                        } else if (!arr && (ov || !(i in fr))) {
1079
                            // console.log('hash: ' + i);
1080
                            fr[i] = fs[i];
1081
                        // if merge is specified and the receiver is an array,
1082
                        // append the array item
1083
                        } else if (arr) {
1084
                            // console.log('array: ' + i);
1085
                            // @TODO probably will need to remove dups
1086
                            fr.push(fs[i]);
1087
                        }
1088
                    }
1089
                }
1090
1091
                _iefix(fr, fs, w);
1092
            };
1093
1094
        var rp = r.prototype, sp = s.prototype;
1095
1096
        switch (mode) {
1097
            case 1: // proto to proto
1098
                f(rp, sp, true);
1099
                break;
1100
            case 2: // object to object and proto to proto
1101
                f(r, s);
1102
                f(rp, sp, true);
1103
                break;
1104
            case 3: // proto to static
1105
                f(r, sp, true);
1106
                break;
1107
            case 4: // static to proto
1108
                f(rp, s);
1109
                break;
1110
            default:  // object to object
1111
                f(r, s);
1112
        }
1113
1114
        return r;
1115
    };
1116
1117
    
1118
1119
}, "3.0.0pr1");
1120
/*
1121
 * YUI object utilities
1122
 * @module yui
1123
 * @submodule object
1124
 */
1125
YUI.add("object", function(Y) {
1126
1127
    /**
1128
     * Adds the following Object utilities to the YUI instance
1129
     * @class YUI~object
1130
     */
1131
1132
    /**
1133
     * Y.Object(o) returns a new object based upon the supplied object.  
1134
     * @method Object
1135
     * @static
1136
     * @param o the supplier object
1137
     * @return {object} the new object
1138
     */
1139
    Y.Object = function(o) {
1140
        var F = function() {};
1141
        F.prototype = o;
1142
        return new F();
1143
    }; 
1144
1145
    var O = Y.Object, L = Y.Lang;
1146
1147
    /**
1148
     * Determines whether or not the property was added
1149
     * to the object instance.  Returns false if the property is not present
1150
     * in the object, or was inherited from the prototype.
1151
     *
1152
     * @deprecated Safari 1.x support has been removed, so this is simply a 
1153
     * wrapper for the native implementation.  Use the native implementation
1154
     * directly instead.
1155
     *
1156
     * @TODO Remove in PR2
1157
     *
1158
     * @method Object.owns
1159
     * @static
1160
     * @param o {any} The object being testing
1161
     * @param p {string} the property to look for
1162
     * @return {boolean} true if the object has the property on the instance
1163
     */
1164
    O.owns = function(o, p) {
1165
        return (o && o.hasOwnProperty) ? o.hasOwnProperty(p) : false;
1166
    };
1167
1168
    /**
1169
     * Returns an array containing the object's keys
1170
     * @method Object.keys
1171
     * @static
1172
     * @param o an object
1173
     * @return {string[]} the keys
1174
     */
1175
    O.keys = function(o) {
1176
        var a=[], i;
1177
        for (i in o) {
1178
            if (o.hasOwnProperty(i)) {
1179
                a.push(i);
1180
            }
1181
        }
1182
1183
        return a;
1184
    };
1185
1186
    /**
1187
     * Executes a function on each item. The function
1188
     * receives the value, the key, and the object
1189
     * as paramters (in that order).
1190
     * @method Object.each
1191
     * @static
1192
     * @param o the object to iterate
1193
     * @param f {function} the function to execute
1194
     * @param c the execution context
1195
     * @param proto {boolean} include proto
1196
     * @return {YUI} the YUI instance
1197
     */
1198
    O.each = function (o, f, c, proto) {
1199
        var s = c || Y;
1200
1201
        for (var i in o) {
1202
            if (proto || o.hasOwnProperty(i)) {
1203
                f.call(s, o[i], i, o);
1204
            }
1205
        }
1206
        return Y;
1207
    };
1208
}, "3.0.0pr1");
1209
/*
1210
 * YUI user agent detection
1211
 * @module yui
1212
 * @submodule ua
1213
 */
1214
YUI.add("ua", function(Y) {
1215
1216
    /**
1217
     * Browser/platform detection
1218
     * @class UA
1219
     * @static
1220
     */
1221
    Y.UA = function() {
1222
1223
        var o={
1224
1225
            /**
1226
             * Internet Explorer version number or 0.  Example: 6
1227
             * @property ie
1228
             * @type float
1229
             * @static
1230
             */
1231
            ie:0,
1232
1233
            /**
1234
             * Opera version number or 0.  Example: 9.2
1235
             * @property opera
1236
             * @type float
1237
             * @static
1238
             */
1239
            opera:0,
1240
1241
            /**
1242
             * Gecko engine revision number.  Will evaluate to 1 if Gecko 
1243
             * is detected but the revision could not be found. Other browsers
1244
             * will be 0.  Example: 1.8
1245
             * <pre>
1246
             * Firefox 1.0.0.4: 1.7.8   <-- Reports 1.7
1247
             * Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8
1248
             * Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8
1249
             * Firefox 3 alpha: 1.9a4   <-- Reports 1.9
1250
             * </pre>
1251
             * @property gecko
1252
             * @type float
1253
             * @static
1254
             */
1255
            gecko:0,
1256
1257
            /**
1258
             * AppleWebKit version.  KHTML browsers that are not WebKit browsers 
1259
             * will evaluate to 1, other browsers 0.  Example: 418.9.1
1260
             * <pre>
1261
             * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the 
1262
             *                                   latest available for Mac OSX 10.3.
1263
             * Safari 2.0.2:         416     <-- hasOwnProperty introduced
1264
             * Safari 2.0.4:         418     <-- preventDefault fixed
1265
             * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
1266
             *                                   different versions of webkit
1267
             * Safari 2.0.4 (419.3): 419     <-- Tiger installations that have been
1268
             *                                   updated, but not updated
1269
             *                                   to the latest patch.
1270
             * Webkit 212 nightly:   522+    <-- Safari 3.0 precursor (with native SVG
1271
             *                                   and many major issues fixed).
1272
             * Safari 3.0.4 (523.12) 523.12  <-- First Tiger release - automatic update
1273
             *                                   from 2.x via the 10.4.11 OS patch
1274
             *                                   
1275
             * </pre>
1276
             * http://developer.apple.com/internet/safari/uamatrix.html
1277
             * @property webkit
1278
             * @type float
1279
             * @static
1280
             */
1281
            webkit:0,
1282
1283
            /**
1284
             * The mobile property will be set to a string containing any relevant
1285
             * user agent information when a modern mobile browser is detected.
1286
             * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
1287
             * devices with the WebKit-based browser, and Opera Mini.  
1288
             * @property mobile 
1289
             * @type string
1290
             * @static
1291
             */
1292
            mobile: null 
1293
        };
1294
1295
        var ua=navigator.userAgent, m;
1296
1297
        // Modern KHTML browsers should qualify as Safari X-Grade
1298
        if ((/KHTML/).test(ua)) {
1299
            o.webkit=1;
1300
        }
1301
        // Modern WebKit browsers are at least X-Grade
1302
        m=ua.match(/AppleWebKit\/([^\s]*)/);
1303
        if (m&&m[1]) {
1304
            o.webkit=parseFloat(m[1]);
1305
1306
            // Mobile browser check
1307
            if (/ Mobile\//.test(ua)) {
1308
                o.mobile = "Apple"; // iPhone or iPod Touch
1309
            } else {
1310
                m=ua.match(/NokiaN[^\/]*/);
1311
                if (m) {
1312
                    o.mobile = m[0]; // Nokia N-series, ex: NokiaN95
1313
                }
1314
            }
1315
1316
        }
1317
1318
        if (!o.webkit) { // not webkit
1319
            // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
1320
            m=ua.match(/Opera[\s\/]([^\s]*)/);
1321
            if (m&&m[1]) {
1322
                o.opera=parseFloat(m[1]);
1323
                m=ua.match(/Opera Mini[^;]*/);
1324
                if (m) {
1325
                    o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
1326
                }
1327
            } else { // not opera or webkit
1328
                m=ua.match(/MSIE\s([^;]*)/);
1329
                if (m&&m[1]) {
1330
                    o.ie=parseFloat(m[1]);
1331
                } else { // not opera, webkit, or ie
1332
                    m=ua.match(/Gecko\/([^\s]*)/);
1333
                    if (m) {
1334
                        o.gecko=1; // Gecko detected, look for revision
1335
                        m=ua.match(/rv:([^\s\)]*)/);
1336
                        if (m&&m[1]) {
1337
                            o.gecko=parseFloat(m[1]);
1338
                        }
1339
                    }
1340
                }
1341
            }
1342
        }
1343
        
1344
        return o;
1345
    }();
1346
}, "3.0.0pr1");
1347
/*
1348
 * YUI setTimeout/setInterval abstraction
1349
 * @module yui
1350
 * @submodule later
1351
 */
1352
YUI.add("later", function(Y) {
1353
1354
    var L = Y.Lang;
1355
1356
    /**
1357
     * Executes the supplied function in the context of the supplied 
1358
     * object 'when' milliseconds later.  Executes the function a 
1359
     * single time unless periodic is set to true.
1360
     * @method later
1361
     * @for YUI
1362
     * @param when {int} the number of milliseconds to wait until the fn 
1363
     * is executed.
1364
     * @param o the context object.
1365
     * @param fn {Function|String} the function to execute or the name of 
1366
     * the method in the 'o' object to execute.
1367
     * @param data [Array] data that is provided to the function.  This accepts
1368
     * either a single item or an array.  If an array is provided, the
1369
     * function is executed with one parameter for each array item.  If
1370
     * you need to pass a single array parameter, it needs to be wrapped in
1371
     * an array [myarray].
1372
     * @param periodic {boolean} if true, executes continuously at supplied 
1373
     * interval until canceled.
1374
     * @return {object} a timer object. Call the cancel() method on this object to 
1375
     * stop the timer.
1376
     */
1377
    var later = function(when, o, fn, data, periodic) {
1378
        when = when || 0; 
1379
        o = o || {};
1380
        var m=fn, d=data, f, r;
1381
1382
        if (L.isString(fn)) {
1383
            m = o[fn];
1384
        }
1385
1386
        if (!m) {
1387
            Y.fail("method undefined");
1388
        }
1389
1390
        if (!L.isArray(d)) {
1391
            d = [data];
1392
        }
1393
1394
        f = function() {
1395
            m.apply(o, d);
1396
        };
1397
1398
        r = (periodic) ? setInterval(f, when) : setTimeout(f, when);
1399
1400
        return {
1401
            interval: periodic,
1402
            cancel: function() {
1403
                if (this.interval) {
1404
                    clearInterval(r);
1405
                } else {
1406
                    clearTimeout(r);
1407
                }
1408
            }
1409
        };
1410
    };
1411
1412
    Y.later = later;
1413
    L.later = later;
1414
1415
}, "3.0.0pr1");
1416
/*
1417
 * YUI initializer
1418
 * @module yui
1419
 * @submodule init
1420
 */
1421
(function() {
1422
1423
    var min = ['yui-base', 'log', 'lang', 'array', 'core'], core,
1424
1425
    M = function(Y) {
1426
1427
        var C = Y.config;
1428
1429
        // apply the minimal required functionality
1430
        Y.use.apply(Y, min);
1431
1432
1433
        if (C.core) {
1434
1435
            core = C.core;
1436
1437
        } else {
1438
1439
            core = ["object", "ua", "later"];
1440
1441
            core.push(
1442
              "get", 
1443
              "loader");
1444
        }
1445
1446
        Y.use.apply(Y, core);
1447
1448
    };
1449
     
1450
    YUI.add("yui", M, "3.0.0pr1");
1451
    
1452
    // {
1453
        // the following will be bound automatically when this code is loaded
1454
      //   use: core
1455
    // });
1456
1457
})();