forked from harvard-lil/libguides-makeover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomepage.js
120 lines (109 loc) · 3.47 KB
/
homepage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
$(document).ready(function() {
//$('#query').focus();
var params = getParams();
if(params.q) {
$("#query").val(params.q);
getResults();
}
if(params.subjects) {
$(".link-grid").hide();
$('.subject-list').show();
}
});
function getResults(){
var homeUrl = window.location.href.replace(window.location.search,'');
$('.search-results').fadeIn();
$('#search-results-back').attr('href', homeUrl);
$('.link-grid').fadeOut();
$('.throbber-loader').show();
query = $("#query").val();
queryPlus = query.replace(' ', '+');
$.getJSON(web_base + "/api/law-hollis/" + queryPlus + "?callback=?", function(data) {
if(data.results.length > 0) {
if(data.results.length < data.totalResults) {
data.term = query;
}
var source = $("#catalog-template").html();
var template = Handlebars.compile(source);
$('#catalog').html(template(data));
}
else {
var source = $("#catalog-template").html();
var template = Handlebars.compile(source);
$('#catalog').html(template({alert: 'No results'}));
}
});
$.getJSON(web_base + "/api/law-libguides/" + query + "?callback=?", function(data) {
if(data.results.length > 0) {
if(data.results.length < data.totalResults) {
data.term = query;
}
var source = $("#libguides-template").html();
var template = Handlebars.compile(source);
$('#libguides').html(template(data));
}
else {
var source = $("#libguides-template").html();
var template = Handlebars.compile(source);
$('#libguides').html(template({alert: 'No results'}));
}
});
$.getJSON(web_base + "/api/libanswers/" + query + "?callback=?", function(data) {
if(data.results.length > 0) {
if(data.results.length < data.totalResults) {
data.term = query;
}
var source = $("#answers-template").html();
var template = Handlebars.compile(source);
$('#answers').html(template(data));
}
else {
var source = $("#answers-template").html();
var template = Handlebars.compile(source);
$('#answers').html(template({alert: 'No results'}));
}
});
$.getJSON(web_base + "/api/law-databases/" + query + "?callback=?", function(data) {
if(data.results.length > 0) {
if(data.results.length < data.totalResults) {
data.term = query;
}
var source = $("#databases-template").html();
var template = Handlebars.compile(source);
$('#databases').html(template(data));
}
else {
var source = $("#databases-template").html();
var template = Handlebars.compile(source);
$('#databases').html(template({alert: 'No results'}));
}
});
}
function getParams() {
var vars = [], hash;
var hashes = window.location.href.slice(inArray('?', window.location.href) + 1).split('&');
// create array for each key
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars[hash[0]] = [];
}
// populate newly created entries with values
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
if (hash[1]) {
vars[hash[0]].push(decodeURIComponent(hash[1].replace(/\+/g, '%20')));
}
}
return vars;
}
function inArray( elem, array ) {
if ( array.indexOf ) {
return array.indexOf( elem );
}
for ( var i = 0, length = array.length; i < length; i++ ) {
if ( array[ i ] === elem ) {
return i;
}
}
return -1;
}