2
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
8
YUI.add('compat', function(Y) {
11
var COMPAT_ARG = '~yui|2|compat~';
14
if (window.YAHOO != YUI) {
16
// get any existing YAHOO obj props
17
var o = (window.YAHOO) ? YUI.merge(window.YAHOO) : null;
19
// Make the YUI global the YAHOO global
22
// augment old YAHOO props
29
Y.namespace("util", "widget", "example");
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;
40
getVersion: function(name) {
41
return this.Env.modules[name] || null;
47
// add old lang properties
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);
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);
60
// extend: Y.bind(Y.extend, Y),
62
// merge: Y.bind(Y.merge, Y)
66
L.augment = L.augmentProto;
68
L.hasOwnProperty = function(o, k) {
69
return (o.hasOwnProperty(k));
72
Y.augmentProto = L.augmentProto;
74
// add register function
76
register: function(name, mainClass, data) {
77
var mods = Y.Env.modules;
79
mods[name] = { versions:[], builds:[] };
81
var m=mods[name],v=data.version,b=data.build,ls=Y.Env.listeners;
87
m.mainClass = mainClass;
88
// fire the module load listeners
89
for (var i=0;i<ls.length;i=i+1) {
92
// label the main class
94
mainClass.VERSION = v;
97
Y.log("mainClass is undefined for module " + name, "warn");
102
// add old load listeners
103
if ("undefined" !== typeof YAHOO_config) {
104
var l=YAHOO_config.listener,ls=Y.Env.listeners,unique=true,i;
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) {
121
// add old registration for yahoo
122
Y.register("yahoo", Y, {version: "3.0.0", build: "1549"});
133
* @deprecated use Y.Env.UA.webkit
135
isSafari: Y.UA.webkit,
143
* @deprecated use Y.Env.UA.webkit
148
* Normalized keycodes for webkit/safari
149
* @property webkitKeymap
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)
171
* @deprecated use Y.Env.UA.ie
177
* @method _getScrollLeft
181
_getScrollLeft: function() {
182
return this._getScroll()[1];
187
* @method _getScrollTop
191
_getScrollTop: function() {
192
return this._getScroll()[0];
196
* Returns the scrollTop and scrollLeft. Used to calculate the
197
* pageX and pageY in Internet Explorer
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];
207
return [db.scrollTop, db.scrollLeft];
214
* Returns the event's pageX
216
* @param {Event} ev the event
217
* @return {int} the event's pageX
220
getPageX: function(ev) {
226
x += this._getScrollLeft();
234
* Returns the charcode for an event
235
* @method getCharCode
236
* @param {Event} ev the event
237
* @return {int} the event's charCode
240
getCharCode: function(ev) {
241
var code = ev.keyCode || ev.charCode || 0;
243
// webkit normalization
244
if (Y.UA.webkit && (code in Y.Event.webkitKeymap)) {
245
code = Y.Event.webkitKeymap[code];
251
* Returns the event's pageY
253
* @param {Event} ev the event
254
* @return {int} the event's pageY
257
getPageY: function(ev) {
263
y += this._getScrollTop();
272
* Returns the pageX and pageY properties as an indexed array.
274
* @param {Event} ev the event
275
* @return {[x, y]} the pageX and pageY properties of the event
278
getXY: function(ev) {
279
return [this.getPageX(ev), this.getPageY(ev)];
283
* Returns the event's related target
284
* @method getRelatedTarget
285
* @param {Event} ev the event
286
* @return {HTMLElement} the event's relatedTarget
289
getRelatedTarget: function(ev) {
290
var t = ev.relatedTarget;
292
if (ev.type == "mouseout") {
294
} else if (ev.type == "mouseover") {
299
return this.resolveTextNode(t);
303
* Returns the time of the event. If the time is not included, the
304
* event is modified using the current time.
306
* @param {Event} ev the event
307
* @return {Date} the time of the event
310
getTime: function(ev) {
312
var t = new Date().getTime();
325
* Convenience method for stopPropagation + preventDefault
327
* @param {Event} ev the event
330
stopEvent: function(ev) {
331
this.stopPropagation(ev);
332
this.preventDefault(ev);
336
* Stops event propagation
337
* @method stopPropagation
338
* @param {Event} ev the event
341
stopPropagation: function(ev) {
342
if (ev.stopPropagation) {
343
ev.stopPropagation();
345
ev.cancelBubble = true;
350
* Prevents the default behavior of the event
351
* @method preventDefault
352
* @param {Event} ev the event
355
preventDefault: function(ev) {
356
if (ev.preventDefault) {
359
ev.returnValue = false;
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.
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
376
getTarget: function(ev, resolveTextNode) {
377
var t = ev.target || ev.srcElement;
378
return this.resolveTextNode(t);
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
390
resolveTextNode: function(node) {
391
if (node && 3 == node.nodeType) {
392
return node.parentNode;
399
* We cache elements bound by id because when the unload event
400
* fires, we can no longer use document.getElementById
404
* @deprecated Elements are not cached any longer
406
getEl: function(id) {
414
* Calls Y.Event.attach with the correct argument order
415
* @method removeListener
417
Y.Event.removeListener = function(el, type, fn, data, override) {
419
var context, a=[type, fn, el];
424
context = (override === true) ? data : override;
433
return Y.Event.detach.apply(Y.Event, a);
437
* Calls Y.Event.detach with the correct argument order
438
* @method addListener
440
Y.Event.addListener = function(el, type, fn, data, override) {
442
// Y.log('addListener:');
443
// Y.log(Y.Array(arguments, 0, true), 1);
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];
453
context = (override === true) ? data : override;
462
return Y.Event.attach.apply(Y.Event, a);
465
Y.Event.on = Y.Event.addListener;
467
var newOnavail = Y.Event.onAvailable;
469
Y.Event.onAvailable = function(id, fn, p_obj, p_override) {
470
return newOnavail(id, fn, p_obj, p_override, false, true);
473
Y.Event.onContentReady = function(id, fn, p_obj, p_override) {
474
return newOnavail(id, fn, p_obj, p_override, true, true);
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);
483
Y.util.Event = Y.Event;
485
var CE = function(type, oScope, silent, signature) {
490
silent: silent || false
491
// signature: signature || CE.LIST
494
CE.superclass.constructor.call(this, type, o);
496
this.signature = signature || CE.LIST;
499
Y.extend(CE, Y.CustomEvent, {
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
514
* Subscriber listener sigature constant. The FLAT type returns two
515
* parameters: the first argument passed to fire and the optional
517
* @property YAHOO.util.CustomEvent.FLAT
523
Y.util.CustomEvent = CE;
525
var EP = function() {
526
//console.log('Compat CustomEvent constructor executed: ' + this._yuid);
528
var sub = this.subscribe;
529
Y.EventTarget.apply(this, arguments);
530
this.subscribe = sub;
531
this.__yuiepinit = function() {};
535
Y.extend(EP, Y.EventTarget, {
537
createEvent: function(type, o) {
539
o.signature = o.signature || CE.FLAT;
540
return this.publish(type, o);
543
subscribe: function(type, fn, obj, override) {
544
var ce = this._yuievt.events[type] || this.createEvent(type),
545
a = Y.Array(arguments);
547
if (override && true !== override) {
552
Y.EventTarget.prototype.subscribe.apply(this, a);
555
fireEvent: function(type) {
556
return this.fire.apply(this, arguments);
559
hasEvent: function(type) {
560
return this.getEvent(type);
564
Y.util.EventProvider = EP;
569
Y.register("event", Y, {version: "3.0.0", build: "1549"});
572
var propertyCache = {};
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
579
var hyphenToCamel = function(property) {
580
if ( !patterns.HYPHEN.test(property) ) {
581
return property; // no hyphens
584
if (propertyCache[property]) { // already converted
585
return propertyCache[property];
588
var converted = property;
590
while( patterns.HYPHEN.exec(converted) ) {
591
converted = converted.replace(RegExp.$1,
592
RegExp.$1.substr(1).toUpperCase());
595
propertyCache[property] = 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
603
if (el.nodeType || el.item) { // Node, or NodeList
607
if (typeof el === 'string') { // id
608
return document.getElementById(el);
611
if ('length' in el) { // array-like
613
for (var i = 0, len = el.length; i < len; ++i) {
614
c[c.length] = Dom.get(el[i]);
620
return el; // some other object, just pass it back
626
isAncestor: function(haystack, needle) {
627
return YUI.DOM.contains(Dom.get(haystack), Dom.get(needle));
630
inDocument: function(el) {
631
return Dom.isAncestor(Y.config.doc.documentElement, el);
634
batch: function(el, method, o, override, args) {
635
el = (el && (el.tagName || el.item)) ? el : Dom.get(el); // skip get() when possible
637
if (!el || !method) {
641
args = Y.Array(args);
643
var scope = (override) ? o : window;
645
var apply = function(el) {
647
var tmp = slice.call(args);
649
return method.apply(scope, tmp);
651
return method.call(scope, el, o);
655
if (el.tagName || el.length === undefined) { // element or not array-like
661
for (var i = 0, len = el.length; i < len; ++i) {
662
collection[collection.length] = apply(el[i]);
668
// 2.x returns false if already present
669
_addClass: function(el, className) {
670
if ( YUI.DOM.hasClass(el, className) ) {
674
YUI.DOM.addClass(el, className);
678
// 2.x returns false if not present
679
_removeClass: function(el, className) {
680
if ( !YUI.DOM.hasClass(el, className) ) {
684
YUI.DOM.removeClass(el, className);
688
// 2.x returns false if no newClass or same as oldClass
689
_replaceClass: function(el, oldClass, newClass) {
690
if (!newClass || oldClass === newClass) {
694
YUI.DOM.replaceClass(el, oldClass, newClass);
698
getElementsByClassName: function(className, tag, root) {
700
root = (root) ? Dom.get(root) : Y.config.doc;
703
nodes = Y.Selector.query(tag + '.' + className, root);
708
getElementsBy: function(method, tag, root) {
710
root = (root) ? Dom.get(root) : null || document;
714
nodes = YUI.DOM.byTag(tag, root, method);
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,
727
_guid: function(el, prefix) {
728
prefix = prefix || 'yui-gen';
729
Dom._id_counter = Dom._id_counter || 0;
731
if (el && el.id) { // do not override existing ID
735
var id = prefix + Dom._id_counter++;
744
_region: function(el) {
745
if ( (el.parentNode === null || el.offsetParent === null ||
746
YUI.DOM.getStyle(el, 'display') == 'none') && el != el.ownerDocument.body) {
750
return YUI.DOM.region(el);
754
_ancestorByClass: function(element, className) {
755
return YUI.DOM.ancestor(element, function(el) {
756
return YUI.DOM.hasClass(el, className);
760
_ancestorByTag: function(element, tag) {
761
tag = tag.toUpperCase();
762
return YUI.DOM.ancestor(element, function(el) {
763
return el.tagName.toUpperCase() === tag;
768
var slice = [].slice;
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);
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));
795
insertAfter: function(newNode, refNode) {
796
YUI.DOM.insertAfter(Dom.get(newNode), Dom.get(refNode));
800
Y.each(wrapped, wrap);
803
getStyle: YUI.DOM.getStyle,
804
setStyle: YUI.DOM.setStyle,
805
getXY: YUI.DOM.getXY,
806
setXY: YUI.DOM.setXY,
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
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);
828
YAHOO.util.Region = function(t, r, b, l) {
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 );
843
// this.logger.debug("does " + this + " contain " + region + " ... " + ret);
846
YAHOO.util.Region.prototype.getArea = function() {
847
return ( (this.bottom - this.top) * (this.right - this.left) );
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 );
856
if (b >= t && r >= l) {
857
return new YAHOO.util.Region(t, r, b, l);
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 );
869
return new YAHOO.util.Region(t, r, b, l);
872
YAHOO.util.Region.prototype.toString = function() {
873
return ( "Region {" +
875
", right: " + this.right +
876
", bottom: " + this.bottom +
877
", left: " + this.left +
881
YAHOO.util.Region.getRegion = function(el) {
882
return YUI.DOM.region(el);
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
891
this.x = this.right = this.left = this[0] = x;
892
this.y = this.top = this.bottom = this[1] = y;
895
YAHOO.util.Point.prototype = new YAHOO.util.Region();
899
}, '3.0.0' ,{requires:['dom','event']});
900
YUI._setup(); YUI.use('dom', 'event', 'compat');