<commit_before>Backbone = require 'backbone'
_ = require 'underscore'

module.exports = class HeroUnitView extends Backbone.View

  initialize: ->
    @$window = $ window
    @$mainHeader = @$('#main-layout-header')
    @$heroUnits = @$('#home-hero-units')
    @setBodyClass()
    @setInterval()
    @$window .on 'scroll', _.throttle @setBodyClass, 100

  setInterval: ->
    clearInterval @interval
    @interval = setInterval @nextHeroUnit, 8000

  setBodyClass: =>
    if @$window.scrollTop() + @$mainHeader.height() <= @$heroUnits.height()
      $activeLi = @$('.home-hero-unit.home-hero-unit-active')
      if $activeLi.hasClass('home-hero-unit-white')
        @$el.removeClass('body-transparent-header-white').addClass 'body-transparent-header'
      else
        @$el.removeClass('body-transparent-header').addClass 'body-transparent-header-white'
    else
      @$el.removeClass 'body-transparent-header body-transparent-header-white'

  nextHeroUnit: (direction = 1) =>
    if direction is 1
      $next = @$('.home-hero-unit.home-hero-unit-active').next()
      $next = @$('.home-hero-unit').first() unless $next.length
    else
      $next = @$('.home-hero-unit.home-hero-unit-active').prev()
      $next = @$('.home-hero-unit').last() unless $next.length
    @showHeroUnit $next.index()

  showHeroUnit: (index) ->
    @$('.home-hero-unit').removeClass('home-hero-unit-active')
    @$('.home-hero-unit').eq(index).addClass('home-hero-unit-active')
    @$("#home-hero-unit-dots li").removeClass 'hhud-active'
    @$("#home-hero-unit-dots li").eq(index).addClass('hhud-active')
    @setBodyClass()

  events:
    'click #home-hero-units-left-arrow': 'onLeftArrow'
    'click #home-hero-units-right-arrow': 'onRightArrow'
    'click #home-hero-unit-dots li': 'onDot'

  onLeftArrow: ->
    @setInterval()
    @nextHeroUnit -1

  onRightArrow: ->
    @setInterval()
    @nextHeroUnit()

  onDot: (e) ->
    @showHeroUnit $(e.target).index()<commit_msg>Let arrow buttons scroll thru heros<commit_after>Backbone = require 'backbone'
_ = require 'underscore'

module.exports = class HeroUnitView extends Backbone.View

  initialize: ->
    @$window = $ window
    @$mainHeader = @$('#main-layout-header')
    @$heroUnits = @$('#home-hero-units')
    @setBodyClass()
    @setInterval()
    @$window.on 'scroll', _.throttle @setBodyClass, 100
    @$window.on 'keyup', (e) => @onKeyUp(e) 

  setInterval: ->
    clearInterval @interval
    @interval = setInterval @nextHeroUnit, 8000

  setBodyClass: =>
    if @$window.scrollTop() + @$mainHeader.height() <= @$heroUnits.height()
      $activeLi = @$('.home-hero-unit.home-hero-unit-active')
      if $activeLi.hasClass('home-hero-unit-white')
        @$el.removeClass('body-transparent-header-white').addClass 'body-transparent-header'
      else
        @$el.removeClass('body-transparent-header').addClass 'body-transparent-header-white'
    else
      @$el.removeClass 'body-transparent-header body-transparent-header-white'

  nextHeroUnit: (direction = 1) =>
    if direction is 1
      $next = @$('.home-hero-unit.home-hero-unit-active').next()
      $next = @$('.home-hero-unit').first() unless $next.length
    else
      $next = @$('.home-hero-unit.home-hero-unit-active').prev()
      $next = @$('.home-hero-unit').last() unless $next.length
    @showHeroUnit $next.index()

  showHeroUnit: (index) ->
    @$('.home-hero-unit').removeClass('home-hero-unit-active')
    @$('.home-hero-unit').eq(index).addClass('home-hero-unit-active')
    @$("#home-hero-unit-dots li").removeClass 'hhud-active'
    @$("#home-hero-unit-dots li").eq(index).addClass('hhud-active')
    @setBodyClass()

  events:
    'click #home-hero-units-left-arrow': 'onLeftArrow'
    'click #home-hero-units-right-arrow': 'onRightArrow'
    'click #home-hero-unit-dots li': 'onDot'

  onKeyUp: (e) ->
    switch e.keyCode
      when 37
        @onLeftArrow()
      when 39
        @onRightArrow()
    false

  onLeftArrow: ->
    @setInterval()
    @nextHeroUnit -1

  onRightArrow: ->
    @setInterval()
    @nextHeroUnit()

  onDot: (e) ->
    @showHeroUnit $(e.target).index()
{'fraction_non_alphanumeric': 0.18511311116516663, 'fraction_numerical': 0.005837995621503284, 'mean_word_length': 3.342133051742344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4539176', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1414, 'n_words': 226}