From 5d41cc633c1ea368519ff959d30c82d1f1521811 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 17 Apr 2013 21:30:05 +0000 Subject: [PATCH] calm down, man Add throttle to the spacebar, so you can no longer load another image whilst the old one is loading. Hopefully this'll negate some of the API failures we've been getting. --- views/imgur/imgurr.jade | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/views/imgur/imgurr.jade b/views/imgur/imgurr.jade index fd7d7d0..a5f4f4d 100644 --- a/views/imgur/imgurr.jade +++ b/views/imgur/imgurr.jade @@ -10,8 +10,10 @@ html(lang='en') function giveMessage(msg) { $('
  • '+msg+'
  • ').prependTo('#history').hide().slideDown(); } + var lock = false function getNewImage() { count += 1; + lock = true; $('#loading').fadeIn(); $('#loading').text('Loading image ' + count + '...'); document.title = 'random imgur (' + count + ')'; @@ -19,6 +21,7 @@ html(lang='en') $('#image').load(function(){}); $.get("/api/imgur/getRandomImage", function(d) { $('#image').attr('src', d.data[0]); + lock = false; $('#details').text("Fetching info..."); giveMessage('' + d.data[0] + ''); $.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) { @@ -37,7 +40,13 @@ html(lang='en') switch(e.which){ case 13: // enter case 32: // space - getNewImage(); + if (lock) { + $('#loading').text(function(index, text){ + return text.replace(/\.(?=[^.]*$)/, "!"); + }); + } else { + getNewImage(); + } break; case 83: // s $('body').toggleClass('crop');