blob: 0e65414216d71df4625e012e83f3288c88d533fe (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
class TimeTravel
constructor: (@overview)->
@container = @overview.container.find('.time-travel')
@todayBt = @container.find(".today")
@prevBt = @container.find(".prev-page")
@nextBt = @container.find(".next-page")
@searchDateBt = @container.find("a.search-date")
@searchDateInput = @container.find("input.date-search")
@initButtons()
initButtons: ->
@prevBt.click (e)=>
@overview.prevPage()
e.preventDefault()
false
@nextBt.click (e)=>
@overview.nextPage()
e.preventDefault()
false
@todayBt.click (e)=>
today = new Date()
month = today.getMonth() + 1
month = "0#{month}" if month < 10
day = today.getDate()
day = "0#{month}" if day < 10
@overview.showDay "#{today.getFullYear()}-#{month}-#{day}"
e.preventDefault()
false
@searchDateBt.click (e)=>
@overview.showDay @searchDateInput.val() if @searchDateInput.val().length > 0
e.preventDefault()
false
scrolledTo: (progress)->
@prevBt.removeClass 'disabled'
@nextBt.removeClass 'disabled'
@prevBt.addClass 'disabled' if progress == 0
@nextBt.addClass 'disabled' if progress == 1
class window.ReferentialOverview
constructor: (selector)->
@container = $(selector)
@timeTravel = new TimeTravel(this)
@currentOffset = 0
$(document).scroll (e)=>
@documentScroll(e)
@documentScroll pageY: $(document).scrollTop()
showDay: (date)->
day = @container.find(".day.#{date}")
@container.find(".day.selected").removeClass('selected')
day.addClass "selected"
offset = day.offset().left
parentOffset = @currentOffset + @container.find(".right").offset().left
@scrollTo parentOffset - offset
currentOffset: ->
@container.find(".right .inner").offset().left
top: ->
@_top ||= @container.find('.days').offset().top - 80
bottom: ->
@_bottom ||= @top() + @container.height() - 50
prevPage: ->
@scrollTo @currentOffset + @container.find(".right").width()
nextPage: ->
@scrollTo @currentOffset - @container.find(".right").width()
minOffset: ->
@_minOffset ||= @container.find(".right").width() - @container.find(".right .line").width()
@_minOffset
scrollTo: (offset)->
@currentOffset = offset
@currentOffset = Math.max(@currentOffset, @minOffset())
@currentOffset = Math.min(@currentOffset, 0)
@container.find(".right .inner .lines").css "margin-left": "#{@currentOffset}px"
@container.find(".head .week:first-child").css "margin-left", "#{@currentOffset}px"
@timeTravel.scrolledTo 1 - (@minOffset() - @currentOffset) / @minOffset()
setTimeout =>
@movePeriodTitles()
, 600
movePeriodTitles: ->
@_right_offset ||= @container.find('.right').offset().left
@container.find(".shifted").removeClass("shifted").css "margin-left", 0
@container.find(".right .line").each (i, l) =>
$(l).find(".period").each (i, _p) =>
p = $(_p)
offset = parseInt(p.css("left")) + @currentOffset
if offset < 0 && - offset < p.width()
offset = Math.min(-offset, p.width() - 100)
p.find(".title").addClass("shifted").css "margin-left", offset + "px"
return
documentScroll: (e)->
if @sticky
if e.pageY < @top() || e.pageY > @bottom()
@container.removeClass "sticky"
@sticky = false
else
if e.pageY > @top() && e.pageY < @bottom()
@sticky = true
@container.addClass "sticky"
export default ReferentialOverview
|