📄 tabview.js
字号:
if (current != value) { this.removeClass('yui-navset-' + current); } switch(value) { case 'bottom': this.appendChild(this._tabParent); break; } } }); /** * The index of the tab currently active. * @attribute activeIndex * @type Int */ this.setAttributeConfig('activeIndex', { 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 } }); /** * The tab currently active. * @attribute activeTab * @type YAHOO.widget.Tab */ this.setAttributeConfig('activeTab', { value: attr.activeTab, method: function(tab) { var activeTab = this.get('activeTab'); if (tab) { tab.set('active', true); //this._configs['activeIndex'].value = this.getTabIndex(tab); // keep in sync } if (activeTab && activeTab != tab) { activeTab.set('active', false); } 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 } }); this.on('activeTabChange', this._handleActiveTabChange); this.on('activeIndexChange', this._handleActiveIndexChange); if ( this._tabParent ) { _initTabs.call(this); } // Due to delegation we add all DOM_EVENTS to the TabView container // but IE will leak when unsupported events are added, so remove these this.DOM_EVENTS.submit = false; this.DOM_EVENTS.focus = false; this.DOM_EVENTS.blur = false; for (var type in this.DOM_EVENTS) { if ( YAHOO.lang.hasOwnProperty(this.DOM_EVENTS, type) ) { this.addListener.call(this, type, this.DOMEventHandler); } } }, _handleActiveTabChange: function(e) { var activeIndex = this.get('activeIndex'), newIndex = this.getTabIndex(e.newValue); if (activeIndex !== newIndex) { if (!(this.set('activeIndex', newIndex)) ) { // NOTE: setting // revert if activeIndex update fails (cancelled via beforeChange) this.set('activeTab', e.prevValue); } } }, _handleActiveIndexChange: 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 // revert if activeTab update fails (cancelled via beforeChange) this.set('activeIndex', e.prevValue); } } } }); /** * 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; } 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; // STRING CONSTANTS var CONTENT_EL = 'contentEl', LABEL_EL = 'labelEl', CONTENT = 'content', ELEMENT = 'element', CACHE_DATA = 'cacheData', DATA_SRC = 'dataSrc', DATA_LOADED = 'dataLoaded', DATA_TIMEOUT = 'dataTimeout', LOAD_METHOD = 'loadMethod', POST_DATA = 'postData', DISABLED = 'disabled'; /** * A representation of a Tab's label and content. * @namespace YAHOO.widget * @class Tab * @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. * @param {Object} properties A key map of initial properties */ var Tab = function(el, attr) { attr = attr || {}; if (arguments.length == 1 && !Lang.isString(el) && !el.nodeName) { attr = el; el = attr.element; } if (!el && !attr.element) { el = _createTabElement.call(this, attr); } this.loadHandler = { success: function(o) { this.set(CONTENT, o.responseText); }, failure: function(o) { } }; Tab.superclass.constructor.call(this, el, attr); this.DOM_EVENTS = {}; // delegating to tabView }; YAHOO.extend(Tab, YAHOO.util.Element, { /** * The default tag name for a Tab's inner element. * @property LABEL_INNER_TAGNAME * @type String * @default "em" */ LABEL_TAGNAME: 'em', /** * The class name applied to active tabs. * @property ACTIVE_CLASSNAME * @type String * @default "selected" */ ACTIVE_CLASSNAME: 'selected', /** * The class name applied to active tabs. * @property ACTIVE_CLASSNAME * @type String * @default "selected" */ HIDDEN_CLASSNAME: 'yui-hidden', /** * The title applied to active tabs. * @property ACTIVE_TITLE * @type String * @default "active" */ ACTIVE_TITLE: 'active', /** * The class name applied to disabled tabs. * @property DISABLED_CLASSNAME * @type String * @default "disabled" */ DISABLED_CLASSNAME: DISABLED, /** * The class name applied to dynamic tabs while loading. * @property LOADING_CLASSNAME * @type String * @default "disabled" */ LOADING_CLASSNAME: 'loading', /** * Provides a reference to the connection request object when data is * loaded dynamically. * @property dataConnection * @type Object */ dataConnection: null, /** * Object containing success and failure callbacks for loading data. * @property loadHandler * @type object */ loadHandler: null, _loading: false, /** * Provides a readable name for the tab. * @method toString * @return String */ toString: function() { var el = this.get(ELEMENT); var id = el.id || el.tagName; return "Tab " + id; }, /** * setAttributeConfigs TabView specific properties. * @method initAttributes * @param {Object} attr Hash of initial attributes */ initAttributes: function(attr) { attr = attr || {}; Tab.superclass.initAttributes.call(this, attr); var el = this.get(ELEMENT); /** * The event that triggers the tab's activation.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -