Skip to content

Instantly share code, notes, and snippets.

@emygeek
Last active February 7, 2017 13:34
Show Gist options
  • Save emygeek/0ded0cfda9bd159d0f6b067498d9353e to your computer and use it in GitHub Desktop.
Save emygeek/0ded0cfda9bd159d0f6b067498d9353e to your computer and use it in GitHub Desktop.
Random QUote Generator (FCC)
<section id="home">
<div class="container">
<div class="col-md-8 col-md-offset-2">
<div class="content">
<h1> Quotes for Positivity </h1>
<div class="quote-area">
<p id="quote-title"class="quote"></p>
<span id="quote-author" class="author"></span>
</div>
<button id="get-quote" class="btn btn-light">New Quote</button>
<button id="tweet" class="btn btn-light">Tweet quote</button>
</div>
</div>
</div>
</section>

Random QUote Generator (FCC)

A random quote generator, using quotesondesign.com API. Users can tweet quotes that they like.

A Pen by Marie on CodePen.

License.

$(document).ready(function(){
$('#tweet').addClass("disabled");
//Get new quote
$('#get-quote').click(function(){
$('#tweet').removeClass("disabled");
$.ajax({
url:'http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',
success: function(data){
var quote = data.shift();
$('#quote-author').text(quote.title);
$('#quote-title').html(quote.content); //The content is retrieved with p tags
},
cache: false
});
});
//Tweet content
$('#tweet').click(function(){
var text = $("#quote-title").text() + " - by " + $("#quote-author").text();
var tweet = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(text);
window.open(tweet, '_blank');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
@import url('https://fonts.googleapis.com/css?family=Raleway');
body{
font-size: 16px;
font-family:'Raleway', sans-serif;
}
.btn-light{
border-radius: 0px;
width:250px;
background:#cdcdcd;
}
.btn-light:hover{
}
button{
margin:10px;
}
#home{
height: 100vh;
display:flex;
align-items:center;
justify-content:center;
background: #62ceaa;
}
.content{
background:rgb(63, 133, 110);
color:#fff;
box-shadow:0px 0px 5px;
padding:50px;
text-align:center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment