summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/NavView.js
blob: e2b334c68f8e6d59848157ab48b71725c9bb9511 (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
var NavView = View.extend({

  el: ".menu",
  
  events: {
    "click li": "click",
  },
  
  initialize: function(){
  },
  
  click: function(e){
    var id = $(e.target).data("id")
    this.pick(id)
  },
  
  pick: function(id){
    var view = app.lookup[ id ]
    this.swap( view, "down" )
  },
  
  previous: function(){
    if ($('body').hasClass('navopen')) {
      $('body').removeClass('navopen')
      return
    }
    var index = Math.max( app.view.page_number - 1, 0 )
    var view = app.projects[ index ]
    this.swap( view, "up" )

    var prevIndex = Math.max( app.view.page_number - 1, 0 )
    var prevView = app.projects[ prevIndex ]
    prevView.preload()
  },
  
  next: function(){
    if ($('body').hasClass('navopen')) {
      $('body').removeClass('navopen')
      return
    }
    var index = (app.view.page_number + 1) % app.projects.length
    var view = app.projects[ index ]
    this.swap( view, "down" )
    
    var nextIndex = (app.view.page_number + 1) % app.projects.length
    var nextView = app.projects[ nextIndex ]
    nextView.preload()
  },
  
  swap: function(view, direction) {
    if (view && ! app.view) {
      app.view = view
      app.view.show()
      return
    }
    if (! view || app.view == view || app.view.showing) {
      return
    }

    direction = direction || "down"

    addClassForPeriod( document.body, direction, app.navigation_delay )
    
    app.view.hide()
    view.show()
    app.view = view
  },
  
  setActive: function(id){
    this.$(".active").removeClass("active")
    this.$("[data-id=" + id + "]").addClass("active")
  },
  
})