dbot/views/imgur/imgurr.jade
Douglas Gardner 5d41cc633c 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.
2013-04-17 21:30:05 +00:00

63 lines
2.0 KiB
Plaintext

!!! 5
html(lang='en')
head
meta(charset='utf-8')
script(type="text/javascript", src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js")
link(rel="stylesheet", href="/imgurr.css")
title random imgur
script
var count = 0;
function giveMessage(msg) {
$('<li>'+msg+'</li>').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 + ')';
$('#loading').fadeIn();
$('#image').load(function(){});
$.get("/api/imgur/getRandomImage", function(d) {
$('#image').attr('src', d.data[0]);
lock = false;
$('#details').text("Fetching info...");
giveMessage('<a href="' + d.data[0] + '">' + d.data[0] + '</a>');
$.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) {
if(info.data[0].indexOf('undefined') == -1) {
$("#details").text(count + ': ' + info.data[0]);
$('#details').show();
} else {
$("#details").hide();
}
$('#loading').fadeOut();
}, "json");
}, "json");
}
$(getNewImage());
$(document).on('keydown', function(e){
switch(e.which){
case 13: // enter
case 32: // space
if (lock) {
$('#loading').text(function(index, text){
return text.replace(/\.(?=[^.]*$)/, "!");
});
} else {
getNewImage();
}
break;
case 83: // s
$('body').toggleClass('crop');
giveMessage("Toggled scrollbars.")
};
});
body
div#loading Loading image 1...
div#details Press [SPACE] to load a new image
ul#history
li Press [SPACE] for next
div#container
img#image