forked from GitHub/dbot
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.
This commit is contained in:
parent
c9fd314ba4
commit
5d41cc633c
@ -10,8 +10,10 @@ html(lang='en')
|
|||||||
function giveMessage(msg) {
|
function giveMessage(msg) {
|
||||||
$('<li>'+msg+'</li>').prependTo('#history').hide().slideDown();
|
$('<li>'+msg+'</li>').prependTo('#history').hide().slideDown();
|
||||||
}
|
}
|
||||||
|
var lock = false
|
||||||
function getNewImage() {
|
function getNewImage() {
|
||||||
count += 1;
|
count += 1;
|
||||||
|
lock = true;
|
||||||
$('#loading').fadeIn();
|
$('#loading').fadeIn();
|
||||||
$('#loading').text('Loading image ' + count + '...');
|
$('#loading').text('Loading image ' + count + '...');
|
||||||
document.title = 'random imgur (' + count + ')';
|
document.title = 'random imgur (' + count + ')';
|
||||||
@ -19,6 +21,7 @@ html(lang='en')
|
|||||||
$('#image').load(function(){});
|
$('#image').load(function(){});
|
||||||
$.get("/api/imgur/getRandomImage", function(d) {
|
$.get("/api/imgur/getRandomImage", function(d) {
|
||||||
$('#image').attr('src', d.data[0]);
|
$('#image').attr('src', d.data[0]);
|
||||||
|
lock = false;
|
||||||
$('#details').text("Fetching info...");
|
$('#details').text("Fetching info...");
|
||||||
giveMessage('<a href="' + d.data[0] + '">' + d.data[0] + '</a>');
|
giveMessage('<a href="' + d.data[0] + '">' + d.data[0] + '</a>');
|
||||||
$.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) {
|
$.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) {
|
||||||
@ -37,7 +40,13 @@ html(lang='en')
|
|||||||
switch(e.which){
|
switch(e.which){
|
||||||
case 13: // enter
|
case 13: // enter
|
||||||
case 32: // space
|
case 32: // space
|
||||||
|
if (lock) {
|
||||||
|
$('#loading').text(function(index, text){
|
||||||
|
return text.replace(/\.(?=[^.]*$)/, "!");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
getNewImage();
|
getNewImage();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 83: // s
|
case 83: // s
|
||||||
$('body').toggleClass('crop');
|
$('body').toggleClass('crop');
|
||||||
|
Loading…
Reference in New Issue
Block a user