Skip to content

Instantly share code, notes, and snippets.

@macgyver
Created December 14, 2011 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macgyver/1477081 to your computer and use it in GitHub Desktop.
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/
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