summaryrefslogtreecommitdiff
path: root/public/assets/js/app.js
blob: 74e4b40718c9dacc569b2a3bb967120becaacfb8 (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
var app = (function() {

  var app = {}
  var last_t = 0, initial_t = 0

  app.init = function() {
    app.loader = new Loader ()
    app.okcms = new OKCMS ()
    app.okcms.getAll().done(function(data) {
      app.bind()
      app.build(data)
      app.resize()
      app.ready()
    }).fail(function(err) {
      console.error('error loading cms', err)
    })
  }

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

  app.build = function(data) {
    window.scrollTo(0,0)
    app.views = {}
    app.nav = new NavView ()
    app.views.home = new HomeView({
      data: data.home
    })
    app.views.page = new PageView({
      data: data.page
    })
    app.views.painting = new PaintingView({
      data: data.painting
    })
    app.views.list = new ListView({
    })
    
    app.preload()
  }
  
  app.preload = function(){
    var $sections = $("#fullpage .section")
    var $first = $sections.first()
    app.loader.preloadImage( $first.data("image"), function(){
      $sections.each(function(index){
        var img = new Image ()
        var $div = $("<div>")
        $div.data("index", index)
        $("#list").append($div)
        var url = $(this).data("image")
        var loaded = false
        var $el = $(this)
        img.onload = function(){
          $el.css("background-image", "url(" + url + ")")
          $div.css("background-image", "url(" + url + ")")
        }
        img.src = url
      })
      app.fullpage()
    })
  }
  
  app.fullpage = function(){
    $("#fullpage .section").on("click", function(){
      $(this).toggleClass("zoomed")
    })
    $('#fullpage').fullpage({
      css3: true,
      scrollingSpeed: 800,
      continuousVertical: false,
      afterLoad: function(anchorLink, index, slideAnchor, slideIndex){
//         app.views.painting.show_slide(index)
        $(".zoomed").removeClass("zoomed")
      },
      onLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){
//         app.views.painting.hide_slide()
        $(".zoomed").removeClass("zoomed")
      }
    })
  }
  
  app.ready = function() {
    if (last_t) return
    setTimeout(function () {
      $("html").removeClass("loading")
    }, 50)
    app.view = null
    app.router = new SiteRouter()
    app.router.launch()
    // app.animate(0)
  }

  app.animate = function (t) {
    requestAnimationFrame(app.animate)
    if (! initial_t) {
      initial_t = t
      return
    }
    t -= initial_t
    var dt = t - last_t
    last_t = t
  }

  app.resize = function () {
  }

  app.iscroll_options = {
    mouseWheel: true,
    scrollbars: true,
    click: is_android,
  }

  return app

})()

document.addEventListener('DOMContentLoaded', app.init)