Commit 567d87d9 authored by Robert Speicher's avatar Robert Speicher

Restructure logo JS to use `setInterval`

parent 9f46ca44
NProgress.configure(showSpinner: false) NProgress.configure(showSpinner: false)
delay = 150
defaultClass = 'tanuki-shape' defaultClass = 'tanuki-shape'
pieces = [ pieces = [
'path#tanuki-right-cheek', 'path#tanuki-right-cheek',
...@@ -9,39 +8,36 @@ pieces = [ ...@@ -9,39 +8,36 @@ pieces = [
'path#tanuki-left-eye, path#tanuki-left-ear', 'path#tanuki-left-eye, path#tanuki-left-ear',
'path#tanuki-left-cheek', 'path#tanuki-left-cheek',
] ]
pieceIndex = 0
firstPiece = pieces[0] firstPiece = pieces[0]
timeout = null
currentTimer = null
delay = 150
clearHighlights = -> clearHighlights = ->
$(".#{defaultClass}.highlight").attr('class', defaultClass) $(".#{defaultClass}.highlight").attr('class', defaultClass)
start = -> start = ->
clearHighlights() clearHighlights()
pieceIndex = 0
pieces.reverse() unless pieces[0] == firstPiece pieces.reverse() unless pieces[0] == firstPiece
work(0) currentTimer = setInterval(work, delay)
stop = -> stop = ->
window.clearTimeout(timeout) clearInterval(currentTimer)
clearHighlights() clearHighlights()
work = (pieceIndex) -> work = ->
# jQuery's addClass won't work on an SVG. Who knew! clearHighlights()
$piece = $(pieces[pieceIndex]) $(pieces[pieceIndex]).attr('class', "#{defaultClass} highlight")
$piece.attr('class', "#{defaultClass} highlight")
# If we hit the last piece, reset the index and then reverse the array to
timeout = setTimeout(-> # get a nice back-and-forth sweeping look
$piece.attr('class', defaultClass) if pieceIndex == pieces.length - 1
pieceIndex = 0
# If we hit the last piece, reset the index and then reverse the array to pieces.reverse()
# get a nice back-and-forth sweeping look else
if pieceIndex + 1 >= pieces.length pieceIndex++
nextIndex = 0
pieces.reverse() $(document).on('page:fetch', start)
else $(document).on('page:change', stop)
nextIndex = pieceIndex + 1
work(nextIndex)
, delay)
$(document).on 'page:fetch', start
$(document).on 'page:change', stop
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment