Skip to content

Instantly share code, notes, and snippets.

@stephepush
Last active September 3, 2017 15:46
Show Gist options
  • Select an option

  • Save stephepush/3786df964b11f7d41adc5cd287ed94fe to your computer and use it in GitHub Desktop.

Select an option

Save stephepush/3786df964b11f7d41adc5cd287ed94fe to your computer and use it in GitHub Desktop.
FCC Random Quote Generator
<html>
<head>
<title></title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Passion+One" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div id="dataDiv" class="col-xs-8 offset-xs-2 col-sm-8 offset-sm-2 col-md-6 offset-md-3 col-lg-4 offset-lg-3">
<blockquote>
<p id="quote"></p>
<p id="author"></p>
</blockquote>
<div id="btns" class="row">
<div class="col-xs-8 offset-xs-2 col-sm-8 offset-sm-2 col-md-6 offset-md-3 col-lg-12 offset-lg-3">
<button class="btn btn-default" id="newQuote" type="button">New Quote</button>
<a target="_blank" class="twitter-share-button" href="https://twitter.com/intent/tweet?text=I%20found%20Stephen%20Peters'%20random%20code%generator:%20http:%3A%2F%2F//codepen.io/stephepush/pen/XKpxxy%2f"><button class="btn btn-default"><i class="fa fa-twitter fa-2x" aria-hidden="true"></i></button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js" integrity="sha256-xNjb53/rY+WmG+4L6tTl9m6PpqknWZvRt0rO1SRnJzw=" crossorigin="anonymous"></script>
<script type="text/javascript" src="./script.js"></script>
</body>
</html>
var quoteGen = function() {
$("#quote, #author").empty();
$.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?', function(data) {
var randomColor = Math.floor(Math.random() * 16777215).toString(16);
$("body, button").animate({
"backgroundColor": "#" + randomColor
});
$('#quote').text(data.quoteText);
$('#author').text("-" + data.quoteAuthor);
if ($('#author').text() === "-") {
$('#author').text("-" + "Unattributed");
}
var twitterLinkRoot = "https://twitter.com/intent/tweet?text="
/*this variable is the raw link from the html twitter button. Up next the parameters, in this case, the words of a generated quote, will be parsed and added in param form so that the user can tweet their favorite quotes*/
var tweetQuote = data.quoteText + " " + data.quoteAuthor;
var tweetQuote = twitterLinkRoot + tweetQuote.split(" ").join('%20');
var submitQuote = $('.twitter-share-button').attr('href', tweetQuote);
});
}; //end of "quoteGen" function
$(document).ready(function() {
quoteGen();
$('#newQuote').on("click", function() {
quoteGen();
});
});
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
body {
font-family: 'Passion One';
}
#dataDiv {
height: auto;
border-radius: 19px;
width: 100%;
margin-top: 5%;
margin-bottom: 12%;
background-color: white;
}
.btn {
height: 50px;
border-radius: 19px;
}
#quote {
font-size: 1.80em;
padding-top: 8%;
}
blockquote {
margin-left: 5%;
}
#btns {
margin-left: 60%;
margin-bottom: 5%;
}
#author {
font-size: 1.80em;
margin-bottom: 0px;
}
#buttons {}
button {
margin-top: 5%;
margin-bottom: 5%;
appearance: none;
box-shadow: none;
color: black;
text-shadow: 1px 0 0 #fff, 0 -1px 0 #fff, 0 1px 0 #fff, -1px 0 0 #fff;
}
button:focus {
outline: none
}
#newQuote {
font-size: 1.3em;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment