/*! * Copyright (c) 2015 Adam Jimenez * * Dual licensed under the MIT (MIT_LICENSE.txt) * and GPL (GPL_LICENSE.txt) licenses * * https://github.com/adamjimenez/ui.tabs.overflowResize */ (function($) { // overridden ui.tabs functions var uiTabsFuncs = { option: $.ui.tabs.prototype.option, _ui: $.ui.tabs.prototype._ui, }; uiTabsFuncs = $.extend( uiTabsFuncs, { add: $.ui.tabs.prototype.add, remove: $.ui.tabs.prototype.remove, resize: $.ui.tabs.prototype.resize } ); $.extend($.ui.tabs.prototype, { overflowResize: function(options) { var self = this, initialized = false, buttonWidth, containerWidth, resizeTimer = null, hover = false; // initialize overflow function init() { destroy(); $(window).on('resize', resize); // $(self._getList()).on('mouseover', mouseenter); // $(self._getList()).on('mouseout', mouseout); initialized = true; resize(); } function destroy() { $(window).off('resize', resize); // $(self._getList()).off('mouseenter', mouseenter); // $(self._getList()).off('mouseout', mouseout); initialized = false; } function doResize(animate) { // get button width var totalButtonWidth = 0; self.tabs.each(function(i) { var tab = self.tabs.eq(i); if (tab.hasClass('button')) { totalButtonWidth += tab.outerWidth(true); } }); // calc new widths if (blnTabsScrollable){ var elem_container = $('.contenedor_tabs_scroller').filter(function() {return !! $(this).find(self._getList().children(':not(.button):visible')).length;}); if (elem_container.length > 0) var containerWidth = elem_container.width()-100; else var containerWidth = parseFloat(window.getComputedStyle(self._getList()[0]).width)-100; } else var containerWidth = parseFloat(window.getComputedStyle(self._getList()[0]).width)-100; /*JESM - Se agrega el que solo obtenga el calculo de tabs visibles*/ var item = self._getList().children(':not(.button):visible'); if(!item.length) return; var totalMargin = (item[0].getBoundingClientRect().width - parseFloat(window.getComputedStyle(item[0]).width)) * self.tabs.length; var availableWidth = containerWidth - totalButtonWidth - totalMargin; tabMaxWidth = availableWidth / item.length; //JESM if (tabMaxWidth < TABMAXWIDTH_DEFINED){ tabMaxWidth = TABMAXWIDTH_DEFINED; var css = {'max-width' : TABMAXWIDTH_DEFINED}; } else var css = {'max-width' : tabMaxWidth}; if(animate) { /*JESM - Se agrega el que solo obtenga el calculo de tabs visibles*/ self._getList().children(':not(.button):visible').animate(css, 'fast'); //subtract padding between tabs } else { /*JESM - Se agrega el que solo obtenga el calculo de tabs visibles*/ self._getList().children(':not(.button):visible').css(css); } } function resize(e, animate) { if (resizeTimer) clearTimeout(resizeTimer); resizeTimer = setTimeout(function(){ doResize(animate) }, 50); } self._ui = function( tab, panel ) { return { tab: tab, panel: panel, index: this.anchors.index( tab ) }; }; self.resize = function(animate) { // get button width var totalButtonWidth = 0; self.tabs.each(function(i) { var tab = self.tabs.eq(i); if (tab.hasClass('button')) { totalButtonWidth += tab.outerWidth(true); } }); // calc new widths if (blnTabsScrollable){ var elem_container = $('.contenedor_tabs_scroller').filter(function() {return !! $(this).find(self._getList().children(':not(.button):visible')).length;}); if (elem_container.length > 0) var containerWidth = elem_container.width()-100; else var containerWidth = parseFloat(window.getComputedStyle(self._getList()[0]).width)-50; } else var containerWidth = parseFloat(window.getComputedStyle(self._getList()[0]).width)-50; /*JESM - Se agrega el que solo obtenga el calculo de tabs visibles*/ var item = self._getList().children(':not(.button):visible'); if(!item.length) return; //JESM - INICIA - Se modifica para obtener los datos del tab activo, porque si el primero está NO VISIBLE "NO" obtiene el width y lo deja sin ajustar var idx = -1; for (var i = 0; i < item.length; i++) { if (item[i].className.indexOf("ui-tabs-active") >= 0) { idx = i break; } } if (idx > -1) var totalMargin = (item[idx].getBoundingClientRect().width - parseFloat(window.getComputedStyle(item[idx]).width)) * self.tabs.length; else //JESM - FIN var totalMargin = (item[0].getBoundingClientRect().width - parseFloat(window.getComputedStyle(item[0]).width)) * self.tabs.length; var availableWidth = containerWidth - totalButtonWidth - totalMargin; tabMaxWidth = availableWidth / item.length; //JESM if (tabMaxWidth < TABMAXWIDTH_DEFINED){ tabMaxWidth = TABMAXWIDTH_DEFINED; var css = {'max-width' : TABMAXWIDTH_DEFINED}; } else var css = {'max-width' : tabMaxWidth}; if(animate) { /*JESM - Se agrega el que solo obtenga el calculo de tabs visibles*/ self._getList().children(':not(.button):visible').animate(css, 'fast'); //subtract padding between tabs } else { /*JESM - Se agrega el que solo obtenga el calculo de tabs visibles*/ self._getList().children(':not(.button):visible').css(css); } } // temporarily remove overflow buttons before adding a tab self.add = function(name, content, iconCls) { var newTab = false; if (!name) { name = 'New tab'; newTab = true; } if (!content) content = ''; var id = $( "