Created
February 3, 2013 11:34
-
-
Save atleastimtrying/4701409 to your computer and use it in GitHub Desktop.
Some thoughts on a timestamp to countdown. depends on moment.js and jquery
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
| class App | |
| constructor: -> | |
| $('.fullscreen').click @fullscreen | |
| $('#display').click -> $(@).hide() | |
| @started = true | |
| @loop() | |
| fullscreen: -> | |
| $('#display').html $(@).parent().html() | |
| $('#display').show() | |
| false | |
| dhm: (total)-> | |
| cd = 24 * 60 * 60 * 1000 | |
| ch = 60 * 60 * 1000 | |
| cm = 60 * 1000 | |
| days = Math.floor total / cd | |
| days_in_ms = days * cd | |
| hours = '0' + Math.floor (total - days_in_ms) / ch | |
| hours_in_ms = hours * ch | |
| mins = '0' + Math.floor (total - days_in_ms - hours_in_ms) / cm | |
| mins_in_ms = mins * cm | |
| secs = '0' + Math.round (total - days_in_ms - hours_in_ms - mins_in_ms) / 1000 | |
| "#{days} : #{hours.substr(-2)} : #{mins.substr(-2)} : #{secs.substr(-2)}" | |
| loop: => | |
| $('p.timer').each (index,element)=> | |
| target = moment.unix($(element).data('timestamp')) | |
| now = moment() | |
| $(element).html @dhm(target.diff(now)) | |
| setTimeout(@loop, 100) if @started | |
| $ -> | |
| window.app = new App() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment