|
Lines 16-23
$(document).ready(function(){
Link Here
|
| 16 |
var userInput = $('#browse-searchterm').val().trim(); |
16 |
var userInput = $('#browse-searchterm').val().trim(); |
| 17 |
var userField = $('#browse-searchfield').val(); |
17 |
var userField = $('#browse-searchfield').val(); |
| 18 |
var userFuzziness = $('input[name=browse-searchfuzziness]:checked', '#browse-searchfuzziness').val(); |
18 |
var userFuzziness = $('input[name=browse-searchfuzziness]:checked', '#browse-searchfuzziness').val(); |
| 19 |
var leftPaneResults = $('#browse-searchresults li').not('.loading, .no-results'); |
19 |
var card_template = $("#card_template"); |
| 20 |
var rightPaneResults = $('#browse-selectionsearch ol li'); |
|
|
| 21 |
|
20 |
|
| 22 |
event.preventDefault(); |
21 |
event.preventDefault(); |
| 23 |
|
22 |
|
|
Lines 25-73
$(document).ready(function(){
Link Here
|
| 25 |
return; |
24 |
return; |
| 26 |
} |
25 |
} |
| 27 |
|
26 |
|
| 28 |
// remove any error states and show the results area (except right pane) |
27 |
/* return the browsing results to empty state in case previous results have been loaded */ |
|
|
28 |
$("#browse-searchresults").empty().append( card_template ); |
| 29 |
|
| 30 |
// remove any error states and show the results area |
| 29 |
$('#browse-suggestionserror').addClass('d-none'); |
31 |
$('#browse-suggestionserror').addClass('d-none'); |
| 30 |
$('#browse-searchresults .no-results').addClass('d-none'); |
32 |
$('.no-results').addClass('d-none'); |
| 31 |
$('#browse-resultswrapper').removeClass('d-none'); |
33 |
$('#browse-resultswrapper').removeClass('d-none'); |
| 32 |
$('#browse-selection').addClass('d-none').text(""); |
34 |
/* Reset results browser to default state */ |
| 33 |
$('#browse-selectionsearch').addClass('d-none'); |
|
|
| 34 |
|
| 35 |
// clear any results from left and right panes |
| 36 |
leftPaneResults.remove(); |
| 37 |
rightPaneResults.remove(); |
| 38 |
|
35 |
|
| 39 |
// show the spinner in the left pane |
36 |
// show the spinner |
| 40 |
$('#browse-searchresults .loading').removeClass('d-none'); |
37 |
$('.loading').removeClass('d-none'); |
| 41 |
|
38 |
|
| 42 |
xhrGetSuggestions = $.get(window.location.pathname, {api: "GetSuggestions", field: userField, prefix: userInput, fuzziness: userFuzziness}) |
39 |
xhrGetSuggestions = $.get(window.location.pathname, {api: "GetSuggestions", field: userField, prefix: userInput, fuzziness: userFuzziness}) |
| 43 |
.always(function() { |
40 |
.always(function() { |
| 44 |
// hide spinner |
41 |
// hide spinner |
| 45 |
$('#browse-searchresults .loading').addClass('d-none'); |
42 |
$('.loading').addClass('d-none'); |
| 46 |
}) |
43 |
}) |
| 47 |
.done(function(data) { |
44 |
.done(function(data) { |
| 48 |
var fragment = document.createDocumentFragment(); |
45 |
var fragment = document.createDocumentFragment(); |
| 49 |
|
46 |
|
| 50 |
if (data.length === 0) { |
47 |
if (data.length === 0) { |
| 51 |
$('#browse-searchresults .no-results').removeClass('d-none'); |
48 |
$('.no-results').removeClass('d-none'); |
| 52 |
|
|
|
| 53 |
return; |
49 |
return; |
| 54 |
} |
50 |
} |
| 55 |
|
51 |
|
| 56 |
// scroll to top of container again |
|
|
| 57 |
$("#browse-searchresults").overflowScrollReset(); |
| 58 |
|
| 59 |
// store the type of search that was performed as an attrib |
52 |
// store the type of search that was performed as an attrib |
| 60 |
$('#browse-searchresults').data('field', userField); |
53 |
$('#browse-searchresults').data('field', userField); |
| 61 |
|
54 |
|
| 62 |
$.each(data, function(index, object) { |
55 |
$.each(data, function(index, object) { |
| 63 |
// use a document fragment so we don't need to nest the elems |
56 |
// use a document fragment so we don't need to nest the elems |
| 64 |
// or append during each iteration (which would be slow) |
57 |
// or append during each iteration (which would be slow) |
| 65 |
var elem = document.createElement("li"); |
58 |
var card = card_template.clone().removeAttr("id"); |
| 66 |
var link = document.createElement("a"); |
59 |
// change card-header id |
| 67 |
link.textContent = object.text; |
60 |
card |
| 68 |
link.setAttribute("href", "#"); |
61 |
.find(".card-header") |
| 69 |
elem.appendChild(link); |
62 |
.attr("id", "heading" + index) |
| 70 |
fragment.appendChild(elem); |
63 |
.find("a").attr("data-target", "#collapse" + index) |
|
|
64 |
.attr("aria-controls", "collapse" + index) |
| 65 |
.text(object.text); |
| 66 |
card |
| 67 |
.find(".collapse") |
| 68 |
.attr("id", "collapse" + index) |
| 69 |
.attr("aria-labelledby", "heading" + index); |
| 70 |
$(fragment).append(card); |
| 71 |
}); |
71 |
}); |
| 72 |
|
72 |
|
| 73 |
$('#browse-searchresults').append(fragment.cloneNode(true)); |
73 |
$('#browse-searchresults').append(fragment.cloneNode(true)); |
|
Lines 81-172
$(document).ready(function(){
Link Here
|
| 81 |
}); |
81 |
}); |
| 82 |
}); |
82 |
}); |
| 83 |
|
83 |
|
| 84 |
$('#browse-searchresults').on("click", 'a', function(event) { |
84 |
$('#browse-searchresults').on("click", 'a.expand-result', function(event) { |
| 85 |
// if there is an in progress request, abort it so we |
85 |
// if there is an in progress request, abort it so we |
| 86 |
// don't end up with a race condition |
86 |
// don't end up with a race condition |
| 87 |
if(xhrGetResults && xhrGetResults.readyState != 4){ |
87 |
if(xhrGetResults && xhrGetResults.readyState != 4){ |
| 88 |
xhrGetResults.abort(); |
88 |
xhrGetResults.abort(); |
| 89 |
} |
89 |
} |
| 90 |
|
90 |
|
| 91 |
var term = $(this).text(); |
91 |
var link = $(this); |
|
|
92 |
var target = link.data("target"); |
| 93 |
var term = link.text(); |
| 94 |
|
| 92 |
var field = $('#browse-searchresults').data('field'); |
95 |
var field = $('#browse-searchresults').data('field'); |
| 93 |
var rightPaneResults = $('#browse-selectionsearch ol li'); |
|
|
| 94 |
|
96 |
|
| 95 |
event.preventDefault(); |
97 |
event.preventDefault(); |
| 96 |
|
98 |
|
| 97 |
// clear any current selected classes and add a new one |
99 |
/* Don't load data via AJAX if it has already been loaded */ |
| 98 |
$(this).parent().siblings().children().removeClass('selected'); |
100 |
if ($(target).find(".result-title").length == 0) { |
| 99 |
$(this).addClass('selected'); |
101 |
// do the query for the term |
| 100 |
|
102 |
xhrGetResults = $.get(window.location.pathname, {api: "GetResults", field: field, term: term}) |
| 101 |
// copy in the clicked text |
103 |
.done(function(data) { |
| 102 |
$('#browse-selection').removeClass('d-none').text(term); |
104 |
var fragment = document.createDocumentFragment(); |
| 103 |
|
105 |
|
| 104 |
// show the right hand pane if it is not shown already |
106 |
if (data.length === 0) { |
| 105 |
$('#browse-selectionsearch').removeClass('d-none'); |
107 |
$('#browse-selectionsearch .no-results').removeClass('d-none'); |
| 106 |
|
108 |
return; |
| 107 |
// hide the no results element |
109 |
} |
| 108 |
$('#browse-selectionsearch .no-results').addClass('d-none'); |
110 |
|
| 109 |
|
111 |
|
| 110 |
// clear results |
112 |
$.each(data, function(index, object) { |
| 111 |
rightPaneResults.remove(); |
113 |
// use a document fragment so we don't need to nest the elems |
| 112 |
|
114 |
// or append during each iteration (which would be slow) |
| 113 |
// turn the spinner on |
115 |
var elem = document.createElement("div"); |
| 114 |
$('#browse-selectionsearch .loading').removeClass('d-none'); |
116 |
elem.className = "result-title"; |
| 115 |
|
117 |
|
| 116 |
// do the query for the term |
118 |
var destination = window.location.pathname; |
| 117 |
xhrGetResults = $.get(window.location.pathname, {api: "GetResults", field: field, term: term}) |
119 |
destination = destination.replace("browse", "detail"); |
| 118 |
.always(function() { |
120 |
destination = destination + "?biblionumber=" + object.id; |
| 119 |
// hide spinner |
121 |
|
| 120 |
$('#browse-selectionsearch .loading').addClass('d-none'); |
122 |
var link = document.createElement("a"); |
| 121 |
}) |
123 |
link.setAttribute("href", destination); |
| 122 |
.done(function(data) { |
124 |
link.setAttribute("target", "_blank"); |
| 123 |
var fragment = document.createDocumentFragment(); |
125 |
link.textContent = object.title; |
| 124 |
|
126 |
if( object.subtitle ){ |
| 125 |
if (data.length === 0) { |
127 |
link.textContent += " " + object.subtitle; |
| 126 |
$('#browse-selectionsearch .no-results').removeClass('d-none'); |
128 |
} |
| 127 |
|
129 |
elem.appendChild(link); |
| 128 |
return; |
130 |
|
| 129 |
} |
131 |
if( object.author ){ |
| 130 |
|
132 |
var author = document.createElement("span"); |
| 131 |
// scroll to top of container again |
133 |
author.className = "author"; |
| 132 |
$("#browse-selectionsearch").overflowScrollReset(); |
134 |
author.textContent = " " + object.author; |
| 133 |
|
135 |
elem.appendChild(author); |
| 134 |
$.each(data, function(index, object) { |
136 |
} |
| 135 |
// use a document fragment so we don't need to nest the elems |
137 |
fragment.appendChild(elem); |
| 136 |
// or append during each iteration (which would be slow) |
138 |
}); |
| 137 |
var elem = document.createElement("li"); |
139 |
|
| 138 |
var title = document.createElement("h4"); |
140 |
$( target ).find(".card-body").append(fragment.cloneNode(true)); |
| 139 |
var link = document.createElement("a"); |
141 |
}) |
| 140 |
var author = document.createElement("p"); |
142 |
.fail(function(jqXHR) { |
| 141 |
var destination = window.location.pathname; |
143 |
//if 500 or 404 (abort is okay though) |
| 142 |
|
144 |
if (jqXHR.statusText !== "abort") { |
| 143 |
destination = destination.replace("browse", "detail"); |
145 |
$('#browse-resultswrapper').addClass('d-none'); |
| 144 |
destination = destination + "?biblionumber=" + object.id; |
146 |
$('#browse-suggestionserror').removeClass('d-none'); |
| 145 |
|
147 |
} |
| 146 |
author.className = "author"; |
|
|
| 147 |
|
| 148 |
link.setAttribute("href", destination); |
| 149 |
link.setAttribute("target", "_blank"); |
| 150 |
link.textContent = object.title; |
| 151 |
title.appendChild(link); |
| 152 |
|
| 153 |
author.textContent = object.author; |
| 154 |
|
| 155 |
elem.appendChild(title); |
| 156 |
elem.appendChild(author); |
| 157 |
fragment.appendChild(elem); |
| 158 |
}); |
148 |
}); |
| 159 |
|
149 |
} |
| 160 |
$('#browse-selectionsearch ol').append(fragment.cloneNode(true)); |
|
|
| 161 |
}) |
| 162 |
.fail(function(jqXHR) { |
| 163 |
//if 500 or 404 (abort is okay though) |
| 164 |
if (jqXHR.statusText !== "abort") { |
| 165 |
$('#browse-resultswrapper').addClass('d-none'); |
| 166 |
$('#browse-suggestionserror').removeClass('d-none'); |
| 167 |
} |
| 168 |
}); |
| 169 |
|
| 170 |
}); |
150 |
}); |
| 171 |
|
|
|
| 172 |
}); |
151 |
}); |