Skip to content

Instantly share code, notes, and snippets.

@CatherineDesigner
Last active January 29, 2019 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CatherineDesigner/3e41a6a3451285bb46c7d7799c421964 to your computer and use it in GitHub Desktop.
Save CatherineDesigner/3e41a6a3451285bb46c7d7799c421964 to your computer and use it in GitHub Desktop.
Random Quote Generator
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Случайная цитата</title>
<link rel="stylesheet" href="style.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Random Quote Generator</h1>
<div class="quote-box">
<div class="quote-text">
<i class="fa fa-quote-left"> </i><span id="text"></span>
<!-- цитата-->
</div>
<div class="quote-author">
- <span id="author"></span>
</div>
<div class="buttons">
<a class="button" id="tweet-quote" title="Tweet this quote!" target="_blank">
<i class="fa fa-twitter"></i>
</a>
<a class="button" id="tumblr-quote" title="Post this quote on tumblr!" target="_blank">
<i class="fa fa-tumblr"></i>
</a>
<button class="button" id="new-quote">New quote</button>
</div>
</div>
<div class="footer"> by <a href="https://codepen.io/catherinedesigner/">FCatherine</a>
</div>
</body>
</html>
function inIframe () { try { return window.self !== window.top; } catch (e) { return true; } }
var colors = ['#16a085', '#27ae60', '#2c3e50', '#f39c12', '#e74c3c', '#9b59b6', '#FB6964', '#342224', "#472E32", "#BDBB99", "#77B1A9", "#73A857"];
var currentQuote = '', currentAuthor = '';
function openURL(url){
window.open(url, 'Share', 'width=550, height=400, toolbar=0, scrollbars=1 ,location=0 ,statusbar=0,menubar=0, resizable=0');
}
function getQuote() {
$.ajax({
headers: {
"X-Mashape-Key": "OivH71yd3tmshl9YKzFH7BTzBVRQp1RaKLajsnafgL2aPsfP9V",
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
url: 'https://andruxnet-random-famous-quotes.p.mashape.com/cat=',
success: function(r) {
if (typeof r === 'string') {
r = JSON.parse(r);
}
if (Array.isArray(r)) {
r = r[0];
}
currentQuote = r.quote;
currentAuthor = r.author;
if(inIframe())
{
$('#tweet-quote').attr('href', 'https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + encodeURIComponent('"' + currentQuote + '" ' + currentAuthor));
$('#tumblr-quote').attr('href', 'https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes,freecodecamp&caption='+encodeURIComponent(currentAuthor)+'&content=' + encodeURIComponent(currentQuote)+'&canonicalUrl=https%3A%2F%2Fwww.tumblr.com%2Fbuttons&shareSource=tumblr_share_button');
}
$(".quote-text").animate({
opacity: 0
}, 500,
function() {
$(this).animate({
opacity: 1
}, 500);
$('#text').text(r.quote);
});
$(".quote-author").animate({
opacity: 0
}, 500,
function() {
$(this).animate({
opacity: 1
}, 500);
$('#author').html(r.author);
});
var color = Math.floor(Math.random() * colors.length);
$("html body").animate({
backgroundColor: colors[color],
color: colors[color]
}, 1000);
$(".button").animate({
backgroundColor: colors[color]
}, 1000);
}
});
}
$(document).ready(function() {
getQuote();
$('#new-quote').on('click', getQuote);
$('#tweet-quote').on('click', function() {
if(!inIframe()) {
openURL('https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + encodeURIComponent('"' + currentQuote + '" ' + currentAuthor));
}
});
$('#tumblr-quote').on('click', function() {
if(!inIframe()) {
openURL('https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes,freecodecamp&caption='+encodeURIComponent(currentAuthor)+'&content=' + encodeURIComponent(currentQuote)+'&canonicalUrl=https%3A%2F%2Fwww.tumblr.com%2Fbuttons&shareSource=tumblr_share_button');
}
});
});
html,body {
background-color: coral;
color: darkgrey;
font-size: 35px;
}
h1 {
text-align:center;
color: gold;
margin-bottom: auto;
}
a {
text-decoration:none;
color: gold;
}
.quote-box {
border-radius:3px;
position:relative;
margin:8% auto auto auto;
width:450px;
padding:40px 50px;
display:table;
background-color:#fff;
}
.quote-text {
color: black;
}
.i {
font-size:1.0em;
margin-right: 0.4em;
text-align:center;
width:450px;
height:auto;
clear:both;
font-weight:500;
font-size:1.75em;
}
.quote-author {
width:450px;
height:auto;
clear:both;
padding-top:20px;
font-size:1em;
text-align:right;
}
.button {
height:38px;
border:none;
border-radius:3px;
color:#fff;
background-color: black;
outline:none;
font-size:0.85em;
padding: 8px 18px 6px 18px;
margin-top:30px;
opacity:1;
cursor:pointer;
}
:hover {
opacity:0.9;
}
#tweet-quote, #tumblr-quote {
float:left;
padding:0px;
padding-top:8px;
margin-right:5px;
height:30px;
width:40px;
}
#new-quote {
float:right;
padding: auto;
font-size: 20px;
}
.footer {
text-align:center;
display:block;
margin:15px auto 30px auto;
font-size:0.5em;
color:gold;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment