summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/lib/view/Scrollable.js
blob: 7f90929ac6edcb749d79ab5dbdc3c628cb7c7ee3 (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
var ScrollableView = View.extend({
  
  events: {
    "load img": "deferRefresh",
  },

  deferScrollToTop: function(){
    this.scrollPosition = 0
    setTimeout(this.scrollToTop.bind(this), 0)
  },
  
  scrollPosition: 0,
  
  resetScroll: function(){
    this.scrollPosition = 0
  },
  
  saveScroll: function(){
    this.scrollPosition = this.scroller.y
  },
  
  restoreScroll: function(){
    setTimeout(function(){
      this.scroller.scrollTo(0, this.scrollPosition)
    }.bind(this), 0)
  },
  
  refreshScroller: function(){
    this.scroller.refresh()
    clearTimeout( this.scrollerRefreshTimeout )
  },

  scrollerRefreshTimeout: null,
  deferRefresh: function(){
    clearTimeout( this.scrollerRefreshTimeout )
    this.scrollerRefreshTimeout = setTimeout(this.refreshScroller.bind(this))
  },
    
  scrollToTop: function(){
    this.scroller.refresh()
    this.scroller.scrollTo(0, 0)
  },

})