1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-22 18:00:06 +01:00

fixing the search

what is it with people constantly changing their api option names
This commit is contained in:
Matthias Kretschmann 2015-05-25 22:15:46 +02:00
parent fb8ad31e36
commit 9c2c3c49f9
2 changed files with 83 additions and 90 deletions

View File

@ -1,5 +1,4 @@
$(ASAP = function() {
$(ASAP = function(){
siteNavigation.init(); siteNavigation.init();
siteEffects.init(); siteEffects.init();
@ -7,7 +6,7 @@ $(ASAP = function(){
}); });
$(window).load( AfterLoad = function() { $(window).load(AfterLoad = function() {
photoGrid.init(); photoGrid.init();
@ -17,40 +16,33 @@ var siteNavigation = {
siteSearch: function() { siteSearch: function() {
var $searchlink = $('.search-btn'), var $searchlink = $('.search-btn'),
$searcharea = $('.topbar .search-area'), $searcharea = $('.topbar .search-area'),
$searchfield = $('.search-field'), $searchfield = $('.search-field'),
$searchresults = $('.search-results'), $searchresults = $('.search-results'),
$searchpop = $('.popover'); $searchpop = $('.popover');
$searchlink.click(function(e){ $searchlink.click(function(e) {
e.preventDefault(); e.preventDefault();
SimpleJekyllSearch.init({
searchInput: $searchfield,
resultsContainer: $searchresults,
dataSource: '/search.json',
searchResultTemplate: '<a class="search-link" href="{url}" title="{title}">{title}</a>',
fuzzy: true
})
// init jekyll search // init jekyll search
// $searchfield.jekyllSearch({ SimpleJekyllSearch({
// searchResults : $searchresults, searchInput: $searchfield,
// searchResultsTitle : '', resultsContainer: $searchresults,
// template : '<a class="search-link" href="{url}" title="{title}">{title}</a>', json: '/search.json',
// fuzzy : true searchResultTemplate: '<a class="search-link" href="{url}" title="{title}">{title}</a>',
// }); fuzzy: true
})
// show search // show search
$searcharea.removeClass('ready bounceOutUp').addClass('ready slideDown'); $searcharea.removeClass('ready bounceOutUp').addClass('ready slideDown');
$searchfield.focus(); $searchfield.focus();
if ( $searchfield.val().length ) { if ($searchfield.val().length) {
$searchpop.removeClass('hide'); $searchpop.removeClass('hide');
} }
// hide menu too just in case // hide menu too just in case
if ( $('body').hasClass('menu-open') ) { if ($('body').hasClass('menu-open')) {
$('body').removeClass('menu-open'); $('body').removeClass('menu-open');
} }
@ -82,7 +74,7 @@ var siteNavigation = {
}); });
// close button // close button
$('.search-close').click(function(e){ $('.search-close').click(function(e) {
e.preventDefault(); e.preventDefault();
// hide search area // hide search area
@ -96,15 +88,15 @@ var siteNavigation = {
siteMenu: function() { siteMenu: function() {
var $thelink = $('.menu-btn'), var $thelink = $('.menu-btn'),
$thepop = $('.nav-main .nav-popover'); $thepop = $('.nav-main .nav-popover');
$thelink.click(function(e){ $thelink.click(function(e) {
e.preventDefault(); e.preventDefault();
// toggle menu // toggle menu
$('body').toggleClass('menu-open'); $('body').toggleClass('menu-open');
if ( $('body').hasClass('menu-open') ) { if ($('body').hasClass('menu-open')) {
$thepop.removeClass('hide'); $thepop.removeClass('hide');
} else { } else {
$thepop.addClass('hide'); $thepop.addClass('hide');
@ -128,10 +120,10 @@ var siteNavigation = {
}); });
}, },
init: function(){ init: function() {
this.siteSearch(); this.siteSearch();
this.siteMenu(); this.siteMenu();
} }
} }
@ -140,17 +132,17 @@ var photoGrid = {
masonryLayout: function() { masonryLayout: function() {
var $container = $('#main .masonry'); var $container = $('#main .masonry');
$container.imagesLoaded( function(){ $container.imagesLoaded(function() {
$container.masonry({ $container.masonry({
itemSelector : 'article', itemSelector: 'article',
columnWidth : '.grid-sizer' columnWidth: '.grid-sizer'
}); });
}); });
}, },
init: function(){ init: function() {
// only fire when photo page present and screen bigger than 480px // only fire when photo page present and screen bigger than 480px
if ( $('.page-photos').length > 0 ) { if ($('.page-photos').length > 0) {
this.masonryLayout(); this.masonryLayout();
} }
} }
@ -162,10 +154,10 @@ var siteEffects = {
adaptiveBackground: function() { adaptiveBackground: function() {
var opts = { var opts = {
selector: '.hmedia img', selector: '.hmedia img',
parent: '.document' parent: '.document'
} }
$('.hmedia img').imagesLoaded( function(){ $('.hmedia img').imagesLoaded(function() {
$.adaptiveBackground.run(opts) $.adaptiveBackground.run(opts)
}); });
@ -173,46 +165,46 @@ var siteEffects = {
$(document).scrollTop($('#main').offset().top); $(document).scrollTop($('#main').offset().top);
}, },
init: function(){ init: function() {
if ( $('.page-single .format-photo').length > 0 ) { if ($('.page-single .format-photo').length > 0) {
this.adaptiveBackground(); this.adaptiveBackground();
} }
} }
} }
var infiniteScroll = { var infiniteScroll = {
infiniteScrollSetup: function() { infiniteScrollSetup: function() {
if ( $('.page-photos').length > 0 ) { if ($('.page-photos').length > 0) {
var items = '#main .masonry'; var items = '#main .masonry';
} else { } else {
var items = '#main article.hentry'; var items = '#main article.hentry';
} }
var $scrollContent = $('#main'); var $scrollContent = $('#main');
$scrollContent.infinitescroll({ $scrollContent.infinitescroll({
loading: { loading: {
img: '' img: ''
}, },
itemSelector : items, itemSelector: items,
nextSelector : '.next a', nextSelector: '.next a',
navSelector : '.paginator', navSelector: '.paginator',
binder : $scrollContent, binder: $scrollContent,
behavior : 'krlc3', behavior: 'krlc3',
}, function($scrollContent) { }, function($scrollContent) {
// run picturefill over retrieved items // run picturefill over retrieved items
picturefill(); picturefill();
// run the photogrid over retrieved items // run the photogrid over retrieved items
photoGrid.init(); photoGrid.init();
}); });
}, },
init: function(){ init: function() {
this.infiniteScrollSetup(); this.infiniteScrollSetup();
} }
} }
@ -224,37 +216,37 @@ var infiniteScroll = {
Usage: behavior: 'krlc3' Usage: behavior: 'krlc3'
-------------------------------- --------------------------------
*/ */
$.extend($.infinitescroll.prototype,{ $.extend($.infinitescroll.prototype, {
_setup_krlc3: function infscr_setup_krlc3 () { _setup_krlc3: function infscr_setup_krlc3() {
var opts = this.options, var opts = this.options,
instance = this, instance = this,
loader = $('<span class="loading"> ...</span>'); loader = $('<span class="loading"> ...</span>');
$(opts.nextSelector).parent().parent().addClass('infiniteLoader'); $(opts.nextSelector).parent().parent().addClass('infiniteLoader');
// Bind nextSelector link to retrieve // Bind nextSelector link to retrieve
$(opts.nextSelector).click(function(e) { $(opts.nextSelector).click(function(e) {
if (e.which == 1 && !e.metaKey && !e.shiftKey) { if (e.which == 1 && !e.metaKey && !e.shiftKey) {
e.preventDefault(); e.preventDefault();
instance.retrieve(); instance.retrieve();
} }
}); });
// custom start // custom start
instance.options.loading.start = function (opts) { instance.options.loading.start = function(opts) {
loader loader
.appendTo(opts.nextSelector) .appendTo(opts.nextSelector)
.show(opts.loading.speed, function () { .show(opts.loading.speed, function() {
instance.beginAjax(opts); instance.beginAjax(opts);
}); });
} }
// custom finish // custom finish
instance.options.loading.finished = function(opts) { instance.options.loading.finished = function(opts) {
loader.detach(); loader.detach();
}; };
} }
}); });

View File

@ -1,4 +1,5 @@
--- ---
layout: null
--- ---
[ [
{% for post in site.posts %} {% for post in site.posts %}