app/assets/javascripts/material/tab.js in material-sass-0.0.4 vs app/assets/javascripts/material/tab.js in material-sass-1.0.0

- old
+ new

@@ -1,31 +1,51 @@ // tab switch - tabSwitch = function(newTab, oldTab) { - var $nav = newTab.closest('.tab-nav'), - $navIndicator = $('.tab-nav-indicator', $nav), - navOffset = $nav.offset().left, - navWidth = $nav.width(), - newTabOffset = newTab.offset().left, - newTabWidth = newTab.outerWidth(); + (function ($) { + 'use strict'; - if (oldTab != null && oldTab.offset().left > newTabOffset) { - $navIndicator.addClass('reverse'); - setTimeout(function() { - $navIndicator.removeClass('reverse'); - }, 450); - }; + $.fn.tabSwitch = function (oldTab) { + var $this = $(this), + $thisNav = $this.closest('.tab-nav'), + $thisNavIndicator = $('.tab-nav-indicator', $thisNav), + thisLeft = $this.offset().left, + thisNavLeft = $thisNav.offset().left, + thisNavWidth = $thisNav.outerWidth(); - $navIndicator.css({ - left: (newTabOffset - navOffset), - right: navOffset + navWidth - newTabOffset - newTabWidth + if (oldTab !== undefined && oldTab[0] !== undefined) { + var oldTabLeft = oldTab.offset().left; + + $thisNavIndicator.css({ + left: (oldTabLeft - thisNavLeft), + right: (thisNavLeft + thisNavWidth - oldTabLeft - oldTab.outerWidth()) + }); + + if (oldTab.offset().left > thisLeft) { + $thisNavIndicator.addClass('reverse'); + + $thisNavIndicator.one('webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend', function () { + $thisNavIndicator.removeClass('reverse'); + }); + }; + }; + + $thisNavIndicator.addClass('animate').css({ + left: (thisLeft - thisNavLeft), + right: (thisNavLeft + thisNavWidth - thisLeft - $this.outerWidth()) + }).one('webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend', function () { + $thisNavIndicator.removeClass('animate'); + }); + + return this; + } + })(jQuery); + + $(function () { + 'use strict'; + + $('.tab-nav').each(function () { + $(this).append('<div class="tab-nav-indicator"></div>'); }); - } - $(document).on('show.bs.tab', '.tab-nav a[data-toggle="tab"]', function(e) { - tabSwitch($(e.target), $(e.relatedTarget)); + $(document).on('show.bs.tab', '.tab-nav a[data-toggle="tab"]', function (e) { + $(e.target).tabSwitch($(e.relatedTarget)); + }); }); - -// tab switch indicator - $('.tab-nav').each(function() { - $(this).append('<div class="tab-nav-indicator"></div>'); - tabSwitch($('.nav > li.active', $(this)), null); - }); \ No newline at end of file