You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
994 B

  1. defaultClass = 'mastodon-shape'
  2. pieces = [
  3. 'path#mastodon-tusk-front, path#mastodon-tusk-back',
  4. 'path#mastodon-nose',
  5. 'path#mastodon-cheek',
  6. 'path#mastodon-forehead',
  7. 'path#mastodon-backhead',
  8. 'path#mastodon-ear',
  9. ]
  10. pieceIndex = 0
  11. firstPiece = pieces[0]
  12. currentTimer = null
  13. delay = 100
  14. runs = 0
  15. stop_at_run = 1
  16. clearHighlights = ->
  17. $(".#{defaultClass}.highlight").attr('class', defaultClass)
  18. start = ->
  19. clearHighlights()
  20. pieceIndex = 0
  21. runs = 0
  22. pieces.reverse() unless pieces[0] == firstPiece
  23. clearInterval(currentTimer) if currentTimer
  24. currentTimer = setInterval(work, delay)
  25. stop = ->
  26. clearInterval(currentTimer)
  27. clearHighlights()
  28. work = ->
  29. clearHighlights()
  30. $(pieces[pieceIndex]).attr('class', "#{defaultClass} highlight")
  31. if pieceIndex == pieces.length - 1
  32. pieceIndex = 0
  33. pieces.reverse()
  34. runs++
  35. else
  36. pieceIndex++
  37. if runs == stop_at_run
  38. stop()
  39. $(document).on 'turbolinks:load', ->
  40. setTimeout(start, 100)