summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/app.js14
-rw-r--r--public/assets/js/lib/HeaderView.js9
-rw-r--r--public/assets/js/lib/Scroller.js125
-rw-r--r--public/assets/js/vendor/util.js3
4 files changed, 141 insertions, 10 deletions
diff --git a/public/assets/js/app.js b/public/assets/js/app.js
index 3476d44..dba055b 100644
--- a/public/assets/js/app.js
+++ b/public/assets/js/app.js
@@ -48,6 +48,11 @@ var app = (function() {
app.lookup[ view.project_id ] = view
return view
})
+
+ Scroller.init({
+ previous: app.nav.previous.bind(app.nav),
+ next: app.nav.next.bind(app.nav),
+ })
}
app.ready = function() {
@@ -57,6 +62,7 @@ var app = (function() {
app.router = new SiteRouter ()
+ app.resizeItems()
app.router.launch()
console.log("launched")
@@ -117,14 +123,6 @@ $('.top').each(function(){
}
})
-$(".item").each(function(i){
- var height = window.innerHeight - $(this).find(".bottom").height()
- if (is_desktop) {
- height -= $("nav").height() // account for top bar
- }
- $(".previous, .next, .flickity-viewport", this).css({ 'height': height })
-})
-
$(".item").addClass("hidden")
app.init()
diff --git a/public/assets/js/lib/HeaderView.js b/public/assets/js/lib/HeaderView.js
index bc64d85..80dd5f8 100644
--- a/public/assets/js/lib/HeaderView.js
+++ b/public/assets/js/lib/HeaderView.js
@@ -13,14 +13,19 @@ var HeaderView = View.extend({
},
updateSlideNumber: function(n){
- this.$slideNumber.html(n + 1)
+ n += 1
+ if (n < 10) n = "0" + n
+ this.$slideNumber.html()
},
updatePageNumber: function(n){
- this.$pageNumber.html(n + 1)
+ n += 1
+ if (n < 10) n = "0" + n
+ this.$pageNumber.html(n)
},
updateSlideCount: function(n){
+ if (n < 10) n = "0" + n
this.$slideCount.html(n)
},
diff --git a/public/assets/js/lib/Scroller.js b/public/assets/js/lib/Scroller.js
new file mode 100644
index 0000000..483a103
--- /dev/null
+++ b/public/assets/js/lib/Scroller.js
@@ -0,0 +1,125 @@
+var Scroller = (function(){
+ var Scroller = {}
+
+ var prev, next
+ var webkitRatio = 1
+
+ Scroller.init = function(opt){
+ previous = opt.previous
+ next = opt.next
+ if (is_mobile) {
+// document.body.addEventListener("touchstart", touchstart)
+// document.body.addEventListener("touchmove", touchmove)
+// document.body.addEventListener("touchend", touchend)
+ }
+ else {
+ document.body.addEventListener("wheel", wheelDelta)
+ document.body.addEventListener("keydown", keydown)
+ }
+ }
+
+ var touching = false, touchStartTime, touchStartY, touchEndY, touchDist, touchScrollTop
+ function touchstart (e) {
+ touching = true
+ touchStartTime = +(new Date)
+ touchStartY = touchEndY = e.touches ? e.touches[0].pageY : e.pageY
+ }
+ function touchmove (e) {
+ if (! touching) return
+ e.preventDefault()
+ var timestamp = +(new Date)
+ var duration = timestamp - touchStartTime
+ touchEndY = e.touches ? e.touches[0].pageY : e.pageY
+ touchDist = touchStartY - touchEndY
+ }
+ function touchend (e) {
+ if (! touching) return
+ e.preventDefault()
+ touching = false
+ var timestamp = +(new Date)
+ var duration = timestamp - touchStartTime
+ touchDist = touchStartY - touchEndY
+ if (Math.abs(touchDist) < 10 || duration < 100) {
+ step(1)
+ }
+ else {
+ touchDist > 0 ? step(1) : step(-1)
+ }
+ }
+
+ function wheelDelta (e){
+ e.preventDefault()
+ var deltaY = 0
+ // WebKit
+ if ( e.deltaY ) {
+ deltaY += e.deltaY * webkitRatio
+ }
+ else if ( e.wheelDeltaY ) {
+ deltaY += e.wheelDeltaY * webkitRatio
+ }
+ // Opera / Explorer 9
+ else if ( e.wheelDelta ) {
+ deltaY += e.wheelDelta * webkitRatio
+ }
+ // Firefox
+ else if ( e.detail ) {
+ deltaY -= e.detail * 2
+ }
+ wheel(deltaY)
+ }
+
+ var lastScrollEvent = +new Date(), lastDY = 0, lastSign = 0
+ function wheel (dy) {
+ if (isNaN(dy)) return
+ var now = +new Date(), newSign = sign(dy)
+
+ if ((now > lastScrollEvent + 300) ||
+ (lastSign !== newSign && Math.abs(dy) > Math.abs(lastDY*2)) ||
+ (lastSign === newSign && Math.log(Math.abs(dy)) > 1+Math.log(Math.abs(lastDY)))) {
+ step(sign(dy))
+ }
+ lastDY = dy
+ lastSign = newSign
+ lastScrollEvent = now
+ }
+ function step (n) {
+ var now = +new Date()
+ if (now < lastScrollEvent + 300) {
+ return
+ }
+ lastScrollEvent = now
+ if (n < 0) {
+ previous()
+ }
+ else {
+ next()
+ }
+ }
+ function keydown (e) {
+ // console.log(e.keyCode)
+ switch (e.keyCode) {
+ case 32: // space
+ e.preventDefault()
+ step(1)
+ break
+ case 36: // home
+ e.preventDefault()
+ break
+ case 35: // end
+ e.preventDefault()
+ break
+ case 33: // page up
+ case 38: // up
+ e.preventDefault()
+ step(-1)
+ break
+ case 34: // page down
+ case 40: // down
+ e.preventDefault()
+ step(1)
+ break
+ }
+ }
+
+ return Scroller
+})() \ No newline at end of file
diff --git a/public/assets/js/vendor/util.js b/public/assets/js/vendor/util.js
index e0e2c0b..e8ad0af 100644
--- a/public/assets/js/vendor/util.js
+++ b/public/assets/js/vendor/util.js
@@ -1,3 +1,6 @@
+function clamp (n,a,b) { return n < a ? a : n < b ? n : b }
+function sign (n) { return n < 0 ? -1 : 1 }
+
function addClassForPeriod(el, className, delay, callback){
delay = delay || 1000
el.classList.add(className)