Created
September 27, 2011 19:53
-
-
Save raine/1246044 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ -> | |
| return unless $('#pages_home').length | |
| $(window).blur -> | |
| disableLoop() | |
| $(window).focus -> | |
| enableLoop() if not window.cInt? | |
| fadeDuration = 1000 | |
| items = ($ elem for elem in $ '.right') | |
| current = 0 | |
| _(items.length).times -> | |
| $('<span>').addClass('dot').appendTo('#ctrl') | |
| $('#ctrl .dot:first').addClass('active') | |
| dots = $('#ctrl .dot') | |
| disableLoop = -> | |
| clearInterval window.cInt if window.cInt? | |
| delete window.cInt | |
| enableLoop = -> | |
| disableLoop() | |
| window.cInt = setInterval showNext, 10000 | |
| dots.click -> | |
| disableLoop() | |
| setTimeout enableLoop, 10000 | |
| showItem $(this).index() | |
| activateDot = (i) -> | |
| dots.removeClass 'active' | |
| $(dots[i]).addClass 'active' | |
| showItem = (i, delayDot) -> | |
| return if i == current | |
| items[current].fadeOut fadeDuration | |
| items[i].fadeIn fadeDuration, -> | |
| activateDot i if delayDot | |
| activateDot i unless delayDot | |
| current = i | |
| showNext = -> | |
| nextIndex = -> | |
| return 0 if current + 1 == items.length | |
| current + 1 | |
| showItem nextIndex(), true | |
| enableLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment