Skip to content

Instantly share code, notes, and snippets.

@dhoko
Last active August 29, 2015 14:05
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 dhoko/7a4452159231674c1cdd to your computer and use it in GitHub Desktop.
Save dhoko/7a4452159231674c1cdd to your computer and use it in GitHub Desktop.
Github emoticons display
function doRequest(url, cb) {
// create the request here
cb = cb || function(){};
var xhr = new XMLHttpRequest();
var requestUrl = url;
xhr.open("GET", requestUrl, true);
xhr.onreadystatechange = function() {
var status;
var data;
// http://xhr.spec.whatwg.org/#dom-xmlhttprequest-readystate
if (xhr.readyState == 4) { // `DONE`
status = xhr.status;
if (status == 200) {
cb(JSON.parse(xhr.responseText));
}
}
};
xhr.send();
}
var body = ['<style>ul {margin:0; padding:0; text-align:center} li { display: inline-block; vertical-align: top; list-style: none; background: #eee; margin: 2em; border: 1px solid rgb(217, 217, 217); width: 15%;}</style><ul><!--'];
var figure = '--><li><figure><img src="%img%" alt=""><figcaption><b>:%txt%:</b></figcaption></figure></li><!--';
doRequest('https://api.github.com/emojis', function (data) {
for(var key in data) {
body.push(figure.replace('%txt%',key).replace('%img%',data[key]))
}
body.push('--></ul>');
document.body.innerHTML = body.join('')
});
@dhoko
Copy link
Author

dhoko commented Aug 26, 2014

@dhoko
Copy link
Author

dhoko commented Aug 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment