BigW Consortium Gitlab

layout_nav.js 1.46 KB
Newer Older
1
/* eslint-disable */
Fatih Acet committed
2 3 4 5 6 7 8 9 10 11 12 13
(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'));
    });
  };

  $(function() {
14 15 16
    var $scrollingTabs = $('.scrolling-tabs');

    hideEndFade($scrollingTabs);
Fatih Acet committed
17
    $(window).off('resize.nav').on('resize.nav', function() {
18
      return hideEndFade($scrollingTabs);
Fatih Acet committed
19
    });
20
    $scrollingTabs.off('scroll').on('scroll', function(event) {
Fatih Acet committed
21 22 23 24 25 26 27
      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);
    });
28 29 30 31 32

    $scrollingTabs.each(function () {
      var $this = $(this),
          scrollingTabWidth = $this.width(),
          $active = $this.find('.active'),
33
          activeWidth = $active.width();
34

35 36 37 38 39 40 41 42
      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);
        }
43 44
      }
    });
Fatih Acet committed
45 46 47
  });

}).call(this);