📄 zptabs-core.js
字号:
if (true == this.noTabBar) { return; } var configIndex = objTab.config.index; var insertBefore = null; if (-1 != configIndex) { // Insert tab link at the specified index var actualIndex = objTab.index; var children = this.config.tabBar.childNodes; var childrenCount = children.length; // If we are inserting the tab at some position if (0 < childrenCount && actualIndex < childrenCount) { insertBefore = children[actualIndex]; } } if (!insertBefore) { // Append tab link on the end of the tab bar this.config.tabBar.appendChild(objTab.linkNode); } else { this.config.tabBar.insertBefore(objTab.linkNode, insertBefore); } // If tab is set to be hidden if (!objTab.config.visible) { objTab.linkNode.style.display = 'none'; }}/** * Attaches a tab to the tabs at a specified index * * @private * @param {object} objTab object tab. */Zapatec.Tabs.prototype.attachTab = function(objTab) { var index = objTab.config.index; if (this.tabsArray.length <= index) { index = -1; } if (-1 == index) { objTab.index = this.tabsArray.length; } else { objTab.index = index; // Shift tabsArray for (var i = this.tabsArray.length - 1; index <= i; --i) { var oldTab = this.tabsArray[i]; oldTab.index = oldTab.index + 1; this.tabsArray[i + 1] = oldTab; } if (index <= this.currentIndex) { ++this.currentIndex; } } // Attach this Tab to Tabs object this.tabsArray[objTab.index] = objTab; this.tabs[objTab.id] = objTab; // Set tab link hash var linkHash = this.config.tabs.id + "=" + objTab.id; objTab.setLinkHash(linkHash); var self = this; objTab.addEventListener("activateTab", function() { self.changeTab(objTab.id); });}/** * Scrolls tabs to the left * * @private * @param {boolean} setTab Whether the function should set the selected tab * on its own. */Zapatec.Tabs.prototype.scrollOneTabLeft = function(setTab) { var tabBar = this.config.tabBar; // Get tabs var items = tabBar.childNodes; // Find first visible tab var i = 0; for (i; i < items.length; i++) { if (items[i].style.display != 'none') { break; } } // Find first hidden tab var j = i; for (j; j < items.length; j++) { if (items[j].style.display == 'none') { break; } } if (j >= items.length) { return; } // Hide first visible tab, show first hidden tab items[i].style.display = 'none'; // If there aren't any hidden tabs left, don't try to display any if (j < items.length) { items[j].style.display = items[j].originalDisplayType; }}/** * Scrolls tabs to the left * * @private * @param {boolean} setTab Whether the function should set the selected tab * on its own. */Zapatec.Tabs.prototype.scrollOneTabRight = function(setTab) { var tabBar = this.config.tabBar; // Get tabs var items = tabBar.childNodes; // Find first visible tab var i = 0; for (i; i < items.length; i++) { if (items[i].style.display != 'none') { break; } } // If i==0, you're at the beginning of the tabs, just exit if (i == 0) { return; } // Find first hidden tab var j = i; for (j; j < items.length; j++) { if (items[j].style.display == 'none') { break; } } // Hide last visible tab, show first hidden tab previous to the first visible tab items[j - 1].style.display = 'none'; items[i - 1].style.display = items[i - 1].originalDisplayType;}/** * Scrolls tabs to the left * * @private * @param {boolean} setTab Whether the function should set the selected tab * on its own. */Zapatec.Tabs.prototype.scrollTabsLeft = function(setTab) { // Quit if you're at the end if (this.config.noMoreTabsLeft) { return; } // Mark that there are now (or will be) hidden tabs on the left this.config.noMoreTabsRight = false; // Check arguments if (!this.config.tabBar) { return; } var tabBar = this.config.tabBar; // Content width of the tab bar var contentWidth = parseInt(tabBar.style.width); // Run through tabs hiding those that are currently visible var items = tabBar.childNodes; var i = this.config.lastIndexLeft - 1; while (++i < items.length) { if (items[i].style.display != 'none') { items[i].style.display = 'none'; } else { this.config.lastIndexLeft = i; break; } } // Now, make elements visible until you run out of room, or until there aren't any left var contentWidth = 0; var tabBarWidth = parseInt(tabBar.style.width); for (i = this.config.lastIndexLeft; i < items.length; i++) { items[i].style.display = items[i].originalDisplayType; contentWidth += items[i].realWidth; // If you've exceeded viewable area, retract if (contentWidth > tabBarWidth) { items[i].style.display = 'none'; this.config.lastIndexRight = i - 1; // Make first visible tab the current tab if (setTab) { this.changeTab(items[this.config.lastIndexLeft].name); } return; } } // Adjust lastIndexRight for last increment performed in for loop this.config.lastIndexRight = i - 1; // Make first visible tab the current tab if (setTab) { this.changeTab(items[this.config.lastIndexLeft].name); } this.config.noMoreTabsLeft = true;}/** * Scrolls tabs to the right * * @private * @param {boolean} setTab Whether the function should set the selected tab * on its own. */Zapatec.Tabs.prototype.scrollTabsRight = function(setTab) { // Quit if you're at the end if (this.config.noMoreTabsRight) { return; } // Mark that there are now (or will be) hidden tabs on the right this.config.noMoreTabsLeft = false; // Check arguments if (!this.config.tabBar) { return; } var tabBar = this.config.tabBar; // Content width of the tab bar var contentWidth = parseInt(tabBar.style.width); // Run through tabs hiding those that are currently visible // Need some sort of pagination here var items = tabBar.childNodes; var i = this.config.lastIndexRight + 1; while (--i >= 0) { if (items[i].style.display != 'none') { items[i].style.display = 'none'; } else { this.config.lastIndexRight = i; break; } } // Now, make elements visible until you run out of room, or until there aren't any left var contentWidth = 0; var tabBarWidth = parseInt(tabBar.style.width); for (i = this.config.lastIndexRight; i >= 0; i--) { items[i].style.display = items[i].originalDisplayType; contentWidth += items[i].realWidth; // If you've exceeded viewable area, retract if (contentWidth > tabBarWidth) { items[i].style.display = 'none'; this.config.lastIndexLeft = i + 1; // Make first visible tab the current tab if (setTab) { this.changeTab(items[this.config.lastIndexRight].name); } return; } } // Adjust lastIndexLeft for last decrement performed in for loop this.config.lastIndexLeft = i + 1; // Make first visible tab the current tab if (setTab) { this.changeTab(items[this.config.lastIndexRight].name); } this.config.noMoreTabsRight = true;}/** * Loads data from the JSON source. * * @private * Following format is recognized: * \code * { * tabs: [ * { * id: [string, optional] id of the tab, * innerHTML: [string] label, * accessKey: [string, optional] access key, * title: [string] title, * url: [string] URL of the content, * tabType: [string] "div" or "iframe" for the content pane * }, * ... * ] * } * \endcode * * @param {object} objSource JSON object. */Zapatec.Tabs.prototype.loadDataJson = function(objSource) { // Check arguments if ((true != this.noTabBar && !this.config.tabBar) || !this.config.tabs) { return; } if (!objSource || !objSource.tabs || !objSource.tabs.length) { return; } // Parse source var iLen = objSource.tabs.length; for (var iTab = 0; iTab < iLen; iTab++) { var objTabDef = objSource.tabs[iTab]; this.addTab(objTabDef); }};/** * Create a new tab instance * * @param {object} objArgs tab configuration */Zapatec.Tabs.prototype.newTab = function(objArgs) { var objTab = new Zapatec.Tab(objArgs); return objTab;}/** * Loads data from the HTML source. * * @private * Following format is recognized: * \code * <div id="tabs"> * <div id="tab-begin"> * <label>The first tab</label> * ... the tab contents here ... * </div> * <div id="tab-second"> * <label>The second tab</label> * ... the tab contents here ... * </div> * ... * </div> * \endcode * * @param {object} objSource HTMLElement object. */Zapatec.Tabs.prototype.loadDataHtml = function(objSource) { // Check arguments if ((true != this.noTabBar && !this.config.tabBar) || !this.config.tabs) { return; } if (!objSource) { objSource = this.config.tabs; } var childs = []; for (var ii = 0; ii < objSource.childNodes.length; ii++) { childs.push(objSource.childNodes[ii]); } // Parse source for (var iChild = 0; iChild < childs.length; iChild++) { var objChild = childs[iChild]; if (objChild.nodeType == 1) { // ELEMENT_NODE // Get label var objLabel = Zapatec.Utils.getFirstChild(objChild, 'label'); if (!objLabel) { continue; } // Remove label objLabel.parentNode.removeChild(objLabel); // Remove child objChild.parentNode.removeChild(objChild); var objArgs = { tabParent: this.config.tabs, id: objChild.getAttribute('id'), linkInnerHTML: objLabel.innerHTML, accessKey: objLabel.getAttribute('accesskey'), title: objLabel.getAttribute('title'), content: objChild, tabType: objChild.getAttribute('tabType'), url: objChild.getAttribute('url'), className: objChild.className, overflow: objChild.style.overflow, visible: objLabel.style.display != "none", refreshOnTabChange: objChild.getAttribute('refreshOnTabChange'), closable: objLabel.getAttribute('closable'), closeAction: objLabel.getAttribute('closeAction') }; var objTab = this.addTab(objArgs); // Return id of the tab trough container element if (objTab.id) { objTab.container.getContainer().setAttribute('id', objTab.id); // Remove id from div to avoid coliding with tab container objChild.removeAttribute('id'); } } } // Mark that we have initialized tabs by parsing html this.isLoadedHtml = true;};/** * Adds a new tab. * * @private * Following format is recognized: * \code * { * id: [string, optional] id of the tab, * innerHTML: [string] label, * accessKey: [string, optional] access key, * title: [string] title, * url: [string] URL of the content, * tabType: [string] "div" or "iframe" for the content pane * index: [number, optional] index to make insert the new tab at * } * \endcode * * @param {object} objTabDef JSON object. */Zapatec.Tabs.prototype.addTab = function(objTabDef) { // Check arguments if ((true != this.noTabBar && !this.config.tabBar) || !this.config.tabs) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -