summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/index/countdown.js
blob: 6020e9d1ee3c40cc80d40dd5620c81054fb8e7ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var Countdown = View.extend({
  
  el: ".countdown",
  countdownTo: new Date(2019, 9, 5, 0, 0, 0),
  
  events: {
  },
  
  initialize: function(){
    this.__super__.initialize.call(this)
    this.update()
  },

  update() {
    var now = (this.countdownTo - new Date()) / 1000
    if (now < 0) {
      if (now > -86400) {
        this.$el.html("<b><i><big>today's the day!</big></i></b>")
      } else {
        this.$el.html("<b><i><big>bucky says congrats!!!!</big></i></b>")
      }
      return
    }
    var seconds = Math.floor(now % 60)
    now /= 60
    var minutes = Math.floor(now % 60)
    now /= 60
    var hours = Math.floor(now % 24)
    now /= 24
    var days = Math.floor(now % 7)
    now /= 7
    var weeks = Math.floor(now)
    var date_string = [
      '<big><b>',
      (weeks ? (
          (weeks && days) ? weeks + ' weeks,' : weeks + ' weeks'
        ) : ''
      ),
      (days ? days + ' days' : ''),
      '</big></b>',
      hours, 'hours,',
      minutes, 'minutes,',
      seconds, 'seconds',
    ].join(' ')
    this.$el.html( date_string + "<br><i style='display: block;margin-top: 4px;'>until the big day!</i>")
    setTimeout(this.update.bind(this), 1000)
  },
})