summaryrefslogtreecommitdiff
path: root/public/assets/js/app.js
blob: 5ae0c99a8637acfeab31f60cdcd5f641f6945453 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var app = (function() {
  var app = {}
  
  app.navigation_delay = 150

  app.iscroll_options = {
    mouseWheel: true,
    scrollbars: true,
    click: is_android,
  }
  
  app.flickity_options = {
    cellAlign: 'left',
    contain: true,
    pageDots: false,
    wrapAround: true,
    accessibility: false,
  }

  app.init = function() {
    app.build()
    app.bind()
    app.ready()
  }

  app.bind = function() {
    if (is_mobile) {
      document.addEventListener('touchmove', function(e) {
        e.preventDefault()
      })
      window.FastClick && FastClick.attach(document.body)
    }
    
    $(window).resize(app.resize)
  }

  app.build = function(data) {
    app.loader = new Loader ()

    app.header = new HeaderView()
    app.nav = new NavView()

    app.$items = $(".item")

    app.resizeItems()

    app.lookup = {}
    app.projects = app.$items.toArray().map(function(el, i){
      var view = new ProjectView ({
        el: el,
        page_number: i,
      })
      app.lookup[ view.project_id ] = view
      return view
    })
    
    Scroller.init({
      previous: app.nav.previous.bind(app.nav),
      next: app.nav.next.bind(app.nav),
      burger: app.header.toggleNav.bind(app.nav),
      left: function(){
        var gallery = $('.item.active .top').data('flickity')
        gallery && gallery.previous()
      },
      right: function(){
        var gallery = $('.item.active .top').data('flickity')
        gallery && gallery.next()
      },
    })
  }

  app.ready = function() {
    setTimeout(function(){
      $("body").removeClass("loading")
    }, 20)
    
    app.router = new SiteRouter ()
    
    app.resizeItems()
    app.router.launch()
    
    console.log("launched")
  }
  
  app.resize = function(){
    // $(".active .cell,.active  .next,.active .previous").css({ 'display': 'none' })
    $('body').addClass('resizing')
    debounce(function() {
      $(".active.item").addClass("hidden")
      setTimeout(function(){
        app.resizeItems()
        app.view.$el.removeClass("hidden")
        // $('.top').flickity('resize')
        $('body').removeClass('resizing')
      }, 400)
    }, 400)
  }
  
  app.resizeItems = function(){
    var windowHeight = window.innerHeight

    if (is_iphone) {
      windowHeight -= 22 // account for lower bar
      window.scrollTo(0,0)
    }

    $(".item").each(function(i){
      
      var height = windowHeight - ($(this).find(".bottom").height() + 10)
      if (is_desktop) {
        height -= $("nav").height() // account for top bar
      }

      $(".cell, .top, .previous, .next, .flickity-viewport", this).css({ 'height': height })
      var cellCount = $(this).find(".cell").length
      if ($.browser.mozilla) {
          $(".bottom", this).css({ 'top': height + 20 })
      }
      else {
        if (cellCount == 0) {
          console.log($(this).data("id"), "NONE")
          $(".bottom", this).css({ 'top': height + 17 })
        }
        else if (cellCount == 1) {
          $(".bottom", this).css({ 'top': height + 20 })
        }
        else {
          $(".bottom", this).css({ 'top': height + 19 })
        }
      }
    })
  }

  return app

})()

app.init()