Skip to content

Instantly share code, notes, and snippets.

@strickc
Created August 30, 2015 08:53
Show Gist options
  • Save strickc/56c7dc01d85b6109f478 to your computer and use it in GitHub Desktop.
Save strickc/56c7dc01d85b6109f478 to your computer and use it in GitHub Desktop.
Random Norris Joke Generator
<div class="container center-text">
<h1><span class="big-h">Norri</span><span class="sub-h"> to live by</span></h1>
<button style="color:#222222;" onclick="newQuote()">Generate new Norris</button>
<div id="quote"></div>
<div id="attrib"></div>
<a id="tweet" class="twitter-share-button"
href="https://twitter.com/intent/tweet?text=Hello%20world" target="_blank" data-size="large" style="display:none">Tweet this</a>
</div>
$(document).ready(function() {
});
function newQuote(){
$("#quote").text('Getting New Joke. . .');
$("#attrib").text("");
document.getElementById("tweet").style.display = 'none';
httpGetAsync("http://api.icndb.com/jokes/random",function(resp){
var obj = JSON.parse(resp);
console.log(obj);
$("#quote").text(obj.value.joke);
$("#attrib").html("Chuck Norris joke courtesy of <a href='http://icndb.com'>icndb.com</a>");
updateTweet(obj.value.joke);
});
}
//http://stackoverflow.com/a/4033310/1124332
function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
function updateTweet(txt){
var link = document.getElementById("tweet");
txt = escape(txt);
link.removeAttribute("href");
link.setAttribute('href', "https://twitter.com/intent/tweet?text="+txt);
link.style.display = 'inline';
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
body{
background-color:#000000;
color: #BBBBBB;
}
.center-text{
text-align:center;
}
.big-h {
font-size: 5em;
font-family: Lobster, Monospace;
}
.sub-h {
margin-top:-50%;
font-size: 2em;
font-family: Lobster, Monospace;
}
#quote {
margin-top: 1em;
font-size:3em;
font-family: Lobster, Monospace;
}
#attrib {
text-align:right;
}
a.twitter-share-button,
a.twitter-mention-button,
a.twitter-hashtag-button {
display: inline-block;
margin-top:5em;
padding: 1px 3px 0 19px;
border: #ccc solid 1px;
border-radius: 3px;
background: #f8f8f8 url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgNzIgNzIiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDcyIDcyIiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxyZWN0IHg9IjAiIGZpbGw9Im5vbmUiIHdpZHRoPSI3MiIgaGVpZ2h0PSI3MiIvPg0KPHBhdGggZmlsbD0iIzU1YWNlZSIgZD0iTTY4LjgxMiwxNS4xNDFjLTIuMzQ4LDEuMDM5LTQuODY5LDEuNzQzLTcuNTE5LDIuMDZjMi43MDMtMS42Miw0Ljc3OC00LjE4Nyw1Ljc1Ni03LjI0NGMtMi41MjksMS41LTUuMzMsMi41OTItOC4zMTMsMy4xNzYNCglDNTYuMzQ5LDEwLjU5MSw1Mi45NDgsOSw0OS4xODIsOWMtNy4yMjksMC0xMy4wOTIsNS44NjEtMTMuMDkyLDEzLjA5M2MwLDEuMDI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S0xOS45NDksMzcuMjUxLTM3LjI0OWMwLTAuNTY2LTAuMDE0LTEuMTM0LTAuMDM5LTEuNjk0QzY0LjgzOCwyMC4wNjgsNjcuMDU4LDE3Ljc2NSw2OC44MTIsMTUuMTQxeiIvPg0KPC9zdmc+DQo=") 2px 3px no-repeat,
linear-gradient(#fff, #dedede);
background-size: 16px 13px, auto auto;
/* Text */
font: bold 11px/17px Helvetica, Arial, sans-serif;
text-decoration: none;
color: #333;
text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
white-space: nowrap;
}
/* Color Highlight for keyboard navigation */
a.twitter-share-button:focus,
a.twitter-mention-button:focus,
a.twitter-hashtag-button:focus {
outline: none;
border-color: #0089cb;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment