diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-01-04 15:18:04 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-01-04 15:32:05 -0500 |
commit | 567d87d90f2ba7195901ea24d240686c6030a4a7 (patch) | |
tree | 6a949fcb0c95de00062c2ffafacd96eea2d44ad9 /app | |
parent | 9f46ca444354d4c6b52de3f23ce17c11f705d006 (diff) | |
download | gitlab-ce-567d87d90f2ba7195901ea24d240686c6030a4a7.tar.gz |
Restructure logo JS to use `setInterval`rs-logo-animation
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/logo.js.coffee | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/app/assets/javascripts/logo.js.coffee b/app/assets/javascripts/logo.js.coffee index b4dc993dead..e864a674cdd 100644 --- a/app/assets/javascripts/logo.js.coffee +++ b/app/assets/javascripts/logo.js.coffee @@ -1,6 +1,5 @@ NProgress.configure(showSpinner: false) -delay = 150 defaultClass = 'tanuki-shape' pieces = [ 'path#tanuki-right-cheek', @@ -9,39 +8,36 @@ pieces = [ 'path#tanuki-left-eye, path#tanuki-left-ear', 'path#tanuki-left-cheek', ] +pieceIndex = 0 firstPiece = pieces[0] -timeout = null + +currentTimer = null +delay = 150 clearHighlights = -> $(".#{defaultClass}.highlight").attr('class', defaultClass) start = -> clearHighlights() + pieceIndex = 0 pieces.reverse() unless pieces[0] == firstPiece - work(0) + currentTimer = setInterval(work, delay) stop = -> - window.clearTimeout(timeout) + clearInterval(currentTimer) clearHighlights() -work = (pieceIndex) -> - # jQuery's addClass won't work on an SVG. Who knew! - $piece = $(pieces[pieceIndex]) - $piece.attr('class', "#{defaultClass} highlight") - - timeout = setTimeout(-> - $piece.attr('class', defaultClass) - - # 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 + 1 >= pieces.length - nextIndex = 0 - pieces.reverse() - else - nextIndex = pieceIndex + 1 - - work(nextIndex) - , delay) - -$(document).on 'page:fetch', start -$(document).on 'page:change', stop +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) |