Last active
August 29, 2015 14:16
-
-
Save it-ony/525fc3f4da36bfaa00f3 to your computer and use it in GitHub Desktop.
Display image of first article of shop
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
// 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