Skip to content

Commit d787e49

Browse files
committed
Format search code
1 parent a7c59b9 commit d787e49

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

javascripts/search.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ $(document).ready(function () {
1212
projectResultArea = $('#search-results-projects > div');
1313
newsResultArea = $('#search-results-news > div');
1414
miscResultArea = $('#search-results-misc > div');
15-
15+
1616
var searchQuery = getQueryParam("search");
1717
if (searchQuery != undefined && searchQuery != "") { //If a search query was provided in the query strings, execute the search
18-
loadSearchData(function() {
18+
loadSearchData(function () {
1919
searchUpdate();
2020
});
2121

2222
$("#search-input").val(searchQuery);
2323
}
2424

2525
//Close the search results if the input and results lose focus
26-
$('body').click(function(event) {
26+
$('body').click(function (event) {
2727
//Check if the click registered on a non search-related element
28-
if(!($(event.target).parents('#search-container').length)) {
28+
if (!($(event.target).parents('#search-container').length)) {
2929
hideSearchDropdown();
3030
}
3131
});
@@ -37,9 +37,9 @@ $(document).ready(function () {
3737

3838
});
3939

40-
Array.prototype.clean = function(deleteValue) {
41-
if(deleteValue == undefined)
42-
deleteValue = '';
40+
Array.prototype.clean = function (deleteValue) {
41+
if (deleteValue == undefined)
42+
deleteValue = '';
4343
for (var i = 0; i < this.length; i++) {
4444
if (this[i] == deleteValue) {
4545
this.splice(i, 1);
@@ -53,18 +53,18 @@ Array.prototype.clean = function(deleteValue) {
5353
//If they have already entered text, open the suggestions
5454
function searchFocus() {
5555
if (!searchData)
56-
loadSearchData(function() {
56+
loadSearchData(function () {
5757
searchUpdate();
5858
});
5959
else
6060
searchUpdate();
6161
}
6262

6363
function searchTextChanged() {
64-
if(searchKeystrokeEventTimer != undefined)
64+
if (searchKeystrokeEventTimer != undefined)
6565
clearTimeout(searchKeystrokeEventTimer);
6666

67-
searchKeystrokeEventTimer = setTimeout(function() {
67+
searchKeystrokeEventTimer = setTimeout(function () {
6868
searchKeystrokeEventTimer = undefined;
6969
searchUpdate();
7070
}, 400);
@@ -80,7 +80,7 @@ function loadSearchData(callback) {
8080
dataLoading = false;
8181
searchData = e.slice(0, -1);
8282

83-
if(callback != undefined)
83+
if (callback != undefined)
8484
callback();
8585
});
8686
}
@@ -93,28 +93,28 @@ function findResults(term) {
9393
//Split by word
9494
var terms = term.toLowerCase().split(/\W/g);
9595
terms = terms.clean();
96-
96+
9797
var result = [];
98-
if(terms.length <= 0)
98+
if (terms.length <= 0)
9999
return result;
100100

101101
//Iterate over the searchable data
102102
for (var i in searchData) {
103103
//Skip this item if there is no title
104-
if(searchData[i].title == undefined)
104+
if (searchData[i].title == undefined)
105105
continue;
106106

107107
var numMatches = 0;
108108
var title = searchData[i].title.toLowerCase();
109-
109+
110110
//Count the number of terms (words) that are present in the title
111-
for(var termIndex = 0; termIndex < terms.length; termIndex++) {
111+
for (var termIndex = 0; termIndex < terms.length; termIndex++) {
112112
if (title.search(terms[termIndex]) != -1)
113-
numMatches++;
113+
numMatches++;
114114
}
115115

116116
//If all terms match, this one is a hit
117-
if(numMatches >= terms.length)
117+
if (numMatches >= terms.length)
118118
result.push(searchData[i]);
119119
}
120120

@@ -145,11 +145,11 @@ function searchUpdate() {
145145
function doSearch(query) {
146146

147147
//Stop all animations
148-
if(itemLoadTimer)
148+
if (itemLoadTimer)
149149
clearTimeout(itemLoadTimer);
150-
$( "#search-dropdown .search-result" ).stop(false, true);
151-
$( "#search-dropdown .search-result" ).show();
152-
150+
$("#search-dropdown .search-result").stop(false, true);
151+
$("#search-dropdown .search-result").show();
152+
153153
//Clear existing results
154154
docResultArea.children('.search-result').remove();
155155
projectResultArea.children('.search-result').remove();
@@ -158,7 +158,7 @@ function doSearch(query) {
158158

159159
//Start the dropdown box's 'open' animation
160160
if (!$('#search-dropdown').is(":visible"))
161-
$('#search-dropdown').slideDown(400, function() {
161+
$('#search-dropdown').slideDown(400, function () {
162162
});
163163

164164
var results = findResults(query);
@@ -168,38 +168,38 @@ function doSearch(query) {
168168
var resultArea = miscResultArea;
169169

170170
var categoryTags = results[i].category.split(' ');
171-
if(categoryTags.indexOf('docs') != -1)
171+
if (categoryTags.indexOf('docs') != -1)
172172
resultArea = docResultArea;
173-
else if(categoryTags.indexOf('projects') != -1)
173+
else if (categoryTags.indexOf('projects') != -1)
174174
resultArea = projectResultArea;
175-
else if(categoryTags.indexOf('news') != -1)
175+
else if (categoryTags.indexOf('news') != -1)
176176
resultArea = newsResultArea;
177177

178-
resultArea.loadTemplate($('#search-result-template'), results[i], { append: true} );
178+
resultArea.loadTemplate($('#search-result-template'), results[i], { append: true });
179179

180180
resultArea.children().last().show(20);
181181

182-
if(i < results.length - 1) {
183-
itemLoadTimer = setTimeout(function() {
182+
if (i < results.length - 1) {
183+
itemLoadTimer = setTimeout(function () {
184184
loadItem(i + 1)
185185
}, 5);
186186
}
187187
}
188188

189-
if(results.length > 0)
189+
if (results.length > 0)
190190
loadItem(0);
191191
}
192192

193193

194194
//Hides the search dropdown and ties up any loose animations
195195
function hideSearchDropdown() {
196-
if(itemLoadTimer)
196+
if (itemLoadTimer)
197197
clearTimeout(itemLoadTimer);
198198
$("#search-dropdown .search-result").stop(false, true);
199199
$("#search-dropdown .search-result").show();
200200

201201
if ($('#search-dropdown').is(":visible")) {
202-
$('#search-dropdown').slideUp(400, function() {
202+
$('#search-dropdown').slideUp(400, function () {
203203
});
204204
}
205205
}

0 commit comments

Comments
 (0)