1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-29 15:42:11 +01:00
blog/_src/assets/js/app.js

249 lines
6.0 KiB
JavaScript
Raw Normal View History

2013-11-23 21:53:52 +01:00
$(ASAP = function(){
2013-11-30 17:13:19 +01:00
siteNavigation.init();
2013-12-16 01:41:20 +01:00
siteEffects.init();
infiniteScroll.init();
2013-11-23 21:53:52 +01:00
});
$(window).load( AfterLoad = function() {
photoGrid.init();
2013-11-23 21:53:52 +01:00
});
2013-11-30 17:13:19 +01:00
var siteNavigation = {
2013-11-30 17:13:19 +01:00
siteSearch: function() {
var $searchlink = $('.search-btn'),
2013-12-07 19:43:12 +01:00
$searcharea = $('.topbar .search-area'),
$searchfield = $('.search-field'),
$searchresults = $('.search-results'),
$searchpop = $('.popover');
2013-12-01 00:47:47 +01:00
$searchlink.click(function(e){
e.preventDefault();
// init jekyll search
$searchfield.jekyllSearch({
searchResults : $searchresults,
searchResultsTitle : '',
template : '<a class="nav-link" href="{url}" title="{title}">{title}</a>',
fuzzy : true
});
2013-12-01 00:47:47 +01:00
// show search
2013-12-04 20:54:40 +01:00
$searcharea.addClass('ready');
2013-12-01 00:47:47 +01:00
$searchfield.focus();
2013-12-04 20:54:40 +01:00
if ( $searchfield.val().length ) {
$searchpop.removeClass('hide');
}
2013-12-01 00:47:47 +01:00
// hide menu too just in case
if ( $('body').hasClass('menu-open') ) {
$('body').removeClass('menu-open');
2013-12-01 00:47:47 +01:00
}
2013-12-01 00:47:47 +01:00
// bind the hide controls
$(document).bind('click.hidethepop', function() {
2013-12-04 20:54:40 +01:00
$searcharea.removeClass('ready');
$searchpop.addClass('hide');
2013-12-01 00:47:47 +01:00
// unbind the hide controls
$(document).unbind('click.hidethepop');
});
2013-12-04 20:57:34 +01:00
// dont close thepop when click on thepop
2013-12-01 00:47:47 +01:00
$searchpop.click(function(e) {
e.stopPropagation();
});
2013-12-04 20:57:34 +01:00
// dont close thepop when click on search field
$searchfield.click(function(e) {
e.stopPropagation();
});
// and dont close thepop now
2013-12-01 00:47:47 +01:00
e.stopPropagation();
});
2013-12-04 20:54:40 +01:00
// finally show popup upon first keypress
$searchfield.on('keyup', function() {
$searchpop.removeClass('hide');
});
2013-12-04 20:54:40 +01:00
// close button
2013-12-01 00:47:47 +01:00
$('.search-close').click(function(e){
e.preventDefault();
2013-12-01 00:47:47 +01:00
// hide search area
2013-12-04 20:54:40 +01:00
$searcharea.removeClass('ready');
$searchpop.addClass('hide');
2013-12-01 00:47:47 +01:00
// empty search field
$searchfield.val('').blur();
});
2013-11-30 17:13:19 +01:00
},
2013-11-30 17:13:19 +01:00
siteMenu: function() {
2013-12-01 00:47:47 +01:00
var $thelink = $('.menu-btn'),
$thepop = $('.nav-main .nav-popover');
2013-12-01 00:47:47 +01:00
$thelink.click(function(e){
e.preventDefault();
2013-12-01 16:00:12 +01:00
// toggle menu
$('body').toggleClass('menu-open');
if ( $('body').hasClass('menu-open') ) {
$thepop.removeClass('hide');
} else {
$thepop.addClass('hide');
}
2013-12-01 00:47:47 +01:00
// bind the hide controls
$(document).bind('click.hidethepop', function() {
$('body').removeClass('menu-open');
$thepop.toggleClass('hide');
// unbind the hide controls
$(document).unbind('click.hidethepop');
2013-12-01 00:47:47 +01:00
});
2013-12-01 00:47:47 +01:00
// dont close thepop when you click on thepop
$thepop.click(function(e) {
e.stopPropagation();
});
// and dont close thepop now
2013-12-01 00:47:47 +01:00
e.stopPropagation();
});
2013-11-30 17:13:19 +01:00
},
2013-11-30 17:13:19 +01:00
init: function(){
this.siteSearch();
this.siteMenu();
}
}
2013-11-29 21:36:09 +01:00
var photoGrid = {
masonryLayout: function() {
var $container = $('#main .masonry');
2013-11-29 21:36:09 +01:00
$container.imagesLoaded( function(){
$container.masonry({
itemSelector : 'article',
columnWidth : '.grid-sizer'
});
});
},
init: function(){
// only fire when photo page present and screen bigger than 480px
if ( $('.page-photos').length > 0 ) {
2013-11-29 21:36:09 +01:00
this.masonryLayout();
}
}
}
2013-11-23 21:53:52 +01:00
var siteEffects = {
adaptiveBackground: function() {
var opts = {
selector: '.hmedia img',
parent: '.document'
}
$('.hmedia img').imagesLoaded( function(){
$.adaptiveBackground.run(opts)
});
2013-12-16 01:41:20 +01:00
// jump to photo background start
$(document).scrollTop($('#main').offset().top);
},
2013-11-23 21:53:52 +01:00
init: function(){
2013-12-16 01:41:20 +01:00
if ( $('.page-single .format-photo').length > 0 ) {
this.adaptiveBackground();
}
2013-11-23 21:53:52 +01:00
}
}
var infiniteScroll = {
infiniteScrollSetup: function() {
2013-12-02 22:49:21 +01:00
if ( $('.page-photos').length > 0 ) {
2013-11-23 21:53:52 +01:00
var items = '#main .masonry';
} else {
var items = '#main article.hentry';
}
var $scrollContent = $('#main');
$scrollContent.infinitescroll({
itemSelector : items,
nextSelector : '.next a',
navSelector : '.paginator',
2013-11-23 21:53:52 +01:00
binder : $scrollContent,
behavior : 'krlc3',
}, function($scrollContent) {
// run picturefill over retrieved items
picturefill();
// run the photogrid over retrieved items
2013-12-02 22:49:21 +01:00
photoGrid.init();
2013-11-23 21:53:52 +01:00
});
},
init: function(){
this.infiniteScrollSetup();
}
}
/*
--------------------------------
Infinite Scroll Behavior
Manual mode with minimal loader
Usage: behavior: 'krlc3'
--------------------------------
*/
$.extend($.infinitescroll.prototype,{
_setup_krlc3: function infscr_setup_krlc3 () {
var opts = this.options,
instance = this,
loader = $('<span class="loading"> ...</span>');
$(opts.nextSelector).parent().parent().addClass('infiniteLoader');
// Bind nextSelector link to retrieve
$(opts.nextSelector).click(function(e) {
if (e.which == 1 && !e.metaKey && !e.shiftKey) {
e.preventDefault();
instance.retrieve();
}
});
// custom start
instance.options.loading.start = function (opts) {
loader
.appendTo(opts.nextSelector)
.show(opts.loading.speed, function () {
instance.beginAjax(opts);
});
}
// custom finish
instance.options.loading.finished = function(opts) {
loader.detach();
};
}
});