blob: c9a266deaba3c6c97639c4d55fb0516c8023fe15 (
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
 | class TimeTravel
  constructor: (@overview)->
    @container = @overview.container.find('.time-travel')
    @todayBt = @container.find(".today")
    @prevBt = @container.find(".prev-page")
    @nextBt = @container.find(".next-page")
    @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
  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)
  showDay: (date)->
    day = @container.find(".day.#{date}")
    offset = day.offset().left
    parentOffset = @container.find(".right .inner").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()
  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
 |