1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-23 18:32:49 +01:00
blog/_src/_assets/js/app.js

171 lines
4.6 KiB
JavaScript
Raw Normal View History

//=require ../../../node_modules/webcomponents.js/CustomElements.js
//=require ../../../node_modules/svg4everybody/svg4everybody.js
//=require ../../../node_modules/jquery/dist/jquery.js
//=require ../../../node_modules/masonry-layout/dist/masonry.pkgd.js
//=require ../../../node_modules/imagesloaded/imagesloaded.js
//=require ../../../bower_components/time-elements/time-elements.js
//=require ../../../bower_components/simple-jekyll-search/dest/jekyll-search.js
$(ASAP = function() {
2013-11-23 21:53:52 +01:00
2013-11-30 17:13:19 +01:00
siteNavigation.init();
2015-06-08 10:53:12 +02:00
//siteEffects.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() {
2015-08-10 00:48:31 +02:00
var $content = $('.site__content'),
2015-08-09 18:15:40 +02:00
$searchlink = $('.search-btn'),
2015-08-10 00:48:31 +02:00
$searcharea = $('.search-area'),
2015-08-09 18:15:40 +02:00
$searchfield = $('#search-input'),
$searchresults = $('#search-results'),
$searchpop = $('#search-popover');
// revert all search elements
function hideSearch() {
$searcharea.removeClass('slideDown').addClass('bounceOutUp');
$searchpop.addClass('hide');
$content.removeClass('search-open-blur');
}
$searchlink.click(function(e) {
2015-05-29 02:39:53 +02:00
e.preventDefault()
SimpleJekyllSearch({
2015-08-09 18:15:40 +02:00
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('search-results'),
json: '/search.json',
2015-08-10 00:48:31 +02:00
searchResultTemplate: '<li class="grid__col"><a class="search-link" href="{url}">{title}</a></li>',
2015-08-09 18:15:40 +02:00
fuzzy: false
})
2015-08-09 18:15:40 +02:00
// show search field
2014-08-10 00:26:08 +02:00
$searcharea.removeClass('ready bounceOutUp').addClass('ready slideDown');
2013-12-01 00:47:47 +01:00
$searchfield.focus();
2015-08-09 18:15:40 +02:00
// blur the content
$content.addClass('search-open-blur');
// show search results upon typing
if ($searchfield.val().length) {
2013-12-04 20:54:40 +01:00
$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() {
2015-08-09 18:15:40 +02:00
hideSearch();
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
$('.search-close').click(function(e) {
2013-12-01 00:47:47 +01:00
e.preventDefault();
2015-08-09 18:15:40 +02:00
hideSearch();
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() {
var $thesite = $('.site'),
$thelink = $('.menu-btn'),
2015-08-09 21:50:06 +02:00
$thepop = $('.nav-popover');
$thelink.click(function(e) {
2013-12-01 00:47:47 +01:00
e.preventDefault();
2013-12-01 16:00:12 +01:00
// toggle menu
$thesite.toggleClass('menu-open');
2013-12-01 00:47:47 +01:00
// bind the hide controls
$(document).bind('click.hidethepop', function() {
$thesite.removeClass('menu-open');
// 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
},
init: function() {
this.siteSearch();
2013-11-30 17:13:19 +01:00
this.siteMenu();
}
2013-11-30 17:13:19 +01:00
}
2013-11-29 21:36:09 +01:00
var photoGrid = {
masonryLayout: function() {
var $container = $('#main .masonry');
$container.imagesLoaded(function() {
2013-11-29 21:36:09 +01:00
$container.masonry({
itemSelector: 'article',
columnWidth: '.grid-sizer'
2013-11-29 21:36:09 +01:00
});
});
},
init: function() {
2013-11-29 21:36:09 +01:00
// 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 = {
init: function() {
2015-05-29 02:39:53 +02:00
}
2013-11-23 21:53:52 +01:00
}