diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-09-24 13:52:25 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-09-24 13:52:25 -0400 |
| commit | 456814755f8c2559f08b6d4d4635a5ea6bc495f0 (patch) | |
| tree | 569b559d7af4b481c19b58fe0c6aaeef19c9f6e6 /public/assets/js/nav.js | |
| parent | b817d4472ca905a0d380cf686ffa62f62297574a (diff) | |
browser functionality all working
Diffstat (limited to 'public/assets/js/nav.js')
| -rw-r--r-- | public/assets/js/nav.js | 20 |
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) }, }) |
