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: { var thesite = $('.site'),
thesite: $('.site'), thelink = $('.menu-btn'),
thelink: $('.menu-btn'), thepop = $('.nav-popover');
thepop: $('.nav-popover')
},
init: function() { var app, _private;
this.menuShow();
},
_private = {
menuShow: function() { menuShow: function() {
var s = this.settings; thelink.on('click', function(e) {
s.thelink.on('click', function(e) {
e.preventDefault(); e.preventDefault();
// toggle menu // toggle menu
s.thesite.toggleClass('menu-open'); thesite.toggleClass('menu-open');
// bind the hide controls // bind the hide controls
$(document).bind('click.hidethepop', function() { $(document).bind('click.hidethepop', function() {
s.thesite.removeClass('menu-open'); thesite.removeClass('menu-open');
// unbind the hide controls // unbind the hide controls
$(document).unbind('click.hidethepop'); $(document).unbind('click.hidethepop');
}); });
// dont close thepop when you click on thepop // dont close thepop when you click on thepop
s.thepop.on('click', function(e) { thepop.on('click', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
@ -35,4 +30,14 @@ var s, Menu = {
e.stopPropagation(); 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: { var content = $('.site__content'),
content: $('.site__content'), searchlink = $('.search-btn'),
searchlink: $('.search-btn'), searcharea = $('.search-area'),
searcharea: $('.search-area'), searchfield = $('#search-input'),
searchfield: $('#search-input'), searchresults = $('#search-results'),
searchresults: $('#search-results'), searchpop = $('#search-popover');
searchpop: $('#search-popover')
},
init: function() { var app, _private;
s = this.settings;
this.searchShow();
this.searchHide();
},
_private = {
searchShow: function() { searchShow: function() {
s.searchlink.on('click', function(e) { searchlink.on('click', function(e) {
e.preventDefault() e.preventDefault();
SimpleJekyllSearch({ SimpleJekyllSearch({
searchInput: document.getElementById('search-input'), searchInput: document.getElementById('search-input'),
@ -25,16 +20,16 @@ var s, Search = {
json: '/search.json', json: '/search.json',
searchResultTemplate: '<li class="grid__col"><a class="search-link" href="{url}">{title}</a></li>', searchResultTemplate: '<li class="grid__col"><a class="search-link" href="{url}">{title}</a></li>',
fuzzy: false fuzzy: false
}) });
// show search field // show search field
s.searcharea.removeClass('ready bounceOutUp').addClass('ready slideDown'); searcharea
s.searchfield.focus(); .removeClass('ready bounceOutUp')
.addClass('ready slideDown')
// blur the content .on('animationend webkitAnimationEnd oAnimationEnd', function(){
s.searcharea.on('animationend webkitAnimationEnd oAnimationEnd', function(){ content.addClass('search-open-blur');
s.content.addClass('search-open-blur');
}); });
searchfield.focus();
// hide menu too just in case // hide menu too just in case
if ($('body').hasClass('menu-open')) { if ($('body').hasClass('menu-open')) {
@ -42,24 +37,24 @@ var s, Search = {
} }
// show search results upon typing // show search results upon typing
if (s.searchfield.val().length) { if (searchfield.val().length) {
s.searchpop.removeClass('hide'); searchpop.removeClass('hide');
} }
// bind the hide controls // bind the hide controls
$(document).bind('click.hidethepop', function() { $(document).bind('click.hidethepop', function() {
Search.searchReset(); _private.searchReset();
// unbind the hide controls // unbind the hide controls
$(document).unbind('click.hidethepop'); $(document).unbind('click.hidethepop');
}); });
// dont close thepop when click on thepop // dont close thepop when click on thepop
s.searchpop.on('click', function(e) { searchpop.on('click', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
// dont close thepop when click on search field // dont close thepop when click on search field
s.searchfield.on('click', function(e) { searchfield.on('click', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
@ -68,8 +63,8 @@ var s, Search = {
}); });
// finally show popup upon first keypress // finally show popup upon first keypress
s.searchfield.on('keyup', function() { searchfield.on('keyup', function() {
s.searchpop.removeClass('hide'); searchpop.removeClass('hide');
}); });
}, },
@ -77,20 +72,32 @@ var s, Search = {
$('.search-close').on('click', function(e) { $('.search-close').on('click', function(e) {
e.preventDefault(); e.preventDefault();
Search.searchReset(); _private.searchReset();
// empty search field // empty search field
s.searchfield.val('').blur(); searchfield.val('').blur();
}); });
}, },
searchReset: function() { searchReset: function() {
// revert all search elements // revert all search elements
s.searcharea.removeClass('slideDown').addClass('bounceOutUp'); searcharea
s.searchpop.addClass('hide'); .removeClass('slideDown')
.addClass('bounceOutUp')
s.searcharea.on('animationend webkitAnimationEnd oAnimationEnd', function(){ .on('animationend webkitAnimationEnd oAnimationEnd', function(){
s.content.removeClass('search-open-blur'); 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 _menu.js
//=include _search.js //=include _search.js
(function() { (function($) {
// //
// init modules // init modules
@ -23,4 +23,4 @@
nosvg: false nosvg: false
}); });
}()); }(jQuery));