summaryrefslogtreecommitdiff
path: root/public/assets/js/nav.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/nav.js')
-rw-r--r--public/assets/js/nav.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/public/assets/js/nav.js b/public/assets/js/nav.js
index 401c6ff..8d172bf 100644
--- a/public/assets/js/nav.js
+++ b/public/assets/js/nav.js
@@ -13,7 +13,7 @@ var NavView = View.extend({
this.$pip = this.$("#pip img")
this.$image = this.$("#luckyimage")
- $(window).on("keydown", app.keydown)
+ $(window).on("keydown", this.keydown.bind(this))
this.latest()
},
@@ -26,40 +26,54 @@ var NavView = View.extend({
this.next()
break
case 38: // up
- this.latest()
+ this.random()
break
case 40: // down
- this.random()
+ this.latest()
break
}
},
latest: function(){
+ if (this.fetching) return
+ this.fetching = true
this.onLatest = true
$.get("/get/latest", this.display.bind(this))
},
prev: function(){
+ if (this.fetching) return
if (this.id - 1 < 1) { return }
+ this.fetching = true
this.onLatest = false
$.get("/get/" + (this.id-1), this.display.bind(this))
},
next: function(){
+ if (this.fetching) return
if (this.onLatest || this.id < 1) { return }
+ this.fetching = true
this.onLatest = false
$.get("/get/" + (this.id+1), this.display.bind(this))
},
random: function(){
+ if (this.fetching) return
+ this.fetching = true
this.onLatest = false
$.get("/get/random", this.display.bind(this))
},
display: function(data){
+ this.fetching = false
+ if (! data.id) {
+ this.onLatest = true
+ return
+ }
this.id = data.id
this.$pip.attr("src", data.url)
this.$image.css("background-image", "url(" + data.url + ")")
+ history.pushState(data, document.title, "/p/" + data.id)
},
})