~landscape/lazr-js/trunk

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/3.0.0/build/compat/compat-debug.js

  • Committer: Sidnei da Silva
  • Date: 2009-10-21 21:43:07 UTC
  • mfrom: (120.2.15 yui-3.0.0)
  • mto: (124.5.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 126.
  • Revision ID: sidnei.da.silva@canonical.com-20091021214307-mpul9404n317puk5
- Merge from yui-3.0.0, resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
 
3
Code licensed under the BSD License:
 
4
http://developer.yahoo.net/yui/license.txt
 
5
version: 3.0.0
 
6
build: 1549
 
7
*/
 
8
YUI.add('compat', function(Y) {
 
9
 
 
10
 
 
11
var COMPAT_ARG = '~yui|2|compat~';
 
12
 
 
13
 
 
14
if (window.YAHOO != YUI) {
 
15
 
 
16
    // get any existing YAHOO obj props
 
17
    var o = (window.YAHOO) ? YUI.merge(window.YAHOO) : null;
 
18
 
 
19
    // Make the YUI global the YAHOO global
 
20
    window.YAHOO = YUI;
 
21
 
 
22
    // augment old YAHOO props
 
23
    if (o) {
 
24
        Y.mix(Y, o);
 
25
    }
 
26
}
 
27
 
 
28
// add old namespaces
 
29
Y.namespace("util", "widget", "example");
 
30
 
 
31
// case/location change
 
32
Y.env = (Y.env) ? Y.mix(Y.env, Y.Env) : Y.Env;
 
33
Y.lang = (Y.lang) ? Y.mix(Y.lang, Y.Lang) : Y.Lang;
 
34
Y.env.ua = Y.UA; 
 
35
 
 
36
// support Y.register
 
37
Y.mix(Y.env, {
 
38
        modules: [],
 
39
        listeners: [],
 
40
        getVersion: function(name) {
 
41
            return this.Env.modules[name] || null;
 
42
        }
 
43
});
 
44
 
 
45
var L = Y.lang;
 
46
 
 
47
// add old lang properties 
 
48
Y.mix(L, {
 
49
 
 
50
    augmentObject: function(r, s) {
 
51
        var a = arguments, wl = (a.length > 2) ? Y.Array(a, 2, true) : null;
 
52
        return Y.mix(r, s, (wl), wl);
 
53
    },
 
54
 
 
55
    augmentProto: function(r, s) {
 
56
        var a = arguments, wl = (a.length > 2) ? Y.Array(a, 2, true) : null;
 
57
        return Y.mix(r, s, (wl), wl, 1);
 
58
    },
 
59
 
 
60
    // extend: Y.bind(Y.extend, Y), 
 
61
    extend: Y.extend,
 
62
    // merge: Y.bind(Y.merge, Y)
 
63
    merge: Y.merge
 
64
}, true);
 
65
 
 
66
L.augment = L.augmentProto;
 
67
 
 
68
L.hasOwnProperty = function(o, k) {
 
69
    return (o.hasOwnProperty(k));
 
70
};
 
71
 
 
72
Y.augmentProto = L.augmentProto;
 
73
 
 
74
// add register function
 
75
Y.mix(Y, {
 
76
    register: function(name, mainClass, data) {
 
77
        var mods = Y.Env.modules;
 
78
        if (!mods[name]) {
 
79
            mods[name] = { versions:[], builds:[] };
 
80
        }
 
81
        var m=mods[name],v=data.version,b=data.build,ls=Y.Env.listeners;
 
82
        m.name = name;
 
83
        m.version = v;
 
84
        m.build = b;
 
85
        m.versions.push(v);
 
86
        m.builds.push(b);
 
87
        m.mainClass = mainClass;
 
88
        // fire the module load listeners
 
89
        for (var i=0;i<ls.length;i=i+1) {
 
90
            ls[i](m);
 
91
        }
 
92
        // label the main class
 
93
        if (mainClass) {
 
94
            mainClass.VERSION = v;
 
95
            mainClass.BUILD = b;
 
96
        } else {
 
97
            Y.log("mainClass is undefined for module " + name, "warn");
 
98
        }
 
99
    }
 
100
});
 
101
 
 
102
// add old load listeners
 
103
if ("undefined" !== typeof YAHOO_config) {
 
104
    var l=YAHOO_config.listener,ls=Y.Env.listeners,unique=true,i;
 
105
    if (l) {
 
106
        // if YAHOO is loaded multiple times we need to check to see if
 
107
        // this is a new config object.  If it is, add the new component
 
108
        // load listener to the stack
 
109
        for (i=0;i<ls.length;i=i+1) {
 
110
            if (ls[i]==l) {
 
111
                unique=false;
 
112
                break;
 
113
            }
 
114
        }
 
115
        if (unique) {
 
116
            ls.push(l);
 
117
        }
 
118
    }
 
119
}
 
120
    
 
121
// add old registration for yahoo
 
122
Y.register("yahoo", Y, {version: "3.0.0", build: "1549"});
 
123
 
 
124
if (Y.Event) {
 
125
 
 
126
    var o = {
 
127
        
 
128
        /**
 
129
         * Safari detection
 
130
         * @property isSafari
 
131
         * @private
 
132
         * @static
 
133
         * @deprecated use Y.Env.UA.webkit
 
134
         */
 
135
        isSafari: Y.UA.webkit,
 
136
        
 
137
        /**
 
138
         * webkit version
 
139
         * @property webkit
 
140
         * @type string
 
141
         * @private
 
142
         * @static
 
143
         * @deprecated use Y.Env.UA.webkit
 
144
         */
 
145
        webkit: Y.UA.webkit,
 
146
 
 
147
        /**
 
148
         * Normalized keycodes for webkit/safari
 
149
         * @property webkitKeymap
 
150
         * @type {int: int}
 
151
         * @private
 
152
         * @static
 
153
         * @final
 
154
         */
 
155
        webkitKeymap: {
 
156
            63232: 38, // up
 
157
            63233: 40, // down
 
158
            63234: 37, // left
 
159
            63235: 39, // right
 
160
            63276: 33, // page up
 
161
            63277: 34, // page down
 
162
            25: 9      // SHIFT-TAB (Safari provides a different key code in
 
163
                       // this case, even though the shiftKey modifier is set)
 
164
        },
 
165
        
 
166
        /**
 
167
         * IE detection 
 
168
         * @property isIE
 
169
         * @private
 
170
         * @static
 
171
         * @deprecated use Y.Env.UA.ie
 
172
         */
 
173
        isIE: Y.UA.ie,
 
174
 
 
175
        /**
 
176
         * Returns scrollLeft
 
177
         * @method _getScrollLeft
 
178
         * @static
 
179
         * @private
 
180
         */
 
181
        _getScrollLeft: function() {
 
182
            return this._getScroll()[1];
 
183
        },
 
184
 
 
185
        /**
 
186
         * Returns scrollTop
 
187
         * @method _getScrollTop
 
188
         * @static
 
189
         * @private
 
190
         */
 
191
        _getScrollTop: function() {
 
192
            return this._getScroll()[0];
 
193
        },
 
194
 
 
195
        /**
 
196
         * Returns the scrollTop and scrollLeft.  Used to calculate the 
 
197
         * pageX and pageY in Internet Explorer
 
198
         * @method _getScroll
 
199
         * @static
 
200
         * @private
 
201
         */
 
202
        _getScroll: function() {
 
203
            var d = Y.config.doc, dd = d.documentElement, db = d.body;
 
204
            if (dd && (dd.scrollTop || dd.scrollLeft)) {
 
205
                return [dd.scrollTop, dd.scrollLeft];
 
206
            } else if (db) {
 
207
                return [db.scrollTop, db.scrollLeft];
 
208
            } else {
 
209
                return [0, 0];
 
210
            }
 
211
        },
 
212
 
 
213
        /**
 
214
         * Returns the event's pageX
 
215
         * @method getPageX
 
216
         * @param {Event} ev the event
 
217
         * @return {int} the event's pageX
 
218
         * @static
 
219
         */
 
220
        getPageX: function(ev) {
 
221
            var x = ev.pageX;
 
222
            if (!x && 0 !== x) {
 
223
                x = ev.clientX || 0;
 
224
 
 
225
                if ( Y.UA.ie ) {
 
226
                    x += this._getScrollLeft();
 
227
                }
 
228
            }
 
229
 
 
230
            return x;
 
231
        },
 
232
 
 
233
        /**
 
234
         * Returns the charcode for an event
 
235
         * @method getCharCode
 
236
         * @param {Event} ev the event
 
237
         * @return {int} the event's charCode
 
238
         * @static
 
239
         */
 
240
        getCharCode: function(ev) {
 
241
            var code = ev.keyCode || ev.charCode || 0;
 
242
 
 
243
            // webkit normalization
 
244
            if (Y.UA.webkit && (code in Y.Event.webkitKeymap)) {
 
245
                code = Y.Event.webkitKeymap[code];
 
246
            }
 
247
            return code;
 
248
        },
 
249
 
 
250
        /**
 
251
         * Returns the event's pageY
 
252
         * @method getPageY
 
253
         * @param {Event} ev the event
 
254
         * @return {int} the event's pageY
 
255
         * @static
 
256
         */
 
257
        getPageY: function(ev) {
 
258
            var y = ev.pageY;
 
259
            if (!y && 0 !== y) {
 
260
                y = ev.clientY || 0;
 
261
 
 
262
                if ( Y.UA.ie ) {
 
263
                    y += this._getScrollTop();
 
264
                }
 
265
            }
 
266
 
 
267
 
 
268
            return y;
 
269
        },
 
270
 
 
271
        /**
 
272
         * Returns the pageX and pageY properties as an indexed array.
 
273
         * @method getXY
 
274
         * @param {Event} ev the event
 
275
         * @return {[x, y]} the pageX and pageY properties of the event
 
276
         * @static
 
277
         */
 
278
        getXY: function(ev) {
 
279
            return [this.getPageX(ev), this.getPageY(ev)];
 
280
        },
 
281
 
 
282
        /**
 
283
         * Returns the event's related target 
 
284
         * @method getRelatedTarget
 
285
         * @param {Event} ev the event
 
286
         * @return {HTMLElement} the event's relatedTarget
 
287
         * @static
 
288
         */
 
289
        getRelatedTarget: function(ev) {
 
290
            var t = ev.relatedTarget;
 
291
            if (!t) {
 
292
                if (ev.type == "mouseout") {
 
293
                    t = ev.toElement;
 
294
                } else if (ev.type == "mouseover") {
 
295
                    t = ev.fromElement;
 
296
                }
 
297
            }
 
298
 
 
299
            return this.resolveTextNode(t);
 
300
        },
 
301
 
 
302
        /**
 
303
         * Returns the time of the event.  If the time is not included, the
 
304
         * event is modified using the current time.
 
305
         * @method getTime
 
306
         * @param {Event} ev the event
 
307
         * @return {Date} the time of the event
 
308
         * @static
 
309
         */
 
310
        getTime: function(ev) {
 
311
            if (!ev.time) {
 
312
                var t = new Date().getTime();
 
313
                try {
 
314
                    ev.time = t;
 
315
                } catch(ex) { 
 
316
                    this.lastError = ex;
 
317
                    return t;
 
318
                }
 
319
            }
 
320
 
 
321
            return ev.time;
 
322
        },
 
323
 
 
324
        /**
 
325
         * Convenience method for stopPropagation + preventDefault
 
326
         * @method stopEvent
 
327
         * @param {Event} ev the event
 
328
         * @static
 
329
         */
 
330
        stopEvent: function(ev) {
 
331
            this.stopPropagation(ev);
 
332
            this.preventDefault(ev);
 
333
        },
 
334
 
 
335
        /**
 
336
         * Stops event propagation
 
337
         * @method stopPropagation
 
338
         * @param {Event} ev the event
 
339
         * @static
 
340
         */
 
341
        stopPropagation: function(ev) {
 
342
            if (ev.stopPropagation) {
 
343
                ev.stopPropagation();
 
344
            } else {
 
345
                ev.cancelBubble = true;
 
346
            }
 
347
        },
 
348
 
 
349
        /**
 
350
         * Prevents the default behavior of the event
 
351
         * @method preventDefault
 
352
         * @param {Event} ev the event
 
353
         * @static
 
354
         */
 
355
        preventDefault: function(ev) {
 
356
            if (ev.preventDefault) {
 
357
                ev.preventDefault();
 
358
            } else {
 
359
                ev.returnValue = false;
 
360
            }
 
361
        },
 
362
 
 
363
        /**
 
364
         * Returns the event's target element.  Safari sometimes provides
 
365
         * a text node, and this is automatically resolved to the text
 
366
         * node's parent so that it behaves like other browsers.
 
367
         * @method getTarget
 
368
         * @param {Event} ev the event
 
369
         * @param {boolean} resolveTextNode when set to true the target's
 
370
         *                  parent will be returned if the target is a 
 
371
         *                  text node.  @deprecated, the text node is
 
372
         *                  now resolved automatically
 
373
         * @return {HTMLElement} the event's target
 
374
         * @static
 
375
         */
 
376
        getTarget: function(ev, resolveTextNode) {
 
377
            var t = ev.target || ev.srcElement;
 
378
            return this.resolveTextNode(t);
 
379
        },
 
380
 
 
381
        /**
 
382
         * In some cases, some browsers will return a text node inside
 
383
         * the actual element that was targeted.  This normalizes the
 
384
         * return value for getTarget and getRelatedTarget.
 
385
         * @method resolveTextNode
 
386
         * @param {HTMLElement} node node to resolve
 
387
         * @return {HTMLElement} the normized node
 
388
         * @static
 
389
         */
 
390
        resolveTextNode: function(node) {
 
391
            if (node && 3 == node.nodeType) {
 
392
                return node.parentNode;
 
393
            } else {
 
394
                return node;
 
395
            }
 
396
        },
 
397
 
 
398
        /**
 
399
         * We cache elements bound by id because when the unload event 
 
400
         * fires, we can no longer use document.getElementById
 
401
         * @method getEl
 
402
         * @static
 
403
         * @private
 
404
         * @deprecated Elements are not cached any longer
 
405
         */
 
406
        getEl: function(id) {
 
407
            return Y.get(id);
 
408
        }
 
409
    };
 
410
 
 
411
    Y.mix(Y.Event, o);
 
412
 
 
413
    /**
 
414
     * Calls Y.Event.attach with the correct argument order
 
415
     * @method removeListener
 
416
     */
 
417
    Y.Event.removeListener = function(el, type, fn, data, override) {
 
418
 
 
419
        var context, a=[type, fn, el];
 
420
 
 
421
        if (data) {
 
422
 
 
423
            if (override) {
 
424
                context = (override === true) ? data : override;
 
425
            }
 
426
 
 
427
            a.push(context);
 
428
            a.push(data);
 
429
        }
 
430
 
 
431
        a.push(COMPAT_ARG);
 
432
 
 
433
        return Y.Event.detach.apply(Y.Event, a);
 
434
    };
 
435
 
 
436
    /**
 
437
     * Calls Y.Event.detach with the correct argument order
 
438
     * @method addListener
 
439
     */
 
440
    Y.Event.addListener = function(el, type, fn, data, override) {
 
441
 
 
442
        // Y.log('addListener:');
 
443
        // Y.log(Y.Array(arguments, 0, true), 1);
 
444
 
 
445
        // var a = Y.Array(arguments, 0, true), el = a.shift();
 
446
        // a.splice(2, 0, el);
 
447
        // return Y.Event.attach.apply(Y.Event, a);
 
448
        var context, a=[type, fn, el];
 
449
 
 
450
        if (data) {
 
451
 
 
452
            if (override) {
 
453
                context = (override === true) ? data : override;
 
454
            }
 
455
 
 
456
            a.push(context);
 
457
            a.push(data);
 
458
        }
 
459
 
 
460
        a.push(COMPAT_ARG);
 
461
 
 
462
        return Y.Event.attach.apply(Y.Event, a);
 
463
    };
 
464
 
 
465
    Y.Event.on = Y.Event.addListener;
 
466
 
 
467
    var newOnavail = Y.Event.onAvailable;
 
468
 
 
469
    Y.Event.onAvailable = function(id, fn, p_obj, p_override) {
 
470
        return newOnavail(id, fn, p_obj, p_override, false, true);
 
471
    };
 
472
 
 
473
    Y.Event.onContentReady = function(id, fn, p_obj, p_override) {
 
474
        return newOnavail(id, fn, p_obj, p_override, true, true);
 
475
    };
 
476
 
 
477
    Y.Event.onDOMReady = function(fn) {
 
478
        var a = Y.Array(arguments, 0, true);
 
479
        a.unshift('event:ready');
 
480
        return Y.on.apply(Y, a);
 
481
    };
 
482
 
 
483
    Y.util.Event = Y.Event;
 
484
 
 
485
    var CE = function(type, oScope, silent, signature) {
 
486
        //debugger;
 
487
 
 
488
        var o = {
 
489
            context: oScope,
 
490
            silent: silent || false
 
491
            // signature: signature || CE.LIST
 
492
        };
 
493
 
 
494
        CE.superclass.constructor.call(this, type, o);
 
495
 
 
496
        this.signature = signature || CE.LIST;
 
497
    };
 
498
 
 
499
    Y.extend(CE, Y.CustomEvent, {
 
500
 
 
501
    });
 
502
 
 
503
    /**
 
504
     * Subscriber listener sigature constant.  The LIST type returns three
 
505
     * parameters: the event type, the array of args passed to fire, and
 
506
     * the optional custom object
 
507
     * @property YAHOO.util.CustomEvent.LIST
 
508
     * @static
 
509
     * @type int
 
510
     */
 
511
    CE.LIST = 0;
 
512
 
 
513
    /**
 
514
     * Subscriber listener sigature constant.  The FLAT type returns two
 
515
     * parameters: the first argument passed to fire and the optional 
 
516
     * custom object
 
517
     * @property YAHOO.util.CustomEvent.FLAT
 
518
     * @static
 
519
     * @type int
 
520
     */
 
521
    CE.FLAT = 1;
 
522
 
 
523
    Y.util.CustomEvent = CE;
 
524
 
 
525
    var EP = function() {
 
526
        //console.log('Compat CustomEvent constructor executed: ' + this._yuid);
 
527
        if (!this._yuievt) {
 
528
            var sub = this.subscribe;
 
529
            Y.EventTarget.apply(this, arguments);
 
530
            this.subscribe = sub;
 
531
            this.__yuiepinit = function() {};
 
532
        }
 
533
    };
 
534
 
 
535
    Y.extend(EP, Y.EventTarget, {
 
536
 
 
537
        createEvent: function(type, o) {
 
538
            o = o || {};
 
539
            o.signature = o.signature || CE.FLAT;
 
540
            return this.publish(type, o);
 
541
        },
 
542
 
 
543
        subscribe: function(type, fn, obj, override) {
 
544
            var ce = this._yuievt.events[type] || this.createEvent(type),
 
545
                a = Y.Array(arguments);
 
546
 
 
547
            if (override && true !== override) {
 
548
                // a[2] = override;
 
549
                // a[1] = obj;
 
550
            }
 
551
 
 
552
            Y.EventTarget.prototype.subscribe.apply(this, a);
 
553
        },
 
554
 
 
555
        fireEvent: function(type) {
 
556
            return this.fire.apply(this, arguments);
 
557
        },
 
558
 
 
559
        hasEvent: function(type) {
 
560
            return this.getEvent(type);
 
561
        }
 
562
    });
 
563
 
 
564
    Y.util.EventProvider = EP;
 
565
 
 
566
}
 
567
 
 
568
 
 
569
Y.register("event", Y, {version: "3.0.0", build: "1549"});
 
570
 
 
571
 
 
572
var propertyCache = {};
 
573
var patterns = {
 
574
    HYPHEN: /(-[a-z])/i, // to normalize get/setStyle
 
575
    ROOT_TAG: /^body|html$/i, // body for quirks mode, html for standards,
 
576
    OP_SCROLL:/^(?:inline|table-row)$/i
 
577
};
 
578
 
 
579
var hyphenToCamel = function(property) {
 
580
    if ( !patterns.HYPHEN.test(property) ) {
 
581
        return property; // no hyphens
 
582
    }
 
583
    
 
584
    if (propertyCache[property]) { // already converted
 
585
        return propertyCache[property];
 
586
    }
 
587
   
 
588
    var converted = property;
 
589
 
 
590
    while( patterns.HYPHEN.exec(converted) ) {
 
591
        converted = converted.replace(RegExp.$1,
 
592
                RegExp.$1.substr(1).toUpperCase());
 
593
    }
 
594
    
 
595
    propertyCache[property] = converted;
 
596
    return converted;
 
597
    //return property.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug
 
598
};
 
599
 
 
600
var Dom = {
 
601
    get: function(el) {
 
602
        if (el) {
 
603
            if (el.nodeType || el.item) { // Node, or NodeList
 
604
                return el;
 
605
            }
 
606
 
 
607
            if (typeof el === 'string') { // id
 
608
                return document.getElementById(el);
 
609
            }
 
610
            
 
611
            if ('length' in el) { // array-like 
 
612
                var c = [];
 
613
                for (var i = 0, len = el.length; i < len; ++i) {
 
614
                    c[c.length] = Dom.get(el[i]);
 
615
                }
 
616
                
 
617
                return c;
 
618
            }
 
619
 
 
620
            return el; // some other object, just pass it back
 
621
        }
 
622
 
 
623
        return null;
 
624
    },
 
625
 
 
626
    isAncestor: function(haystack, needle) {
 
627
        return YUI.DOM.contains(Dom.get(haystack), Dom.get(needle));
 
628
    },
 
629
 
 
630
    inDocument: function(el) {
 
631
        return Dom.isAncestor(Y.config.doc.documentElement, el);
 
632
    },
 
633
   
 
634
    batch: function(el, method, o, override, args) {
 
635
        el = (el && (el.tagName || el.item)) ? el : Dom.get(el); // skip get() when possible 
 
636
 
 
637
        if (!el || !method) { 
 
638
            return false; 
 
639
        }  
 
640
        if (args) {
 
641
            args = Y.Array(args);
 
642
        }
 
643
        var scope = (override) ? o : window; 
 
644
         
 
645
        var apply = function(el) {
 
646
            if (args) {
 
647
                var tmp = slice.call(args);
 
648
                tmp.unshift(el);
 
649
                return method.apply(scope, tmp);
 
650
            } else {
 
651
                return method.call(scope, el, o);
 
652
            }
 
653
        };
 
654
 
 
655
        if (el.tagName || el.length === undefined) { // element or not array-like  
 
656
            return apply(el); 
 
657
        }  
 
658
 
 
659
        var collection = []; 
 
660
         
 
661
        for (var i = 0, len = el.length; i < len; ++i) { 
 
662
            collection[collection.length] = apply(el[i]);
 
663
        } 
 
664
        
 
665
        return collection;
 
666
    },
 
667
 
 
668
    // 2.x returns false if already present
 
669
    _addClass: function(el, className) {
 
670
        if ( YUI.DOM.hasClass(el, className) ) {
 
671
            return false;
 
672
        }
 
673
 
 
674
        YUI.DOM.addClass(el, className);
 
675
        return true;
 
676
    },
 
677
 
 
678
    // 2.x returns false if not present
 
679
    _removeClass: function(el, className) {
 
680
        if ( !YUI.DOM.hasClass(el, className) ) {
 
681
            return false;
 
682
        }
 
683
 
 
684
        YUI.DOM.removeClass(el, className);
 
685
        return true;
 
686
    },
 
687
 
 
688
    // 2.x returns false if no newClass or same as oldClass
 
689
    _replaceClass: function(el, oldClass, newClass) {
 
690
        if (!newClass || oldClass === newClass) {
 
691
            return false;
 
692
        }
 
693
 
 
694
        YUI.DOM.replaceClass(el, oldClass, newClass);
 
695
        return true;
 
696
    },
 
697
 
 
698
    getElementsByClassName: function(className, tag, root) {
 
699
        tag = tag || '*';
 
700
        root = (root) ? Dom.get(root) : Y.config.doc; 
 
701
        var nodes = [];
 
702
        if (root) {
 
703
            nodes = Y.Selector.query(tag + '.' + className, root);
 
704
        }
 
705
        return nodes;
 
706
    },
 
707
 
 
708
    getElementsBy: function(method, tag, root) {
 
709
        tag = tag || '*';
 
710
        root = (root) ? Dom.get(root) : null || document;
 
711
 
 
712
        var nodes = [];
 
713
        if (root) {
 
714
            nodes = YUI.DOM.byTag(tag, root, method);
 
715
        }
 
716
        return nodes;
 
717
    },
 
718
 
 
719
    getViewportWidth: YUI.DOM.winWidth,
 
720
    getViewportHeight: YUI.DOM.winHeight,
 
721
    getDocumentWidth: YUI.DOM.docWidth,
 
722
    getDocumentHeight: YUI.DOM.docHeight,
 
723
    getDocumentScrollTop: YUI.DOM.docScrollY,
 
724
    getDocumentScrollLeft: YUI.DOM.docScrollX,
 
725
    getDocumentHeight: YUI.DOM.docHeight,
 
726
 
 
727
    _guid: function(el, prefix) {
 
728
        prefix = prefix || 'yui-gen';
 
729
        Dom._id_counter = Dom._id_counter || 0;
 
730
 
 
731
        if (el && el.id) { // do not override existing ID
 
732
            return el.id;
 
733
        } 
 
734
 
 
735
        var id = prefix + Dom._id_counter++;
 
736
 
 
737
        if (el) {
 
738
            el.id = id;
 
739
        }
 
740
        
 
741
        return id;
 
742
    },
 
743
 
 
744
    _region: function(el) {
 
745
        if ( (el.parentNode === null || el.offsetParent === null ||
 
746
                YUI.DOM.getStyle(el, 'display') == 'none') && el != el.ownerDocument.body) {
 
747
            return false;
 
748
        }
 
749
 
 
750
        return YUI.DOM.region(el);
 
751
 
 
752
    },
 
753
 
 
754
    _ancestorByClass: function(element, className) {
 
755
        return YUI.DOM.ancestor(element, function(el) {
 
756
            return YUI.DOM.hasClass(el, className);
 
757
        });
 
758
    },
 
759
 
 
760
    _ancestorByTag: function(element, tag) {
 
761
        tag = tag.toUpperCase();
 
762
        return YUI.DOM.ancestor(element, function(el) {
 
763
            return el.tagName.toUpperCase() === tag;
 
764
        });
 
765
    }
 
766
};
 
767
 
 
768
var slice = [].slice;
 
769
 
 
770
var wrap = function(fn, name) {
 
771
    Dom[name] = function() {
 
772
        var args = slice.call(arguments);
 
773
        args[0] = Dom.get(args[0]);
 
774
        return fn.apply(Dom, args);
 
775
    };
 
776
};
 
777
 
 
778
var wrapped = {
 
779
    getAncestorBy: YUI.DOM.ancestor,
 
780
    getAncestorByClassName: Dom._ancestorByClass,
 
781
    getAncestorByTagName: Dom._ancestorByTag,
 
782
    getPreviousSiblingBy: YUI.DOM.previous,
 
783
    getPreviousSibling: YUI.DOM.previous,
 
784
    getNextSiblingBy: YUI.DOM.next,
 
785
    getNextSibling: YUI.DOM.next,
 
786
    getFirstChildBy: YUI.DOM.firstChild,
 
787
    getFirstChild: YUI.DOM.firstChild,
 
788
    getLastChildBy: YUI.DOM.lastChild,
 
789
    getLastChild: YUI.DOM.lastChild,
 
790
    getChildrenBy: YUI.DOM.children,
 
791
    getChildren: YUI.DOM.children,
 
792
    insertBefore: function(newNode, refNode) {
 
793
        YUI.DOM.insertBefore(Dom.get(newNode), Dom.get(refNode));
 
794
    },
 
795
    insertAfter: function(newNode, refNode) {
 
796
        YUI.DOM.insertAfter(Dom.get(newNode), Dom.get(refNode));
 
797
    }
 
798
};
 
799
 
 
800
Y.each(wrapped, wrap);
 
801
 
 
802
var batched = {
 
803
    getStyle: YUI.DOM.getStyle,
 
804
    setStyle: YUI.DOM.setStyle,
 
805
    getXY: YUI.DOM.getXY,
 
806
    setXY: YUI.DOM.setXY,
 
807
    getX: YUI.DOM.getX,
 
808
    getY: YUI.DOM.getY,
 
809
    setX: YUI.DOM.setX, 
 
810
    setY: YUI.DOM.setY, 
 
811
    getRegion: Dom._region,
 
812
    hasClass: YUI.DOM.hasClass,
 
813
    addClass: Dom._addClass,
 
814
    removeClass: Dom._removeClass,
 
815
    replaceClass: Dom._replaceClass,
 
816
    generateId: Dom._guid
 
817
};
 
818
 
 
819
Y.each(batched, function(v, n) {
 
820
    Dom[n] = function(el) {
 
821
        var args = slice.call(arguments, 1);
 
822
        return Dom.batch(el, v, null, null, args);
 
823
    };
 
824
});
 
825
 
 
826
Y.util.Dom = Dom;
 
827
 
 
828
YAHOO.util.Region = function(t, r, b, l) {
 
829
    this.top = t;
 
830
    this[1] = t;
 
831
    this.right = r;
 
832
    this.bottom = b;
 
833
    this.left = l;
 
834
    this[0] = l;
 
835
};
 
836
 
 
837
YAHOO.util.Region.prototype.contains = function(region) {
 
838
    return ( region.left   >= this.left   && 
 
839
             region.right  <= this.right  && 
 
840
             region.top    >= this.top    && 
 
841
             region.bottom <= this.bottom    );
 
842
 
 
843
    // this.logger.debug("does " + this + " contain " + region + " ... " + ret);
 
844
};
 
845
 
 
846
YAHOO.util.Region.prototype.getArea = function() {
 
847
    return ( (this.bottom - this.top) * (this.right - this.left) );
 
848
};
 
849
 
 
850
YAHOO.util.Region.prototype.intersect = function(region) {
 
851
    var t = Math.max( this.top,    region.top    );
 
852
    var r = Math.min( this.right,  region.right  );
 
853
    var b = Math.min( this.bottom, region.bottom );
 
854
    var l = Math.max( this.left,   region.left   );
 
855
    
 
856
    if (b >= t && r >= l) {
 
857
        return new YAHOO.util.Region(t, r, b, l);
 
858
    } else {
 
859
        return null;
 
860
    }
 
861
};
 
862
 
 
863
YAHOO.util.Region.prototype.union = function(region) {
 
864
    var t = Math.min( this.top,    region.top    );
 
865
    var r = Math.max( this.right,  region.right  );
 
866
    var b = Math.max( this.bottom, region.bottom );
 
867
    var l = Math.min( this.left,   region.left   );
 
868
 
 
869
    return new YAHOO.util.Region(t, r, b, l);
 
870
};
 
871
 
 
872
YAHOO.util.Region.prototype.toString = function() {
 
873
    return ( "Region {"    +
 
874
             "top: "       + this.top    + 
 
875
             ", right: "   + this.right  + 
 
876
             ", bottom: "  + this.bottom + 
 
877
             ", left: "    + this.left   + 
 
878
             "}" );
 
879
};
 
880
 
 
881
YAHOO.util.Region.getRegion = function(el) {
 
882
    return YUI.DOM.region(el);
 
883
};
 
884
 
 
885
YAHOO.util.Point = function(x, y) {
 
886
   if (YAHOO.lang.isArray(x)) { // accept input from Dom.getXY, Event.getXY, etc.
 
887
      y = x[1]; // dont blow away x yet
 
888
      x = x[0];
 
889
   }
 
890
   
 
891
    this.x = this.right = this.left = this[0] = x;
 
892
    this.y = this.top = this.bottom = this[1] = y;
 
893
};
 
894
 
 
895
YAHOO.util.Point.prototype = new YAHOO.util.Region();
 
896
 
 
897
 
 
898
 
 
899
}, '3.0.0' ,{requires:['dom','event']});
 
900
YUI._setup(); YUI.use('dom', 'event', 'compat');