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.
<header class="site-header">
<div class="site-title">
A Serverless Blog
</div>
<div class="site-subtitle">
All the code that powers this blog is right here.
</div>
</header>
<main class="site-wrap">
<div id="articles-list">
<div class="articles-container" />
</div>
<article id="article-whole" class="article-whole start-hidden" >
<div></div>
</article>
</main>
* {
box-sizing: border-box;
}
.site-header {
border-top: 1rem solid #556CF6;
background: #26232d;
padding: 2rem;
position: relative;
}
.site-title {
font-size: 2rem;
letter-spacing: 3px;
}
.site-subtitle {
font-style: italic;
opacity: 0.5;
}
.sign-in-button {
position: absolute;
top: 1rem;
right: 1rem;
}
.site-wrap {
padding: 2rem;
}
.article-block {
max-width: 650px;
margin: 0 auto 2rem;
background: #403E4F;
padding: 2rem;
box-shadow: 0.25rem 0.25rem 1.3rem rgba(0, 0, 0, 0.33);
}
time {
display: block;
padding: 0.25rem 0.75rem;
text-transform: uppercase;
letter-spacing: 0.25rem;
background: linear-gradient(
to right,
#4a4c5a,
#403E4D
);
font-size: 0.75rem;
}
.article-body {
color: #9e9fa8;
}
.article-whole {
max-width: 850px;
margin: 0 auto;
}
body {
margin: 0;
background: #323041;
color: white;
font-family: 'PT Serif', serif;
line-height: 1.4;
}
h1, h2, h3, h4, h5, h6,
.site-title {
font-family: 'Barlow Semi Condensed', sans-serif;
text-transform: uppercase;
}
h1, h2, h3, h4, h5, h6 {
margin: 0 0 1rem 0;
letter-spacing: 0.1rem;
line-height: 1;
}
h1 {
font-size: 3.0rem;
letter-spacing: 0.1rem;
}
a {
color: #8b9bff;
font-weight: bold;
border-bottom: 1px solid;
text-decoration: none;
padding: 0.25rem 0.5rem;
}
a svg {
fill: currentcolor;
vertical-align: bottom;
}
a:hover,
a:focus {
background: rgba(0, 0, 0, 0.33);
}
.start-hidden {
display: none;
}
var blog_api_url = 'https://us-central1-duncan-131.cloudfunctions.net/posts';
var posts_list = document.getElementById('articles-list');
var post_full = document.getElementById('article-whole');
var posts_container = posts_list.querySelector('.articles-container');
var loadJsonFromFirebase = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function () {
callback(JSON.parse(this.response));
});
xhr.open("GET", url);
xhr.send();
};
var getQueryParam = function(param) {
let params = window.location.search.substr(1);
params = params.split("&");
let paramList = {};
for (let i = 0; i < params.length; i++) {
let tmp = params[i].split("=");
paramList[tmp[0]] = decodeURI(tmp[1]);
}
return paramList[param];
}
// hide the individual post and show the list of posts
const showListClick = (e) => {
// hide the single post
post_full.classList.add('start-hidden');
// show the full list
posts_container.classList.remove('start-hidden');
}
// handle selecting the links in the list
const showPostClick = (e) => {
let post_id = e.target.dataset.post;
if (post_id) {
// load the post from ajax call
loadJsonFromFirebase(blog_api_url + '/' + post_id, function(data) {
let ts = new Date(data.created);
let div = document.createElement('div');
div.innerHTML = `
<h1>${data.title}</h1>
<time>${ts.toDateString()}</time>
<div class="article-body">
<p>${data.content}</p>
</div>
`;
post_full.replaceChild(div, post_full.firstChild);
// hide the full list
posts_container.classList.add('start-hidden');
// show the single post
post_full.classList.remove('start-hidden');
});
}
};
//document.getElementById('post-view-all').addEventListener('click', showListClick);
posts_list.addEventListener('click', showPostClick);
loadJsonFromFirebase(blog_api_url, function(data) {
let list = document.createElement('div');
Object.keys(data).forEach(function(key) {
let ts = new Date(data[key].created);
list.innerHTML += `<article class="article-block">
<h2>${data[key].title}</h2>
<time>${ts.toDateString()}</time>
<div class="excerpt">
<p>${data[key].content.substr(0, 150)}...</p>
</div>
<a data-post="${key}">Read Post</a>
</article>`;
});
posts_container.insertBefore(list, posts_container.firstChild);
});
Also see: Tab Triggers