1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-09-24 10:08:50 +02:00
blog/_src/_assets/js/app.js

158 lines
4.0 KiB
JavaScript
Raw Normal View History

$(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() {
var $searchlink = $('.search-btn'),
$searcharea = $('.topbar .search-area'),
$searchfield = $('.search-field'),
$searchresults = $('.search-results'),
$searchpop = $('.popover');
$searchlink.click(function(e) {
2015-05-29 02:39:53 +02:00
e.preventDefault()
// init jekyll search
SimpleJekyllSearch({
searchInput: $searchfield,
resultsContainer: $searchresults,
json: '/search.json',
searchResultTemplate: '<a class="search-link" href="{url}" title="{title}">{title}</a>',
fuzzy: true
})
2013-12-01 00:47:47 +01:00
// show search
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();
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() {
2014-08-10 00:26:08 +02:00
$searcharea.removeClass('slideDown');
2013-12-04 20:54:40 +01:00
$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
$('.search-close').click(function(e) {
2013-12-01 00:47:47 +01:00
e.preventDefault();
2013-12-01 00:47:47 +01:00
// hide search area
2014-08-10 00:26:08 +02:00
$searcharea.removeClass('slideDown').addClass('bounceOutUp');
2013-12-04 20:54:40 +01:00
$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');
$thelink.click(function(e) {
2013-12-01 00:47:47 +01:00
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
},
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
}