2017-01-12 03:49:57 +00:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, no-unused-vars, one-var, one-var-declaration-per-line, vars-on-top, max-len */
|
|
|
|
|
2016-07-24 20:45:11 +00:00
|
|
|
(function() {
|
|
|
|
var hideEndFade;
|
|
|
|
|
|
|
|
hideEndFade = function($scrollingTabs) {
|
|
|
|
return $scrollingTabs.each(function() {
|
|
|
|
var $this;
|
|
|
|
$this = $(this);
|
|
|
|
return $this.siblings('.fade-right').toggleClass('scrolling', $this.width() < $this.prop('scrollWidth'));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-28 14:56:08 +00:00
|
|
|
$(document).on('init.scrolling-tabs', () => {
|
|
|
|
const $scrollingTabs = $('.scrolling-tabs').not('.is-initialized');
|
|
|
|
$scrollingTabs.addClass('is-initialized');
|
2016-09-15 08:38:47 +00:00
|
|
|
|
|
|
|
hideEndFade($scrollingTabs);
|
2016-07-24 20:45:11 +00:00
|
|
|
$(window).off('resize.nav').on('resize.nav', function() {
|
2016-09-15 08:38:47 +00:00
|
|
|
return hideEndFade($scrollingTabs);
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
2016-09-15 08:38:47 +00:00
|
|
|
$scrollingTabs.off('scroll').on('scroll', function(event) {
|
2016-07-24 20:45:11 +00:00
|
|
|
var $this, currentPosition, maxPosition;
|
|
|
|
$this = $(this);
|
|
|
|
currentPosition = $this.scrollLeft();
|
|
|
|
maxPosition = $this.prop('scrollWidth') - $this.outerWidth();
|
|
|
|
$this.siblings('.fade-left').toggleClass('scrolling', currentPosition > 0);
|
|
|
|
return $this.siblings('.fade-right').toggleClass('scrolling', currentPosition < maxPosition - 1);
|
|
|
|
});
|
2016-09-15 08:38:47 +00:00
|
|
|
|
|
|
|
$scrollingTabs.each(function () {
|
2017-01-12 03:49:57 +00:00
|
|
|
var $this = $(this);
|
|
|
|
var scrollingTabWidth = $this.width();
|
|
|
|
var $active = $this.find('.active');
|
|
|
|
var activeWidth = $active.width();
|
2016-09-15 08:38:47 +00:00
|
|
|
|
2016-09-16 12:52:06 +00:00
|
|
|
if ($active.length) {
|
|
|
|
var offset = $active.offset().left + activeWidth;
|
|
|
|
|
|
|
|
if (offset > scrollingTabWidth - 30) {
|
|
|
|
var scrollLeft = scrollingTabWidth / 2;
|
|
|
|
scrollLeft = (offset - scrollLeft) - (activeWidth / 2);
|
|
|
|
$this.scrollLeft(scrollLeft);
|
|
|
|
}
|
2016-09-15 08:38:47 +00:00
|
|
|
}
|
|
|
|
});
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
2017-02-10 06:50:50 +00:00
|
|
|
}).call(window);
|