2015-12-02 00:19:46 +01:00
|
|
|
|
2016-04-16 16:17:14 +02:00
|
|
|
//=require ../../../node_modules/simple-jekyll-search/dest/jekyll-search.js
|
2015-12-02 00:19:46 +01:00
|
|
|
|
2015-11-19 16:52:44 +01:00
|
|
|
var Search = (function(w, d) {
|
|
|
|
|
2015-12-02 00:46:25 +01:00
|
|
|
var app, _private, _config;
|
|
|
|
|
|
|
|
_config = {
|
|
|
|
content : $('.site__content'),
|
|
|
|
searchlink : $('.search-btn'),
|
|
|
|
searcharea : $('.search-area'),
|
|
|
|
searchfield : $('#search-input'),
|
|
|
|
searchresults : $('#search-results'),
|
|
|
|
searchpop : $('#search-popover'),
|
|
|
|
body : $('body')
|
|
|
|
};
|
2015-11-19 16:52:44 +01:00
|
|
|
|
|
|
|
_private = {
|
|
|
|
searchShow: function() {
|
2015-11-20 22:30:58 +01:00
|
|
|
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searchlink.on('click', function(e) {
|
2015-11-19 16:52:44 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// show search field
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searcharea
|
2015-11-28 01:19:31 +01:00
|
|
|
.removeClass('is-ready animation-bounceOutUp')
|
|
|
|
.addClass('is-ready animation-slideDown')
|
2015-11-19 16:52:44 +01:00
|
|
|
.on('animationend webkitAnimationEnd oAnimationEnd', function(){
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.body.addClass('has-search-open');
|
2015-11-19 16:52:44 +01:00
|
|
|
});
|
2015-11-20 22:30:58 +01:00
|
|
|
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searchfield.focus();
|
2015-11-19 16:52:44 +01:00
|
|
|
|
2015-11-20 22:30:58 +01:00
|
|
|
_private.searchSimpleJekyllSearch();
|
2015-11-19 16:52:44 +01:00
|
|
|
|
2015-11-20 22:30:58 +01:00
|
|
|
// hide menu too just in case
|
2015-12-02 00:46:25 +01:00
|
|
|
if (_config.body.hasClass('has-menu-open')) {
|
|
|
|
_config.body.removeClass('has-menu-open');
|
2015-11-19 16:52:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// bind the hide controls
|
|
|
|
$(document).bind('click.hidethepop', function() {
|
|
|
|
_private.searchReset();
|
|
|
|
|
|
|
|
// unbind the hide controls
|
|
|
|
$(document).unbind('click.hidethepop');
|
|
|
|
});
|
|
|
|
|
|
|
|
// dont close thepop when click on thepop
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searchpop.on('click', function(e) {
|
2015-11-19 16:52:44 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
// dont close thepop when click on search field
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searchfield.on('click', function(e) {
|
2015-11-19 16:52:44 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// and dont close thepop now
|
|
|
|
e.stopPropagation();
|
2015-11-19 16:07:27 +01:00
|
|
|
});
|
2015-11-20 22:30:58 +01:00
|
|
|
},
|
2015-11-19 14:55:49 +01:00
|
|
|
|
2015-11-20 22:30:58 +01:00
|
|
|
searchResultsShow: function() {
|
|
|
|
// show popup upon first keypress
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searchfield.on('keyup', function() {
|
|
|
|
_config.searchpop.removeClass('hide');
|
2015-11-19 16:52:44 +01:00
|
|
|
});
|
|
|
|
},
|
2015-11-19 14:55:49 +01:00
|
|
|
|
2015-11-20 22:30:58 +01:00
|
|
|
searchSimpleJekyllSearch: function() {
|
|
|
|
SimpleJekyllSearch({
|
|
|
|
searchInput: document.getElementById('search-input'),
|
|
|
|
resultsContainer: document.getElementById('search-results'),
|
|
|
|
json: '/search.json',
|
|
|
|
searchResultTemplate: '<li class="grid__col"><a class="search-link" href="{url}">{title}</a></li>',
|
|
|
|
fuzzy: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-11-19 16:52:44 +01:00
|
|
|
searchHide: function() {
|
|
|
|
$('.search-close').on('click', function(e) {
|
|
|
|
e.preventDefault();
|
2015-11-19 14:55:49 +01:00
|
|
|
|
2015-11-19 16:52:44 +01:00
|
|
|
_private.searchReset();
|
2015-11-19 14:55:49 +01:00
|
|
|
|
2015-11-19 16:52:44 +01:00
|
|
|
// empty search field
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searchfield.val('').blur();
|
2015-11-19 14:55:49 +01:00
|
|
|
});
|
2015-11-19 16:52:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
searchReset: function() {
|
|
|
|
// revert all search elements
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searcharea
|
2015-11-28 01:19:31 +01:00
|
|
|
.removeClass('animation-slideDown')
|
|
|
|
.addClass('animation-bounceOutUp')
|
2015-11-19 16:52:44 +01:00
|
|
|
.on('animationend webkitAnimationEnd oAnimationEnd', function(){
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.body.removeClass('has-search-open');
|
2015-11-19 16:52:44 +01:00
|
|
|
});
|
2015-12-02 00:46:25 +01:00
|
|
|
_config.searchpop.addClass('hide');
|
2015-11-19 16:52:44 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
app = {
|
|
|
|
init: function() {
|
|
|
|
_private.searchShow();
|
2015-11-20 22:30:58 +01:00
|
|
|
_private.searchResultsShow();
|
2015-11-19 16:52:44 +01:00
|
|
|
_private.searchHide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
|
|
|
})(document, window);
|