diff options
Diffstat (limited to 'site/public/assets/javascripts')
| -rw-r--r-- | site/public/assets/javascripts/_env.js | 555 | ||||
| -rw-r--r-- | site/public/assets/javascripts/app.js | 20 | ||||
| -rw-r--r-- | site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCameraMobile.js | 225 | ||||
| -rw-r--r-- | site/public/assets/javascripts/vendor/fastclick.js | 790 | ||||
| -rw-r--r-- | site/public/assets/javascripts/vendor/flickity.pkgd.js | 215 | ||||
| -rw-r--r-- | site/public/assets/javascripts/vendor/loader.js | 23 | ||||
| -rw-r--r-- | site/public/assets/javascripts/vendor/polyfill.js | 32 | ||||
| -rw-r--r-- | site/public/assets/javascripts/vendor/util.js | 21 |
8 files changed, 1628 insertions, 253 deletions
diff --git a/site/public/assets/javascripts/_env.js b/site/public/assets/javascripts/_env.js index 3badf41..95afd50 100644 --- a/site/public/assets/javascripts/_env.js +++ b/site/public/assets/javascripts/_env.js @@ -1,59 +1,128 @@ -var base_href = "http://okfocus.s3.amazonaws.com/2h/" -var box_images = shuffle([ - "1.gif", "2.gif", "3.gif", "4.gif", "5.gif", -// "dies2.gif", "dies3.gif", - "6.gif", "7.gif", "8.gif", "9.gif", - "12.gif", "13.gif", "14.gif", "15.gif", - "16.gif", "17.gif", // "CCP-GIF.gif", "dies1.gif", -]) - -var strips = [] +var strips = [], boxImages = [] var done_loading = false, menu_open = false, entry_open = false +var shuffled_indexes + +var wasPrev = false, navWidth + +/** + * Polls the viewport to check when fullscreening is settled + * TODO Doesn't work in IE10 and under + */ +function onFullScreenSettle(raf, fullScreenEl, fn, freq) { + freq = freq || 200 + + function pollSettled(fullscreen, getHeight) { + var isSettled = settledPredicate(getHeight) + var poll = throttle(function doPoll() { + if (isSettled()) { + fn(fullscreen) + } else { + raf(poll) + } + }, freq) + raf(poll) + } + + function settledPredicate(getHeight) { + var count = 0 + // Guard against a false positive by requiring predicate to match + // passCount number of times + var passCount = 2 + var last + /** + * Checks whether the fullscreen element height has changed + * since the last poll + */ + return function isSettled() { + var height = getHeight() + if (!last) { + last = height + } else { + var result = height === last && (++count === passCount) + last = height + return result + } + } + } + + // If fullscreening in progress + if (fullScreenEl) { + pollSettled(true, function() { + return fullScreenEl.offsetHeight + }) + // Otherwise, fullscreen is turning off + } else { + pollSettled(false, function() { + return window.innerHeight + }) + } +} var environment = {}, hashes = {} environment.init = function(){ - var loader = new Loader(function(){ - environment.ready() - }) - loader.preloadImages(box_images.map(function(url){ - return base_href + url - })) + $("#scene").addClass("fade") + var loader = new Loader(environment.ready, new HustleLoader) + var preloadImages = $("#preload-image-list").html().split("\n").filter(function(s){ return !!s }) + boxImages = $("#box-image-list").html().split("\n") + var postImages = $(".sub a").toArray().map(function(el){ return $(el).data("image") }) + + var images = preloadImages.concat(postImages).concat(boxImages).filter(function(s){ return !!s }) + loader.preloadImages( images ) loader.ready() } environment.ready = function(){ if (window.innerWidth < 500) document.body.classList.add('mobile') - controls = new MX.OrbitCamera({ - radius: 1000, - radiusRange: [ 10, 2000 ], - rotationX: PI/2, - rotationY: PI, - wheelEase: 20, - ease: 100 - }) + if (is_mobile) { + controls = new MX.OrbitCameraMobile({ + radius: 100000, + radiusRange: [ 10, 2000 ], + rotationX: PI/2, + rotationY: PI, + wheelEase: 20, + ease: 100 + }) + } + else { + controls = new MX.OrbitCamera({ + radius: 100000, + radiusRange: [ 10, 2000 ], + rotationX: PI/2, + rotationY: PI, + wheelEase: 20, + ease: 100 + }) + } controls.init() $('.cat').click( function(){ - $('.cat').removeClass('active') - $('.sub').removeClass('active') - $(this).addClass('active') - $(this).next('.sub').addClass('active') + if ($(this).hasClass('active')) { + $('.cat').removeClass('active') + $('.sub').removeClass('active') + } + else { + $('.cat').removeClass('active') + $('.sub').removeClass('active') + $(this).addClass('active') + $(this).next('.sub').addClass('active') + } }) $("nav a").click(function(e){ + if ($(this).parent().hasClass("contact")) return; + e.preventDefault() - - var hash = "#" + $(this).data("hash") + + var page = "/" + $(this).data("type") + "/" + $(this).data("id") + var hash = "#" + page if (done_loading && window.location.hash == hash) return window.location.hash = hash $("nav a.active").removeClass("active") - $(this).addClass("active") + var $link = $(this) + $link.addClass("active") open_entry() - - var page = $(this).attr("href") - if (page.indexOf("#") !== -1) page = "#" $("#entry_container").removeClass("visible") @@ -61,29 +130,30 @@ environment.ready = function(){ $loader.load(page + " .entry", function(){ display_entry($loader.children()[0]) }) - }) $("nav .about").click(function(e){ e.preventDefault() - if (done_loading && window.location.hash == "#about") return - window.location.hash = "#about" + if (done_loading && window.location.hash == "#/about") return + window.location.hash = "#/about" $("nav a.active").removeClass("active") open_entry() $("#entry_container").removeClass("visible") var $loader = $("<div>") - $loader.load("about .entry", function(){ + $loader.load("/about/ .entry", function(){ + console.log($loader.html()) display_entry($loader.children()[0]) }) }) +/* $("nav .contact").click(function(e){ e.preventDefault() - if (done_loading && window.location.hash == "#contact") return - window.location.hash = "#contact" + if (done_loading && window.location.hash == "#/contact") return + window.location.hash = "#/contact" $("nav a.active").removeClass("active") open_entry() @@ -94,29 +164,28 @@ environment.ready = function(){ display_entry($loader.children()[0]) }) }) - $("nav .index").click(function(e){ - e.preventDefault() - - if (done_loading && window.location.hash == "#index") return - window.location.hash = "#index" - - $("nav a.active").removeClass("active") - open_entry() - - $("#entry_container").removeClass("visible") - var $loader = $("<div>") - $loader.load("all .entry", function(){ - display_entry($loader.children()[0]) - }) - }) +*/ + // $("nav .index").click() $(".toggleRapper").click(toggle_menu) - $(".toplogo").click(hide_entry) $(document).on("click", ".project", function(){ - var hash = as_hash( $(this).find("span").text() ) - load_hash(hash) + var page = "/" + $(this).data("type") + "/" + $(this).data("id") + $(".entry").css("pointer-events", "none") + load_hash(page) + }) + $(".toplogo,.logo").click(function(e){ + e.preventDefault() + $(".active").removeClass('active') + $('.cat.active, .sub.active, .sub.a').addClass('active') + controls.pause() + window.location.hash = "#" + // $(".index").trigger("click") + load_index() + // hide_entry() }) + Share.init() + $(window).mousedown(function(e){ if (! menu_open) { controls.pause() @@ -147,52 +216,75 @@ environment.ready = function(){ var current_hash = window.location.hash.replace("#","") $("nav a").each(function(){ - var key = as_hash(this.innerHTML) - hashes[key] = this - $(this).data("hash", key) + var page = "/" + $(this).data("type") + "/" + $(this).data("id") + hashes[page] = this + $(this).data("hash", page) }) - hashes['about'] = $("nav .about") - hashes['contact'] = $("nav .contact") - hashes['index'] = $("nav .index") + hashes['/about'] = $("nav .about") + // hashes['/contact'] = $("nav .contact") + // hashes['/index'] = $("nav .index") if (current_hash in hashes) { - toggle_menu() + toggle_menu(false) load_hash(current_hash) setTimeout(build_scene, 200) } else { build_scene() + setTimeout(function(){ + $("#scene").removeClass("fade") + }, 100) } setTimeout(function(){ done_loading = true }, 200) -// $(".mx-scenery").on("mouseenter", function(e){ -// e.stopPropagation() -// $(this).addClass("red") -// }) -// $(".mx-scenery").on("mouseleave", function(e){ -// e.stopPropagation() -// $(".red").removeClass("red") -// }) $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange', function(){ - setTimeout(function(){ - if (window.innerHeight == screen.height) { + onFullScreenSettle(requestAnimationFrame, getFullScreenElement(), onSettle) + + function onSettle(isFullScreen) { + if (isFullScreen) { $("html").addClass("full-screen") } else { $("html").removeClass("full-screen") } - setTimeout(function(){ - resize_gallery() - }, 100) - }, 500) + resize_gallery(isFullScreen) + } }) + + $("#scene_container").click(function(e){ + if ( $("body").hasClass("menuActive") || $(".entry").length ) { + return + } + else { + toggle_menu() + } + }) + if (is_desktop) { + $(document).on("mouseenter", ".project", function(){ + var type = $(this).data("type") + $(".entry").addClass("hover") + $(this).addClass("hover") + $(".top .cat").not("[data-type=" + type + "]").addClass("no-hover") + $(".cat[data-type=" + type + "]").addClass("hover") + }) + $(document).on("mouseleave", ".project", function(){ + var type = $(this).data("type") + $(".entry").removeClass("hover") + $(this).removeClass("hover") + $(".cat").removeClass("hover").removeClass("no-hover") + }) + } } function build_scene () { + controls.setZoom(100000) + controls.zoom(1000) + +/* strips.push( new Strip({ - images: box_images.slice(0, 5), + images: $(".sub[data-type=advertising] a"), x: -100, y: 100, rotationY: PI/4, @@ -200,7 +292,7 @@ function build_scene () { }) ) strips.push( new Strip({ - images: box_images.slice(5, 10), + images: $(".sub[data-type=retail] a"), x: 100, y: 100, rotationX: PI/4, @@ -209,7 +301,7 @@ function build_scene () { }) ) strips.push( new Strip({ - images: box_images.slice(10, 15), + images: $(".sub[data-type=experiential] a"), x: 0, y: 100, z: 100, @@ -218,7 +310,44 @@ function build_scene () { }) ) strips.push( new Strip({ - images: box_images.slice(15, 20), + images: $(".sub[data-type=content] a"), + x: 0, + y: 100, + z: -50, + rotationX: PI/2, + rotationY: PI/100, + offset: 200, + }) ) +*/ + + strips.push( new Strip({ + images: boxImages.slice(0, 5), + x: -100, + y: 100, + rotationY: PI/4, + offset: 100, + }) ) + + strips.push( new Strip({ + images: boxImages.slice(5, 10), + x: 100, + y: 100, + rotationX: PI/4, + rotationY: PI/-100, + offset: 200, + }) ) + + strips.push( new Strip({ + images: boxImages.slice(10, 15), + x: 0, + y: 100, + z: 100, + rotationY: PI/6, + offset: 300, + }) ) + + strips.push( new Strip({ + images: boxImages.slice(15, 20), x: 0, y: 100, z: -50, @@ -227,6 +356,20 @@ function build_scene () { offset: 200, }) ) + function resize_for_prev_next(){ + navWidth = $("nav").width() + } + resize_for_prev_next() + $(window).resize(resize_for_prev_next) + $(window).mousemove(function(e){ + if (! gallery) return + prev = ((e.pageX - navWidth) / window.innerWidth) < 0.415 + if (prev !== wasPrev) { + wasPrev = prev + $("#okgallery").toggleClass("prev", prev) + } + }) + strips.forEach(function(strip){ strip.update(0) }) scene.update() @@ -235,6 +378,25 @@ function build_scene () { var entry_open_time = 0; +function load_index (e){ + e && e.preventDefault() + // if (done_loading && window.location.hash == "#/index") return + // window.location.hash = "#/index" + // console.log("load index") + + $("nav a.active").removeClass("active") + open_entry(true) + + window.location.hash = "#" + + $("#entry_container").removeClass("visible") + var $loader = $("<div>") + $loader.load("all .entry", function(){ + $("body").addClass("menuActive") + display_entry($loader.children()[0]) + }) +} + function as_hash (txt) { return txt.replace(/\s/g,'_') } @@ -245,8 +407,8 @@ function load_hash (hash) { $menu.parent().prev(".cat").addClass('active') $menu.trigger("click") } -function open_entry () { - if (is_mobile) { +function open_entry (entryIsAll) { + if (is_mobile && ! entryIsAll) { $("body").removeClass("menuActive") } if (! entry_open) { @@ -259,24 +421,49 @@ function open_entry () { entry_open_time = +new Date $("#entry_container").addClass("fade") } -function display_entry ($el) { +function display_entry (el) { var now = +new Date + var $el = $(el) + var isIndex = $el.hasClass("all") + if (is_mobile) { + $("body").toggleClass("menuActive", isIndex) +// $el.find(".brady > a").remove() + } + if (isIndex) { + var $project_list = $el.find("#project_list") + var $projects = $project_list.find(".project") + if (! shuffled_indexes) { + shuffled_indexes = [] + for (var i = 0; i < $projects.length; i++) { + shuffled_indexes[i] = i + } + shuffle(shuffled_indexes) + } + $project_list.html("") + for (var i = 0; i < $projects.length; i++) { + $project_list.append($projects[shuffled_indexes[i]]) + } + } setTimeout(function(){ $("#entry_container").empty().append($el) $("#entry_container").removeClass("fade") - build_gallery() + setTimeout(function(){ + build_gallery() + }) if (is_mobile) { $(".video").each(function(){ load_video( $(this) ) }) } - if (window.location.hash.match(/about|contact|index/)) { + if (window.location.hash.match(/about|contact/) || $(".entry").hasClass("all")) { setTimeout(function(){ $(".entry").addClass("ready") + if ($(".entry").hasClass("all")) { + setTimeout(function(){ + $(".entry").removeClass("undone") + }, 500) + } }, 100) - setTimeout(function(){ - $(".entry").addClass("done") - }, 600) } else { $(".entry").addClass("ready") @@ -285,8 +472,11 @@ function display_entry ($el) { $("#entry_container").scrollTop(0) $("#entry_container").addClass("visible") - controls.setZoom(100000) - setTimeout(function(){ controls.zoom(100) }, 100) + $("#scene").addClass("fade") + $(".cat").removeClass("hover").removeClass("no-hover") + setTimeout(function(){ + $("#scene").hide() + }, 200) } function hide_entry () { $("nav .active").removeClass("active") @@ -298,7 +488,7 @@ function hide_entry () { controls.zoom(1500) window.location.hash = "#" } -function toggle_menu (){ +function toggle_menu (isInitialLoad){ $("body").toggleClass("menuActive") menu_open = $("body").hasClass("menuActive") @@ -306,8 +496,10 @@ function toggle_menu (){ $("#entry_container").removeClass("visible") } - if (menu_open) { + if (menu_open && isInitialLoad !== false) { controls.pause() + // $(".index").trigger("click") + load_index() } if (! menu_open && entry_open && ! is_mobile) { entry_open = false @@ -328,11 +520,16 @@ function toggle_menu (){ var gallery = null function build_gallery () { videos = [] + wasPrev = -1 var $el = $("#entry_container #okgallery") if (! $el.length) { gallery = null return } + var $cells = $("#entry_container #okgallery .cell") + if ($cells.length == 1) { + $(".entry").addClass("singleton") + } var $next = $el.next(".next") var $caption = $el.next(".caption") gallery = new Flickity( "#okgallery", { @@ -347,20 +544,28 @@ function build_gallery () { }) $("#okgallery .video").each(function(){ - var $play = $('<div class="play"></div>') var $el = $(this) + if (! is_mobile) { + var $underlay = $('<div class="underlay"></div>') + $underlay.css("background-image", $el.css("background-image")) + $el.css("background-image", 'none') + } + var $play = $('<div class="play"></div>') $el.append($play) - $play.click(function(e){ - e.stopPropagation() - e.preventDefault() - if ($el.hasClass('loaded')) { - var player = $el.data('player') - player.api('play') - } - else { - load_video($el) - } - }) + $el.append($underlay) + if (is_desktop) { + $play.on("click", function(e){ + e.stopPropagation() + e.preventDefault() + if ($el.hasClass('loaded')) { + var player = $el.data('player') + player.api('play') + } + else { + load_video($el) + } + }) + } }) $(".caption").click(function(){ @@ -368,12 +573,14 @@ function build_gallery () { }) gallery.on("cellSelect", function(){ + if (! gallery.selectedElement) return $caption.html( $(gallery.selectedElement).data("caption") ) videos.forEach(function(player){ player.api('pause') }) }) gallery.on("settle", function(){ + if (! gallery || ! gallery.selectedElement) { return } $caption.html( $(gallery.selectedElement).data("caption") ) }) gallery.on("staticClick", function(e){ @@ -383,23 +590,27 @@ function build_gallery () { // load_video($el) } else { - next() + if ($("#okgallery").hasClass("prev")) { + gallery.previous() + } else { + gallery.next() + } } }) - // $next.on("click", next) - function next(){ - gallery.next() - } gallery.loader.on("progress", function(imagesLoaded, loadingImage){ $(loadingImage.img).addClass('loaded') + $(loadingImage.img).parent().removeClass('loading') }) + $(".nextbutton").click(function(){ gallery.next() }) + $(".prevbutton").click(function(){ gallery.previous() }) } -function resize_gallery () { +function resize_gallery (isFullScreen) { if (! gallery) return; - var isFullscreen = $("html").hasClass("full-screen") - $("#okgallery").find(".cell img").each(function(){ - var h = isFullscreen ? window.innerHeight : 0.6 * window.innerHeight - var w = isFullscreen ? "auto" : this.naturalWidth / this.naturalHeight * h + var fullScreenElement = getFullScreenElement() + var $gallery = $("#okgallery") + $gallery.find(".cell img").each(function(){ + var h = isFullScreen ? $(fullScreenElement).height() : $gallery.height() + var w = isFullScreen ? "auto" : this.naturalWidth / this.naturalHeight * h $(this).css({ width: w, height: h, }) @@ -414,12 +625,17 @@ function load_video ($el) { var vimeo_id = $el.data("video").match(/\d+/)[0] var $embed = $('<iframe src="https://player.vimeo.com/video/' + vimeo_id + '?autoplay=1&title=0&byline=0&portrait=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>') $el.append($embed) - var $mask = $('<div class="mask"></div>') - $el.append($mask) + if (! is_mobile) { +// var $mask = $('<div class="mask"></div>') +// $el.append($mask) + } var player = $f( $el.find("iframe")[0] ) $el.data('player', player) player.addEvent('ready', function(){ +// console.log("ready") + $el.addClass('playing') player.addEvent('play', function(){ +// console.log("playing") $el.addClass('playing') }) player.addEvent('pause', function(){ @@ -436,24 +652,6 @@ environment.updateOnReady = function(t){ controls.update() } -var titles = [ - "BARNEY'S, GAGA CONSTELLATION", - "CCP GAMES, EVE ONLINE", - "DIESEL ACCESSORIES", - "DIESEL CAMPAIGN FW13/SS14", - "DIESEL CAMPAIGN FW14", - "#DIESELREBOOT", - "#DIESELTRIBUTE", - "DIESEL JOGG JEANS", - "DIESEL WATCHES", - 'MAC, "UNTITLED, SELF-PORTRAIT"', - "MUGLER, BROTHERS OF ARCADIA", - "MUGLER, LADY GAGA", - "MUGLER, MEN’S FW11", - "NICOLA’S, HO HO HO CHRISTMAS SHOP", - "NICOLA'S, LANE CRAWFORD", - "NICOLA’S, NEW YORK" -] var Strip = function( opt ){ this.opt = opt @@ -467,13 +665,20 @@ var Strip = function( opt ){ root.addTo(scene) var prev = root - this.els = opt.images.map(function(url, i){ + this.els = ( opt.images.toArray ? opt.images.toArray() : opt.images ).map(function(el, i){ + var url + if (typeof el == "string") { + url = el + } + else { + var data = $(el).data() + url = data.image + } var el = new MX.Image({ - src: base_href + url, + src: url, onload: function(img){ } }) - $(el.el).attr("data-title", choice(titles)) el.setCSSTransformOrigin( "50% 100%" ) el.addTo(prev) el.update() @@ -494,3 +699,73 @@ Strip.prototype.update = function(t){ el.y = el.height / 2 }) } + +function HustleLoader () { + var svg = document.getElementById("loader_svg_status") + function init(){ + build() + } + function build(){ + setTimeout(function(){ $("#loader_svg").addClass("slide") }, 100) + } + this.update = function (i) { + var y = lerp(1-i, 336, 118) + svg.setAttribute("y", y ) + } + this.finish = function(cb){ + $("#loader_rapper").addClass("hidden") + setTimeout(cb, 100) + setTimeout(function(){ + $("#loader_rapper").hide() + }, 500) + } + init() +} + +var Share = { + init: function(){ + $(document).on("click", ".fb", Share.facebook) + $(document).on("click", ".tw", Share.twitter) + setTimeout(function(){ + window.fbAsyncInit = function() { + FB.init({ + appId : '643786815755427', + xfbml : true, + version : 'v2.3' + }); + }; + + (function(d, s, id){ + var js, fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) {return;} + js = d.createElement(s); js.id = id; + js.src = "//connect.facebook.net/en_US/sdk.js"; + fjs.parentNode.insertBefore(js, fjs); + }(document, 'script', 'facebook-jssdk')); + }, 1000) + }, + + facebook: function (e) { + e.preventDefault() + // var link = window.location.href + // var msg = $(".postname").html() + // var url = "https://www.facebook.com/share.php?u=" + encodeURIComponent(link) + "&t=" + encodeURIComponent(msg) + // window.open(url, "_blank") + + var picture = $(".gallery img").first().attr("src") || ($(".gallery .underlay").css('background-image') || "").replace("url(","").replace(")","") || "http://twohustlers.com/assets/images/2H_LOGOMARK.png" + FB.ui({ + method: 'feed', + link: window.location.href, + caption: $(".postname").html(), + picture: picture, + }, function(response){}); + }, + + twitter: function (e) { + e.preventDefault() + var link = window.location.href + var msg = $(".postname").html() + var url = "https://twitter.com/home?status=" + encodeURIComponent(msg + " " + link) + window.open(url, "_blank") + }, +}
\ No newline at end of file diff --git a/site/public/assets/javascripts/app.js b/site/public/assets/javascripts/app.js index dd68726..4e00f30 100644 --- a/site/public/assets/javascripts/app.js +++ b/site/public/assets/javascripts/app.js @@ -18,7 +18,13 @@ app.init = function () { } app.launch = function () { - if ($.browser.msie || ! has3d()) { return app.fallback() } + // if ($.browser.msie || ! has3d()) { return app.fallback() } + if ($.browser.msie) { + $("html").addClass("msie") + } + else { + $("html").addClass("notmsie") + } scene = new MX.Scene().addTo('#scene') @@ -36,14 +42,10 @@ app.launch = function () { // app.movements.update(dt || 0) } - var loader = new Loader(function(){ - $("#loader").hide() - window.environment && window.environment.init() - animate() - }) - - // loader.preloadImages([]) - loader.ready() + FastClick.attach(document.body) + + window.environment && window.environment.init() + animate() window.scrollTo(0,0) } diff --git a/site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCameraMobile.js b/site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCameraMobile.js new file mode 100644 index 0000000..510a002 --- /dev/null +++ b/site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCameraMobile.js @@ -0,0 +1,225 @@ +MX.OrbitCameraMobile = function(opt){ + var exports = {}, bound = false + exports.opt = opt = defaults(opt, { + el: window, // object to bind events on + camera: scene.camera, // camera object we'll be moving + radius: 100, + radiusRange: [ 10, 1000 ], + rotationX: PI/2, + rotationY: 0, + center: { x: 0, y: 0, z: 0 }, + sensitivity: 10, // moving 1 pixel is like moving N radians + wheelSensitivity: 10, + ease: 10, + wheelEase: 10, + }) + var rx, ry, radius, px, py, epsilon = 1e-10 + var rotationSum = 0 + var rotationMedian = 0 + var orientationMax = 0 + var samples = 0 + var sampleThreshold = 20 + var lastAlpha + + exports.dragging = false + exports.init = function(){ + ry = opt.rotationY + rx = opt.rotationX + radius = opt.radius + exports.wheel = new wheel({ + el: opt.el, + update: function(e, delta){ + opt.radius = clamp( opt.radius + delta * opt.wheelSensitivity, opt.radiusRange[0], opt.radiusRange[1] ) + }, + }) + exports.bind() + + exports.orientationchange() + } + exports.toggle = function(state){ + if (state) exports.bind() + else exports.unbind() + } + exports.bind = function(){ + if (bound) return; + bound = true + opt.el.addEventListener("touchstart", touch(down)) + window.addEventListener("touchmove", touch(move)) + window.addEventListener("touchend", touch(up)) + + window.addEventListener('orientationchange', exports.orientationchange) + window.addEventListener("devicemotion", exports.devicemotion) + window.addEventListener("deviceorientation", exports.deviceorientation) + + exports.wheel.unlock() + } + exports.unbind = function(){ + if (! bound) return; + bound = false + exports.wheel.lock() + } + function cancelable (fn) { + return function(e){ + e.preventDefault() + fn(e) + } + } + function touch (fn){ + return function(e){ + fn(e.touches[0]) + } + } + function down (e) { + px = e.pageX + py = e.pageY + exports.dragging = true + } + function move (e) { + if (! exports.dragging) return + exports.delta(px- e.pageX, py - e.pageY) + px = e.pageX + py = e.pageY + } + function up (e) { + exports.dragging = false + } + + exports.orientationchange = function(e){ + is_portrait = window.innerWidth < window.innerHeight + if (is_portrait) { + lastAlpha = 0 + } + } + exports.devicemotion = function(e) { + if (! is_portrait) return; + var rotationBeta = e.rotationRate.alpha; // weird! + rotationSum += rotationBeta; + samples += 1; + } + exports.deviceorientation = function (e) { + if (! lastAlpha) { lastAlpha = e.alpha } + is_portrait ? exports.portraitorientation(e) : exports.landscapeorientation(e) + } + exports.portraitorientation = function(e) { + // compass gives most accurate orientation in portrait mode + var alpha, dx = 0, dy = 0 + + if (e.webkitCompassHeading) { + alpha = 180 - e.webkitCompassHeading; + } + else { + alpha = 180 - e.alpha; + } + + // android rotates in reverse + if (is_android) { + alpha = 360 - alpha + } + + // use rotationRate to gauge if we've tilted the screen past vertical + // for looking at ceiling + if (e.beta > orientationMax) { + orientationMax = e.beta + rotationMedian = rotationSum + } + + // this number was only going to 83 max.. not 90.. weird + var beta = e.beta + 7; + + // if we've got enough motion data, we should be able to determine + // if we've tilted backwards. otherwise, lock to the horizon. + if (! is_android && samples > sampleThreshold) { + dx = rotationSum > rotationMedian ? e.beta - 90 : 90 - e.beta + } + else { + dx = 0 + } + + // avoid jumping around in a circle + if (Math.abs(alpha - lastAlpha) < 100 || Math.abs(alpha - lastAlpha) > 300) { + dy = alpha - lastAlpha + lastAlpha = alpha + } + + // avoid jumping around in a circle #2 + if (dy > 300) { + dy -= 360 + } else if (dy < -300) { + dy += 360 + } + opt.rotationX = MX.toRad(dx * -5) + opt.rotationY += MX.toRad(dy * 10) + } + exports.landscapeorientation = function (e) { + var dx, dy + + dx = e.gamma > 0 ? 90 - e.gamma : 90 + e.gamma + dy = e.alpha - lastAlpha + lastAlpha = e.alpha + + // avoid the sudden jump from 0 to -360 + if (dy > 300) { + dy -= 360 + } + else if (dy < -300) { + dy += 360 + } + + opt.rotationX = dx > 45 ? 0 : MX.toRad(dx) + opt.rotationY += MX.toRad(dy) + } + + + exports.delta = function(x,y){ + opt.rotationY += x/window.innerWidth * opt.sensitivity + opt.rotationX = opt.rotationX + y/window.innerHeight * opt.sensitivity + } + exports.move = function(y, x){ + opt.rotationY = y + if (typeof x == "number") { opt.rotationX = x } + } + exports.zoom = function(r){ + opt.radius = r + } + exports.setZoom = function(r){ + radius = opt.radius = r + } + exports.zoomPercent = function(n){ + opt.radius = lerp(n, opt.radiusRange[0], opt.radiusRange[1]) + } + exports.zoomDelta = function(r){ + opt.radius += r + } + exports.pause = function(){ + var sy = sign(opt.rotationY-ry) + var sx = sign(opt.rotationX-rx) + opt.rotationY = ry + sy * 0.1 + opt.rotationX = rx + sx * 0.1 + } + exports.update = function(){ + if (abs(ry - opt.rotationY) > epsilon) { + ry = avg(ry, opt.rotationY, opt.ease) + } + else { + ry = opt.rotationY + } + if (abs(rx - opt.rotationX) > epsilon) { + rx = avg(rx, opt.rotationX, opt.ease) + } + else { + rx = opt.rotationX + } + if (abs(radius - opt.radius) > epsilon) { + radius = avg(radius, opt.radius, opt.wheelEase) + } + else { + radius = opt.radius + } + opt.camera.x = opt.center.x + radius * sin(rx) * cos(ry) + opt.camera.z = opt.center.y + radius * sin(rx) * sin(ry) + opt.camera.y = opt.center.z + radius * cos(rx) + opt.camera.rotationX = PI/2 - rx + opt.camera.rotationY = ry + PI/2 + } + return exports +} diff --git a/site/public/assets/javascripts/vendor/fastclick.js b/site/public/assets/javascripts/vendor/fastclick.js new file mode 100644 index 0000000..9c746c2 --- /dev/null +++ b/site/public/assets/javascripts/vendor/fastclick.js @@ -0,0 +1,790 @@ +/** + * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs. + * + * @version 1.0.1 + * @codingstandard ftlabs-jsv2 + * @copyright The Financial Times Limited [All Rights Reserved] + * @license MIT License (see LICENSE.txt) + */ + +/*jslint browser:true, node:true*/ +/*global define, Event, Node*/ + + +/** + * Instantiate fast-clicking listeners on the specified layer. + * + * @constructor + * @param {Element} layer The layer to listen on + * @param {Object} options The options to override the defaults + */ +function FastClick(layer, options) { + 'use strict'; + var oldOnClick; + + options = options || {}; + + /** + * Whether a click is currently being tracked. + * + * @type boolean + */ + this.trackingClick = false; + + + /** + * Timestamp for when click tracking started. + * + * @type number + */ + this.trackingClickStart = 0; + + + /** + * The element being tracked for a click. + * + * @type EventTarget + */ + this.targetElement = null; + + + /** + * X-coordinate of touch start event. + * + * @type number + */ + this.touchStartX = 0; + + + /** + * Y-coordinate of touch start event. + * + * @type number + */ + this.touchStartY = 0; + + + /** + * ID of the last touch, retrieved from Touch.identifier. + * + * @type number + */ + this.lastTouchIdentifier = 0; + + + /** + * Touchmove boundary, beyond which a click will be cancelled. + * + * @type number + */ + this.touchBoundary = options.touchBoundary || 10; + + + /** + * The FastClick layer. + * + * @type Element + */ + this.layer = layer; + + /** + * The minimum time between tap(touchstart and touchend) events + * + * @type number + */ + this.tapDelay = options.tapDelay || 200; + + if (FastClick.notNeeded(layer)) { + return; + } + + // Some old versions of Android don't have Function.prototype.bind + function bind(method, context) { + return function() { return method.apply(context, arguments); }; + } + + + var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel']; + var context = this; + for (var i = 0, l = methods.length; i < l; i++) { + context[methods[i]] = bind(context[methods[i]], context); + } + + // Set up event handlers as required + if (deviceIsAndroid) { + layer.addEventListener('mouseover', this.onMouse, true); + layer.addEventListener('mousedown', this.onMouse, true); + layer.addEventListener('mouseup', this.onMouse, true); + } + + layer.addEventListener('click', this.onClick, true); + layer.addEventListener('touchstart', this.onTouchStart, false); + layer.addEventListener('touchmove', this.onTouchMove, false); + layer.addEventListener('touchend', this.onTouchEnd, false); + layer.addEventListener('touchcancel', this.onTouchCancel, false); + + // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) + // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick + // layer when they are cancelled. + if (!Event.prototype.stopImmediatePropagation) { + layer.removeEventListener = function(type, callback, capture) { + var rmv = Node.prototype.removeEventListener; + if (type === 'click') { + rmv.call(layer, type, callback.hijacked || callback, capture); + } else { + rmv.call(layer, type, callback, capture); + } + }; + + layer.addEventListener = function(type, callback, capture) { + var adv = Node.prototype.addEventListener; + if (type === 'click') { + adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) { + if (!event.propagationStopped) { + callback(event); + } + }), capture); + } else { + adv.call(layer, type, callback, capture); + } + }; + } + + // If a handler is already declared in the element's onclick attribute, it will be fired before + // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and + // adding it as listener. + if (typeof layer.onclick === 'function') { + + // Android browser on at least 3.2 requires a new reference to the function in layer.onclick + // - the old one won't work if passed to addEventListener directly. + oldOnClick = layer.onclick; + layer.addEventListener('click', function(event) { + oldOnClick(event); + }, false); + layer.onclick = null; + } +} + + +/** + * Android requires exceptions. + * + * @type boolean + */ +var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0; + + +/** + * iOS requires exceptions. + * + * @type boolean + */ +var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent); + + +/** + * iOS 4 requires an exception for select elements. + * + * @type boolean + */ +var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent); + + +/** + * iOS 6.0(+?) requires the target element to be manually derived + * + * @type boolean + */ +var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS ([6-9]|\d{2})_\d/).test(navigator.userAgent); + + +/** + * Determine whether a given element requires a native click. + * + * @param {EventTarget|Element} target Target DOM element + * @returns {boolean} Returns true if the element needs a native click + */ +FastClick.prototype.needsClick = function(target) { + 'use strict'; + switch (target.nodeName.toLowerCase()) { + + // Don't send a synthetic click to disabled inputs (issue #62) + case 'button': + case 'select': + case 'textarea': + if (target.disabled) { + return true; + } + + break; + case 'input': + + // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) + if ((deviceIsIOS && target.type === 'file') || target.disabled) { + return true; + } + + break; + case 'label': + case 'video': + return true; + } + + return (/\bneedsclick\b/).test(target.className); +}; + + +/** + * Determine whether a given element requires a call to focus to simulate click into element. + * + * @param {EventTarget|Element} target Target DOM element + * @returns {boolean} Returns true if the element requires a call to focus to simulate native click. + */ +FastClick.prototype.needsFocus = function(target) { + 'use strict'; + switch (target.nodeName.toLowerCase()) { + case 'textarea': + return true; + case 'select': + return !deviceIsAndroid; + case 'input': + switch (target.type) { + case 'button': + case 'checkbox': + case 'file': + case 'image': + case 'radio': + case 'submit': + return false; + } + + // No point in attempting to focus disabled inputs + return !target.disabled && !target.readOnly; + default: + return (/\bneedsfocus\b/).test(target.className); + } +}; + + +/** + * Send a click event to the specified element. + * + * @param {EventTarget|Element} targetElement + * @param {Event} event + */ +FastClick.prototype.sendClick = function(targetElement, event) { + 'use strict'; + var clickEvent, touch; + + // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24) + if (document.activeElement && document.activeElement !== targetElement) { + document.activeElement.blur(); + } + + touch = event.changedTouches[0]; + + // Synthesise a click event, with an extra attribute so it can be tracked + clickEvent = document.createEvent('MouseEvents'); + clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); + clickEvent.forwardedTouchEvent = true; + targetElement.dispatchEvent(clickEvent); +}; + +FastClick.prototype.determineEventType = function(targetElement) { + 'use strict'; + + //Issue #159: Android Chrome Select Box does not open with a synthetic click event + if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') { + return 'mousedown'; + } + + return 'click'; +}; + + +/** + * @param {EventTarget|Element} targetElement + */ +FastClick.prototype.focus = function(targetElement) { + 'use strict'; + var length; + + // Issue #160: on iOS 7, some input elements (e.g. date datetime) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. + if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time') { + length = targetElement.value.length; + targetElement.setSelectionRange(length, length); + } else { + targetElement.focus(); + } +}; + + +/** + * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it. + * + * @param {EventTarget|Element} targetElement + */ +FastClick.prototype.updateScrollParent = function(targetElement) { + 'use strict'; + var scrollParent, parentElement; + + scrollParent = targetElement.fastClickScrollParent; + + // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the + // target element was moved to another parent. + if (!scrollParent || !scrollParent.contains(targetElement)) { + parentElement = targetElement; + do { + if (parentElement.scrollHeight > parentElement.offsetHeight) { + scrollParent = parentElement; + targetElement.fastClickScrollParent = parentElement; + break; + } + + parentElement = parentElement.parentElement; + } while (parentElement); + } + + // Always update the scroll top tracker if possible. + if (scrollParent) { + scrollParent.fastClickLastScrollTop = scrollParent.scrollTop; + } +}; + + +/** + * @param {EventTarget} targetElement + * @returns {Element|EventTarget} + */ +FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) { + 'use strict'; + + // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node. + if (eventTarget.nodeType === Node.TEXT_NODE) { + return eventTarget.parentNode; + } + + return eventTarget; +}; + + +/** + * On touch start, record the position and scroll offset. + * + * @param {Event} event + * @returns {boolean} + */ +FastClick.prototype.onTouchStart = function(event) { + 'use strict'; + var targetElement, touch, selection; + + // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111). + if (event.targetTouches.length > 1) { + return true; + } + + targetElement = this.getTargetElementFromEventTarget(event.target); + touch = event.targetTouches[0]; + + if (deviceIsIOS) { + + // Only trusted events will deselect text on iOS (issue #49) + selection = window.getSelection(); + if (selection.rangeCount && !selection.isCollapsed) { + return true; + } + + if (!deviceIsIOS4) { + + // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23): + // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched + // with the same identifier as the touch event that previously triggered the click that triggered the alert. + // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an + // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform. + if (touch.identifier === this.lastTouchIdentifier) { + event.preventDefault(); + return false; + } + + this.lastTouchIdentifier = touch.identifier; + + // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and: + // 1) the user does a fling scroll on the scrollable layer + // 2) the user stops the fling scroll with another tap + // then the event.target of the last 'touchend' event will be the element that was under the user's finger + // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check + // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42). + this.updateScrollParent(targetElement); + } + } + + this.trackingClick = true; + this.trackingClickStart = event.timeStamp; + this.targetElement = targetElement; + + this.touchStartX = touch.pageX; + this.touchStartY = touch.pageY; + + // Prevent phantom clicks on fast double-tap (issue #36) + if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { + event.preventDefault(); + } + + return true; +}; + + +/** + * Based on a touchmove event object, check whether the touch has moved past a boundary since it started. + * + * @param {Event} event + * @returns {boolean} + */ +FastClick.prototype.touchHasMoved = function(event) { + 'use strict'; + var touch = event.changedTouches[0], boundary = this.touchBoundary; + + if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { + return true; + } + + return false; +}; + + +/** + * Update the last position. + * + * @param {Event} event + * @returns {boolean} + */ +FastClick.prototype.onTouchMove = function(event) { + 'use strict'; + if (!this.trackingClick) { + return true; + } + + // If the touch has moved, cancel the click tracking + if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) { + this.trackingClick = false; + this.targetElement = null; + } + + return true; +}; + + +/** + * Attempt to find the labelled control for the given label element. + * + * @param {EventTarget|HTMLLabelElement} labelElement + * @returns {Element|null} + */ +FastClick.prototype.findControl = function(labelElement) { + 'use strict'; + + // Fast path for newer browsers supporting the HTML5 control attribute + if (labelElement.control !== undefined) { + return labelElement.control; + } + + // All browsers under test that support touch events also support the HTML5 htmlFor attribute + if (labelElement.htmlFor) { + return document.getElementById(labelElement.htmlFor); + } + + // If no for attribute exists, attempt to retrieve the first labellable descendant element + // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label + return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); +}; + + +/** + * On touch end, determine whether to send a click event at once. + * + * @param {Event} event + * @returns {boolean} + */ +FastClick.prototype.onTouchEnd = function(event) { + 'use strict'; + var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; + + if (!this.trackingClick) { + return true; + } + + // Prevent phantom clicks on fast double-tap (issue #36) + if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { + this.cancelNextClick = true; + return true; + } + + // Reset to prevent wrong click cancel on input (issue #156). + this.cancelNextClick = false; + + this.lastClickTime = event.timeStamp; + + trackingClickStart = this.trackingClickStart; + this.trackingClick = false; + this.trackingClickStart = 0; + + // On some iOS devices, the targetElement supplied with the event is invalid if the layer + // is performing a transition or scroll, and has to be re-detected manually. Note that + // for this to function correctly, it must be called *after* the event target is checked! + // See issue #57; also filed as rdar://13048589 . + if (deviceIsIOSWithBadTarget) { + touch = event.changedTouches[0]; + + // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null + targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; + targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; + } + + targetTagName = targetElement.tagName.toLowerCase(); + if (targetTagName === 'label') { + forElement = this.findControl(targetElement); + if (forElement) { + this.focus(targetElement); + if (deviceIsAndroid) { + return false; + } + + targetElement = forElement; + } + } else if (this.needsFocus(targetElement)) { + + // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. + // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). + if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) { + this.targetElement = null; + return false; + } + + this.focus(targetElement); + this.sendClick(targetElement, event); + + // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open. + // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others) + if (!deviceIsIOS || targetTagName !== 'select') { + this.targetElement = null; + event.preventDefault(); + } + + return false; + } + + if (deviceIsIOS && !deviceIsIOS4) { + + // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled + // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42). + scrollParent = targetElement.fastClickScrollParent; + if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) { + return true; + } + } + + // Prevent the actual click from going though - unless the target node is marked as requiring + // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted. + if (!this.needsClick(targetElement)) { + event.preventDefault(); + this.sendClick(targetElement, event); + } + + return false; +}; + + +/** + * On touch cancel, stop tracking the click. + * + * @returns {void} + */ +FastClick.prototype.onTouchCancel = function() { + 'use strict'; + this.trackingClick = false; + this.targetElement = null; +}; + + +/** + * Determine mouse events which should be permitted. + * + * @param {Event} event + * @returns {boolean} + */ +FastClick.prototype.onMouse = function(event) { + 'use strict'; + + // If a target element was never set (because a touch event was never fired) allow the event + if (!this.targetElement) { + return true; + } + + if (event.forwardedTouchEvent) { + return true; + } + + // Programmatically generated events targeting a specific element should be permitted + if (!event.cancelable) { + return true; + } + + // Derive and check the target element to see whether the mouse event needs to be permitted; + // unless explicitly enabled, prevent non-touch click events from triggering actions, + // to prevent ghost/doubleclicks. + if (!this.needsClick(this.targetElement) || this.cancelNextClick) { + + // Prevent any user-added listeners declared on FastClick element from being fired. + if (event.stopImmediatePropagation) { + event.stopImmediatePropagation(); + } else { + + // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) + event.propagationStopped = true; + } + + // Cancel the event + event.stopPropagation(); + event.preventDefault(); + + return false; + } + + // If the mouse event is permitted, return true for the action to go through. + return true; +}; + + +/** + * On actual clicks, determine whether this is a touch-generated click, a click action occurring + * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or + * an actual click which should be permitted. + * + * @param {Event} event + * @returns {boolean} + */ +FastClick.prototype.onClick = function(event) { + 'use strict'; + var permitted; + + // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early. + if (this.trackingClick) { + this.targetElement = null; + this.trackingClick = false; + return true; + } + + // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target. + if (event.target.type === 'submit' && event.detail === 0) { + return true; + } + + permitted = this.onMouse(event); + + // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through. + if (!permitted) { + this.targetElement = null; + } + + // If clicks are permitted, return true for the action to go through. + return permitted; +}; + + +/** + * Remove all FastClick's event listeners. + * + * @returns {void} + */ +FastClick.prototype.destroy = function() { + 'use strict'; + var layer = this.layer; + + if (deviceIsAndroid) { + layer.removeEventListener('mouseover', this.onMouse, true); + layer.removeEventListener('mousedown', this.onMouse, true); + layer.removeEventListener('mouseup', this.onMouse, true); + } + + layer.removeEventListener('click', this.onClick, true); + layer.removeEventListener('touchstart', this.onTouchStart, false); + layer.removeEventListener('touchmove', this.onTouchMove, false); + layer.removeEventListener('touchend', this.onTouchEnd, false); + layer.removeEventListener('touchcancel', this.onTouchCancel, false); +}; + + +/** + * Check whether FastClick is needed. + * + * @param {Element} layer The layer to listen on + */ +FastClick.notNeeded = function(layer) { + 'use strict'; + var metaViewport; + var chromeVersion; + + // Devices that don't support touch don't need FastClick + if (typeof window.ontouchstart === 'undefined') { + return true; + } + + // Chrome version - zero for other browsers + chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; + + if (chromeVersion) { + + if (deviceIsAndroid) { + metaViewport = document.querySelector('meta[name=viewport]'); + + if (metaViewport) { + // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89) + if (metaViewport.content.indexOf('user-scalable=no') !== -1) { + return true; + } + // Chrome 32 and above with width=device-width or less don't need FastClick + if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) { + return true; + } + } + + // Chrome desktop doesn't need FastClick (issue #15) + } else { + return true; + } + } + + // IE10 with -ms-touch-action: none, which disables double-tap-to-zoom (issue #97) + if (layer.style.msTouchAction === 'none') { + return true; + } + + return false; +}; + + +/** + * Factory method for creating a FastClick object + * + * @param {Element} layer The layer to listen on + * @param {Object} options The options to override the defaults + */ +FastClick.attach = function(layer, options) { + 'use strict'; + return new FastClick(layer, options); +}; + + +if (typeof define !== 'undefined' && define.amd) { + + // AMD. Register as an anonymous module. + define(function() { + 'use strict'; + return FastClick; + }); +} else if (typeof module !== 'undefined' && module.exports) { + module.exports = FastClick.attach; + module.exports.FastClick = FastClick; +} else { + window.FastClick = FastClick; +} diff --git a/site/public/assets/javascripts/vendor/flickity.pkgd.js b/site/public/assets/javascripts/vendor/flickity.pkgd.js index 6389014..0471fa5 100644 --- a/site/public/assets/javascripts/vendor/flickity.pkgd.js +++ b/site/public/assets/javascripts/vendor/flickity.pkgd.js @@ -1,6 +1,10 @@ /*! - * Flickity PACKAGED v0.2.3 + * Flickity PACKAGED v1.0.1 * Touch, responsive, flickable galleries + * + * Licensed GPLv3 for open source use + * or Flickity Commercial License for commercial use + * * http://flickity.metafizzy.co * Copyright 2015 Metafizzy */ @@ -1176,7 +1180,7 @@ if ( typeof define === 'function' && define.amd ) { })( window ); /** - * matchesSelector v1.0.2 + * matchesSelector v1.0.3 * matchesSelector( element, '.selector' ) * MIT license */ @@ -1189,6 +1193,10 @@ if ( typeof define === 'function' && define.amd ) { var matchesMethod = ( function() { + // check for the standard method name first + if ( ElemProto.matches ) { + return 'matches'; + } // check un-prefixed if ( ElemProto.matchesSelector ) { return 'matchesSelector'; @@ -1280,7 +1288,7 @@ if ( typeof define === 'function' && define.amd ) { })( Element.prototype ); /** - * Fizzy UI utils v0.1.1 + * Fizzy UI utils v1.0.1 * MIT license */ @@ -1380,7 +1388,7 @@ utils.indexOf = Array.prototype.indexOf ? function( ary, obj ) { // ----- removeFrom ----- // -utils.removeFrom = function( obj, ary ) { +utils.removeFrom = function( ary, obj ) { var index = utils.indexOf( ary, obj ); if ( index != -1 ) { ary.splice( index, 1 ); @@ -1499,14 +1507,12 @@ utils.debounceMethod = function( _class, methodName, threshold ) { // ----- htmlInit ----- // -var jQuery = window.jQuery; - // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/ -function toDashed( str ) { +utils.toDashed = function( str ) { return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) { return $1 + '-' + $2; }).toLowerCase(); -} +}; var console = window.console; /** @@ -1516,7 +1522,7 @@ var console = window.console; */ utils.htmlInit = function( WidgetClass, namespace ) { docReady( function() { - var dashedNamespace = toDashed( namespace ); + var dashedNamespace = utils.toDashed( namespace ); var elems = document.querySelectorAll( '.js-' + dashedNamespace ); var dataAttr = 'data-' + dashedNamespace + '-options'; @@ -1538,6 +1544,7 @@ utils.htmlInit = function( WidgetClass, namespace ) { // initialize var instance = new WidgetClass( elem, options ); // make available via $().data('layoutname') + var jQuery = window.jQuery; if ( jQuery ) { jQuery.data( elem, namespace, instance ); } @@ -1893,8 +1900,12 @@ return proto; })); /*! - * Flickity v0.2.3 + * Flickity v1.0.1 * Touch, responsive, flickable galleries + * + * Licensed GPLv3 for open source use + * or Flickity Commercial License for commercial use + * * http://flickity.metafizzy.co * Copyright 2015 Metafizzy */ @@ -1999,7 +2010,8 @@ Flickity.defaults = { // initialIndex: 0, percentPosition: true, resize: true, - selectedAttraction: 0.025 + selectedAttraction: 0.025, + setGallerySize: true // watchCSS: false, // wrapAround: false }; @@ -2075,7 +2087,6 @@ Flickity.prototype.activate = function() { this.getSize(); // get cells from children this.reloadCells(); - this.setContainerSize(); if ( this.options.accessibility ) { // allow element to focusable @@ -2109,7 +2120,7 @@ Flickity.prototype.reloadCells = function() { this.cells = this._makeCells( this.slider.children ); this.positionCells(); this._getWrapShiftCells(); - this.setContainerSize(); + this.setGallerySize(); }; /** @@ -2215,8 +2226,10 @@ Flickity.prototype.setCellAlign = function() { this.cellAlign = shorthand ? shorthand[ this.originSide ] : this.options.cellAlign; }; -Flickity.prototype.setContainerSize = function() { - this.viewport.style.height = this.maxCellHeight + 'px'; +Flickity.prototype.setGallerySize = function() { + if ( this.options.setGallerySize ) { + this.viewport.style.height = this.maxCellHeight + 'px'; + } }; Flickity.prototype._getWrapShiftCells = function() { @@ -2267,13 +2280,21 @@ Flickity.prototype._containCells = function() { var lastCell = this.getLastCell(); var contentWidth = this.slideableWidth - lastCell.size[ endMargin ]; var endLimit = contentWidth - this.size.innerWidth * ( 1 - this.cellAlign ); + // content is less than gallery size + var isContentSmaller = contentWidth < this.size.innerWidth; // contain each cell target for ( var i=0, len = this.cells.length; i < len; i++ ) { var cell = this.cells[i]; // reset default target cell.setDefaultTarget(); - cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin ); - cell.target = Math.min( cell.target, endLimit ); + if ( isContentSmaller ) { + // all cells fit inside gallery + cell.target = contentWidth * this.cellAlign; + } else { + // contain to bounds + cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin ); + cell.target = Math.min( cell.target, endLimit ); + } } }; @@ -2293,7 +2314,7 @@ Flickity.prototype.dispatchEvent = function( type, event, args ) { if ( event ) { // create jQuery event var $event = jQuery.Event( event ); - $event.type = type + '.flickity'; + $event.type = type; this.$element.trigger( $event, args ); } else { // just trigger with type if no event available @@ -2330,7 +2351,7 @@ Flickity.prototype.select = function( index, isWrap ) { this.selectedIndex = index; this.setSelectedCell(); this.startAnimation(); - this.dispatchEvent('select'); + this.dispatchEvent('cellSelect'); } }; @@ -2448,7 +2469,7 @@ Flickity.prototype.resize = function() { } this.positionCells(); this._getWrapShiftCells(); - this.setContainerSize(); + this.setGallerySize(); this.positionSliderAtSelected(); }; @@ -2554,6 +2575,9 @@ Flickity.prototype.destroy = function() { eventie.unbind( window, 'resize', this ); } this.emit('destroy'); + if ( jQuery && this.$element ) { + jQuery.removeData( this.element, 'flickity' ); + } delete this.element.flickityGUID; delete instances[ this.guid ]; }; @@ -2599,7 +2623,7 @@ return Flickity; })); /*! - * Unipointer v0.1.0 + * Unipointer v1.1.0 * base class for doing one thing with pointer event * MIT license */ @@ -2736,7 +2760,7 @@ Unipointer.prototype._pointerDown = function( event, pointer ) { Unipointer.prototype.pointerDown = function( event, pointer ) { this._bindPostStartEvents( event ); - this.emitEvent( 'pointerDown', [ this, event, pointer ] ); + this.emitEvent( 'pointerDown', [ event, pointer ] ); }; // hash of events to be bound after start event @@ -2813,7 +2837,7 @@ Unipointer.prototype._pointerMove = function( event, pointer ) { // public Unipointer.prototype.pointerMove = function( event, pointer ) { - this.emitEvent( 'pointerMove', [ this, event, pointer ] ); + this.emitEvent( 'pointerMove', [ event, pointer ] ); }; // ----- end event ----- // @@ -2850,7 +2874,7 @@ Unipointer.prototype._pointerUp = function( event, pointer ) { // public Unipointer.prototype.pointerUp = function( event, pointer ) { - this.emitEvent( 'pointerUp', [ this, event, pointer ] ); + this.emitEvent( 'pointerUp', [ event, pointer ] ); }; // ----- pointer done ----- // @@ -2896,7 +2920,7 @@ Unipointer.prototype._pointerCancel = function( event, pointer ) { // public Unipointer.prototype.pointerCancel = function( event, pointer ) { - this.emitEvent( 'pointerCancel', [ this, event, pointer ] ); + this.emitEvent( 'pointerCancel', [ event, pointer ] ); }; // ----- ----- // @@ -2916,7 +2940,7 @@ return Unipointer; })); /*! - * Unidragger v0.2.0 + * Unidragger v1.1.3 * Draggable base class * MIT license */ @@ -3050,13 +3074,6 @@ var disableImgOndragstart = !isIE8 ? noop : function( handle ) { // ----- start event ----- // -var allowTouchstartNodes = Unidragger.allowTouchstartNodes = { - INPUT: true, - A: true, - BUTTON: true, - SELECT: true -}; - /** * pointer start * @param {Event} event @@ -3071,7 +3088,7 @@ Unidragger.prototype.pointerDown = function( event, pointer ) { } // bind move and end events this._bindPostStartEvents( event ); - this.emitEvent( 'pointerDown', [ this, event, pointer ] ); + this.emitEvent( 'pointerDown', [ event, pointer ] ); }; // base pointer down logic @@ -3079,11 +3096,10 @@ Unidragger.prototype._dragPointerDown = function( event, pointer ) { // track to see when dragging starts this.pointerDownPoint = Unipointer.getPointerPoint( pointer ); + // prevent default, unless touchstart or <select> + var isTouchstart = event.type == 'touchstart'; var targetNodeName = event.target.nodeName; - // HACK iOS, allow clicks on buttons, inputs, and links - var isTouchstartNode = event.type == 'touchstart' && allowTouchstartNodes[ targetNodeName ]; - // do not prevent default on touchstart nodes or <select> - if ( !isTouchstartNode && targetNodeName != 'SELECT' ) { + if ( !isTouchstart && targetNodeName != 'SELECT' ) { preventDefaultEvent( event ); } }; @@ -3097,7 +3113,7 @@ Unidragger.prototype._dragPointerDown = function( event, pointer ) { */ Unidragger.prototype.pointerMove = function( event, pointer ) { var moveVector = this._dragPointerMove( event, pointer ); - this.emitEvent( 'pointerMove', [ this, event, pointer, moveVector ] ); + this.emitEvent( 'pointerMove', [ event, pointer, moveVector ] ); this._dragMove( event, pointer, moveVector ); }; @@ -3129,7 +3145,7 @@ Unidragger.prototype.hasDragStarted = function( moveVector ) { * @param {Event or Touch} pointer */ Unidragger.prototype.pointerUp = function( event, pointer ) { - this.emitEvent( 'pointerUp', [ this, event, pointer ] ); + this.emitEvent( 'pointerUp', [ event, pointer ] ); this._dragPointerUp( event, pointer ); }; @@ -3155,7 +3171,7 @@ Unidragger.prototype._dragStart = function( event, pointer ) { }; Unidragger.prototype.dragStart = function( event, pointer ) { - this.emitEvent( 'dragStart', [ this, event, pointer ] ); + this.emitEvent( 'dragStart', [ event, pointer ] ); }; // dragMove @@ -3169,7 +3185,8 @@ Unidragger.prototype._dragMove = function( event, pointer, moveVector ) { }; Unidragger.prototype.dragMove = function( event, pointer, moveVector ) { - this.emitEvent( 'dragMove', [ this, event, pointer, moveVector ] ); + preventDefaultEvent( event ); + this.emitEvent( 'dragMove', [ event, pointer, moveVector ] ); }; // dragEnd @@ -3186,7 +3203,7 @@ Unidragger.prototype._dragEnd = function( event, pointer ) { }; Unidragger.prototype.dragEnd = function( event, pointer ) { - this.emitEvent( 'dragEnd', [ this, event, pointer ] ); + this.emitEvent( 'dragEnd', [ event, pointer ] ); }; // ----- onclick ----- // @@ -3202,15 +3219,16 @@ Unidragger.prototype.onclick = function( event ) { // triggered after pointer down & up with no/tiny movement Unidragger.prototype._staticClick = function( event, pointer ) { - // allow click in text input - if ( event.target.nodeName == 'INPUT' && event.target.type == 'text' ) { + // allow click in <input>s and <textarea>s + var nodeName = event.target.nodeName; + if ( nodeName == 'INPUT' || nodeName == 'TEXTAREA' ) { event.target.focus(); } this.staticClick( event, pointer ); }; Unidragger.prototype.staticClick = function( event, pointer ) { - this.emitEvent( 'staticClick', [ this, event, pointer ] ); + this.emitEvent( 'staticClick', [ event, pointer ] ); }; // ----- ----- // @@ -3325,10 +3343,6 @@ proto.unbindDrag = function() { delete this.isDragBound; }; -proto.hasDragStarted = function( moveVector ) { - return Math.abs( moveVector.x ) > 3; -}; - proto._uiChangeDrag = function() { delete this.isFreeScrolling; }; @@ -3345,7 +3359,9 @@ proto.pointerDown = function( event, pointer ) { // kludge to blur focused inputs in dragger var focused = document.activeElement; - if ( focused && focused.blur && focused != this.element ) { + if ( focused && focused.blur && focused != this.element && + // do not blur body for IE9 & 10, #117 + focused != document.body ) { focused.blur(); } this.pointerDownFocus( event ); @@ -3375,6 +3391,8 @@ proto.pointerDownFocus = function( event ) { } }; +// ----- move ----- // + proto.pointerMove = function( event, pointer ) { var moveVector = this._dragPointerMove( event, pointer ); this.touchVerticalScrollMove( event, pointer, moveVector ); @@ -3382,6 +3400,12 @@ proto.pointerMove = function( event, pointer ) { this.dispatchEvent( 'pointerMove', event, [ pointer, moveVector ] ); }; +proto.hasDragStarted = function( moveVector ) { + return !this.isTouchScrolling && Math.abs( moveVector.x ) > 3; +}; + +// ----- up ----- // + proto.pointerUp = function( event, pointer ) { delete this.isTouchScrolling; classie.remove( this.viewport, 'is-pointer-down' ); @@ -3405,11 +3429,16 @@ function getPointerWindowY( pointer ) { } proto.touchVerticalScrollMove = function( event, pointer, moveVector ) { - if ( !this.options.touchVerticalScroll || !touchScrollEvents[ event.type ] ) { + // do not scroll if already dragging, if disabled + var touchVerticalScroll = this.options.touchVerticalScroll; + // if touchVerticalScroll is 'withDrag', allow scrolling and dragging + var canNotScroll = touchVerticalScroll == 'withDrag' ? !touchVerticalScroll : + this.isDragging || !touchVerticalScroll; + if ( canNotScroll || !touchScrollEvents[ event.type ] ) { return; } - // don't start vertical scrolling until pointer has moved 16 pixels in a direction - if ( !this.isTouchScrolling && Math.abs( moveVector.y ) > 16 ) { + // don't start vertical scrolling until pointer has moved 10 pixels in a direction + if ( !this.isTouchScrolling && Math.abs( moveVector.y ) > 10 ) { // start touch vertical scrolling // scroll & pointerY when started this.startScrollY = window.pageYOffset; @@ -3417,13 +3446,6 @@ proto.touchVerticalScrollMove = function( event, pointer, moveVector ) { // start scroll animation this.isTouchScrolling = true; } - if ( !this.isTouchScrolling ) { - return; - } - // scroll window - var scrollDelta = this.pointerWindowStartY - getPointerWindowY( pointer ); - var scrollY = this.startScrollY + scrollDelta; - window.scroll( window.pageXOffset, scrollY ); }; // -------------------------- dragging -------------------------- // @@ -3435,6 +3457,8 @@ proto.dragStart = function( event, pointer ) { }; proto.dragMove = function( event, pointer, moveVector ) { + preventDefaultEvent( event ); + this.previousDragX = this.x; var movedX = moveVector.x; @@ -3584,11 +3608,9 @@ proto.dragEndBoostSelect = function() { proto.staticClick = function( event, pointer ) { // get clickedCell, if cell was clicked var clickedCell = this.getParentCell( event.target ); - var clickedCellIndex = clickedCell && - utils.indexOf( this.cells, clickedCell ); - var clickedCellElem = clickedCell && clickedCell.element; - this.dispatchEvent( 'staticClick', event, - [ pointer, clickedCellIndex, clickedCellElem ] ); + var cellElem = clickedCell && clickedCell.element; + var cellIndex = clickedCell && utils.indexOf( this.cells, clickedCell ); + this.dispatchEvent( 'staticClick', event, [ pointer, cellElem, cellIndex ] ); }; // ----- ----- // @@ -3602,7 +3624,7 @@ return Flickity; })); /*! - * Tap listener v0.1.0 + * Tap listener v1.1.0 * listens to taps * MIT license */ @@ -3688,7 +3710,7 @@ TapListener.prototype.pointerUp = function( event, pointer ) { pointerPoint.y <= boundingRect.bottom + scrollY; // trigger callback if pointer is inside element if ( isInside ) { - this.emitEvent( 'tap', [ this, event, pointer ] ); + this.emitEvent( 'tap', [ event, pointer ] ); } }; @@ -3797,10 +3819,10 @@ PrevNextButton.prototype._create = function() { } // update on select var _this = this; - this.onselect = function() { + this.onCellSelect = function() { _this.update(); }; - this.parent.on( 'select', this.onselect ); + this.parent.on( 'cellSelect', this.onCellSelect ); // tap this.on( 'tap', this.onTap ); // pointerDown @@ -3906,8 +3928,8 @@ PrevNextButton.prototype.destroy = function() { utils.extend( Flickity.defaults, { prevNextButtons: true, - leftArrowText: '‹', - rightArrowText: '›' + leftArrowText: '‹', + rightArrowText: '›' }); Flickity.createMethods.push('_createPrevNextButtons'); @@ -4000,10 +4022,10 @@ PageDots.prototype._create = function() { this.dots = []; // update on select var _this = this; - this.onselect = function() { + this.onCellSelect = function() { _this.updateSelected(); }; - this.parent.on( 'select', this.onselect ); + this.parent.on( 'cellSelect', this.onCellSelect ); // tap this.on( 'tap', this.onTap ); // pointerDown @@ -4073,7 +4095,7 @@ PageDots.prototype.updateSelected = function() { this.selectedDot.className = 'dot is-selected'; }; -PageDots.prototype.onTap = function( instance, event ) { +PageDots.prototype.onTap = function( event ) { var target = event.target; // only care about dot clicks if ( target.nodeName != 'LI' ) { @@ -4430,7 +4452,7 @@ Flickity.prototype.remove = function( elems ) { cell = cells[i]; cell.remove(); // remove item from collection - utils.removeFrom( cell, this.cells ); + utils.removeFrom( this.cells, cell ); } if ( cells.length ) { @@ -4479,7 +4501,7 @@ Flickity.prototype.cellChange = function( changedCellIndex ) { this._positionCells( changedCellIndex ); this._getWrapShiftCells(); - this.setContainerSize(); + this.setGallerySize(); // position slider if ( this.options.freeScroll ) { this.positionSlider(); @@ -4532,7 +4554,7 @@ return Flickity; }); /*! - * Flickity asNavFor v0.1.1 + * Flickity asNavFor v1.0.1 * enable asNavFor for Flickity */ @@ -4556,7 +4578,7 @@ return Flickity; // CommonJS module.exports = factory( window, - require('dessandro-classie'), + require('desandro-classie'), require('flickity'), require('fizzy-ui-utils') ); @@ -4610,7 +4632,7 @@ Flickity.prototype.setNavCompanion = function( elem ) { this.onNavCompanionSelect = function() { _this.navCompanionSelect(); }; - companion.on( 'select', this.onNavCompanionSelect ); + companion.on( 'cellSelect', this.onNavCompanionSelect ); // click this.on( 'staticClick', this.onNavStaticClick ); @@ -4645,9 +4667,9 @@ Flickity.prototype.removeNavSelectedElement = function() { delete this.navSelectedElement; }; -Flickity.prototype.onNavStaticClick = function( event, pointer, clickedCellIndex ) { - if ( typeof clickedCellIndex == 'number' ) { - this.navCompanion.select( clickedCellIndex ); +Flickity.prototype.onNavStaticClick = function( event, pointer, cellElement, cellIndex ) { + if ( typeof cellIndex == 'number' ) { + this.navCompanion.select( cellIndex ); } }; @@ -4659,7 +4681,7 @@ Flickity.prototype.destroyAsNavFor = function() { if ( !this.navCompanion ) { return; } - this.navCompanion.off( 'select', this.onNavCompanionSelect ); + this.navCompanion.off( 'cellSelect', this.onNavCompanionSelect ); this.off( 'staticClick', this.onNavStaticClick ); delete this.navCompanion; }; @@ -5007,7 +5029,7 @@ function makeArray( obj ) { }); /*! - * Flickity imagesLoaded v0.1.2 + * Flickity imagesLoaded v1.0.0 * enables imagesLoaded option for Flickity */ @@ -5022,30 +5044,27 @@ function makeArray( obj ) { // AMD define( [ 'flickity/js/index', - 'imagesloaded/imagesloaded', - 'fizzy-ui-utils/utils' - ], function( Flickity, imagesLoaded, utils ) { - return factory( window, Flickity, imagesLoaded, utils ); + 'imagesloaded/imagesloaded' + ], function( Flickity, imagesLoaded ) { + return factory( window, Flickity, imagesLoaded ); }); } else if ( typeof exports == 'object' ) { // CommonJS module.exports = factory( window, require('flickity'), - require('imagesloaded'), - require('fizzy-ui-utils') + require('imagesloaded') ); } else { // browser global window.Flickity = factory( window, window.Flickity, - window.imagesLoaded, - window.fizzyUIUtils + window.imagesLoaded ); } -}( window, function factory( window, Flickity, imagesLoaded, utils ) { +}( window, function factory( window, Flickity, imagesLoaded ) { Flickity.createMethods.push('_createImagesLoaded'); @@ -5060,12 +5079,8 @@ Flickity.prototype.imagesLoaded = function() { } var _this = this; function onImagesLoadedProgress( instance, image ) { - // check if image is a cell - var cell = _this.getCell( image.img ); - // otherwise get its parents - var cellElem = cell && cell.element || - utils.getParent( image.img, '.flickity-slider > *' ); - _this.cellSizeChange( cellElem ); + var cell = _this.getParentCell( image.img ); + _this.cellSizeChange( cell && cell.element ); } this.loader = imagesLoaded( this.slider ).on( 'progress', onImagesLoadedProgress ); }; diff --git a/site/public/assets/javascripts/vendor/loader.js b/site/public/assets/javascripts/vendor/loader.js index 4c1c8cd..b939941 100644 --- a/site/public/assets/javascripts/vendor/loader.js +++ b/site/public/assets/javascripts/vendor/loader.js @@ -1,13 +1,17 @@ var Loader = Loader || (function(){ - function Loader (readyCallback){ + function Loader (readyCallback, view){ this.assets = {}; this.images = []; this.readyCallback = readyCallback; + this.count = 0 + this.view = view + this.loaded = false } // Register an asset as loading Loader.prototype.register = function(s){ this.assets[s] = false; + this.count += 1 } // Signal that an asset has loaded @@ -16,10 +20,18 @@ var Loader = Loader || (function(){ this.assets[s] = true; if (this.loaded) return; + + this.view && this.view.update( this.percentRemaining() ) + if (! this.isReady()) return; this.loaded = true; - this.readyCallback && this.readyCallback(); + if (this.view) { + this.view && this.view.finish(this.readyCallback) + } + else { + this.readyCallback && this.readyCallback(); + } } // (boolean) Is the loader ready? @@ -31,6 +43,11 @@ var Loader = Loader || (function(){ } return true; } + + // (float) Percentage of assets remaining + Loader.prototype.percentRemaining = function(){ + return this.remainingAssets() / this.count + } // (int) Number of assets remaining Loader.prototype.remainingAssets = function(){ @@ -38,7 +55,7 @@ var Loader = Loader || (function(){ for (var s in this.assets) { if (this.assets.hasOwnProperty(s) && this.assets[s] != true) { n++; - console.log('remaining: ' + s); + // console.log('remaining: ' + s); } } return n; diff --git a/site/public/assets/javascripts/vendor/polyfill.js b/site/public/assets/javascripts/vendor/polyfill.js index 411d90f..8c26e80 100644 --- a/site/public/assets/javascripts/vendor/polyfill.js +++ b/site/public/assets/javascripts/vendor/polyfill.js @@ -97,4 +97,34 @@ function fullscreen (el) { } else if (el.webkitRequestFullscreen) { el.webkitRequestFullscreen(); } -}
\ No newline at end of file +} + +/* + * Proper fullscreen detection using the HTML5 + * Full Screen API. Not supported on mobile or + * IE10 and under + * TODO Need to disable fullscreen button on IE10 and lower + */ +function isFullScreen() { + return !!getFullScreenElement() +} + +function getFullScreenElement() { + return document.fullScreenElement || + document.webkitFullscreenElement || + document.mozFullScreenElement || + document.msFullscreenElement +} + +var raf = window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame + +var caf = window.cancelAnimationFrame || + window.webkitCancelAnimationFrame || + window.mozCancelAnimationFrame || + window.oCancelAnimationFrame || + window.msCancelAnimationFrame + diff --git a/site/public/assets/javascripts/vendor/util.js b/site/public/assets/javascripts/vendor/util.js index 0f5c6ed..487fe56 100644 --- a/site/public/assets/javascripts/vendor/util.js +++ b/site/public/assets/javascripts/vendor/util.js @@ -240,6 +240,27 @@ if (!Function.prototype.bind) { }; }()); +/* + * Throttle a function to be called no more often + * than ms milliseconds + */ +function throttle(fn, ms) { + ms = ms || 100 + var ready = true + var last + return function() { + var now = Date.now() + if (ready) { + last = now + return fn.apply(this, arguments) + ready = false + } else { + if (now - last > ms) { + ready = true + } + } + } +} function selectElementContents(el) { if (window.getSelection && document.createRange) { |
