Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
Added dependency-loading for scripts & changed how to style images.
Browse files Browse the repository at this point in the history
- JavaScript now only loads when needed
- Featured images now load using the {{image}} helper.
- Tag pages now show the blog cover image
- Images now use #fragments instead of classes. Enabling styling using markdown.
  • Loading branch information
Gustav Lindqvist committed Sep 26, 2014
1 parent 90ba513 commit 3c4a718
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 59 deletions.
2 changes: 1 addition & 1 deletion assets/css/style.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/js/helper/gallery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
88 changes: 52 additions & 36 deletions assets/js/scripts.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
/* global hljs, $, console */
/* jshint browser: true */
hljs.initHighlightingOnLoad();

$("#main").fitVids();

function featuredImage() {
if($('#featured').length){
$('#header').css('background-image','url('+$('#featured').attr('src')+')');
}
/*******************
* HIGHLIGHT CODE *
*******************/
if($("code").length != 0){
$.getScript("/assets/js/helper/highlight.min.js", function() {
hljs.initHighlightingOnLoad();
});
}

/**********************
* RESPONSIVE VIDEOS *
**********************/

function fullImage(){
$(".full").each(function() {
$(this).addClass("full-loaded");
$(this).closest("p").css("min-height",$(this).height());
$(this).closest("p").addClass("full-image-container");
});
}
$.getScript("/assets/js/helper/jquery.fitvids.js", function() {
$("#main").fitVids();
});

$(".gallery").imagesLoaded(gallery);
$(window).resize(gallery);
/************
* GALLERY *
************/

if($(".gallery").length != 0){ // If there is a gallery present.
$.getScript("/assets/js/helper/imagesloaded.pkgd.min.js", function() {
$(".gallery").imagesLoaded(gallery);
$(window).resize(gallery);
});
}

function gallery(){
var size = 0;
if ($(window).height() > $(window).width()){
size = $(window).height();
} else {
size = $(window).width();
}
if (size < 210 ){
size = 210;
}
$('.gallery').removeWhitespace().collagePlus(
{
'targetHeight':size/5
$.getScript("/assets/js/helper/gallery.min.js", function() { // Load in script for gallery
var size = 0;
if ($(window).height() > $(window).width()){
size = $(window).height();
} else {
size = $(window).width();
}
);
if (size < 210 ){
size = 210;
}
$('.gallery').removeWhitespace().collagePlus(
{
'targetHeight':size/5
}
);
});
}

var timesince=function(t){var n={prefix:"",future:"",suffix:" sedan",seconds:"Några sekunder",minute:"En minut",minutes:"%d minuter",hour:"Mindre än en timme",hours:"%d timmar",day:"En dag",days:"%d dagar",month:"En månad",months:"%d månader",year:"Ungefär ett år",years:"%d år"};var r=function(e,t){return n[e]&&n[e].replace(/%d/i,Math.abs(Math.round(t)))};var i=function(e){if(!e)return;e=parseInt(e)*1e3;e=new Date(e);var t=new Date;var i=(t.getTime()-e)*.001>>0;var s=i/60;var o=s/60;var u=o/24;var a=u/365;return n.prefix+(i<0&&r("future")||i<45&&r("seconds",i)||i<90&&r("minute",1)||s<45&&r("minutes",s)||s<90&&r("hour",1)||o<24&&r("hours",o)||o<42&&r("day",1)||u<30&&r("days",u)||u<45&&r("month",1)||u<365&&r("months",u/30)||a<1.5&&r("year",1)||r("years",a))+(i<0&&""||n.suffix)};var s=document.getElementsByClassName("timesince");for(var o in s){var u=s[o];if(typeof u==="object"){u.innerHTML=i(u.dataset.timesince||u.dataset.timesince)}}setTimeout(timesince,6e4)}


$(window).load(timesince);
$("#main").imagesLoaded(fullImage);
$("#main").imagesLoaded(featuredImage);
$(window).resize(fullImage);
/**********************
* FULL WIDTH IMAGES *
**********************/

$.getScript("/assets/js/helper/imagesloaded.pkgd.min.js", function() {
function fullImage(){
$('img[src$="#full"]').each(function() {
$(this).addClass("full-loaded");
$(this).closest("p").css("min-height",$(this).height());
$(this).closest("p").addClass("full-image-container");
});
}
$("#main").imagesLoaded(fullImage);
$(window).resize(fullImage);
});
7 changes: 1 addition & 6 deletions default.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
{{> footer}}
</footer>
{{ghost_foot}}
<script type="text/javascript" src="{{asset 'js/jquery.collagePlus.min.js'}}"></script>
<script type="text/javascript" src="{{asset 'js/jquery.removeWhitespace.min.js'}}"></script>
<script type="text/javascript" src="{{asset 'js/imagesloaded.pkgd.min.js'}}"></script>
<script type="text/javascript" src="{{asset 'js/highlight.min.js'}}"></script>
<script type="text/javascript" src="{{asset 'js/jquery.fitvids.js'}}"></script>
<script type="text/javascript" src="{{asset 'js/scripts.js'}}"></script>
<script src="{{asset 'js/scripts.js'}}"></script>
{{> tracking}}
</body>
</html>
4 changes: 2 additions & 2 deletions page.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{!< default}}
{{#post ~}}
<header id="header" class="animated fadeIn">
<header id="header" class="animated fadeIn"{{#if image}} style="background-image: url({{image}})"{{/if}}>
<div class="header-background">
<section class="blog-content">
<a itemprop="name url" class="blog-title" href="{{@blog.url}}">{{@blog.title}}</a>
Expand All @@ -16,7 +16,7 @@
<article itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting" class="animated fadeIn content post {{post_class}}">
<header class="post-meta">
<span itemprop="name headline">{{{title}}}</span>
<time class="timesince date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='D MMM YYYY'}}" data-timesince="{{date format='X'}}">{{date format='D MMM YYYY'}}</time>
<time class="date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='D MMM YYYY'}}">{{date published_at timeago='true'}}</time>
<span itemprop="keywords" class="tags">{{tags prefix="on " separator=", "}}</span>
</header>
<section class="post-content" itemprop="articleBody text">
Expand Down
2 changes: 1 addition & 1 deletion partials/loop.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<span class="post-data"><time class="timesince date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='D MMM YYYY'}}" data-timesince="{{date format='X'}}">{{date format='D MMMM YYYY'}}</time> <span class="tags">{{tags prefix="in " separator=", "}}</span></span>
<span class="side-meta">
<span class="date"><strong>Published</strong>
<time class="timesince date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='D MMMM YYYY'}}" data-timesince="{{date format='X'}}">{{date format='D MMM YYYY'}}</time></span>
<time class="date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='D MMMM YYYY'}}">{{date published_at timeago='true'}}</time></span>
<span class="tags">
<strong>Tags</strong>
<span itemprop="keywords">
Expand Down
7 changes: 4 additions & 3 deletions post.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{!< default}}
{{#post ~}}
<header id="header" class="animated fadeIn">
<header id="header" class="animated fadeIn"{{#if image}} style="background-image: url({{image}})"{{/if}}>
<div class="header-background">
<section class="blog-content">
<a itemprop="name url" class="blog-title" href="{{@blog.url}}">{{@blog.title}}</a>
Expand All @@ -9,15 +9,16 @@
</section>
<section class="header-content">
<h1 class="post-title animated fadeInUp">{{{title}}}</h1>
<span class="post-data animated fadeInUp"><time class="timesince date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='D MMM YYYY'}}" data-timesince="{{date format='X'}}">{{date format='D MMM YYYY'}}</time> <span class="tags">{{tags prefix="i " separator=", "}}</span></span>

<span class="post-data animated fadeInUp"><time class="date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='D MMM YYYY'}}">{{date published_at timeago='true'}}</time> <span class="tags">{{tags prefix="on " separator=", "}}</span></span>
</section>
</div>
</header>
<main id="main">
<article itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting" class="animated fadeIn content post {{post_class}}">
<header class="post-meta">
<span itemprop="name headline">{{{title}}}</span>
<time class="timesince date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='DD MMMM YYYY'}}" data-timesince="{{date format='X'}}">{{date format='DD MMMM YYYY'}}</time>
<time class="date" datetime="{{date format='YYYY-MM-DDTHH:mm'}}" title="{{date format='DD MMMM YYYY'}}">{{date published_at timeago='true'}}</time>
<span itemprop="keywords" class="tags">{{tags prefix="on " separator=", "}}</span>
</header>
<section class="post-content" itemprop="articleBody text">
Expand Down
44 changes: 35 additions & 9 deletions sass/formatting.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ ul, ol {

ul {
list-style: square inside;
ul, ol {
margin-top: 10px;
margin-left: 20px
}
}

ol {
list-style: decimal inside;
ul, ol {
margin-top: 10px;
margin-left: 20px
}
}

em {
Expand Down Expand Up @@ -102,15 +110,19 @@ img {
max-width: 100%;
max-width: calc(100% + 40px);
margin-left: auto;
margin-left: calc(0% - 20px);
&.small {
margin-left: calc(0% - 20px);
&[src$="#small"] {
max-width: 100%;
width: auto;
margin: {
left: auto;
right: auto;
}
}
&[src$="#large"] {
max-width: calc(100% + 40px);
margin-left: calc(0% - 20px);
}
&:not(.full-loaded){
@include transition(all 0.2s);
}
Expand Down Expand Up @@ -177,11 +189,18 @@ pre {
@include font-size(60);
}
img {
max-width: 120%;
width: 120%;
margin-left: -10%;
max-width: 110%;
width: 110%;
margin-left: -5%;
margin-top: 40px;
margin-bottom: 40px;
&[src$="#large"] {
max-width: 120%;
width: 120%;
margin-left: -10%;
margin-top: 40px;
margin-bottom: 40px;
}
}
.full-image-container {
margin: 80px 0;
Expand All @@ -204,11 +223,18 @@ pre {

@media screen and (min-width: $desktop-width) {
img {
max-width: 200%;
width: 200%;
margin-left: -50%;
max-width: 150%;
width: 150%;
margin-left: -25%;
margin-top: 40px;
margin-bottom: 80px;
margin-bottom: 40px;
&[src$="#large"]{
max-width: 200%;
width: 200%;
margin-left: -50%;
margin-top: 40px;
margin-bottom: 80px;
}
}
.wide {
max-width: 200%;
Expand Down
2 changes: 1 addition & 1 deletion tag.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{!< default}}
<header id="header" class="animated fadeIn">
<header id="header" class="animated fadeIn"{{#if @blog.cover}} style="background-image: url({{@blog.cover}})"{{/if}}>
<div class="header-background">
<section class="blog-content">
<a itemprop="name url" class="blog-title" href="/">{{@blog.title}}</a>
Expand Down

0 comments on commit 3c4a718

Please sign in to comment.