Skip to content

Instantly share code, notes, and snippets.

@it-ony
Last active August 29, 2015 14:16
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 it-ony/525fc3f4da36bfaa00f3 to your computer and use it in GitHub Desktop.
Save it-ony/525fc3f4da36bfaa00f3 to your computer and use it in GitHub Desktop.
Display image of first article of shop
// MIT LICENSE, Tony Findeisen
(function(undefined) {
var shopId = 205909,
id = 'callback_' + shopId,
locale = 'de_DE';
var script = document.createElement('script');
script.src = 'http://api.spreadshirt.de/api/v1/shops/' + shopId + '/articles?limit=1&locale=' + locale + '&mediaType=jsonp&callback=' + id;
document.write('<div id="' + id + '"></div>');
document.getElementsByTagName('head')[0].appendChild(script);
window[id] = function(data) {
window[id] = undefined;
var img = new Image(),
href = data.articles[0].resources[0].href;
if (location.protocol != "file:") {
href = href.replace(/https?:/, '');
}
img.src = href;
document.getElementById(id).appendChild(img);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment