diff options
Diffstat (limited to 'tree/public/assets/js/app.js')
| -rw-r--r-- | tree/public/assets/js/app.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tree/public/assets/js/app.js b/tree/public/assets/js/app.js new file mode 100644 index 0000000..dc67379 --- /dev/null +++ b/tree/public/assets/js/app.js @@ -0,0 +1,90 @@ +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) + environment.init() + corner.init() + app.views = {} + app.nav = new NavView () + app.views.home = new HomeView({ + data: data.home + }) + app.views.experiments = new ExperimentsView({ + data: data.experiments + }) + app.views.projects = new ProjectsView({ + data: data.projects + }) + app.views.press = new PressView({ + data: data.press + }) + app.views.about = new AboutView({ + data: data.about + }) + } + + 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 + environment.update(t, dt) + corner.update(t, dt) + } + + app.resize = function () { + environment.resize && environment.resize() + } + + app.iscroll_options = { + mouseWheel: true, + scrollbars: true, + click: is_android, + } + + return app + +})() + +document.addEventListener('DOMContentLoaded', app.init) |
