re-indented algolia_search.js so that it uses 4-space indents.

This commit is contained in:
Sybren A. Stüvel 2016-09-06 11:52:26 +02:00
parent 3bb55fd3db
commit 305d9b44ec

View File

@ -28,15 +28,21 @@ $(document).ready(function() {
var params = {
hitsPerPage: HITS_PER_PAGE,
maxValuesPerFacet: MAX_VALUES_PER_FACET,
facets: $.map(FACET_CONFIG, function(facet) { return !facet.disjunctive ? facet.name : null; }),
disjunctiveFacets: $.map(FACET_CONFIG, function(facet) { return facet.disjunctive ? facet.name : null; })
facets: $.map(FACET_CONFIG, function(facet) {
return !facet.disjunctive ? facet.name : null;
}),
disjunctiveFacets: $.map(FACET_CONFIG, function(facet) {
return facet.disjunctive ? facet.name : null;
})
};
// Setup the search helper
var helper = algoliasearchHelper(algolia, INDEX_NAME, params);
// Check if we passed hidden facets in the FACET_CONFIG
var result = $.grep(FACET_CONFIG, function(e){ return e.hidden && e.hidden == true; });
var result = $.grep(FACET_CONFIG, function(e) {
return e.hidden && e.hidden == true;
});
for (var i = 0; i < result.length; i++) {
var f = result[i];
helper.addFacetRefinement(f.name, f.value);
@ -76,18 +82,18 @@ $(document).ready(function() {
firstHit.addClass('active');
firstHit.find('#search-loading').addClass('active');
var getNode = setTimeout(function(){
$.get('/nodes/' + firstHit.attr('data-hit-id') + '/view', function(dataHtml){
var getNode = setTimeout(function() {
$.get('/nodes/' + firstHit.attr('data-hit-id') + '/view', function(dataHtml) {
$('#search-hit-container').html(dataHtml);
})
.done(function(){
.done(function() {
$('.search-loading').removeClass('active');
$('#search-error').hide();
$('#search-hit-container').show();
clearTimeout(getNode);
})
.fail(function(data){
.fail(function(data) {
$('.search-loading').removeClass('active');
$('#search-hit-container').hide();
$('#search-error').show().html('Houston!\n\n' + data.status + ' ' + data.statusText);
@ -174,11 +180,21 @@ $(document).ready(function() {
var values = [];
for (var v in facetResult.data) {
var label = '';
if (v === 'true') { label = 'Yes'; }
else if (v === 'false') { label = 'No'; }
if (v === 'true') {
label = 'Yes';
} else if (v === 'false') {
label = 'No';
}
// Remove any underscore from the value
else { label = v.replace(/_/g," "); }
values.push({ label: label, value: v, count: facetResult.data[v], refined: helper.isRefined(facetParams.name, v) });
else {
label = v.replace(/_/g, " ");
}
values.push({
label: label,
value: v,
count: facetResult.data[v],
refined: helper.isRefined(facetParams.name, v)
});
}
var sortFunction = facetParams.sortFunction || sortByCountDesc;
if (facetParams.topListIfRefined) sortFunction = sortByRefined(sortFunction);
@ -214,7 +230,10 @@ $(document).ready(function() {
// Process pagination
var pages = [];
if (content.page > maxPages) {
pages.push({ current: false, number: 1 });
pages.push({
current: false,
number: 1
});
// They don't really add much...
// pages.push({ current: false, number: '...', disabled: true });
}
@ -222,12 +241,18 @@ $(document).ready(function() {
if (p < 0 || p >= content.nbPages) {
continue;
}
pages.push({ current: content.page === p, number: (p + 1) });
pages.push({
current: content.page === p,
number: (p + 1)
});
}
if (content.page + maxPages < content.nbPages) {
// They don't really add much...
// pages.push({ current: false, number: '...', disabled: true });
pages.push({ current: false, number: content.nbPages });
pages.push({
current: false,
number: content.nbPages
});
}
var pagination = {
pages: pages,
@ -252,35 +277,37 @@ $(document).ready(function() {
}
// Click binding
$(document).on('click','.show-more, .show-less',function(e) {
$(document).on('click', '.show-more, .show-less', function(e) {
e.preventDefault();
$(this).closest('ul').find('.show-more').toggle();
$(this).closest('ul').find('.show-less').toggle();
return false;
});
$(document).on('click','.toggleRefine',function() {
$(document).on('click', '.toggleRefine', function() {
helper.toggleRefine($(this).data('facet'), $(this).data('value')).search();
return false;
});
$(document).on('click','.gotoPage',function() {
$(document).on('click', '.gotoPage', function() {
helper.setCurrentPage(+$(this).data('page') - 1).search();
$("html, body").animate({scrollTop:0}, '500', 'swing');
$("html, body").animate({
scrollTop: 0
}, '500', 'swing');
return false;
});
$(document).on('click','.sortBy',function() {
$(document).on('click', '.sortBy', function() {
$(this).closest('.btn-group').find('.sort-by').text($(this).text());
helper.setIndex(INDEX_NAME + $(this).data('index-suffix')).search();
return false;
});
$(document).on('click','#input-loop',function() {
$(document).on('click', '#input-loop', function() {
$inputField.val('').change();
});
// Dynamic styles
$('#facets').on("mouseenter mouseleave", ".button-checkbox", function(e){
$('#facets').on("mouseenter mouseleave", ".button-checkbox", function(e) {
$(this).parent().find('.facet_link').toggleClass("hover");
});
$('#facets').on("mouseenter mouseleave", ".facet_link", function(e){
$('#facets').on("mouseenter mouseleave", ".facet_link", function(e) {
$(this).parent().find('.button-checkbox button.btn').toggleClass("hover");
});
@ -290,15 +317,15 @@ $(document).ready(function() {
* ***********/
function toggleIconEmptyInput(isEmpty) {
if(isEmpty) {
if (isEmpty) {
$('#input-loop').addClass('glyphicon-loop');
$('#input-loop').removeClass('glyphicon-remove');
}
else {
} else {
$('#input-loop').removeClass('glyphicon-loop');
$('#input-loop').addClass('glyphicon-remove');
}
}
function numberWithDelimiter(number, delimiter) {
number = number + '';
delimiter = delimiter || ',';
@ -306,12 +333,14 @@ $(document).ready(function() {
split[0] = split[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + delimiter);
return split.join('.');
}
var sortByCountDesc = function sortByCountDesc (a, b) { return b.count - a.count; };
var sortByName = function sortByName (a, b) {
var sortByCountDesc = function sortByCountDesc(a, b) {
return b.count - a.count;
};
var sortByName = function sortByName(a, b) {
return a.value.localeCompare(b.value);
};
var sortByRefined = function sortByRefined (sortFunction) {
return function (a, b) {
var sortByRefined = function sortByRefined(sortFunction) {
return function(a, b) {
if (a.refined !== b.refined) {
if (a.refined) return -1;
if (b.refined) return 1;
@ -319,11 +348,16 @@ $(document).ready(function() {
return sortFunction(a, b);
};
};
function initWithUrlParams() {
var sPageURL = location.hash;
if (!sPageURL || sPageURL.length === 0) { return true; }
if (!sPageURL || sPageURL.length === 0) {
return true;
}
var sURLVariables = sPageURL.split('&');
if (!sURLVariables || sURLVariables.length === 0) { return true; }
if (!sURLVariables || sURLVariables.length === 0) {
return true;
}
var query = decodeURIComponent(sURLVariables[0].split('=')[1]);
$inputField.val(query);
helper.setQuery(query);
@ -334,15 +368,16 @@ $(document).ready(function() {
helper.toggleRefine(facet, value, false);
}
// Page has to be set in the end to avoid being overwritten
var page = decodeURIComponent(sURLVariables[1].split('=')[1])-1;
var page = decodeURIComponent(sURLVariables[1].split('=')[1]) - 1;
helper.setCurrentPage(page);
}
function setURLParams(state) {
var urlParams = '#';
var currentQuery = state.query;
urlParams += 'q=' + encodeURIComponent(currentQuery);
var currentPage = state.page+1;
var currentPage = state.page + 1;
urlParams += '&page=' + currentPage;
for (var facetRefine in state.facetsRefinements) {
urlParams += '&' + encodeURIComponent(facetRefine) + '=' + encodeURIComponent(state.facetsRefinements[facetRefine]);
@ -356,4 +391,3 @@ $(document).ready(function() {
}
});