update YUI to 2.8.0r4

This commit is contained in:
Graham Knop 2009-09-21 12:54:44 -05:00
parent 27f474ec64
commit 2d28e0c0ba
2007 changed files with 344487 additions and 210070 deletions

View file

@ -1,8 +1,8 @@
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.6.0
version: 2.8.0r4
*/
(function() {
@ -13,13 +13,17 @@ version: 2.6.0
*
*/
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
Tab = YAHOO.widget.Tab,
doc = document;
var Y = YAHOO.util,
Dom = Y.Dom,
Event = Y.Event,
document = window.document,
// STRING CONSTANTS
var ELEMENT = 'element';
// STRING CONSTANTS
ACTIVE = 'active',
ACTIVE_INDEX = 'activeIndex',
ACTIVE_TAB = 'activeTab',
CONTENT_EL = 'contentEl',
ELEMENT = 'element',
/**
* A widget to control tabbed views.
@ -33,7 +37,7 @@ version: 2.6.0
* @param {Object} attr (optional) A key map of the tabView's
* initial attributes. Ignored if first arg is attributes object.
*/
var TabView = function(el, attr) {
TabView = function(el, attr) {
attr = attr || {};
if (arguments.length == 1 && !YAHOO.lang.isString(el) && !el.nodeName) {
attr = el; // treat first arg as attr object
@ -41,12 +45,12 @@ version: 2.6.0
}
if (!el && !attr.element) { // create if we dont have one
el = _createTabViewElement.call(this, attr);
el = this._createTabViewElement(attr);
}
TabView.superclass.constructor.call(this, el, attr);
TabView.superclass.constructor.call(this, el, attr);
};
YAHOO.extend(TabView, YAHOO.util.Element, {
YAHOO.extend(TabView, Y.Element, {
/**
* The className to add when building from scratch.
* @property CLASSNAME
@ -88,7 +92,13 @@ version: 2.6.0
* @return void
*/
addTab: function(tab, index) {
var tabs = this.get('tabs');
var tabs = this.get('tabs'),
before = this.getTab(index),
tabParent = this._tabParent,
contentParent = this._contentParent,
tabElement = tab.get(ELEMENT),
contentEl = tab.get(CONTENT_EL);
if (!tabs) { // not ready yet
this._queue[this._queue.length] = ['addTab', arguments];
return false;
@ -96,15 +106,7 @@ version: 2.6.0
index = (index === undefined) ? tabs.length : index;
var before = this.getTab(index);
var self = this;
var el = this.get(ELEMENT);
var tabParent = this._tabParent;
var contentParent = this._contentParent;
var tabElement = tab.get(ELEMENT);
var contentEl = tab.get('contentEl');
tabs.splice(index, 0, tab);
if ( before ) {
tabParent.insertBefore(tabElement, before.get(ELEMENT));
@ -116,33 +118,24 @@ version: 2.6.0
contentParent.appendChild(contentEl);
}
if ( !tab.get('active') ) {
if ( !tab.get(ACTIVE) ) {
tab.set('contentVisible', false, true); /* hide if not active */
} else {
this.set('activeTab', tab, true);
this.set(ACTIVE_TAB, tab, true);
this.set('activeIndex', index, true);
}
var activate = function(e) {
YAHOO.util.Event.preventDefault(e);
var silent = false;
this._initTabEvents(tab);
},
if (this == self.get('activeTab')) {
silent = true; // dont fire activeTabChange if already active
}
self.set('activeTab', this, silent);
};
tab.addListener( tab.get('activationEvent'), activate);
tab.addListener('activationEventChange', function(e) {
if (e.prevValue != e.newValue) {
tab.removeListener(e.prevValue, activate);
tab.addListener(e.newValue, activate);
}
});
tabs.splice(index, 0, tab);
_initTabEvents: function(tab) {
tab.addListener( tab.get('activationEvent'), tab._onActivate, this, tab);
tab.addListener( tab.get('activationEventChange'), tab._onActivationEventChange, this, tab);
},
_removeTabEvents: function(tab) {
tab.removeListener(tab.get('activationEvent'), tab._onActivate, this, tab);
tab.removeListener('activationEventChange', tab._onActivationEventChange, this, tab);
},
/**
@ -152,19 +145,18 @@ version: 2.6.0
* @return void
*/
DOMEventHandler: function(e) {
var el = this.get(ELEMENT);
var target = YAHOO.util.Event.getTarget(e);
var tabParent = this._tabParent;
var target = Event.getTarget(e),
tabParent = this._tabParent,
tabs = this.get('tabs'),
tab,
tabEl,
contentEl;
if (Dom.isAncestor(tabParent, target) ) {
var tabEl;
var tab = null;
var contentEl;
var tabs = this.get('tabs');
for (var i = 0, len = tabs.length; i < len; i++) {
tabEl = tabs[i].get(ELEMENT);
contentEl = tabs[i].get('contentEl');
contentEl = tabs[i].get(CONTENT_EL);
if ( target == tabEl || Dom.isAncestor(tabEl, target) ) {
tab = tabs[i];
@ -195,8 +187,8 @@ version: 2.6.0
* @return int
*/
getTabIndex: function(tab) {
var index = null;
var tabs = this.get('tabs');
var index = null,
tabs = this.get('tabs');
for (var i = 0, len = tabs.length; i < len; ++i) {
if (tab == tabs[i]) {
index = i;
@ -214,24 +206,27 @@ version: 2.6.0
* @return void
*/
removeTab: function(tab) {
var tabCount = this.get('tabs').length;
var tabCount = this.get('tabs').length,
index = this.getTabIndex(tab);
var index = this.getTabIndex(tab);
var nextIndex = index + 1;
if ( tab == this.get('activeTab') ) { // select next tab
if (tabCount > 1) {
if (index + 1 == tabCount) {
this.set('activeIndex', index - 1);
} else {
this.set('activeIndex', index + 1);
if ( tab === this.get(ACTIVE_TAB) ) {
if (tabCount > 1) { // select another tab
if (index + 1 === tabCount) { // if last, activate previous
this.set(ACTIVE_INDEX, index - 1);
} else { // activate next tab
this.set(ACTIVE_INDEX, index + 1);
}
} else { // no more tabs
this.set(ACTIVE_TAB, null);
}
}
this._removeTabEvents(tab);
this._tabParent.removeChild( tab.get(ELEMENT) );
this._contentParent.removeChild( tab.get('contentEl') );
this._contentParent.removeChild( tab.get(CONTENT_EL) );
this._configs.tabs.value.splice(index, 1);
tab.fireEvent('remove', { type: 'remove', tabview: this });
},
/**
@ -249,8 +244,12 @@ version: 2.6.0
* @method contentTransition
*/
contentTransition: function(newTab, oldTab) {
newTab.set('contentVisible', true);
oldTab.set('contentVisible', false);
if (newTab) {
newTab.set('contentVisible', true);
}
if (oldTab) {
oldTab.set('contentVisible', false);
}
},
/**
@ -289,7 +288,7 @@ version: 2.6.0
*/
this._tabParent =
this.getElementsByClassName(this.TAB_PARENT_CLASSNAME,
'ul' )[0] || _createTabParent.call(this);
'ul' )[0] || this._createTabParent();
/**
* The container of the tabView's content elements.
@ -299,7 +298,7 @@ version: 2.6.0
*/
this._contentParent =
this.getElementsByClassName(this.CONTENT_PARENT_CLASSNAME,
'div')[0] || _createContentParent.call(this);
'div')[0] || this._createContentParent();
/**
* How the Tabs should be oriented relative to the TabView.
@ -317,10 +316,8 @@ version: 2.6.0
this.removeClass('yui-navset-' + current);
}
switch(value) {
case 'bottom':
if (value === 'bottom') {
this.appendChild(this._tabParent);
break;
}
}
});
@ -330,13 +327,14 @@ version: 2.6.0
* @attribute activeIndex
* @type Int
*/
this.setAttributeConfig('activeIndex', {
this.setAttributeConfig(ACTIVE_INDEX, {
value: attr.activeIndex,
method: function(value) {
//this.set('activeTab', this.getTab(value));
},
validator: function(value) {
return !this.getTab(value).get('disabled'); // cannot activate if disabled
var ret = true;
if (value && this.getTab(value).get('disabled')) { // cannot activate if disabled
ret = false;
}
return ret;
}
});
@ -345,37 +343,40 @@ version: 2.6.0
* @attribute activeTab
* @type YAHOO.widget.Tab
*/
this.setAttributeConfig('activeTab', {
this.setAttributeConfig(ACTIVE_TAB, {
value: attr.activeTab,
method: function(tab) {
var activeTab = this.get('activeTab');
var activeTab = this.get(ACTIVE_TAB);
if (tab) {
tab.set('active', true);
//this._configs['activeIndex'].value = this.getTabIndex(tab); // keep in sync
tab.set(ACTIVE, true);
}
if (activeTab && activeTab != tab) {
activeTab.set('active', false);
if (activeTab && activeTab !== tab) {
activeTab.set(ACTIVE, false);
}
if (activeTab && tab != activeTab) { // no transition if only 1
if (activeTab && tab !== activeTab) { // no transition if only 1
this.contentTransition(tab, activeTab);
} else if (tab) {
tab.set('contentVisible', true);
}
},
validator: function(value) {
return !value.get('disabled'); // cannot activate if disabled
var ret = true;
if (value && value.get('disabled')) { // cannot activate if disabled
ret = false;
}
return ret;
}
});
this.on('activeTabChange', this._handleActiveTabChange);
this.on('activeIndexChange', this._handleActiveIndexChange);
this.on('activeTabChange', this._onActiveTabChange);
this.on('activeIndexChange', this._onActiveIndexChange);
YAHOO.log('attributes initialized', 'info', 'TabView');
if ( this._tabParent ) {
_initTabs.call(this);
this._initTabs();
}
// Due to delegation we add all DOM_EVENTS to the TabView container
@ -391,110 +392,136 @@ version: 2.6.0
}
},
_handleActiveTabChange: function(e) {
var activeIndex = this.get('activeIndex'),
/**
* Removes selected state from the given tab if it is the activeTab
* @method deselectTab
* @param {Int} index The tab index to deselect
*/
deselectTab: function(index) {
if (this.getTab(index) === this.get('activeTab')) {
this.set('activeTab', null);
}
},
/**
* Makes the tab at the given index the active tab
* @method selectTab
* @param {Int} index The tab index to be made active
*/
selectTab: function(index) {
this.set('activeTab', this.getTab(index));
},
_onActiveTabChange: function(e) {
var activeIndex = this.get(ACTIVE_INDEX),
newIndex = this.getTabIndex(e.newValue);
if (activeIndex !== newIndex) {
if (!(this.set('activeIndex', newIndex)) ) { // NOTE: setting
if (!(this.set(ACTIVE_INDEX, newIndex)) ) { // NOTE: setting
// revert if activeIndex update fails (cancelled via beforeChange)
this.set('activeTab', e.prevValue);
this.set(ACTIVE_TAB, e.prevValue);
}
}
},
_handleActiveIndexChange: function(e) {
_onActiveIndexChange: function(e) {
// no set if called from ActiveTabChange event
if (e.newValue !== this.getTabIndex(this.get('activeTab'))) {
if (!(this.set('activeTab', this.getTab(e.newValue))) ) { // NOTE: setting
if (e.newValue !== this.getTabIndex(this.get(ACTIVE_TAB))) {
if (!(this.set(ACTIVE_TAB, this.getTab(e.newValue))) ) { // NOTE: setting
// revert if activeTab update fails (cancelled via beforeChange)
this.set('activeIndex', e.prevValue);
this.set(ACTIVE_INDEX, e.prevValue);
}
}
},
/**
* Creates Tab instances from a collection of HTMLElements.
* @method _initTabs
* @private
* @return void
*/
_initTabs: function() {
var tabs = Dom.getChildren(this._tabParent),
contentElements = Dom.getChildren(this._contentParent),
activeIndex = this.get(ACTIVE_INDEX),
tab,
attr,
active;
for (var i = 0, len = tabs.length; i < len; ++i) {
attr = {};
if (contentElements[i]) {
attr.contentEl = contentElements[i];
}
tab = new YAHOO.widget.Tab(tabs[i], attr);
this.addTab(tab);
if (tab.hasClass(tab.ACTIVE_CLASSNAME) ) {
active = tab;
}
}
if (activeIndex) {
this.set(ACTIVE_TAB, this.getTab(activeIndex));
} else {
this._configs.activeTab.value = active; // dont invoke method
this._configs.activeIndex.value = this.getTabIndex(active);
}
},
_createTabViewElement: function(attr) {
var el = document.createElement('div');
if ( this.CLASSNAME ) {
el.className = this.CLASSNAME;
}
YAHOO.log('TabView Dom created', 'info', 'TabView');
return el;
},
_createTabParent: function(attr) {
var el = document.createElement('ul');
if ( this.TAB_PARENT_CLASSNAME ) {
el.className = this.TAB_PARENT_CLASSNAME;
}
this.get(ELEMENT).appendChild(el);
return el;
},
_createContentParent: function(attr) {
var el = document.createElement('div');
if ( this.CONTENT_PARENT_CLASSNAME ) {
el.className = this.CONTENT_PARENT_CLASSNAME;
}
this.get(ELEMENT).appendChild(el);
return el;
}
});
/**
* Creates Tab instances from a collection of HTMLElements.
* @method initTabs
* @private
* @return void
*/
var _initTabs = function() {
var tab,
attr,
contentEl;
var el = this.get(ELEMENT);
var tabs = Dom.getChildren(this._tabParent);
var contentElements = Dom.getChildren(this._contentParent);
for (var i = 0, len = tabs.length; i < len; ++i) {
attr = {};
if (contentElements[i]) {
attr.contentEl = contentElements[i];
}
tab = new YAHOO.widget.Tab(tabs[i], attr);
this.addTab(tab);
if (tab.hasClass(tab.ACTIVE_CLASSNAME) ) {
this._configs.activeTab.value = tab; // dont invoke method
this._configs.activeIndex.value = this.getTabIndex(tab);
}
}
};
var _createTabViewElement = function(attr) {
var el = doc.createElement('div');
if ( this.CLASSNAME ) {
el.className = this.CLASSNAME;
}
YAHOO.log('TabView Dom created', 'info', 'TabView');
return el;
};
var _createTabParent = function(attr) {
var el = doc.createElement('ul');
if ( this.TAB_PARENT_CLASSNAME ) {
el.className = this.TAB_PARENT_CLASSNAME;
}
this.get(ELEMENT).appendChild(el);
return el;
};
var _createContentParent = function(attr) {
var el = doc.createElement('div');
if ( this.CONTENT_PARENT_CLASSNAME ) {
el.className = this.CONTENT_PARENT_CLASSNAME;
}
this.get(ELEMENT).appendChild(el);
return el;
};
YAHOO.widget.TabView = TabView;
})();
(function() {
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
Lang = YAHOO.lang;
var Y = YAHOO.util,
Dom = Y.Dom,
Lang = YAHOO.lang,
// STRING CONSTANTS
var CONTENT_EL = 'contentEl',
ACTIVE_TAB = 'activeTab',
LABEL = 'label',
LABEL_EL = 'labelEl',
CONTENT = 'content',
CONTENT_EL = 'contentEl',
ELEMENT = 'element',
CACHE_DATA = 'cacheData',
DATA_SRC = 'dataSrc',
@ -502,7 +529,7 @@ version: 2.6.0
DATA_TIMEOUT = 'dataTimeout',
LOAD_METHOD = 'loadMethod',
POST_DATA = 'postData',
DISABLED = 'disabled';
DISABLED = 'disabled',
/**
* A representation of a Tab's label and content.
@ -511,10 +538,10 @@ version: 2.6.0
* @extends YAHOO.util.Element
* @constructor
* @param element {HTMLElement | String} (optional) The html element that
* represents the TabView. An element will be created if none provided.
* represents the Tab. An element will be created if none provided.
* @param {Object} properties A key map of initial properties
*/
var Tab = function(el, attr) {
Tab = function(el, attr) {
attr = attr || {};
if (arguments.length == 1 && !Lang.isString(el) && !el.nodeName) {
attr = el;
@ -522,7 +549,7 @@ version: 2.6.0
}
if (!el && !attr.element) {
el = _createTabElement.call(this, attr);
el = this._createTabElement(attr);
}
this.loadHandler = {
@ -557,9 +584,9 @@ version: 2.6.0
/**
* The class name applied to active tabs.
* @property ACTIVE_CLASSNAME
* @property HIDDEN_CLASSNAME
* @type String
* @default "selected"
* @default "yui-hidden"
*/
HIDDEN_CLASSNAME: 'yui-hidden',
@ -610,13 +637,13 @@ version: 2.6.0
* @return String
*/
toString: function() {
var el = this.get(ELEMENT);
var id = el.id || el.tagName;
var el = this.get(ELEMENT),
id = el.id || el.tagName;
return "Tab " + id;
},
/**
* setAttributeConfigs TabView specific properties.
* setAttributeConfigs Tab specific properties.
* @method initAttributes
* @param {Object} attr Hash of initial attributes
*/
@ -624,8 +651,6 @@ version: 2.6.0
attr = attr || {};
Tab.superclass.initAttributes.call(this, attr);
var el = this.get(ELEMENT);
/**
* The event that triggers the tab's activation.
* @attribute activationEvent
@ -641,8 +666,9 @@ version: 2.6.0
* @type HTMLElement
*/
this.setAttributeConfig(LABEL_EL, {
value: attr.labelEl || _getlabelEl.call(this),
value: attr[LABEL_EL] || this._getLabelEl(),
method: function(value) {
value = Dom.get(value);
var current = this.get(LABEL_EL);
if (current) {
@ -650,12 +676,9 @@ version: 2.6.0
return false; // already set
}
this.replaceChild(value, current);
} else if (el.firstChild) { // ensure label is firstChild by default
this.insertBefore(value, el.firstChild);
} else {
this.appendChild(value);
}
current.parentNode.replaceChild(value, current);
this.set(LABEL, value.innerHTML);
}
}
});
@ -664,15 +687,15 @@ version: 2.6.0
* @attribute label
* @type String
*/
this.setAttributeConfig('label', {
value: attr.label || _getLabel.call(this),
this.setAttributeConfig(LABEL, {
value: attr.label || this._getLabel(),
method: function(value) {
var labelEl = this.get(LABEL_EL);
if (!labelEl) { // create if needed
this.set(LABEL_EL, _createlabelEl.call(this));
this.set(LABEL_EL, this._createLabelEl());
}
_setLabel.call(this, value);
labelEl.innerHTML = value;
}
});
@ -682,15 +705,20 @@ version: 2.6.0
* @type HTMLElement
*/
this.setAttributeConfig(CONTENT_EL, {
value: attr.contentEl || document.createElement('div'),
value: attr[CONTENT_EL] || document.createElement('div'),
method: function(value) {
value = Dom.get(value);
var current = this.get(CONTENT_EL);
if (current) {
if (current == value) {
if (current === value) {
return false; // already set
}
this.replaceChild(value, current);
if (!this.get('selected')) {
Dom.addClass(value, this.HIDDEN_CLASSNAME);
}
current.parentNode.replaceChild(value, current);
this.set(CONTENT, value.innerHTML);
}
}
});
@ -701,14 +729,12 @@ version: 2.6.0
* @type String
*/
this.setAttributeConfig(CONTENT, {
value: attr.content,
value: attr[CONTENT],
method: function(value) {
this.get(CONTENT_EL).innerHTML = value;
}
});
var _dataLoaded = false;
/**
* The tab's data source, used for loading content dynamically.
* @attribute dataSrc
@ -836,7 +862,6 @@ version: 2.6.0
value: attr.contentVisible,
method: function(value) {
if (value) {
//this.get(CONTENT_EL).style.display = 'block';
Dom.removeClass(this.get(CONTENT_EL), this.HIDDEN_CLASSNAME);
if ( this.get(DATA_SRC) ) {
@ -855,7 +880,7 @@ version: 2.6.0
},
_dataConnect: function() {
if (!YAHOO.util.Connect) {
if (!Y.Connect) {
YAHOO.log('YAHOO.util.Connect dependency not met',
'error', 'Tab');
return false;
@ -863,7 +888,7 @@ version: 2.6.0
Dom.addClass(this.get(CONTENT_EL).parentNode, this.LOADING_CLASSNAME);
this._loading = true;
this.dataConnection = YAHOO.util.Connect.asyncRequest(
this.dataConnection = Y.Connect.asyncRequest(
this.get(LOAD_METHOD),
this.get(DATA_SRC),
{
@ -890,60 +915,81 @@ version: 2.6.0
this.get(POST_DATA)
);
},
_createTabElement: function(attr) {
var el = document.createElement('li'),
a = document.createElement('a'),
label = attr.label || null,
labelEl = attr.labelEl || null;
a.href = attr.href || '#'; // TODO: Use Dom.setAttribute?
el.appendChild(a);
if (labelEl) { // user supplied labelEl
if (!label) { // user supplied label
label = this._getLabel();
}
} else {
labelEl = this._createLabelEl();
}
a.appendChild(labelEl);
YAHOO.log('creating Tab Dom', 'info', 'Tab');
return el;
},
_getLabelEl: function() {
return this.getElementsByTagName(this.LABEL_TAGNAME)[0];
},
_createLabelEl: function() {
var el = document.createElement(this.LABEL_TAGNAME);
return el;
},
_getLabel: function() {
var el = this.get(LABEL_EL);
if (!el) {
return undefined;
}
return el.innerHTML;
},
_onActivate: function(e, tabview) {
var tab = this,
silent = false;
Y.Event.preventDefault(e);
if (tab === tabview.get(ACTIVE_TAB)) {
silent = true; // dont fire activeTabChange if already active
}
tabview.set(ACTIVE_TAB, tab, silent);
},
_onActivationEventChange: function(e) {
var tab = this;
if (e.prevValue != e.newValue) {
tab.removeListener(e.prevValue, tab._onActivate);
tab.addListener(e.newValue, tab._onActivate, this, tab);
}
}
});
var _createTabElement = function(attr) {
var el = document.createElement('li');
var a = document.createElement('a');
a.href = attr.href || '#';
el.appendChild(a);
var label = attr.label || null;
var labelEl = attr.labelEl || null;
if (labelEl) { // user supplied labelEl
if (!label) { // user supplied label
label = _getLabel.call(this, labelEl);
}
} else {
labelEl = _createlabelEl.call(this);
}
a.appendChild(labelEl);
YAHOO.log('creating Tab Dom', 'info', 'Tab');
return el;
};
var _getlabelEl = function() {
return this.getElementsByTagName(this.LABEL_TAGNAME)[0];
};
var _createlabelEl = function() {
var el = document.createElement(this.LABEL_TAGNAME);
return el;
};
var _setLabel = function(label) {
var el = this.get(LABEL_EL);
el.innerHTML = label;
};
var _getLabel = function() {
var label,
el = this.get(LABEL_EL);
if (!el) {
return undefined;
}
return el.innerHTML;
};
/**
* Fires when a tab is removed from the tabview
* @event remove
* @type CustomEvent
* @param {Event} An event object with fields for "type" ("remove")
* and "tabview" (the tabview instance it was removed from)
*/
YAHOO.widget.Tab = Tab;
})();
YAHOO.register("tabview", YAHOO.widget.TabView, {version: "2.6.0", build: "1321"});
YAHOO.register("tabview", YAHOO.widget.TabView, {version: "2.8.0r4", build: "2449"});