2017-01-11 22:49:57 -05: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 */
|
2017-04-24 10:52:53 -04:00
|
|
|
import _ from 'underscore';
|
2017-07-19 21:26:18 -04:00
|
|
|
import Cookies from 'js-cookie';
|
2017-07-17 18:33:12 -04:00
|
|
|
import NewNavSidebar from './new_sidebar';
|
2017-07-19 05:36:08 -04:00
|
|
|
import initFlyOutNav from './fly_out_nav';
|
2017-01-11 22:49:57 -05:00
|
|
|
|
2016-07-24 16:45:11 -04: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 10:56:08 -04:00
|
|
|
$(document).on('init.scrolling-tabs', () => {
|
|
|
|
const $scrollingTabs = $('.scrolling-tabs').not('.is-initialized');
|
|
|
|
$scrollingTabs.addClass('is-initialized');
|
2016-09-15 04:38:47 -04:00
|
|
|
|
|
|
|
hideEndFade($scrollingTabs);
|
2016-07-24 16:45:11 -04:00
|
|
|
$(window).off('resize.nav').on('resize.nav', function() {
|
2016-09-15 04:38:47 -04:00
|
|
|
return hideEndFade($scrollingTabs);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-09-15 04:38:47 -04:00
|
|
|
$scrollingTabs.off('scroll').on('scroll', function(event) {
|
2016-07-24 16:45:11 -04: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 04:38:47 -04:00
|
|
|
|
|
|
|
$scrollingTabs.each(function () {
|
2017-01-11 22:49:57 -05:00
|
|
|
var $this = $(this);
|
|
|
|
var scrollingTabWidth = $this.width();
|
|
|
|
var $active = $this.find('.active');
|
|
|
|
var activeWidth = $active.width();
|
2016-09-15 04:38:47 -04:00
|
|
|
|
2016-09-16 08:52:06 -04: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 04:38:47 -04:00
|
|
|
}
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-24 10:52:53 -04:00
|
|
|
|
|
|
|
function applyScrollNavClass() {
|
2017-05-12 10:42:09 -04:00
|
|
|
const scrollOpacityHeight = 40;
|
|
|
|
$('.navbar-border').css('opacity', Math.min($(window).scrollTop() / scrollOpacityHeight, 1));
|
2017-04-24 10:52:53 -04:00
|
|
|
}
|
|
|
|
|
2017-05-12 10:42:09 -04:00
|
|
|
$(() => {
|
2017-07-19 05:36:08 -04:00
|
|
|
if (Cookies.get('new_nav') === 'true') {
|
2017-07-19 21:26:18 -04:00
|
|
|
const newNavSidebar = new NewNavSidebar();
|
|
|
|
newNavSidebar.bindEvents();
|
2017-07-24 09:36:31 -04:00
|
|
|
|
2017-07-19 05:36:08 -04:00
|
|
|
initFlyOutNav();
|
|
|
|
}
|
2017-07-19 21:26:18 -04:00
|
|
|
|
2017-05-12 10:42:09 -04:00
|
|
|
$(window).on('scroll', _.throttle(applyScrollNavClass, 100));
|
|
|
|
});
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|