Last active
August 29, 2015 14:05
-
-
Save dhoko/7a4452159231674c1cdd to your computer and use it in GitHub Desktop.
Github emoticons display
This file contains hidden or 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
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('') | |
}); |
Author
dhoko
commented
Aug 26, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment