summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/logo.js.coffee
blob: e864a674cdd70ba615327f1968702b0b522fcbb4 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
NProgress.configure(showSpinner: false)

defaultClass = 'tanuki-shape'
pieces = [
  'path#tanuki-right-cheek',
  'path#tanuki-right-eye, path#tanuki-right-ear',
  'path#tanuki-nose',
  'path#tanuki-left-eye, path#tanuki-left-ear',
  'path#tanuki-left-cheek',
]
pieceIndex = 0
firstPiece = pieces[0]

currentTimer = null
delay        = 150

clearHighlights = ->
  $(".#{defaultClass}.highlight").attr('class', defaultClass)

start = ->
  clearHighlights()
  pieceIndex = 0
  pieces.reverse() unless pieces[0] == firstPiece
  currentTimer = setInterval(work, delay)

stop = ->
  clearInterval(currentTimer)
  clearHighlights()

work = ->
  clearHighlights()
  $(pieces[pieceIndex]).attr('class', "#{defaultClass} highlight")

  # If we hit the last piece, reset the index and then reverse the array to
  # get a nice back-and-forth sweeping look
  if pieceIndex == pieces.length - 1
    pieceIndex = 0
    pieces.reverse()
  else
    pieceIndex++

$(document).on('page:fetch',  start)
$(document).on('page:change', stop)