Commit 7d75c877 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Fixed yesterday & tomorrow links

parent 0531a92c
...@@ -13,7 +13,9 @@ STORAGE_PROGRAMS = 'tvgids-programs' ...@@ -13,7 +13,9 @@ STORAGE_PROGRAMS = 'tvgids-programs'
# Utils # Utils
# #
seconds_today = (time) -> (time - (new Date()).setHours(0, 0, 0, 0)) / 1000 day_start = -> (new Date()).setHours(0, 0, 0, 0)
day_offset = -> Settings.get('day') * 24 * 60 * 60 * 1000
seconds_today = (time) -> (time - day_start() - day_offset()) / 1000
time2px = (seconds) -> HOUR_WIDTH / 3600 * seconds time2px = (seconds) -> HOUR_WIDTH / 3600 * seconds
zeropad = (digit) -> if digit < 10 then '0' + digit else String(digit) zeropad = (digit) -> if digit < 10 then '0' + digit else String(digit)
format_time = (time) -> format_time = (time) ->
...@@ -185,17 +187,8 @@ AppView = Backbone.View.extend( ...@@ -185,17 +187,8 @@ AppView = Backbone.View.extend(
events: events:
# TODO: move to initialize # TODO: move to initialize
'click #yesterday': -> @loadDay(-1)
'click #today': -> @loadDay(0)
'click #tomorrow': -> @loadDay(1)
'scroll': 'moveTimeline' 'scroll': 'moveTimeline'
moveTimeline: ->
if @$el.scrollTop() != @prevScrollTop
@trigger('scroll', @$el.scrollTop() - @prevScrollTop)
@prevScrollTop = @$el.scrollTop()
@$('.timeline').css('top', (@$el.scrollTop() + 37) + 'px')
initialize: -> initialize: ->
@prevScrollTop = null @prevScrollTop = null
...@@ -204,10 +197,14 @@ AppView = Backbone.View.extend( ...@@ -204,10 +197,14 @@ AppView = Backbone.View.extend(
@labelview = new ChannelLabelsView(app: @) @labelview = new ChannelLabelsView(app: @)
$('#yesterday').click(-> Settings.set(day: -1))
$('#today').click(-> Settings.set(day: 0))
$('#tomorrow').click(-> Settings.set(day: 1))
Channels.fetch() Channels.fetch()
@centerIndicator() @centerIndicator()
@updateIndicator() @updateIndicator()
setInterval((=> @updateIndicator()), 3600000 / HOUR_WIDTH) setInterval((=> @updateIndicator()), 60 * 60 * 1000 / HOUR_WIDTH)
addChannels: -> addChannels: ->
@$('.channels > .channel').remove() @$('.channels > .channel').remove()
...@@ -216,25 +213,33 @@ AppView = Backbone.View.extend( ...@@ -216,25 +213,33 @@ AppView = Backbone.View.extend(
view.render() view.render()
@$('.channels').append(view.el) @$('.channels').append(view.el)
, @) , @)
@updateIndicator()
@fetchPrograms() @fetchPrograms()
loadDay: (day) ->
Settings.set(day: day)
@$('.navbar .active').removeClass('active')
$(@$('.navbar .navitem')[day + 1]).addClass('active')
updateIndicator: -> updateIndicator: ->
if Settings.get('day') == 0
left = time2px(seconds_today(Date.now())) + CHANNEL_LABEL_WIDTH - 1 left = time2px(seconds_today(Date.now())) + CHANNEL_LABEL_WIDTH - 1
@$('.indicator') @$('.indicator')
.css('left', left + 'px') .css('left', left + 'px')
.height(@$('.channels').height() - 2) .height(@$('.channels').height() - 2)
.show()
else
@$('.indicator').hide()
centerIndicator: -> centerIndicator: ->
@$el.scrollLeft(@$('.indicator').position().left - @$el.width() / 2) @$el.scrollLeft(@$('.indicator').position().left - @$el.width() / 2)
fetchPrograms: -> fetchPrograms: ->
Channels.fetchPrograms(Settings.get('day')) day = Settings.get('day')
Channels.fetchPrograms(day)
@updateIndicator()
$('.navbar .active').removeClass('active')
$($('.navbar .navitem')[day + 1]).addClass('active')
moveTimeline: ->
if @$el.scrollTop() != @prevScrollTop
@trigger('scroll', @$el.scrollTop() - @prevScrollTop)
@prevScrollTop = @$el.scrollTop()
@$('.timeline').css('top', (@$el.scrollTop() + 37) + 'px')
) )
# #
......
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