Created
December 14, 2011 15:43
-
-
Save macgyver/1477081 to your computer and use it in GitHub Desktop.
A dotjs script to display comics near the "signed prints" select list at http://store.xkcd.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var select = $('select#SignedPrints'), | |
form = select.closest('form'), | |
dst = $('<img>').css({display:'block',margin:'0 auto 5px'}); | |
form.before(dst); | |
select.bind('change', function(){ | |
var option = $(this), | |
id = $(this).val().replace(/.*-0?(\d*)-.*/, '$1'), | |
uri = 'http://xkcd.com/' + id; | |
dst.css('opacity', '0.5'); | |
$.ajax({ | |
url: uri, | |
success: function(response) { | |
var page = $(response), | |
src = page.find('#middleContent img'); | |
dst.attr('src', src.attr('src')) | |
.attr('title', src.attr('title')); | |
dst.bind('load', function(){ dst.css('opacity', 1) }); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment