diff options
Diffstat (limited to 'public/assets/js')
| -rw-r--r-- | public/assets/js/app.js | 27 | ||||
| -rw-r--r-- | public/assets/js/lib/NavView.js | 8 | ||||
| -rw-r--r-- | public/assets/js/lib/ProjectView.js | 52 |
3 files changed, 68 insertions, 19 deletions
diff --git a/public/assets/js/app.js b/public/assets/js/app.js index 319a939..040b99c 100644 --- a/public/assets/js/app.js +++ b/public/assets/js/app.js @@ -18,8 +18,8 @@ var app = (function() { } app.init = function() { - app.bind() app.build() + app.bind() app.ready() } @@ -28,20 +28,25 @@ var app = (function() { document.addEventListener('touchmove', function(e) { e.preventDefault() }) - FastClick.attach(document.body) + 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() - var items = $(".item") + // should this go here or elsewhere? + app.resizeItems() + + var $items = $(".item") + app.lookup = {} - app.projects = items.toArray().map(function(el, i){ + app.projects = $items.toArray().map(function(el, i){ var view = new ProjectView ({ el: el, page_number: i, @@ -63,7 +68,6 @@ var app = (function() { gallery && gallery.next() }, }) - } app.ready = function() { @@ -123,17 +127,4 @@ var app = (function() { })() -app.resizeItems() - -$('.top').each(function(){ - if ($(this).find(".cell").length > 1) { - $(this).flickity(app.flickity_options).on( 'cellSelect', function(e) { - var gallery = $(e.target).data('flickity') - app.header.updateSlideNumber( gallery.selectedIndex ) - }) - } -}) - -$(".item").addClass("hidden") - app.init() diff --git a/public/assets/js/lib/NavView.js b/public/assets/js/lib/NavView.js index b2fe341..e2b334c 100644 --- a/public/assets/js/lib/NavView.js +++ b/public/assets/js/lib/NavView.js @@ -27,6 +27,10 @@ var NavView = View.extend({ 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(){ @@ -37,6 +41,10 @@ var NavView = View.extend({ 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) { diff --git a/public/assets/js/lib/ProjectView.js b/public/assets/js/lib/ProjectView.js index b119b65..97a7e1c 100644 --- a/public/assets/js/lib/ProjectView.js +++ b/public/assets/js/lib/ProjectView.js @@ -12,7 +12,24 @@ var ProjectView = View.extend({ this.project_id = this.$el.data("id") this.page_number = opt.page_number this.slide_count = this.$(".cell").length - console.log("INIT", this.project_id) + + this.$iframes = this.$(".cell.iframe") + this.$images = this.$(".cell.image") + this.$videos = this.$(".cell.video") + + this.images = this.$images.toArray().map(function(img){ return $(img).data("uri") }) + + if (is_mobile) { + $iframes.remove() + $videos.remove() + } + + if (this.$(".cell").length > 1) { + this.$(".top").flickity(app.flickity_options).on( 'cellSelect', function(e) { + var gallery = $(e.target).data('flickity') + app.header.updateSlideNumber( gallery.selectedIndex ) + }) + } var $viewport = this.$(".flickity-viewport") if (! $viewport.length) { @@ -30,6 +47,14 @@ var ProjectView = View.extend({ this.$el.append( $("<figure>").addClass("page-up") ) this.$el.append( $("<figure>").addClass("page-down") ) } + + this.$el.addClass('hidden') + }, + + preload: function(){ + if (this.images.length) { + app.loader.preloadImage( this.images[0] ) + } }, show: function(){ @@ -46,6 +71,24 @@ var ProjectView = View.extend({ app.router.pushState("/project/" + this.project_id) } + this.$images.each(function(){ + var uri = $(this).data("uri") + $(this).css("background-image", "url(" + uri + ")") + }) + + if (is_mobile) { + this.$images.each(function(){ + var uri = $(this).data("uri") + $(this).css("background-image", "url(" + uri + ")") + }) + } + else { + this.$iframes.each(function(){ + var uri = $(this).data("uri") + $(this).html("<iframe src='" + uri + "'>") + }) + } + app.nav.setActive( this.project_id ) this.showing = true @@ -58,6 +101,13 @@ var ProjectView = View.extend({ addClassForPeriod( this.el, "hiding", app.navigation_delay, function(){ this.$el.addClass("hidden") this.$el.removeClass("active") + + this.$images.each(function(){ + $(this).css("background-image", "") + }) + this.$iframes.html("") + this.$videos.html("") + }.bind(this) ) }, |
