JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div id="wrapper">
<div class="container">
<div class="row">
<div id="quote" class="col-12 fade">
</div>
</div>
<div class="row u-cntr">
<div class="col-4">
<a id="twitter" href="#" target="_blank"><i class="icon fab fa-twitter-square"></i></a>
</div>
<div class="col-4"></div>
<div class="col-4">
<button id="getQuote" class="btn">Next Quote</button>
</div>
</div>
</div>
</div>
$white: #FAFAFA
$gray: #333333
// Text Colors
$orange: #FF7C19
$purple: darken(purple, 5%)
$light-purple: #6d00d2
$blue: #276689
$green: darken(green, 5%)
body
background-color: transparent
padding: 150px 0
a
color: $gray
html
height: 100%
transition: all .5s ease
&.style1
background: radial-gradient(farthest-corner at bottom 250px left, #9500cc 0%, #0076cc 200%)
blockquote, svg
color: $purple
button
color: $purple
border-color: $purple
&:hover
background-color: $purple
color: $white
&.style2
background: radial-gradient(farthest-corner at bottom 250px left, #2b802b 0%, #32836f 100%)
blockquote, svg
color: $green
button
color: $green
border-color: $green
&:hover
background-color: $green
color: $white
&.style3
background: radial-gradient(farthest-corner at bottom 250px left, red 0%, orange 75%, yellow 100%)
blockquote, svg
color: $orange
button
color: $orange
border-color: $orange
&:hover
background-color: $orange
color: $white
&.style4
background: radial-gradient(farthest-corner at bottom 250px left, #276689 0%, #2eb4d8 100%)
blockquote, svg
color: $blue
button
color: $blue
border-color: $blue
&:hover
background-color: $blue
color: $white
&.style5
background: radial-gradient(farthest-corner at bottom 250px left, #c300ff 0%, #6d00d2 100%)
blockquote, svg
color: $light-purple
button
color: $light-purple
border-color: $light-purple
&:hover
background-color: $light-purple
color: $white
#wrapper
display: block
position: relative
width: 100%
.container
max-width: 650px
border-radius: 2px
background-color: $white
color: $gray
box-shadow: 2px 2px 3px 1px rgba(0,0,0,.35)
@media screen and (max-width: 760px)
.container
max-width: none
width: 95%
.icon, .btn
transition: all .25s ease
.icon
font-size: 4.5rem
margin-top: 20px
cursor: pointer
margin: 0 10px
.btn
font-family: 'Open Sans', sans-serif
font-size: 1.7rem
margin-top: 3px
margin-bottom: 25px
padding: 8px 12px
outline: none
border: 1px solid $gray
border-radius: 2px
background-color: $white
color: $gray
cursor: pointer
transition: all .25s ease
&:hover
color: $white
background-color: $gray
#quote
opacity: 1
transition: all 1s ease
&.fade
transition: all .5s ease
opacity: 0
blockquote
font-size: 2.2rem
svg
margin-right: 25px
p
display: inline
cite
display: block
margin-left: 35px
margin-top: 15px
'use strict';
// https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1
/*
tweet url: https://twitter.com/intent/tweet?hashtags=quotes&related=brycejech%2Ccreator&text=THE_TEXT;
*/
(function(){
const twitter = document.getElementById('twitter'),
quote = document.getElementById('quote');
const styles = [1,2,3,4,5];
function loadQuote(){
const opts = {
url: 'https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&t=' + Date.now(),
method: 'GET',
dataType: 'json',
success: function(data){
const obj = data[0],
html = '<blockquote><i class="fas fa-quote-left"></i>' + obj.content + '<cite>- ' + obj.title + '</cite></blockquote>';
twitter.href = getTweetURL({author: obj.title, quote: obj.content});
quote.innerHTML = html;
quote.classList.remove('fade');
applyRandomStyle();
},
error: function(xhr, status, err){
console.log(xhr);
console.log(status);
console.log(err);
}
}
document.getElementById('quote').classList.add('fade');
ajax(opts);
}
function applyRandomStyle(){
const el = document.getElementsByTagName('html')[0],
curStyle = getCurrentStyle();
let className;
// don't duplicate current style
while((className = getRandomStyle()) == curStyle){
className = getRandomStyle();
}
el.classList.remove(curStyle);
el.classList.add(className);
}
function getCurrentStyle(){
let elem = document.getElementsByTagName('html')[0];
for(let i = 0; i < elem.classList.length; i++){
if(/style\d/.test(elem.classList[i])) return elem.classList[i];
}
return undefined;
}
function getRandomStyle(){
return 'style' + styles[Math.floor(Math.random() * styles.length)]
}
function getTweetURL(obj){
let quote = obj.quote
.replace(/<.*?>/gi, '') // strip html
// common html entities
.replace(/’/gi, "'")
.replace(/–/gi, "-")
.replace(/(”)|(“)/gi, "'")
// trailing whitespace
.trim(),
author = obj.author;
return `https://twitter.com/intent/tweet?hashtags=quotes&related=brycejech%2Ccreator&text="${quote}"%0A-%20${author}%0A`;
}
/*
CONTROL FLOW
*/
loadQuote();
document.getElementById('getQuote').addEventListener('click', function(){
loadQuote();
});
})();
Also see: Tab Triggers