1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-23 02:10:01 +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 thesite = $('.site'),
thelink = $('.menu-btn'),
thepop = $('.nav-popover');
var app, _private, _config;
var app, _private;
_config = {
thesite : $('.site'),
thelink : $('.menu-btn'),
thepop : $('.nav-popover')
};
_private = {
menuShow: function() {
thelink.on('click', function(e) {
_config.thelink.on('click', function(e) {
e.preventDefault();
// toggle menu
thesite.toggleClass('has-menu-open');
_config.thesite.toggleClass('has-menu-open');
// bind the hide controls
$(document).bind('click.hidethepop', function() {
thesite.removeClass('has-menu-open');
_config.thesite.removeClass('has-menu-open');
// unbind the hide controls
$(document).unbind('click.hidethepop');
});
// dont close thepop when you click on thepop
thepop.on('click', function(e) {
_config.thepop.on('click', function(e) {
e.stopPropagation();
});

View File

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