2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('compat', function(Y) {
15 var COMPAT_ARG = '~yui|2|compat~', o, L;
18 if (window.YAHOO != YUI) {
20 // get any existing YAHOO obj props
21 o = (window.YAHOO) ? YUI.merge(window.YAHOO) : null;
23 // Make the YUI global the YAHOO global
26 // augment old YAHOO props
33 Y.namespace("util", "widget", "example");
35 // case/location change
36 Y.env = (Y.env) ? Y.mix(Y.env, Y.Env) : Y.Env;
37 Y.lang = (Y.lang) ? Y.mix(Y.lang, Y.Lang) : Y.Lang;
44 getVersion: function(name) {
45 return this.Env.modules[name] || null;
51 // add old lang properties
54 augmentObject: function(r, s) {
55 var a = arguments, wl = (a.length > 2) ? Y.Array(a, 2, true) : null,
56 ov = (wl), args = [r, s, ov];
58 if (wl && wl[0] !== true) {
62 return Y.mix.apply(Y, args);
65 augmentProto: function(r, s) {
66 var a = arguments, wl = (a.length > 2) ? Y.Array(a, 2, true) : null,
67 ov = (wl), args = [r, s, ov];
68 return Y.augment.apply(Y, args);
71 // extend: Y.bind(Y.extend, Y),
73 // merge: Y.bind(Y.merge, Y)
77 L.augment = L.augmentProto;
79 L.hasOwnProperty = function(o, k) {
80 return (o.hasOwnProperty(k));
83 Y.augmentProto = L.augmentProto;
85 // add register function
87 register: function(name, mainClass, data) {
88 var mods = Y.Env.modules;
90 mods[name] = { versions:[], builds:[] };
92 var m=mods[name],v=data.version,b=data.build,ls=Y.Env.listeners;
98 m.mainClass = mainClass;
99 // fire the module load listeners
100 for (var i=0;i<ls.length;i=i+1) {
103 // label the main class
105 mainClass.VERSION = v;
112 // add old load listeners
113 if ("undefined" != typeof YAHOO_config) {
114 var l=YAHOO_config.listener,ls=Y.Env.listeners,unique=true,i;
116 // if YAHOO is loaded multiple times we need to check to see if
117 // this is a new config object. If it is, add the new component
118 // load listener to the stack
119 for (i=0;i<ls.length;i=i+1) {
131 // add old registration for yahoo
132 Y.register("yahoo", Y, {version: "3.3.0", build: "3167"});
143 * @deprecated use Y.Env.UA.webkit
145 isSafari: Y.UA.webkit,
153 * @deprecated use Y.Env.UA.webkit
158 * Normalized keycodes for webkit/safari
159 * @property webkitKeymap
170 63276: 33, // page up
171 63277: 34, // page down
172 25: 9 // SHIFT-TAB (Safari provides a different key code in
173 // this case, even though the shiftKey modifier is set)
181 * @deprecated use Y.Env.UA.ie
187 * @method _getScrollLeft
191 _getScrollLeft: function() {
192 return this._getScroll()[1];
197 * @method _getScrollTop
201 _getScrollTop: function() {
202 return this._getScroll()[0];
206 * Returns the scrollTop and scrollLeft. Used to calculate the
207 * pageX and pageY in Internet Explorer
212 _getScroll: function() {
213 var d = Y.config.doc, dd = d.documentElement, db = d.body;
214 if (dd && (dd.scrollTop || dd.scrollLeft)) {
215 return [dd.scrollTop, dd.scrollLeft];
217 return [db.scrollTop, db.scrollLeft];
224 * Returns the event's pageX
226 * @param {Event} ev the event
227 * @return {int} the event's pageX
230 getPageX: function(ev) {
236 x += this._getScrollLeft();
244 * Returns the charcode for an event
245 * @method getCharCode
246 * @param {Event} ev the event
247 * @return {int} the event's charCode
250 getCharCode: function(ev) {
251 var code = ev.keyCode || ev.charCode || 0;
253 // webkit normalization
254 if (Y.UA.webkit && (code in Y.Event.webkitKeymap)) {
255 code = Y.Event.webkitKeymap[code];
261 * Returns the event's pageY
263 * @param {Event} ev the event
264 * @return {int} the event's pageY
267 getPageY: function(ev) {
273 y += this._getScrollTop();
282 * Returns the pageX and pageY properties as an indexed array.
284 * @param {Event} ev the event
285 * @return {[x, y]} the pageX and pageY properties of the event
288 getXY: function(ev) {
289 return [this.getPageX(ev), this.getPageY(ev)];
293 * Returns the event's related target
294 * @method getRelatedTarget
295 * @param {Event} ev the event
296 * @return {HTMLElement} the event's relatedTarget
299 getRelatedTarget: function(ev) {
300 var t = ev.relatedTarget;
302 if (ev.type == "mouseout") {
304 } else if (ev.type == "mouseover") {
309 return this.resolveTextNode(t);
313 * Returns the time of the event. If the time is not included, the
314 * event is modified using the current time.
316 * @param {Event} ev the event
317 * @return {Date} the time of the event
320 getTime: function(ev) {
322 var t = new Date().getTime();
335 * Convenience method for stopPropagation + preventDefault
337 * @param {Event} ev the event
340 stopEvent: function(ev) {
341 this.stopPropagation(ev);
342 this.preventDefault(ev);
346 * Stops event propagation
347 * @method stopPropagation
348 * @param {Event} ev the event
351 stopPropagation: function(ev) {
352 if (ev.stopPropagation) {
353 ev.stopPropagation();
355 ev.cancelBubble = true;
360 * Prevents the default behavior of the event
361 * @method preventDefault
362 * @param {Event} ev the event
365 preventDefault: function(ev) {
366 if (ev.preventDefault) {
369 ev.returnValue = false;
374 * Returns the event's target element. Safari sometimes provides
375 * a text node, and this is automatically resolved to the text
376 * node's parent so that it behaves like other browsers.
378 * @param {Event} ev the event
379 * @param {boolean} resolveTextNode when set to true the target's
380 * parent will be returned if the target is a
381 * text node. @deprecated, the text node is
382 * now resolved automatically
383 * @return {HTMLElement} the event's target
386 getTarget: function(ev, resolveTextNode) {
387 var t = ev.target || ev.srcElement;
388 return this.resolveTextNode(t);
392 * In some cases, some browsers will return a text node inside
393 * the actual element that was targeted. This normalizes the
394 * return value for getTarget and getRelatedTarget.
395 * @method resolveTextNode
396 * @param {HTMLElement} node node to resolve
397 * @return {HTMLElement} the normized node
400 resolveTextNode: function(node) {
401 if (node && 3 == node.nodeType) {
402 return node.parentNode;
409 * We cache elements bound by id because when the unload event
410 * fires, we can no longer use document.getElementById
414 * @deprecated Elements are not cached any longer
416 getEl: function(id) {
424 * Calls Y.Event.attach with the correct argument order
425 * @method removeListener
427 Y.Event.removeListener = function(el, type, fn, data, override) {
429 var context, a=[type, fn, el];
434 context = (override === true) ? data : override;
443 return Y.Event.detach.apply(Y.Event, a);
447 * Calls Y.Event.detach with the correct argument order
448 * @method addListener
450 Y.Event.addListener = function(el, type, fn, data, override) {
453 // var a = Y.Array(arguments, 0, true), el = a.shift();
454 // a.splice(2, 0, el);
455 // return Y.Event.attach.apply(Y.Event, a);
456 var context, a=[type, fn, el];
461 context = (override === true) ? data : override;
470 return Y.Event.attach.apply(Y.Event, a);
473 Y.Event.on = Y.Event.addListener;
475 var newOnavail = Y.Event.onAvailable;
477 Y.Event.onAvailable = function(id, fn, p_obj, p_override) {
478 return newOnavail(id, fn, p_obj, p_override, false, true);
481 Y.Event.onContentReady = function(id, fn, p_obj, p_override) {
482 return newOnavail(id, fn, p_obj, p_override, true, true);
485 Y.Event.onDOMReady = function() {
486 var a = Y.Array(arguments, 0, true);
487 a.unshift('domready');
488 return Y.on.apply(Y, a);
491 Y.util.Event = Y.Event;
493 var CE = function(type, oScope, silent, signature) {
498 silent: silent || false
499 // signature: signature || CE.LIST
502 CE.superclass.constructor.call(this, type, o);
504 this.signature = signature || CE.LIST;
507 Y.extend(CE, Y.CustomEvent, {
512 * Subscriber listener sigature constant. The LIST type returns three
513 * parameters: the event type, the array of args passed to fire, and
514 * the optional custom object
515 * @property YAHOO.util.CustomEvent.LIST
522 * Subscriber listener sigature constant. The FLAT type returns two
523 * parameters: the first argument passed to fire and the optional
525 * @property YAHOO.util.CustomEvent.FLAT
531 Y.util.CustomEvent = CE;
533 var EP = function() {
534 //console.log('Compat CustomEvent constructor executed: ' + this._yuid);
536 var sub = this.subscribe;
537 Y.EventTarget.apply(this, arguments);
538 this.subscribe = sub;
539 this.__yuiepinit = function() {};
543 Y.extend(EP, Y.EventTarget, {
545 createEvent: function(type, o) {
546 // if (!this._yuievt) {
547 // Y.EventTarget.call(this);
550 o.signature = o.signature || CE.FLAT;
551 return this.publish(type, o);
554 subscribe: function(type, fn, obj, override) {
555 var ce = this._yuievt.events[type] || this.createEvent(type),
556 a = Y.Array(arguments);
558 if (override && true !== override) {
563 Y.EventTarget.prototype.on.apply(this, a);
566 fireEvent: function(type) {
567 return this.fire.apply(this, arguments);
570 hasEvent: function(type) {
572 Y.EventTarget.call(this);
574 return this.getEvent(type);
578 Y.util.EventProvider = EP;
583 Y.register("event", Y.util.Event, {version: "3.3.0", build: "3167"});
586 var propertyCache = {};
588 HYPHEN: /(-[a-z])/i, // to normalize get/setStyle
589 ROOT_TAG: /^body|html$/i, // body for quirks mode, html for standards,
590 OP_SCROLL:/^(?:inline|table-row)$/i
592 var slice = [].slice;
594 var hyphenToCamel = function(property) {
595 if ( !patterns.HYPHEN.test(property) ) {
596 return property; // no hyphens
599 if (propertyCache[property]) { // already converted
600 return propertyCache[property];
603 var converted = property;
605 while( patterns.HYPHEN.exec(converted) ) {
606 converted = converted.replace(RegExp.$1,
607 RegExp.$1.substr(1).toUpperCase());
610 propertyCache[property] = converted;
612 //return property.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug
616 _firstChild: function(node) {
617 return Y.Selector.query('> *', node, true);
622 if (el.nodeType || el.item) { // Node, or NodeList
626 if (typeof el === 'string') { // id
627 return document.getElementById(el);
630 if ('length' in el) { // array-like
632 for (var i = 0, len = el.length; i < len; ++i) {
633 c[c.length] = Dom.get(el[i]);
639 return el; // some other object, just pass it back
645 isAncestor: function(haystack, needle) {
646 return YUI.DOM.contains(Dom.get(haystack), Dom.get(needle));
649 inDocument: function(el) {
650 return Dom.isAncestor(Y.config.doc.documentElement, el);
653 batch: function(el, method, o, override, args) {
654 el = (el && (el.tagName || el.item)) ? el : Dom.get(el); // skip get() when possible
656 if (!el || !method) {
660 args = Y.Array(args);
662 var scope = (override) ? o : window;
664 var apply = function(el) {
666 var tmp = slice.call(args);
668 return method.apply(scope, tmp);
670 return method.call(scope, el, o);
674 if (el.tagName || el.length === undefined) { // element or not array-like
680 for (var i = 0, len = el.length; i < len; ++i) {
681 collection[collection.length] = apply(el[i]);
687 // 2.x returns false if already present
688 _addClass: function(el, className) {
689 if ( YUI.DOM.hasClass(el, className) ) {
693 YUI.DOM.addClass(el, className);
697 // 2.x returns false if not present
698 _removeClass: function(el, className) {
699 if ( !YUI.DOM.hasClass(el, className) ) {
703 YUI.DOM.removeClass(el, className);
707 // 2.x returns false if no newClass or same as oldClass
708 _replaceClass: function(el, oldClass, newClass) {
709 if (!newClass || oldClass === newClass) {
713 YUI.DOM.replaceClass(el, oldClass, newClass);
717 getElementsByClassName: function(className, tag, root) {
719 root = (root) ? Dom.get(root) : Y.config.doc;
722 nodes = Y.Selector.query(tag + '.' + className, root);
727 getElementsBy: function(method, tag, root) {
729 root = (root) ? Dom.get(root) : null || document;
732 var nodes = Y.Selector.query(tag, root);
736 getViewportWidth: YUI.DOM.winWidth,
737 getViewportHeight: YUI.DOM.winHeight,
738 getDocumentWidth: YUI.DOM.docWidth,
739 getDocumentHeight: YUI.DOM.docHeight,
740 getDocumentScrollTop: YUI.DOM.docScrollY,
741 getDocumentScrollLeft: YUI.DOM.docScrollX,
743 _guid: function(el, prefix) {
744 prefix = prefix || 'yui-gen';
745 Dom._id_counter = Dom._id_counter || 0;
747 if (el && el.id) { // do not override existing ID
751 var id = prefix + Dom._id_counter++;
760 _region: function(el) {
761 if ( (el.parentNode === null || el.offsetParent === null ||
762 YUI.DOM.getStyle(el, 'display') == 'none') && el != el.ownerDocument.body) {
766 return YUI.DOM.region(el);
770 _ancestorByClass: function(element, className) {
771 return YUI.DOM.ancestor(element, function(el) {
772 return YUI.DOM.hasClass(el, className);
776 _ancestorByTag: function(element, tag) {
777 tag = tag.toUpperCase();
778 return YUI.DOM.ancestor(element, function(el) {
779 return el.tagName.toUpperCase() === tag;
785 var wrap = function(fn, name) {
786 Dom[name] = function() {
787 var args = slice.call(arguments);
788 args[0] = Dom.get(args[0]);
789 return fn.apply(Dom, args);
794 getAncestorBy: YUI.DOM.ancestor,
795 getAncestorByClassName: Dom._ancestorByClass,
796 getAncestorByTagName: Dom._ancestorByTag,
797 getPreviousSiblingBy: YUI.DOM.previous,
798 getPreviousSibling: YUI.DOM.previous,
799 getNextSiblingBy: YUI.DOM.next,
800 getNextSibling: YUI.DOM.next,
801 getFirstChildBy: Dom._firstChild,
802 getFirstChild: Dom._firstChild,
803 getLastChildBy: YUI.DOM.lastChild,
804 getLastChild: YUI.DOM.lastChild,
805 getChildrenBy: YUI.DOM.children,
806 getChildren: YUI.DOM.children,
807 insertBefore: function(newNode, refNode) {
808 YUI.DOM.insertBefore(Dom.get(newNode), Dom.get(refNode));
810 insertAfter: function(newNode, refNode) {
811 YUI.DOM.insertAfter(Dom.get(newNode), Dom.get(refNode));
815 Y.each(wrapped, wrap);
818 getStyle: YUI.DOM.getStyle,
819 setStyle: YUI.DOM.setStyle,
820 getXY: YUI.DOM.getXY,
821 setXY: YUI.DOM.setXY,
826 getRegion: Dom._region,
827 hasClass: YUI.DOM.hasClass,
828 addClass: Dom._addClass,
829 removeClass: Dom._removeClass,
830 replaceClass: Dom._replaceClass,
831 generateId: Dom._guid
834 Y.each(batched, function(v, n) {
835 Dom[n] = function(el) {
836 var args = slice.call(arguments, 1);
837 return Dom.batch(el, v, null, null, args);
843 YAHOO.util.Region = function(t, r, b, l) {
852 YAHOO.util.Region.prototype.contains = function(region) {
853 return ( region.left >= this.left &&
854 region.right <= this.right &&
855 region.top >= this.top &&
856 region.bottom <= this.bottom );
860 YAHOO.util.Region.prototype.getArea = function() {
861 return ( (this.bottom - this.top) * (this.right - this.left) );
864 YAHOO.util.Region.prototype.intersect = function(region) {
865 var t = Math.max( this.top, region.top );
866 var r = Math.min( this.right, region.right );
867 var b = Math.min( this.bottom, region.bottom );
868 var l = Math.max( this.left, region.left );
870 if (b >= t && r >= l) {
871 return new YAHOO.util.Region(t, r, b, l);
877 YAHOO.util.Region.prototype.union = function(region) {
878 var t = Math.min( this.top, region.top );
879 var r = Math.max( this.right, region.right );
880 var b = Math.max( this.bottom, region.bottom );
881 var l = Math.min( this.left, region.left );
883 return new YAHOO.util.Region(t, r, b, l);
886 YAHOO.util.Region.prototype.toString = function() {
887 return ( "Region {" +
889 ", right: " + this.right +
890 ", bottom: " + this.bottom +
891 ", left: " + this.left +
895 YAHOO.util.Region.getRegion = function(el) {
896 return YUI.DOM.region(el);
899 YAHOO.util.Point = function(x, y) {
900 if (YAHOO.lang.isArray(x)) { // accept input from Dom.getXY, Event.getXY, etc.
901 y = x[1]; // dont blow away x yet
905 this.x = this.right = this.left = this[0] = x;
906 this.y = this.top = this.bottom = this[1] = y;
909 YAHOO.util.Point.prototype = new YAHOO.util.Region();
911 YAHOO.register("dom", YAHOO.util.Dom, {version: "3.3.0", build: "3167"});
915 }, '3.3.0' ,{requires:['dom','dom-style-ie','event-base','dump','substitute']});
916 YUI._setup(); YUI.use('compat');