about summary refs log tree commit diff
path: root/app/assets/javascripts/mastodon-logo.coffee
blob: 0b4e67e798a7e91bec17f9d6e8dc651a24f7c2c0 (plain) (blame)
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
44
45
46
47
48
defaultClass = 'mastodon-shape'
pieces = [
  'path#mastodon-tusk-front, path#mastodon-tusk-back',
  'path#mastodon-nose',
  'path#mastodon-cheek',
  'path#mastodon-forehead',
  'path#mastodon-backhead',
  'path#mastodon-ear',
]
pieceIndex = 0
firstPiece = pieces[0]

currentTimer = null
delay        = 100
runs         = 0
stop_at_run  = 1

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

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

stop = ->
  clearInterval(currentTimer)
  clearHighlights()

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

  if pieceIndex == pieces.length - 1
    pieceIndex = 0
    pieces.reverse()
    runs++
  else
    pieceIndex++

  if runs == stop_at_run
    stop()

$(document).on 'turbolinks:load', ->
  setTimeout(start, 100)