From 8ba93bf8c71d636161ab53fd16d9f5a447240d24 Mon Sep 17 00:00:00 2001 From: Mike Jacobson Date: Tue, 22 Aug 2017 08:24:39 -0700 Subject: [PATCH] Fix window resize when multiple instances on page Fixes issue #33 --- bower.json | 2 +- dist/jquery.scrolling-tabs.css | 2 +- dist/jquery.scrolling-tabs.js | 28 +++- dist/jquery.scrolling-tabs.min.css | 2 +- dist/jquery.scrolling-tabs.min.js | 4 +- package.json | 2 +- run/data-driven-mult.html | 214 +++++++++++++++++++++++++++++ run/markup-only-mult.html | 207 ++++++++++++++++++++++++++++ src/js/_main.js | 1 + src/js/api.js | 8 +- src/js/elementsHandler.js | 7 +- src/js/header.js | 2 +- src/js/scrollingTabsControl.js | 1 + src/js/smartresize.js | 7 +- src/js/tabListeners.js | 2 + 15 files changed, 471 insertions(+), 18 deletions(-) create mode 100644 run/data-driven-mult.html create mode 100644 run/markup-only-mult.html diff --git a/bower.json b/bower.json index d696cc3..b6d0bf3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-bootstrap-scrolling-tabs", - "version": "2.0.0", + "version": "2.0.1", "main": [ "./dist/jquery.scrolling-tabs.js", "./dist/jquery.scrolling-tabs.css" diff --git a/dist/jquery.scrolling-tabs.css b/dist/jquery.scrolling-tabs.css index 2b12625..e1b9cc8 100644 --- a/dist/jquery.scrolling-tabs.css +++ b/dist/jquery.scrolling-tabs.css @@ -1,6 +1,6 @@ /** * jquery-bootstrap-scrolling-tabs - * @version v2.0.0 + * @version v2.0.1 * @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs * @author Mike Jacobson * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/jquery.scrolling-tabs.js b/dist/jquery.scrolling-tabs.js index 13b9240..29ef197 100644 --- a/dist/jquery.scrolling-tabs.js +++ b/dist/jquery.scrolling-tabs.js @@ -1,6 +1,6 @@ /** * jquery-bootstrap-scrolling-tabs - * @version v2.0.0 + * @version v2.0.1 * @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs * @author Mike Jacobson * @license MIT License, http://www.opensource.org/licenses/MIT @@ -224,6 +224,7 @@ ;(function ($, window) { 'use strict'; + /* jshint unused:false */ /* exported CONSTANTS */ var CONSTANTS = { @@ -283,9 +284,12 @@ timeout = setTimeout(delayed, threshold || 100); }; }; - $.fn[sr] = function (fn) { return fn ? this.bind(CONSTANTS.EVENTS.WINDOW_RESIZE, debounce(fn)) : this.trigger(sr); }; + $.fn[sr] = function (fn, customEventName) { + var eventName = customEventName || CONSTANTS.EVENTS.WINDOW_RESIZE; + return fn ? this.bind(eventName, debounce(fn)) : this.trigger(sr); + }; - })('smartresize'); + })('smartresizeScrtabs'); /* *********************************************************************************** * ElementsHandler - Class that each instance of ScrollingTabsControl will instantiate @@ -444,7 +448,8 @@ var ehd = this, stc = ehd.stc, evh = stc.eventHandlers, - ev = CONSTANTS.EVENTS; + ev = CONSTANTS.EVENTS, + resizeEventName = ev.WINDOW_RESIZE + stc.instanceId; if (settings.enableSwiping) { ehd.listenForTouchEvents(); @@ -469,7 +474,9 @@ .on(ev.CLICK, stc.tabClickHandler); } - stc.$win.off('.scrtabs').smartresize(function (e) { evh.handleWindowResize.call(evh, e); }); + stc.$win + .off(resizeEventName) + .smartresizeScrtabs(function (e) { evh.handleWindowResize.call(evh, e); }, resizeEventName); $('body').on(CONSTANTS.EVENTS.FORCE_REFRESH, stc.elementsHandler.refreshAllElementSizes.bind(stc.elementsHandler)); }; @@ -921,6 +928,7 @@ var stc = this; stc.$tabsContainer = $tabsContainer; + stc.instanceId = $.fn.scrollingTabs.nextInstanceId++; stc.movableContainerLeftPos = 0; stc.scrollArrowsVisible = false; @@ -1520,6 +1528,7 @@ }); function handleClickOnDropdownMenuItem() { + /* jshint validthis: true */ var $selectedMenuItemAnc = $(this), $selectedMenuItemLi = $selectedMenuItemAnc.parent('li'), $selectedMenuItemDropdownMenu = $selectedMenuItemLi.parent('.dropdown-menu'), @@ -1603,6 +1612,7 @@ } function scrollToActiveTab() { + /* jshint validthis: true */ var $targetElInstance = $(this), scrtabsData = $targetElInstance.data('scrtabs'); @@ -1669,6 +1679,7 @@ }; function destroyPlugin() { + /* jshint validthis: true */ var $targetElInstance = $(this), scrtabsData = $targetElInstance.data('scrtabs'), $tabsContainer; @@ -1727,7 +1738,10 @@ $targetElInstance.removeData('scrtabs'); - $(window).off(CONSTANTS.EVENTS.WINDOW_RESIZE); + while(--$.fn.scrollingTabs.nextInstanceId >= 0) { + $(window).off(CONSTANTS.EVENTS.WINDOW_RESIZE + $.fn.scrollingTabs.nextInstanceId); + } + $('body').off(CONSTANTS.EVENTS.FORCE_REFRESH); } @@ -1743,6 +1757,8 @@ } }; + $.fn.scrollingTabs.nextInstanceId = 0; + $.fn.scrollingTabs.defaults = { tabs: null, propPaneId: 'paneId', diff --git a/dist/jquery.scrolling-tabs.min.css b/dist/jquery.scrolling-tabs.min.css index de733ab..fb47e4a 100644 --- a/dist/jquery.scrolling-tabs.min.css +++ b/dist/jquery.scrolling-tabs.min.css @@ -1,6 +1,6 @@ /** * jquery-bootstrap-scrolling-tabs - * @version v2.0.0 + * @version v2.0.1 * @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs * @author Mike Jacobson * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/jquery.scrolling-tabs.min.js b/dist/jquery.scrolling-tabs.min.js index 085af38..93301d7 100644 --- a/dist/jquery.scrolling-tabs.min.js +++ b/dist/jquery.scrolling-tabs.min.js @@ -1,8 +1,8 @@ /** * jquery-bootstrap-scrolling-tabs - * @version v2.0.0 + * @version v2.0.1 * @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs * @author Mike Jacobson * @license MIT License, http://www.opensource.org/licenses/MIT */ -!function(e,t){"use strict";function n(e){this.stc=e}function i(e){this.stc=e}function a(e){this.stc=e}function r(e){var t=this;t.$tabsContainer=e,t.movableContainerLeftPos=0,t.scrollArrowsVisible=!1,t.scrollToTabEdge=!1,t.disableScrollArrowsOnFullyScrolled=!1,t.reverseScroll=!1,t.widthMultiplier=1,t.scrollMovement=new a(t),t.eventHandlers=new i(t),t.elementsHandler=new n(t)}function o(t,n,i){var a,r=n.tabs,o={paneId:n.propPaneId,title:n.propTitle,active:n.propActive,disabled:n.propDisabled,content:n.propContent},l=n.ignoreTabPanes,c=r.length&&void 0!==r[0][o.content],d=E.getNewElNavTabs(),b=E.getNewElTabContent(),f=l?null:function(){a.after(b)};if(r.length)return r.forEach(function(e){E.getNewElTabLi(e,o,!0).appendTo(d),!l&&c&&E.getNewElTabPane(e,o,!0).appendTo(b)}),a=s(d,n,i,f),a.appendTo(t),t.data({scrtabs:{tabs:r,propNames:o,ignoreTabPanes:l,hasTabContent:c,scroller:a}}),a.find(".nav-tabs > li").each(function(t){A.storeDataOnLiEl(e(this),r,t)}),t}function s(e,t,n,i){var a=E.getNewElScrollerElementWrappingNavTabsInstance(e.clone(!0),t),o=new r(a),s=e.data("scrtabs");return s?s.scroller=a:e.data("scrtabs",{scroller:a}),e.replaceWith(a.css("visibility","hidden")),t.tabClickHandler&&"function"==typeof t.tabClickHandler&&(a.hasTabClickHandler=!0,o.tabClickHandler=t.tabClickHandler),a.initTabs=function(){o.initTabs(t,a,n,i)},a.scrollToActiveTab=function(){o.scrollToActiveTab(t)},a.initTabs(),v(a,o),a}function l(e){var t=e.updatedTabsArray,n=e.propNames,i=e.ignoreTabPanes,a=e.options,r=e.$currTabLis,o=e.$navTabs,s=i?null:e.$currTabContentPanesContainer,l=i?null:e.$currTabContentPanes,c=!1;return t.forEach(function(e,d){var b,f=r.find('a[href="#'+e[n.paneId]+'"]'),v=d>=r.length;f.length||(c=!0,f=E.getNewElTabLi(e,n,a.forceActiveTab),A.storeDataOnLiEl(f,t,d),v?f.appendTo(o):f.insertBefore(r.eq(d)),i||void 0===e[n.content]||(b=E.getNewElTabPane(e,n,a.forceActiveTab),v?b.appendTo(s):b.insertBefore(l.eq(d))))}),c}function c(e){var t=e.tabLi,n=e.ignoreTabPanes,i=t.$li,a=t.$contentPane,r=t.origTabData,o=t.newTabData,s=e.propNames,l=!1;return r[s.title]!==o[s.title]&&(i.find('a[role="tab"]').html(r[s.title]=o[s.title]),l=!0),r[s.disabled]!==o[s.disabled]&&(o[s.disabled]?(i.addClass("disabled"),i.find('a[role="tab"]').attr("data-toggle","")):(i.removeClass("disabled"),i.find('a[role="tab"]').attr("data-toggle","tab")),r[s.disabled]=o[s.disabled],l=!0),e.options.forceActiveTab&&(i[o[s.active]?"addClass":"removeClass"]("active"),a[o[s.active]?"addClass":"removeClass"]("active"),r[s.active]=o[s.active],l=!0),n||r[s.content]===o[s.content]||(a.html(r[s.content]=o[s.content]),l=!0),l}function d(e){var t,n=e.tabLi,i=e.ignoreTabPanes,a=n.$li;return-1===n.newIdx&&(a.hasClass("active")&&(t=A.getIndexOfClosestEnabledTab(e.$currTabLis,n.currDomIdx))>-1&&(e.$currTabLis.eq(t).addClass("active"),i||e.$currTabContentPanes.eq(t).addClass("active")),a.remove(),i||n.$contentPane.remove(),!0)}function b(t){var n=t.$currTabLis,i=t.updatedTabsArray,a=t.propNames,r=t.ignoreTabPanes,o=[],s=r?null:[];return!!A.didTabOrderChange(n,i,a)&&(i.forEach(function(t){var i=t[a.paneId];o.push(n.find('a[role="tab"][href="#'+i+'"]').parent("li")),r||s.push(e("#"+i))}),t.$navTabs.append(o),r||t.$currTabContentPanesContainer.append(s),!0)}function f(t){var n=t.$currTabLis,i=t.updatedTabsArray,a=t.propNames,r=!1;return n.each(function(n){var o=e(this),s=o.data("tab"),l=A.getTabIndexByPaneId(i,a.paneId,s[a.paneId]),b=l>-1?i[l]:null;if(t.tabLi={$li:o,currDomIdx:n,newIdx:l,$contentPane:E.getElTabPaneForLi(o),origTabData:s,newTabData:b},d(t))return void(r=!0);c(t)&&(r=!0)}),r}function v(t,n){function i(t){e(t.target).append(r.off(T.EVENTS.CLICK))}function a(i){function a(){var n=e(this),i=n.parent("li"),a=i.parent(".dropdown-menu"),r=n.attr("href");i.hasClass("active")||(t.find("li.active").not(c).add(a.find("li.active")).removeClass("active"),c.add(i).addClass("active"),e(".tab-content .tab-pane.active").removeClass("active"),e(r).addClass("active"))}var o,s,l,c=e(i.target),d=c.offset(),b=t.find('li[role="presentation"].active');r=c.find(".dropdown-menu").attr("data-"+T.DATA_KEY_DDMENU_MODIFIED,!0),b[0]!==c[0]&&r.find("li.active").removeClass("active"),r.on(T.EVENTS.CLICK,'a[role="tab"]',a),e("body").append(r),o=r.width()+d.left,s=t.width()-(n.$slideRightArrow.outerWidth()+1),l=d.left,o>s&&(l-=o-s),r.css({display:"block",top:d.top+c.outerHeight()-2,left:l})}var r;t.on(T.EVENTS.DROPDOWN_MENU_SHOW,a).on(T.EVENTS.DROPDOWN_MENU_HIDE,i)}function C(e,t){var n=e.data().scrtabs,i=n.scroller,a=e.find(".scrtabs-tab-container .nav-tabs"),r=e.find(".tab-content"),o=!1,s={options:t,updatedTabsArray:n.tabs,propNames:n.propNames,ignoreTabPanes:n.ignoreTabPanes,$navTabs:a,$currTabLis:a.find("> li"),$currTabContentPanesContainer:r,$currTabContentPanes:r.find(".tab-pane")};return l(s)&&(o=!0),b(s)&&(o=!0),f(s)&&(o=!0),o&&i.initTabs(),o}function u(t,n){t.data("scrtabs")&&(!t.data("scrtabs").isWrapperOnly&&C(t,n)||e("body").trigger(T.EVENTS.FORCE_REFRESH))}function h(){var t=e(this),n=t.data("scrtabs");n&&n.scroller.scrollToActiveTab()}function S(){var n,i=e(this),a=i.data("scrtabs");a&&("self"===a.enableSwipingElement?i.removeClass(T.CSS_CLASSES.ALLOW_SCROLLBAR):"parent"===a.enableSwipingElement&&i.closest(".scrtabs-tab-container").parent().removeClass(T.CSS_CLASSES.ALLOW_SCROLLBAR),a.scroller.off(T.EVENTS.DROPDOWN_MENU_SHOW).off(T.EVENTS.DROPDOWN_MENU_HIDE),a.scroller.find("[data-"+T.DATA_KEY_DDMENU_MODIFIED+"]").css({display:"",left:"",top:""}).off(T.EVENTS.CLICK).removeAttr("data-"+T.DATA_KEY_DDMENU_MODIFIED),a.scroller.hasTabClickHandler&&i.find('a[data-toggle="tab"]').off(".scrtabs"),a.isWrapperOnly?(n=i.parents(".scrtabs-tab-container"),n.length&&n.replaceWith(i)):(a.scroller&&a.scroller.initTabs&&(a.scroller.initTabs=null),i.find(".scrtabs-tab-container").add(".tab-content").remove()),i.removeData("scrtabs"),e(t).off(T.EVENTS.WINDOW_RESIZE),e("body").off(T.EVENTS.FORCE_REFRESH))}var T={CONTINUOUS_SCROLLING_TIMEOUT_INTERVAL:50,SCROLL_OFFSET_FRACTION:6,DATA_KEY_DDMENU_MODIFIED:"scrtabsddmenumodified",DATA_KEY_IS_MOUSEDOWN:"scrtabsismousedown",CSS_CLASSES:{SCROLL_ARROW_DISABLE:"scrtabs-disable"},SLIDE_DIRECTION:{LEFT:1,RIGHT:2},EVENTS:{CLICK:"click.scrtabs",DROPDOWN_MENU_HIDE:"hide.bs.dropdown.scrtabs",DROPDOWN_MENU_SHOW:"show.bs.dropdown.scrtabs",FORCE_REFRESH:"forcerefresh.scrtabs",MOUSEDOWN:"mousedown.scrtabs",MOUSEUP:"mouseup.scrtabs",TABS_READY:"ready.scrtabs",TOUCH_END:"touchend.scrtabs",TOUCH_MOVE:"touchmove.scrtabs",TOUCH_START:"touchstart.scrtabs",WINDOW_RESIZE:"resize.scrtabs"}};!function(t){var n=function(e,t,n){var i;return function(){function a(){n||e.apply(r,o),i=null}var r=this,o=arguments;i?clearTimeout(i):n&&e.apply(r,o),i=setTimeout(a,t||100)}};e.fn[t]=function(e){return e?this.bind(T.EVENTS.WINDOW_RESIZE,n(e)):this.trigger(t)}}("smartresize"),function(n){n.initElements=function(e){var t=this;t.setElementReferences(),t.setEventListeners(e)},n.listenForTouchEvents=function(){var e,t,n,i=this,a=i.stc,r=a.scrollMovement,o=T.EVENTS,s=!1;a.$movableContainer.on(o.TOUCH_START,function(n){s=!0,t=a.movableContainerLeftPos,e=n.originalEvent.changedTouches[0].pageX}).on(o.TOUCH_END,function(){s=!1}).on(o.TOUCH_MOVE,function(i){if(s){var o,l=i.originalEvent.changedTouches[0].pageX,c=l-e;n=t+c,n>0?n=0:(o=r.getMinPos(),n li"),r.$slideLeftArrow=r.reverseScroll?n:i,r.$slideRightArrow=r.reverseScroll?i:n,r.$scrollArrows=r.$slideLeftArrow.add(r.$slideRightArrow),r.$win=e(t)},n.setElementWidths=function(){var e=this,t=e.stc;t.winWidth=t.$win.width(),t.scrollArrowsCombinedWidth=t.$slideLeftArrow.outerWidth()+t.$slideRightArrow.outerWidth(),e.setFixedContainerWidth(),e.setMovableContainerWidth()},n.setEventListeners=function(t){var n=this,i=n.stc,a=i.eventHandlers,r=T.EVENTS;t.enableSwiping&&n.listenForTouchEvents(),i.$slideLeftArrow.off(".scrtabs").on(r.MOUSEDOWN,function(e){a.handleMousedownOnSlideMovContainerLeftArrow.call(a,e)}).on(r.MOUSEUP,function(e){a.handleMouseupOnSlideMovContainerLeftArrow.call(a,e)}).on(r.CLICK,function(e){a.handleClickOnSlideMovContainerLeftArrow.call(a,e)}),i.$slideRightArrow.off(".scrtabs").on(r.MOUSEDOWN,function(e){a.handleMousedownOnSlideMovContainerRightArrow.call(a,e)}).on(r.MOUSEUP,function(e){a.handleMouseupOnSlideMovContainerRightArrow.call(a,e)}).on(r.CLICK,function(e){a.handleClickOnSlideMovContainerRightArrow.call(a,e)}),i.tabClickHandler&&i.$tabsLiCollection.find('a[data-toggle="tab"]').off(r.CLICK).on(r.CLICK,i.tabClickHandler),i.$win.off(".scrtabs").smartresize(function(e){a.handleWindowResize.call(a,e)}),e("body").on(T.EVENTS.FORCE_REFRESH,i.elementsHandler.refreshAllElementSizes.bind(i.elementsHandler))},n.setFixedContainerWidth=function(){var e=this,t=e.stc,n=t.$tabsContainer.get(0).getBoundingClientRect();t.fixedContainerWidth=n.width||n.right-n.left,t.fixedContainerWidth=t.fixedContainerWidth*t.widthMultiplier,t.$fixedContainer.width(t.fixedContainerWidth)},n.setFixedContainerWidthForHiddenScrollArrows=function(){var e=this,t=e.stc;t.$fixedContainer.width(t.fixedContainerWidth)},n.setFixedContainerWidthForVisibleScrollArrows=function(){var e=this,t=e.stc;t.$fixedContainer.width(t.fixedContainerWidth-t.scrollArrowsCombinedWidth)},n.setMovableContainerWidth=function(){var t=this,n=t.stc,i=n.$tabsUl.find("> li");n.movableContainerWidth=0,i.length&&(i.each(function(){var t=e(this),i=0;n.isNavPills&&(i=parseInt(t.css("margin-left"),10)+parseInt(t.css("margin-right"),10)),n.movableContainerWidth+=t.outerWidth()+i}),n.movableContainerWidth+=1,n.movableContainerWidtht.fixedContainerWidth;n&&!t.scrollArrowsVisible?(t.$scrollArrows.show(),t.scrollArrowsVisible=!0):!n&&t.scrollArrowsVisible&&(t.$scrollArrows.hide(),t.scrollArrowsVisible=!1),t.scrollArrowsVisible?e.setFixedContainerWidthForVisibleScrollArrows():e.setFixedContainerWidthForHiddenScrollArrows()}}(n.prototype),function(e){e.handleClickOnSlideMovContainerLeftArrow=function(){this.stc.scrollMovement.incrementMovableContainerLeft()},e.handleClickOnSlideMovContainerRightArrow=function(){this.stc.scrollMovement.incrementMovableContainerRight()},e.handleMousedownOnSlideMovContainerLeftArrow=function(){var e=this,t=e.stc;t.$slideLeftArrow.data(T.DATA_KEY_IS_MOUSEDOWN,!0),t.scrollMovement.continueSlideMovableContainerLeft()},e.handleMousedownOnSlideMovContainerRightArrow=function(){var e=this,t=e.stc;t.$slideRightArrow.data(T.DATA_KEY_IS_MOUSEDOWN,!0),t.scrollMovement.continueSlideMovableContainerRight()},e.handleMouseupOnSlideMovContainerLeftArrow=function(){this.stc.$slideLeftArrow.data(T.DATA_KEY_IS_MOUSEDOWN,!1)},e.handleMouseupOnSlideMovContainerRightArrow=function(){this.stc.$slideRightArrow.data(T.DATA_KEY_IS_MOUSEDOWN,!1)},e.handleWindowResize=function(){var e=this,t=e.stc,n=t.$win.width();if(n===t.winWidth)return!1;t.winWidth=n,t.elementsHandler.refreshAllElementSizes()}}(i.prototype),function(t){t.continueSlideMovableContainerLeft=function(){var e=this,t=e.stc;setTimeout(function(){t.movableContainerLeftPos<=e.getMinPos()||!t.$slideLeftArrow.data(T.DATA_KEY_IS_MOUSEDOWN)||e.incrementMovableContainerLeft()||e.continueSlideMovableContainerLeft()},T.CONTINUOUS_SCROLLING_TIMEOUT_INTERVAL)},t.continueSlideMovableContainerRight=function(){var e=this,t=e.stc;setTimeout(function(){t.movableContainerLeftPos>=0||!t.$slideRightArrow.data(T.DATA_KEY_IS_MOUSEDOWN)||e.incrementMovableContainerRight()||e.continueSlideMovableContainerRight()},T.CONTINUOUS_SCROLLING_TIMEOUT_INTERVAL)},t.decrementMovableContainerLeftPos=function(e){var t=this,n=t.stc;n.movableContainerLeftPos-=n.fixedContainerWidth/T.SCROLL_OFFSET_FRACTION,n.movableContainerLeftPos0?n.movableContainerLeftPos=0:n.scrollToTabEdge&&t.setMovableContainerLeftPosToTabEdge(T.SLIDE_DIRECTION.RIGHT)),t.slideMovableContainerToLeftPos(),t.enableSlideLeftArrow(),0===n.movableContainerLeftPos},t.refreshScrollArrowsDisabledState=function(){var e=this,t=e.stc;if(t.disableScrollArrowsOnFullyScrolled&&t.scrollArrowsVisible){if(t.movableContainerLeftPos>=0)return e.disableSlideRightArrow(),void e.enableSlideLeftArrow();if(t.movableContainerLeftPos<=e.getMinPos())return e.disableSlideLeftArrow(),void e.enableSlideRightArrow();e.enableSlideLeftArrow(),e.enableSlideRightArrow()}},t.scrollToActiveTab=function(){var e,t,n,i,a,r,o=this,s=o.stc;if(s.scrollArrowsVisible&&(e=s.$tabsUl.find("li.active"),e.length))return t=e.offset().left-s.$fixedContainer.offset().left,n=t+e.outerWidth(),i=s.fixedContainerWidth-20,n>i?(r=s.$slideRightArrow.outerWidth(),s.movableContainerLeftPos-=n-i+r,o.slideMovableContainerToLeftPos(),!0):(a=s.$slideLeftArrow.outerWidth(),ta)return i.movableContainerLeftPos=t===T.SLIDE_DIRECTION.RIGHT?-(r-n):-r,!1})},t.slideMovableContainerToLeftPos=function(){var e,t=this,n=t.stc,i=t.getMinPos();n.movableContainerLeftPos>0?n.movableContainerLeftPos=0:n.movableContainerLeftPos')}function i(t,n){var i=e('
'),a=n.leftArrowContent||'
',r=e(a),o=n.rightArrowContent||'
',s=e(o),l=e('
'),c=e('
');return n.disableScrollArrowsOnFullyScrolled&&r.add(s).addClass("scrtabs-disable"),i.append(r,l.append(c.append(t)),s)}function a(t,n){return e('').attr("href","#"+t[n.paneId]).html(t[n.title])}function r(){return e('
')}function o(t,n,i){var r=e('
  • '),o=a(t,n).appendTo(r);return t[n.disabled]?(r.addClass("disabled"),o.attr("data-toggle","")):i&&t[n.active]&&r.addClass("active"),r}function s(t,n,i){var a=e('
    ').attr("id",t[n.paneId]).html(t[n.content]);return i&&t[n.active]&&a.addClass("active"),a}return{getElTabPaneForLi:t,getNewElNavTabs:n,getNewElScrollerElementWrappingNavTabsInstance:i,getNewElTabAnchor:a,getNewElTabContent:r,getNewElTabLi:o,getNewElTabPane:s}}(),A=function(){function t(t,n,a){var r=!1;return t.each(function(t){var o=i(n,a.paneId,e(this).data("tab")[a.paneId]);if(o>-1&&o!==t)return r=!0,!1}),r}function n(e,t){for(var n=e.length-1,i=-1,a=0,r=0;-1===i&&r>=0;)((r=t+ ++a)<=n&&!e.eq(r).hasClass("disabled")||(r=t-a)>=0&&!e.eq(r).hasClass("disabled"))&&(i=r);return i}function i(e,t,n){var i=-1;return e.some(function(e,a){if(e[t]===n)return i=a,!0}),i}function a(t,n,i){t.data({tab:e.extend({},n[i]),index:i})}return{didTabOrderChange:t,getIndexOfClosestEnabledTab:n,getTabIndexByPaneId:i,storeDataOnLiEl:a}}(),p={destroy:function(){return this.each(S)},init:function(t){var n=this,i=n.length-1,a=e.extend({},e.fn.scrollingTabs.defaults,t||{});return a.tabs?n.each(function(t){o(e(this),a,t li").each(function(t){A.storeDataOnLiEl(e(this),r,t)}),t}function s(e,t,n,a){var i=E.getNewElScrollerElementWrappingNavTabsInstance(e.clone(!0),t),o=new r(i),s=e.data("scrtabs");return s?s.scroller=i:e.data("scrtabs",{scroller:i}),e.replaceWith(i.css("visibility","hidden")),t.tabClickHandler&&"function"==typeof t.tabClickHandler&&(i.hasTabClickHandler=!0,o.tabClickHandler=t.tabClickHandler),i.initTabs=function(){o.initTabs(t,i,n,a)},i.scrollToActiveTab=function(){o.scrollToActiveTab(t)},i.initTabs(),v(i,o),i}function l(e){var t=e.updatedTabsArray,n=e.propNames,a=e.ignoreTabPanes,i=e.options,r=e.$currTabLis,o=e.$navTabs,s=a?null:e.$currTabContentPanesContainer,l=a?null:e.$currTabContentPanes,c=!1;return t.forEach(function(e,d){var b,f=r.find('a[href="#'+e[n.paneId]+'"]'),v=d>=r.length;f.length||(c=!0,f=E.getNewElTabLi(e,n,i.forceActiveTab),A.storeDataOnLiEl(f,t,d),v?f.appendTo(o):f.insertBefore(r.eq(d)),a||void 0===e[n.content]||(b=E.getNewElTabPane(e,n,i.forceActiveTab),v?b.appendTo(s):b.insertBefore(l.eq(d))))}),c}function c(e){var t=e.tabLi,n=e.ignoreTabPanes,a=t.$li,i=t.$contentPane,r=t.origTabData,o=t.newTabData,s=e.propNames,l=!1;return r[s.title]!==o[s.title]&&(a.find('a[role="tab"]').html(r[s.title]=o[s.title]),l=!0),r[s.disabled]!==o[s.disabled]&&(o[s.disabled]?(a.addClass("disabled"),a.find('a[role="tab"]').attr("data-toggle","")):(a.removeClass("disabled"),a.find('a[role="tab"]').attr("data-toggle","tab")),r[s.disabled]=o[s.disabled],l=!0),e.options.forceActiveTab&&(a[o[s.active]?"addClass":"removeClass"]("active"),i[o[s.active]?"addClass":"removeClass"]("active"),r[s.active]=o[s.active],l=!0),n||r[s.content]===o[s.content]||(i.html(r[s.content]=o[s.content]),l=!0),l}function d(e){var t,n=e.tabLi,a=e.ignoreTabPanes,i=n.$li;return-1===n.newIdx&&(i.hasClass("active")&&(t=A.getIndexOfClosestEnabledTab(e.$currTabLis,n.currDomIdx))>-1&&(e.$currTabLis.eq(t).addClass("active"),a||e.$currTabContentPanes.eq(t).addClass("active")),i.remove(),a||n.$contentPane.remove(),!0)}function b(t){var n=t.$currTabLis,a=t.updatedTabsArray,i=t.propNames,r=t.ignoreTabPanes,o=[],s=r?null:[];return!!A.didTabOrderChange(n,a,i)&&(a.forEach(function(t){var a=t[i.paneId];o.push(n.find('a[role="tab"][href="#'+a+'"]').parent("li")),r||s.push(e("#"+a))}),t.$navTabs.append(o),r||t.$currTabContentPanesContainer.append(s),!0)}function f(t){var n=t.$currTabLis,a=t.updatedTabsArray,i=t.propNames,r=!1;return n.each(function(n){var o=e(this),s=o.data("tab"),l=A.getTabIndexByPaneId(a,i.paneId,s[i.paneId]),b=l>-1?a[l]:null;if(t.tabLi={$li:o,currDomIdx:n,newIdx:l,$contentPane:E.getElTabPaneForLi(o),origTabData:s,newTabData:b},d(t))return void(r=!0);c(t)&&(r=!0)}),r}function v(t,n){function a(t){e(t.target).append(r.off(S.EVENTS.CLICK))}function i(a){function i(){var n=e(this),a=n.parent("li"),i=a.parent(".dropdown-menu"),r=n.attr("href");a.hasClass("active")||(t.find("li.active").not(c).add(i.find("li.active")).removeClass("active"),c.add(a).addClass("active"),e(".tab-content .tab-pane.active").removeClass("active"),e(r).addClass("active"))}var o,s,l,c=e(a.target),d=c.offset(),b=t.find('li[role="presentation"].active');r=c.find(".dropdown-menu").attr("data-"+S.DATA_KEY_DDMENU_MODIFIED,!0),b[0]!==c[0]&&r.find("li.active").removeClass("active"),r.on(S.EVENTS.CLICK,'a[role="tab"]',i),e("body").append(r),o=r.width()+d.left,s=t.width()-(n.$slideRightArrow.outerWidth()+1),l=d.left,o>s&&(l-=o-s),r.css({display:"block",top:d.top+c.outerHeight()-2,left:l})}var r;t.on(S.EVENTS.DROPDOWN_MENU_SHOW,i).on(S.EVENTS.DROPDOWN_MENU_HIDE,a)}function C(e,t){var n=e.data().scrtabs,a=n.scroller,i=e.find(".scrtabs-tab-container .nav-tabs"),r=e.find(".tab-content"),o=!1,s={options:t,updatedTabsArray:n.tabs,propNames:n.propNames,ignoreTabPanes:n.ignoreTabPanes,$navTabs:i,$currTabLis:i.find("> li"),$currTabContentPanesContainer:r,$currTabContentPanes:r.find(".tab-pane")};return l(s)&&(o=!0),b(s)&&(o=!0),f(s)&&(o=!0),o&&a.initTabs(),o}function u(t,n){t.data("scrtabs")&&(!t.data("scrtabs").isWrapperOnly&&C(t,n)||e("body").trigger(S.EVENTS.FORCE_REFRESH))}function h(){var t=e(this),n=t.data("scrtabs");n&&n.scroller.scrollToActiveTab()}function T(){var n,a=e(this),i=a.data("scrtabs");if(i){for("self"===i.enableSwipingElement?a.removeClass(S.CSS_CLASSES.ALLOW_SCROLLBAR):"parent"===i.enableSwipingElement&&a.closest(".scrtabs-tab-container").parent().removeClass(S.CSS_CLASSES.ALLOW_SCROLLBAR),i.scroller.off(S.EVENTS.DROPDOWN_MENU_SHOW).off(S.EVENTS.DROPDOWN_MENU_HIDE),i.scroller.find("[data-"+S.DATA_KEY_DDMENU_MODIFIED+"]").css({display:"",left:"",top:""}).off(S.EVENTS.CLICK).removeAttr("data-"+S.DATA_KEY_DDMENU_MODIFIED),i.scroller.hasTabClickHandler&&a.find('a[data-toggle="tab"]').off(".scrtabs"),i.isWrapperOnly?(n=a.parents(".scrtabs-tab-container"),n.length&&n.replaceWith(a)):(i.scroller&&i.scroller.initTabs&&(i.scroller.initTabs=null),a.find(".scrtabs-tab-container").add(".tab-content").remove()),a.removeData("scrtabs");--e.fn.scrollingTabs.nextInstanceId>=0;)e(t).off(S.EVENTS.WINDOW_RESIZE+e.fn.scrollingTabs.nextInstanceId);e("body").off(S.EVENTS.FORCE_REFRESH)}}var S={CONTINUOUS_SCROLLING_TIMEOUT_INTERVAL:50,SCROLL_OFFSET_FRACTION:6,DATA_KEY_DDMENU_MODIFIED:"scrtabsddmenumodified",DATA_KEY_IS_MOUSEDOWN:"scrtabsismousedown",CSS_CLASSES:{SCROLL_ARROW_DISABLE:"scrtabs-disable"},SLIDE_DIRECTION:{LEFT:1,RIGHT:2},EVENTS:{CLICK:"click.scrtabs",DROPDOWN_MENU_HIDE:"hide.bs.dropdown.scrtabs",DROPDOWN_MENU_SHOW:"show.bs.dropdown.scrtabs",FORCE_REFRESH:"forcerefresh.scrtabs",MOUSEDOWN:"mousedown.scrtabs",MOUSEUP:"mouseup.scrtabs",TABS_READY:"ready.scrtabs",TOUCH_END:"touchend.scrtabs",TOUCH_MOVE:"touchmove.scrtabs",TOUCH_START:"touchstart.scrtabs",WINDOW_RESIZE:"resize.scrtabs"}};!function(t){var n=function(e,t,n){var a;return function(){function i(){n||e.apply(r,o),a=null}var r=this,o=arguments;a?clearTimeout(a):n&&e.apply(r,o),a=setTimeout(i,t||100)}};e.fn[t]=function(e,a){var i=a||S.EVENTS.WINDOW_RESIZE;return e?this.bind(i,n(e)):this.trigger(t)}}("smartresizeScrtabs"),function(n){n.initElements=function(e){var t=this;t.setElementReferences(),t.setEventListeners(e)},n.listenForTouchEvents=function(){var e,t,n,a=this,i=a.stc,r=i.scrollMovement,o=S.EVENTS,s=!1;i.$movableContainer.on(o.TOUCH_START,function(n){s=!0,t=i.movableContainerLeftPos,e=n.originalEvent.changedTouches[0].pageX}).on(o.TOUCH_END,function(){s=!1}).on(o.TOUCH_MOVE,function(a){if(s){var o,l=a.originalEvent.changedTouches[0].pageX,c=l-e;n=t+c,n>0?n=0:(o=r.getMinPos(),n li"),r.$slideLeftArrow=r.reverseScroll?n:a,r.$slideRightArrow=r.reverseScroll?a:n,r.$scrollArrows=r.$slideLeftArrow.add(r.$slideRightArrow),r.$win=e(t)},n.setElementWidths=function(){var e=this,t=e.stc;t.winWidth=t.$win.width(),t.scrollArrowsCombinedWidth=t.$slideLeftArrow.outerWidth()+t.$slideRightArrow.outerWidth(),e.setFixedContainerWidth(),e.setMovableContainerWidth()},n.setEventListeners=function(t){var n=this,a=n.stc,i=a.eventHandlers,r=S.EVENTS,o=r.WINDOW_RESIZE+a.instanceId;t.enableSwiping&&n.listenForTouchEvents(),a.$slideLeftArrow.off(".scrtabs").on(r.MOUSEDOWN,function(e){i.handleMousedownOnSlideMovContainerLeftArrow.call(i,e)}).on(r.MOUSEUP,function(e){i.handleMouseupOnSlideMovContainerLeftArrow.call(i,e)}).on(r.CLICK,function(e){i.handleClickOnSlideMovContainerLeftArrow.call(i,e)}),a.$slideRightArrow.off(".scrtabs").on(r.MOUSEDOWN,function(e){i.handleMousedownOnSlideMovContainerRightArrow.call(i,e)}).on(r.MOUSEUP,function(e){i.handleMouseupOnSlideMovContainerRightArrow.call(i,e)}).on(r.CLICK,function(e){i.handleClickOnSlideMovContainerRightArrow.call(i,e)}),a.tabClickHandler&&a.$tabsLiCollection.find('a[data-toggle="tab"]').off(r.CLICK).on(r.CLICK,a.tabClickHandler),a.$win.off(o).smartresizeScrtabs(function(e){i.handleWindowResize.call(i,e)},o),e("body").on(S.EVENTS.FORCE_REFRESH,a.elementsHandler.refreshAllElementSizes.bind(a.elementsHandler))},n.setFixedContainerWidth=function(){var e=this,t=e.stc,n=t.$tabsContainer.get(0).getBoundingClientRect();t.fixedContainerWidth=n.width||n.right-n.left,t.fixedContainerWidth=t.fixedContainerWidth*t.widthMultiplier,t.$fixedContainer.width(t.fixedContainerWidth)},n.setFixedContainerWidthForHiddenScrollArrows=function(){var e=this,t=e.stc;t.$fixedContainer.width(t.fixedContainerWidth)},n.setFixedContainerWidthForVisibleScrollArrows=function(){var e=this,t=e.stc;t.$fixedContainer.width(t.fixedContainerWidth-t.scrollArrowsCombinedWidth)},n.setMovableContainerWidth=function(){var t=this,n=t.stc,a=n.$tabsUl.find("> li");n.movableContainerWidth=0,a.length&&(a.each(function(){var t=e(this),a=0;n.isNavPills&&(a=parseInt(t.css("margin-left"),10)+parseInt(t.css("margin-right"),10)),n.movableContainerWidth+=t.outerWidth()+a}),n.movableContainerWidth+=1,n.movableContainerWidtht.fixedContainerWidth;n&&!t.scrollArrowsVisible?(t.$scrollArrows.show(),t.scrollArrowsVisible=!0):!n&&t.scrollArrowsVisible&&(t.$scrollArrows.hide(),t.scrollArrowsVisible=!1),t.scrollArrowsVisible?e.setFixedContainerWidthForVisibleScrollArrows():e.setFixedContainerWidthForHiddenScrollArrows()}}(n.prototype),function(e){e.handleClickOnSlideMovContainerLeftArrow=function(){this.stc.scrollMovement.incrementMovableContainerLeft()},e.handleClickOnSlideMovContainerRightArrow=function(){this.stc.scrollMovement.incrementMovableContainerRight()},e.handleMousedownOnSlideMovContainerLeftArrow=function(){var e=this,t=e.stc;t.$slideLeftArrow.data(S.DATA_KEY_IS_MOUSEDOWN,!0),t.scrollMovement.continueSlideMovableContainerLeft()},e.handleMousedownOnSlideMovContainerRightArrow=function(){var e=this,t=e.stc;t.$slideRightArrow.data(S.DATA_KEY_IS_MOUSEDOWN,!0),t.scrollMovement.continueSlideMovableContainerRight()},e.handleMouseupOnSlideMovContainerLeftArrow=function(){this.stc.$slideLeftArrow.data(S.DATA_KEY_IS_MOUSEDOWN,!1)},e.handleMouseupOnSlideMovContainerRightArrow=function(){this.stc.$slideRightArrow.data(S.DATA_KEY_IS_MOUSEDOWN,!1)},e.handleWindowResize=function(){var e=this,t=e.stc,n=t.$win.width();if(n===t.winWidth)return!1;t.winWidth=n,t.elementsHandler.refreshAllElementSizes()}}(a.prototype),function(t){t.continueSlideMovableContainerLeft=function(){var e=this,t=e.stc;setTimeout(function(){t.movableContainerLeftPos<=e.getMinPos()||!t.$slideLeftArrow.data(S.DATA_KEY_IS_MOUSEDOWN)||e.incrementMovableContainerLeft()||e.continueSlideMovableContainerLeft()},S.CONTINUOUS_SCROLLING_TIMEOUT_INTERVAL)},t.continueSlideMovableContainerRight=function(){var e=this,t=e.stc;setTimeout(function(){t.movableContainerLeftPos>=0||!t.$slideRightArrow.data(S.DATA_KEY_IS_MOUSEDOWN)||e.incrementMovableContainerRight()||e.continueSlideMovableContainerRight()},S.CONTINUOUS_SCROLLING_TIMEOUT_INTERVAL)},t.decrementMovableContainerLeftPos=function(e){var t=this,n=t.stc;n.movableContainerLeftPos-=n.fixedContainerWidth/S.SCROLL_OFFSET_FRACTION,n.movableContainerLeftPos0?n.movableContainerLeftPos=0:n.scrollToTabEdge&&t.setMovableContainerLeftPosToTabEdge(S.SLIDE_DIRECTION.RIGHT)),t.slideMovableContainerToLeftPos(),t.enableSlideLeftArrow(),0===n.movableContainerLeftPos},t.refreshScrollArrowsDisabledState=function(){var e=this,t=e.stc;if(t.disableScrollArrowsOnFullyScrolled&&t.scrollArrowsVisible){if(t.movableContainerLeftPos>=0)return e.disableSlideRightArrow(),void e.enableSlideLeftArrow();if(t.movableContainerLeftPos<=e.getMinPos())return e.disableSlideLeftArrow(),void e.enableSlideRightArrow();e.enableSlideLeftArrow(),e.enableSlideRightArrow()}},t.scrollToActiveTab=function(){var e,t,n,a,i,r,o=this,s=o.stc;if(s.scrollArrowsVisible&&(e=s.$tabsUl.find("li.active"),e.length))return t=e.offset().left-s.$fixedContainer.offset().left,n=t+e.outerWidth(),a=s.fixedContainerWidth-20,n>a?(r=s.$slideRightArrow.outerWidth(),s.movableContainerLeftPos-=n-a+r,o.slideMovableContainerToLeftPos(),!0):(i=s.$slideLeftArrow.outerWidth(),ti)return a.movableContainerLeftPos=t===S.SLIDE_DIRECTION.RIGHT?-(r-n):-r,!1})},t.slideMovableContainerToLeftPos=function(){var e,t=this,n=t.stc,a=t.getMinPos();n.movableContainerLeftPos>0?n.movableContainerLeftPos=0:n.movableContainerLeftPos')}function a(t,n){var a=e('
    '),i=n.leftArrowContent||'
    ',r=e(i),o=n.rightArrowContent||'
    ',s=e(o),l=e('
    '),c=e('
    ');return n.disableScrollArrowsOnFullyScrolled&&r.add(s).addClass("scrtabs-disable"),a.append(r,l.append(c.append(t)),s)}function i(t,n){return e('').attr("href","#"+t[n.paneId]).html(t[n.title])}function r(){return e('
    ')}function o(t,n,a){var r=e('
  • '),o=i(t,n).appendTo(r);return t[n.disabled]?(r.addClass("disabled"),o.attr("data-toggle","")):a&&t[n.active]&&r.addClass("active"),r}function s(t,n,a){var i=e('
    ').attr("id",t[n.paneId]).html(t[n.content]);return a&&t[n.active]&&i.addClass("active"),i}return{getElTabPaneForLi:t,getNewElNavTabs:n,getNewElScrollerElementWrappingNavTabsInstance:a,getNewElTabAnchor:i,getNewElTabContent:r,getNewElTabLi:o,getNewElTabPane:s}}(),A=function(){function t(t,n,i){var r=!1;return t.each(function(t){var o=a(n,i.paneId,e(this).data("tab")[i.paneId]);if(o>-1&&o!==t)return r=!0,!1}),r}function n(e,t){for(var n=e.length-1,a=-1,i=0,r=0;-1===a&&r>=0;)((r=t+ ++i)<=n&&!e.eq(r).hasClass("disabled")||(r=t-i)>=0&&!e.eq(r).hasClass("disabled"))&&(a=r);return a}function a(e,t,n){var a=-1;return e.some(function(e,i){if(e[t]===n)return a=i,!0}),a}function i(t,n,a){t.data({tab:e.extend({},n[a]),index:a})}return{didTabOrderChange:t,getIndexOfClosestEnabledTab:n,getTabIndexByPaneId:a,storeDataOnLiEl:i}}(),p={destroy:function(){return this.each(T)},init:function(t){var n=this,a=n.length-1,i=e.extend({},e.fn.scrollingTabs.defaults,t||{});return i.tabs?n.each(function(t){o(e(this),i,t + + + + + + + + + + + + +
    +
    jquery-bootstrap-scrolling-tabs Demo - Data Driven
    +
    Using Tabs Array
    +
    + + + + + +
    + +
    + + +
    +

    +
    + + + + + + + + + + diff --git a/run/markup-only-mult.html b/run/markup-only-mult.html new file mode 100644 index 0000000..0592bf0 --- /dev/null +++ b/run/markup-only-mult.html @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + +
    jquery-bootstrap-scrolling-tabs Demo - Markup Only + + +
    + + + + + + + + +
    +
    + + + + + + + + + + + + + + + diff --git a/src/js/_main.js b/src/js/_main.js index 4e3a1df..1162b9e 100644 --- a/src/js/_main.js +++ b/src/js/_main.js @@ -1,6 +1,7 @@ //=include usage.js ;(function ($, window) { 'use strict'; + /* jshint unused:false */ //=include constants.js //=include smartresize.js diff --git a/src/js/api.js b/src/js/api.js index fc5ab5d..99a8932 100644 --- a/src/js/api.js +++ b/src/js/api.js @@ -54,6 +54,7 @@ var methods = { }; function destroyPlugin() { + /* jshint validthis: true */ var $targetElInstance = $(this), scrtabsData = $targetElInstance.data('scrtabs'), $tabsContainer; @@ -112,7 +113,10 @@ function destroyPlugin() { $targetElInstance.removeData('scrtabs'); - $(window).off(CONSTANTS.EVENTS.WINDOW_RESIZE); + while(--$.fn.scrollingTabs.nextInstanceId >= 0) { + $(window).off(CONSTANTS.EVENTS.WINDOW_RESIZE + $.fn.scrollingTabs.nextInstanceId); + } + $('body').off(CONSTANTS.EVENTS.FORCE_REFRESH); } @@ -128,6 +132,8 @@ $.fn.scrollingTabs = function(methodOrOptions) { } }; +$.fn.scrollingTabs.nextInstanceId = 0; + $.fn.scrollingTabs.defaults = { tabs: null, propPaneId: 'paneId', diff --git a/src/js/elementsHandler.js b/src/js/elementsHandler.js index bda0e5b..6172560 100644 --- a/src/js/elementsHandler.js +++ b/src/js/elementsHandler.js @@ -155,7 +155,8 @@ function ElementsHandler(scrollingTabsControl) { var ehd = this, stc = ehd.stc, evh = stc.eventHandlers, - ev = CONSTANTS.EVENTS; + ev = CONSTANTS.EVENTS, + resizeEventName = ev.WINDOW_RESIZE + stc.instanceId; if (settings.enableSwiping) { ehd.listenForTouchEvents(); @@ -180,7 +181,9 @@ function ElementsHandler(scrollingTabsControl) { .on(ev.CLICK, stc.tabClickHandler); } - stc.$win.off('.scrtabs').smartresize(function (e) { evh.handleWindowResize.call(evh, e); }); + stc.$win + .off(resizeEventName) + .smartresizeScrtabs(function (e) { evh.handleWindowResize.call(evh, e); }, resizeEventName); $('body').on(CONSTANTS.EVENTS.FORCE_REFRESH, stc.elementsHandler.refreshAllElementSizes.bind(stc.elementsHandler)); }; diff --git a/src/js/header.js b/src/js/header.js index 7b81c84..f9f6dc3 100644 --- a/src/js/header.js +++ b/src/js/header.js @@ -1,6 +1,6 @@ /** * jquery-bootstrap-scrolling-tabs - * @version v2.0.0 + * @version v2.0.1 * @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs * @author Mike Jacobson * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/src/js/scrollingTabsControl.js b/src/js/scrollingTabsControl.js index ca53f86..81f3e85 100644 --- a/src/js/scrollingTabsControl.js +++ b/src/js/scrollingTabsControl.js @@ -5,6 +5,7 @@ function ScrollingTabsControl($tabsContainer) { var stc = this; stc.$tabsContainer = $tabsContainer; + stc.instanceId = $.fn.scrollingTabs.nextInstanceId++; stc.movableContainerLeftPos = 0; stc.scrollArrowsVisible = false; diff --git a/src/js/smartresize.js b/src/js/smartresize.js index 3b53baa..845559a 100644 --- a/src/js/smartresize.js +++ b/src/js/smartresize.js @@ -21,6 +21,9 @@ timeout = setTimeout(delayed, threshold || 100); }; }; - $.fn[sr] = function (fn) { return fn ? this.bind(CONSTANTS.EVENTS.WINDOW_RESIZE, debounce(fn)) : this.trigger(sr); }; + $.fn[sr] = function (fn, customEventName) { + var eventName = customEventName || CONSTANTS.EVENTS.WINDOW_RESIZE; + return fn ? this.bind(eventName, debounce(fn)) : this.trigger(sr); + }; -})('smartresize'); +})('smartresizeScrtabs'); diff --git a/src/js/tabListeners.js b/src/js/tabListeners.js index 07fa463..2c54bf3 100644 --- a/src/js/tabListeners.js +++ b/src/js/tabListeners.js @@ -264,6 +264,7 @@ function listenForDropdownMenuTabs($scroller, stc) { }); function handleClickOnDropdownMenuItem() { + /* jshint validthis: true */ var $selectedMenuItemAnc = $(this), $selectedMenuItemLi = $selectedMenuItemAnc.parent('li'), $selectedMenuItemDropdownMenu = $selectedMenuItemLi.parent('.dropdown-menu'), @@ -347,6 +348,7 @@ function refreshTargetElementInstance($container, options) { } function scrollToActiveTab() { + /* jshint validthis: true */ var $targetElInstance = $(this), scrtabsData = $targetElInstance.data('scrtabs');