summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/layout_nav.js.coffee
blob: f639f7f589278e96a212dd4261c9496e963428a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
hideEndFade = ($scrollingTabs) ->
  $scrollingTabs.each ->
    $this = $(@)

    $this
      .siblings('.fade-right')
      .toggleClass('scrolling', $this.width() < $this.prop('scrollWidth'))

$ ->

  hideEndFade($('.scrolling-tabs'))

  $(window)
    .off 'resize.nav'
    .on 'resize.nav', ->
      hideEndFade($('.scrolling-tabs'))

  $('.scrolling-tabs').on 'scroll', (event) ->
    $this = $(this)
    currentPosition = $this.scrollLeft()
    maxPosition = $this.prop('scrollWidth') - $this.outerWidth()

    $this.siblings('.fade-left').toggleClass('scrolling', currentPosition > 0)
    $this.siblings('.fade-right').toggleClass('scrolling', currentPosition < maxPosition - 1)