Merge pull request #371 from zuzak/imgur-history

Imgur history
This commit is contained in:
reality 2013-04-17 14:13:00 -07:00
commit 787480647d
2 changed files with 80 additions and 21 deletions

View File

@ -5,11 +5,13 @@
#container,#image { #container,#image {
margin:0; margin:0;
max-height:100%; max-height:100%;
max-width:100%;
padding:0; padding:0;
} }
#details { #details {
display:none; display:none;
font-family:sans-serif;
font-weight:700; font-weight:700;
left:25px; left:25px;
min-width:280px; min-width:280px;
@ -18,37 +20,81 @@
top:25px; top:25px;
} }
#link { #history {
left:25px; left:25px;
text-align:center; margin:0;
width:168px; max-height:210px;
font-family:monospace overflow:hidden;
padding:0;
top:95px;
} }
#link,#loading { #history li {
font-family:monospace;
left:25px;
margin-bottom:10px;
opacity:0.1;
text-align:center;
width:168px;
}
#history li,#loading {
display:block;
font-family:monospace; font-family:monospace;
font-size:10px; font-size:10px;
padding:10px; padding:10px;
top:95px; }
#history li:hover,#history li:nth-of-type(1) {
opacity:1!important;
}
#history li:nth-of-type(2) {
opacity:0.8;
}
#history li:nth-of-type(3) {
opacity:0.6;
}
#history li:nth-of-type(4) {
opacity:0.4;
}
#history li:nth-of-type(5) {
opacity:0.2;
}
#history,#loading,#details {
position:absolute;
} }
#loading { #loading {
font-weight:500; font-weight:500;
left:220px; left:220px;
min-width:95px; min-width:95px;
top:95px;
} }
#loading,#details,#link { #loading,#details,#history li {
background:rgba(43,43,43,0.8); background:rgba(43,43,43,0.8);
border-radius:5px; border-radius:5px;
color:#85bf25; color:#85bf25;
font-family:sans-serif; }
position:absolute;
a {
color:inherit;
}
body.crop {
overflow:hidden;
} }
html,body { html,body {
background-color:#121211; background-color:#121211;
border:0;
height:100%; height:100%;
margin:0; margin:0;
overflow:auto;
padding:0; padding:0;
} }

View File

@ -7,9 +7,12 @@ html(lang='en')
title random imgur title random imgur
script script
var count = 0; var count = 0;
function giveMessage(msg) {
$('<li>'+msg+'</li>').prependTo('#history').hide().slideDown();
}
function getNewImage() { function getNewImage() {
count += 1; count += 1;
$('#loading').show(); $('#loading').fadeIn();
$('#loading').text('Loading image ' + count + '...'); $('#loading').text('Loading image ' + count + '...');
document.title = 'random imgur (' + count + ')'; document.title = 'random imgur (' + count + ')';
$('#loading').fadeIn(); $('#loading').fadeIn();
@ -17,8 +20,7 @@ html(lang='en')
$.get("/api/imgur/getRandomImage", function(d) { $.get("/api/imgur/getRandomImage", function(d) {
$('#image').attr('src', d.data[0]); $('#image').attr('src', d.data[0]);
$('#details').text("Fetching info..."); $('#details').text("Fetching info...");
$('#link').text(d.data[0]); giveMessage('<a href="' + d.data[0] + '">' + d.data[0] + '</a>');
$('#link').attr('href',d.data[0]);
$.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) { $.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) {
if(info.data[0].indexOf('undefined') == -1) { if(info.data[0].indexOf('undefined') == -1) {
$("#details").text(count + ': ' + info.data[0]); $("#details").text(count + ': ' + info.data[0]);
@ -31,10 +33,21 @@ html(lang='en')
}, "json"); }, "json");
} }
$(getNewImage()); $(getNewImage());
$(document).on('keydown', function(e){(e.which==32)&&(getNewImage()) }); $(document).on('keydown', function(e){
switch(e.which){
case 13: // enter
case 32: // space
getNewImage();
break;
case 83: // s
$('body').toggleClass('crop');
giveMessage("Toggled scrollbars.")
};
});
body body
div#loading Loading image 1... div#loading Loading image 1...
div#details Press [SPACE] to load a new image div#details Press [SPACE] to load a new image
a#link [SPACE] for next ul#history
li Press [SPACE] for next
div#container div#container
img#image img#image