1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-09-24 01:58:50 +02:00

more js modularization

This commit is contained in:
Matthias Kretschmann 2015-11-19 16:52:44 +01:00
parent 6fed71618a
commit 60dd4498aa
3 changed files with 119 additions and 107 deletions

View File

@ -1,33 +1,28 @@
var s, Menu = {
var Menu = (function(w, d) {
settings: {
thesite: $('.site'),
thelink: $('.menu-btn'),
thepop: $('.nav-popover')
},
var thesite = $('.site'),
thelink = $('.menu-btn'),
thepop = $('.nav-popover');
init: function() {
this.menuShow();
},
var app, _private;
_private = {
menuShow: function() {
var s = this.settings;
s.thelink.on('click', function(e) {
thelink.on('click', function(e) {
e.preventDefault();
// toggle menu
s.thesite.toggleClass('menu-open');
thesite.toggleClass('menu-open');
// bind the hide controls
$(document).bind('click.hidethepop', function() {
s.thesite.removeClass('menu-open');
thesite.removeClass('menu-open');
// unbind the hide controls
$(document).unbind('click.hidethepop');
});
// dont close thepop when you click on thepop
s.thepop.on('click', function(e) {
thepop.on('click', function(e) {
e.stopPropagation();
});
@ -35,4 +30,14 @@ var s, Menu = {
e.stopPropagation();
});
}
};
};
app = {
init: function() {
_private.menuShow();
}
};
return app;
})(window, document);

View File

@ -1,23 +1,18 @@
var s, Search = {
var Search = (function(w, d) {
settings: {
content: $('.site__content'),
searchlink: $('.search-btn'),
searcharea: $('.search-area'),
searchfield: $('#search-input'),
searchresults: $('#search-results'),
searchpop: $('#search-popover')
},
var content = $('.site__content'),
searchlink = $('.search-btn'),
searcharea = $('.search-area'),
searchfield = $('#search-input'),
searchresults = $('#search-results'),
searchpop = $('#search-popover');
init: function() {
s = this.settings;
this.searchShow();
this.searchHide();
},
var app, _private;
_private = {
searchShow: function() {
s.searchlink.on('click', function(e) {
e.preventDefault()
searchlink.on('click', function(e) {
e.preventDefault();
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
@ -25,16 +20,16 @@ var s, Search = {
json: '/search.json',
searchResultTemplate: '<li class="grid__col"><a class="search-link" href="{url}">{title}</a></li>',
fuzzy: false
})
});
// show search field
s.searcharea.removeClass('ready bounceOutUp').addClass('ready slideDown');
s.searchfield.focus();
// blur the content
s.searcharea.on('animationend webkitAnimationEnd oAnimationEnd', function(){
s.content.addClass('search-open-blur');
searcharea
.removeClass('ready bounceOutUp')
.addClass('ready slideDown')
.on('animationend webkitAnimationEnd oAnimationEnd', function(){
content.addClass('search-open-blur');
});
searchfield.focus();
// hide menu too just in case
if ($('body').hasClass('menu-open')) {
@ -42,24 +37,24 @@ var s, Search = {
}
// show search results upon typing
if (s.searchfield.val().length) {
s.searchpop.removeClass('hide');
if (searchfield.val().length) {
searchpop.removeClass('hide');
}
// bind the hide controls
$(document).bind('click.hidethepop', function() {
Search.searchReset();
_private.searchReset();
// unbind the hide controls
$(document).unbind('click.hidethepop');
});
// dont close thepop when click on thepop
s.searchpop.on('click', function(e) {
searchpop.on('click', function(e) {
e.stopPropagation();
});
// dont close thepop when click on search field
s.searchfield.on('click', function(e) {
searchfield.on('click', function(e) {
e.stopPropagation();
});
@ -68,8 +63,8 @@ var s, Search = {
});
// finally show popup upon first keypress
s.searchfield.on('keyup', function() {
s.searchpop.removeClass('hide');
searchfield.on('keyup', function() {
searchpop.removeClass('hide');
});
},
@ -77,20 +72,32 @@ var s, Search = {
$('.search-close').on('click', function(e) {
e.preventDefault();
Search.searchReset();
_private.searchReset();
// empty search field
s.searchfield.val('').blur();
searchfield.val('').blur();
});
},
searchReset: function() {
// revert all search elements
s.searcharea.removeClass('slideDown').addClass('bounceOutUp');
s.searchpop.addClass('hide');
s.searcharea.on('animationend webkitAnimationEnd oAnimationEnd', function(){
s.content.removeClass('search-open-blur');
searcharea
.removeClass('slideDown')
.addClass('bounceOutUp')
.on('animationend webkitAnimationEnd oAnimationEnd', function(){
content.removeClass('search-open-blur');
});
searchpop.addClass('hide');
}
};
};
app = {
init: function() {
_private.searchShow();
_private.searchHide();
}
};
return app;
})(document, window);

View File

@ -11,7 +11,7 @@
//=include _menu.js
//=include _search.js
(function() {
(function($) {
//
// init modules
@ -23,4 +23,4 @@
nosvg: false
});
}());
}(jQuery));