📄 zptabs-core.js
字号:
return; } if (!objTabDef) { return; } // Parse source // If no tabType is set to this tab if (!objTabDef.tabType) { // Use config option from Tabs objTabDef.tabType = this.config.tabType; } objTabDef.tabParent = this.config.tabs; objTabDef.changeUrl = this.config.changeUrl; if (!objTabDef.lang) { // Use config option from Tabs objTabDef.lang = this.config.lang; } if (!objTabDef.mouseOverChangesTab) { // Use config option from Tabs objTabDef.mouseOverChangesTab = this.config.mouseOverChangesTab; } if (!objTabDef.refreshOnTabChange) { // Use config option from Tabs objTabDef.refreshOnTabChange = this.config.refreshOnTabChange; } if (!objTabDef.shouldLoadOnInit) { // Use config option from Tabs objTabDef.shouldLoadOnInit = this.config.shouldLoadOnInit; } if (!objTabDef.overflow && '' != objTabDef.overflow) { // Use config option from Tabs objTabDef.overflow = this.config.overflow; } if (!objTabDef.closable) { // Use config option from Tabs objTabDef.closable = this.config.closable; } if (!objTabDef.closeAction) { // Use config option from Tabs objTabDef.closeAction = this.config.closeAction; } objTabDef.theme = this.config.theme; objTabDef.themePath = this.config.themePath; objTabDef.tabsId = this.id; // Create tab var objTab = this.newTab(objTabDef); // Return id of the tab through objTabDef if (objTab.id) { objTabDef.id = objTab.id; } var index = objTabDef.index; this.attachTab(objTab); this.addToTabBar(objTab); return objTab;};/** * Remove a tab from tabs. * * @private * * @param {string} strTabId Id of tab to remove */Zapatec.Tabs.prototype.removeTab = function(strTabId) { var objTab = this.getTab(strTabId); if (!objTab) { return; } // Determine if we are removing the currently active tab var isRemovingCurrent = objTab.index == this.currentIndex; var newCurrentIndex; if (objTab.index <= this.currentIndex) { newCurrentIndex = this.currentIndex - 1; if (newCurrentIndex < 0) { newCurrentIndex = 0; } } // Remove tab link from tab bar this.config.tabBar.removeChild(objTab.linkNode); this.tabs[strTabId] = null; // Create a new tabsArray without the tab being removed var newTabsArray = []; var toIndex = 0; for (var fromIndex = 0; fromIndex < this.tabsArray.length; ++fromIndex) { var fromTab = this.tabsArray[fromIndex]; if (objTab.index != fromTab.index) { fromTab.index = toIndex; newTabsArray[toIndex] = fromTab; ++toIndex; } } this.tabsArray = newTabsArray; // Remove content pane var container = objTab.container.getContainer(); objTab.container.getContainer().parentNode.removeChild(objTab.container.getContainer()); // if we are removing the currently active tab if (isRemovingCurrent) { this.currentIndex = -1; if (newCurrentIndex < this.tabsArray.length) { // Change tab this.changeTab(this.tabsArray[newCurrentIndex].id); } } if (newCurrentIndex) { // Set new currently active tab index this.currentIndex = newCurrentIndex; }}/** * Display a new tab. If onBeforeTabChange() returns false, the operation is * cancelled. * * @param {string} strNewTabId id of the new tab. */Zapatec.Tabs.prototype.changeTab = function(strNewTabId) { var strCurrTabId = null; var objTab = null; if (this.tabsArray[this.currentIndex]) { strCurrTabId = this.tabsArray[this.currentIndex].id; objTab = this.tabsArray[this.currentIndex]; } if (strCurrTabId != strNewTabId) { // Check if callback function allows to change tab var boolChangeTab = true; if (typeof this.config.onBeforeTabChange == 'function') { boolChangeTab = this.config.onBeforeTabChange({ oldTabId: strCurrTabId, newTabId: strNewTabId }); } if (!boolChangeTab) { // Return focus back if (objTab && objTab.linkNode.focus) { // Need to focus on tab first because FF 1.5 seems to have separate // focus for links objTab.linkNode.focus(); // Focus on content (in separate thread to let it focus on tab first) setTimeout(function() { if (objTab.focusOn && objTab.focusOn.focus) { objTab.focusOn.focus(); } }, 0); } return; } if (this.config.scrolls) { // If you're moving out of the visible tabs, scroll accordingly var _newTab = this.tabsArray[this.tabs[strNewTabId].index].linkNode; if (this.tabsArray[this.currentIndex]) { var _curTab = this.tabsArray[this.currentIndex].linkNode; } else { var _curTab = this.tabsArray[0].linkNode; } if (_curTab.arrayPosition < _newTab.arrayPosition) { if (this.config.scrollMultiple) { while (_newTab.style.display == 'none') { this.scrollTabsLeft(false); } } else { while (_newTab.style.display == 'none') { this.scrollOneTabLeft(false); } } } else if (_curTab.arrayPosition > _newTab.arrayPosition) { if (this.config.scrollMultiple) { while (_newTab.style.display == 'none') { this.scrollTabsRight(false); } } else { while (_newTab.style.display == 'none') { this.scrollOneTabRight(false); } } } } // Change tab if (objTab) { // Hide old tab objTab.container.hide(); Zapatec.Utils.removeClass(objTab.linkNode, 'zpTabsActive'); } objTab = this.tabs[strNewTabId]; // Show new tab if (!this.config.showEffect) { objTab.container.show(); } else { Zapatec.Effects.init(objTab.container.getContainer(), true, this.config.showEffectSpeed, this.config.showEffect); } // Refresh iframe element? if (this.config.refreshOnTabChange) { var iframes = objTab.container.getContainer().getElementsByTagName('iframe'); for (var i = 0; i < iframes.length; i++) { window.parent.frames[iframes[i].name].location.reload(true) } } if (!objTab.config.visible) { objTab.setVisible(true); } Zapatec.Utils.addClass(objTab.linkNode, 'zpTabsActive'); this.currentIndex = objTab.index; // Reload tab if needed and call onTabChange this.refreshTab(objTab, strCurrTabId, strNewTabId); }};/** * Reloads tab content if needed and calls onTabChange event after that. * * @private * @param {object} objTab tab to refresh * @param {string} strCurrTabId old tab id * @param {string} strNewTabId new tab id */Zapatec.Tabs.prototype.refreshTab = function(objTab, strCurrTabId, strNewTabId) { var url = null; if (objTab.config.contentType == "html/url") { url = objTab.config.content; } else { url = objTab.config.url; } // If onTabChange handler is specified if (typeof this.config.onTabChange == 'function') { var self = this; // Mark that onTabChange is to be called objTab.pendingOnTabChange = function() { // Call onTabChange event handler self.config.onTabChange({ oldTabId: strCurrTabId, newTabId: strNewTabId }); } } // If tab is configured to load content from external source and // tab is still empty or it is configured to refresh on every tab change if (url) { var isIframeDiffSrc = objTab.config.tabType == 'iframe' && objTab.lastUrlSet != url; // If tab is a div and it's an empty one var isEmptyDiv = objTab.config.tabType == 'div' && !objTab.container.getContainer().childNodes.length; // If Internet Explorer if (Zapatec.is_ie) { // If tab is a div and it only contains a WCH var tabContents = objTab.container.getContainer().childNodes; if (objTab.config.tabType == 'div' && 1 == tabContents.length && tabContents[0].id.match(/wch/gi)) { // Mark tab as empty isEmptyDiv = true; } } if (isEmptyDiv || isIframeDiffSrc || objTab.config.refreshOnTabChange) { // Load remote url inside tab objTab.setPaneContent(url, 'html/url'); return; } } else { if (!url) { // Update tab content objTab.setPaneContent(); } } if (objTab.pendingOnTabChange) { // Call onTabChange event handler objTab.pendingOnTabChange(self); objTab.pendingOnTabChange = null; }}/** * Gets a tab with a given id * * @param {string} tabId id of the tab to get */Zapatec.Tabs.prototype.getTab = function(tabId) { var objTab = this.tabs[tabId]; return objTab;};/** * Gets a tab with a given index * * @param {number} tabIndex index of the tab to get */Zapatec.Tabs.prototype.getTabByIndex = function(tabIndex) { var objTab = this.tabsArray[tabIndex]; return objTab;};/** * Get next visible/hidden tab. * * @param {boolean} isVisible type of tab to get * @param {number} tabIndex index of the pivot tab */Zapatec.Tabs.prototype.getNextTab = function(isVisible, tabIndex) { var nextTabIndex = tabIndex + 1; while (nextTabIndex < this.tabsArray.length) { var objTab = this.tabsArray[nextTabIndex]; if (objTab.config.visible == isVisible) { return objTab; } ++nextTabIndex; } return null;}/** * Get previous visible/hidden tab. * * @param {boolean} isVisible type of tab to get * @param {number} tabIndex index of the pivot tab */Zapatec.Tabs.prototype.getPreviousTab = function(isVisible, tabIndex) { var previousTabIndex = tabIndex - 1; while (0 <= previousTabIndex) { var objTab = this.tabsArray[previousTabIndex]; if (objTab.config.visible == isVisible) { return objTab; } --previousTabIndex; } return null;}/** * Moves to the next tab. */Zapatec.Tabs.prototype.nextTab = function() { var nextTab = this.getNextTab(true, this.currentIndex); if (nextTab) { this.changeTab(nextTab.id); } else { // Get first visible tab nextTab = this.getNextTab(true, -1); if (nextTab) { this.changeTab(nextTab.id); } }};/** * Moves to the previous tab. */Zapatec.Tabs.prototype.prevTab = function() { // Get first visible tab before the current one var previousTab = this.getPreviousTab(true, this.currentIndex); if (previousTab) { this.changeTab(previousTab.id); } else { // Get last visible tab previousTab = this.getPreviousTab(true, this.tabsArray.length); if (previousTab) { this.changeTab(previousTab.id); } }};/** * Moves to the first tab. */Zapatec.Tabs.prototype.firstTab = function() { this.changeTab(this.tabsArray[0].id);};/** * Moves to the last tab. */Zapatec.Tabs.prototype.lastTab = function() { this.changeTab(this.tabsArray[this.tabsArray.length - 1].id);};/** * Indicates if current tab is first. * * @return {boolean} true if we are at the first tab, false otherwise. */Zapatec.Tabs.prototype.isFirstTab = function() { return this.currentIndex == 0;};/** * Indicates if current tab is last. * * @return {boolean} true if we are at the last tab, false otherwise. */Zapatec.Tabs.prototype.isLastTab = function() { return this.currentIndex == this.tabsArray.length - 1;};/** * Gets the tab that is to become active after Tabs initialization * * @private */Zapatec.Tabs.prototype.getInitialActiveTabId = function() { var strId = null; if (this.config.activeTabId) { strId = this.config.activeTabId; } else { // Default to first tab strId = this.tabsArray[0].id; } // If url shows tab to be made active if (!this.config.ignoreUrl) { // Parse url param for a tab with a matching id var str = this.config.tabs.id + "="; var url = document.URL; var pos = url.lastIndexOf(str); // If such param exists if (-1 != pos) { pos += str.length; str = url.substring(pos); // Tab id ends where next param begins var tabId = str.split("&")[0]; // If a tab exists for tabId stated in the URL if (this.tabs[tabId]) { strId = tabId; } } } return strId;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -