/** * TabPanel.js * * Released under LGPL License. * Copyright (c) 1999-2017 Ephox Corp. All rights reserved * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ import Panel from './Panel'; import $ from 'tinymce/core/api/dom/DomQuery'; import DomUtils from './DomUtils'; /** * Creates a tab panel control. * * @-x-less TabPanel.less * @class tinymce.ui.TabPanel * @extends tinymce.ui.Panel * * @setting {Number} activeTab Active tab index. */ export default Panel.extend({ Defaults: { layout: 'absolute', defaults: { type: 'panel' } }, /** * Activates the specified tab by index. * * @method activateTab * @param {Number} idx Index of the tab to activate. */ activateTab (idx) { let activeTabElm; if (this.activeTabId) { activeTabElm = this.getEl(this.activeTabId); $(activeTabElm).removeClass(this.classPrefix + 'active'); activeTabElm.setAttribute('aria-selected', 'false'); } this.activeTabId = 't' + idx; activeTabElm = this.getEl('t' + idx); activeTabElm.setAttribute('aria-selected', 'true'); $(activeTabElm).addClass(this.classPrefix + 'active'); this.items()[idx].show().fire('showtab'); this.reflow(); this.items().each(function (item, i) { if (idx !== i) { item.hide(); } }); }, /** * Renders the control as a HTML string. * * @method renderHtml * @return {String} HTML representing the control. */ renderHtml () { const self = this; const layout = self._layout; let tabsHtml = ''; const prefix = self.classPrefix; self.preRender(); layout.preRender(self); self.items().each(function (ctrl, i) { const id = self._id + '-t' + i; ctrl.aria('role', 'tabpanel'); ctrl.aria('labelledby', id); tabsHtml += ( '