1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-02-14 21:10:25 +01:00

nicer config pattern for each js module

This commit is contained in:
Matthias Kretschmann 2015-12-02 00:46:25 +01:00
parent 448f96ac35
commit 8f67edf876
2 changed files with 34 additions and 31 deletions

View File

@ -1,28 +1,30 @@
var Menu = (function(w, d) { var Menu = (function(w, d) {
var thesite = $('.site'), var app, _private, _config;
thelink = $('.menu-btn'),
thepop = $('.nav-popover');
var app, _private; _config = {
thesite : $('.site'),
thelink : $('.menu-btn'),
thepop : $('.nav-popover')
};
_private = { _private = {
menuShow: function() { menuShow: function() {
thelink.on('click', function(e) { _config.thelink.on('click', function(e) {
e.preventDefault(); e.preventDefault();
// toggle menu // toggle menu
thesite.toggleClass('has-menu-open'); _config.thesite.toggleClass('has-menu-open');
// bind the hide controls // bind the hide controls
$(document).bind('click.hidethepop', function() { $(document).bind('click.hidethepop', function() {
thesite.removeClass('has-menu-open'); _config.thesite.removeClass('has-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
thepop.on('click', function(e) { _config.thepop.on('click', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });

View File

@ -3,38 +3,39 @@
var Search = (function(w, d) { var Search = (function(w, d) {
var content = $('.site__content'), var app, _private, _config;
searchlink = $('.search-btn'),
searcharea = $('.search-area'),
searchfield = $('#search-input'),
searchresults = $('#search-results'),
searchpop = $('#search-popover');
var app, _private; _config = {
content : $('.site__content'),
searchlink : $('.search-btn'),
searcharea : $('.search-area'),
searchfield : $('#search-input'),
searchresults : $('#search-results'),
searchpop : $('#search-popover'),
body : $('body')
};
_private = { _private = {
searchShow: function() { searchShow: function() {
var body = $('body'); _config.searchlink.on('click', function(e) {
searchlink.on('click', function(e) {
e.preventDefault(); e.preventDefault();
// show search field // show search field
searcharea _config.searcharea
.removeClass('is-ready animation-bounceOutUp') .removeClass('is-ready animation-bounceOutUp')
.addClass('is-ready animation-slideDown') .addClass('is-ready animation-slideDown')
.on('animationend webkitAnimationEnd oAnimationEnd', function(){ .on('animationend webkitAnimationEnd oAnimationEnd', function(){
body.addClass('has-search-open'); _config.body.addClass('has-search-open');
}); });
searchfield.focus(); _config.searchfield.focus();
_private.searchSimpleJekyllSearch(); _private.searchSimpleJekyllSearch();
// hide menu too just in case // hide menu too just in case
if (body.hasClass('has-menu-open')) { if (_config.body.hasClass('has-menu-open')) {
body.removeClass('has-menu-open'); _config.body.removeClass('has-menu-open');
} }
// bind the hide controls // bind the hide controls
@ -46,11 +47,11 @@ var Search = (function(w, d) {
}); });
// dont close thepop when click on thepop // dont close thepop when click on thepop
searchpop.on('click', function(e) { _config.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
searchfield.on('click', function(e) { _config.searchfield.on('click', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
@ -61,8 +62,8 @@ var Search = (function(w, d) {
searchResultsShow: function() { searchResultsShow: function() {
// show popup upon first keypress // show popup upon first keypress
searchfield.on('keyup', function() { _config.searchfield.on('keyup', function() {
searchpop.removeClass('hide'); _config.searchpop.removeClass('hide');
}); });
}, },
@ -83,19 +84,19 @@ var Search = (function(w, d) {
_private.searchReset(); _private.searchReset();
// empty search field // empty search field
searchfield.val('').blur(); _config.searchfield.val('').blur();
}); });
}, },
searchReset: function() { searchReset: function() {
// revert all search elements // revert all search elements
searcharea _config.searcharea
.removeClass('animation-slideDown') .removeClass('animation-slideDown')
.addClass('animation-bounceOutUp') .addClass('animation-bounceOutUp')
.on('animationend webkitAnimationEnd oAnimationEnd', function(){ .on('animationend webkitAnimationEnd oAnimationEnd', function(){
$('body').removeClass('has-search-open'); _config.body.removeClass('has-search-open');
}); });
searchpop.addClass('hide'); _config.searchpop.addClass('hide');
} }
}; };