Skip to content

Instantly share code, notes, and snippets.

@excalliburbd
Created October 13, 2016 11:38
Show Gist options
  • Select an option

  • Save excalliburbd/d21616e31769de580c35a4591c1ee684 to your computer and use it in GitHub Desktop.

Select an option

Save excalliburbd/d21616e31769de580c35a4591c1ee684 to your computer and use it in GitHub Desktop.
Random Quote Machine -- FCC Zipline
<div class="container">
<div class="jumbotron">
<h1 class="display-3">Random Quotes!</h1>
<div class="card card-inverse card-info text-xs-center">
<div class="card-block">
<blockquote class="blockquote blockquote-reverse">
<p class="m-b-0">Loading...</p>
<footer class="blockquote-footer"><cite title="Source Title"></cite></footer>
</blockquote>
</div>
</div>
<hr class="m-y-2">
<a class="btn btn-primary btn-lg" role="button">More</a>
<a class="btn btn-info btn-lg" rol"button">Tweet</a>
</div>
</div>
$(document).ready(function() {
var quoteNode = $('p');
var authorNode = $('cite');
var buttons = $('a');
quoteGen(quoteNode, authorNode);
buttons.first().click(function() {
history.go(0);
})
buttons.last().click(function() {
if (quoteNode.text().length > 140) {
var limit = quoteNode.text().slice(0, 136) + "...";
}
var tweet = limit || quoteNode.text();
window.open("https://twitter.com/intent/tweet?text=" + encodeURIComponent(tweet));
})
});
var quoteGen = function(quote, author) {
var url = "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback="
$.getJSON(url, function(data) {
quote.html(data[0].content);
author.text(data[0].title);
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
.blockquote{
border-right: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment