1
|
/**
|
2
|
* SPDX-License-Identifier: Apache-2.0
|
3
|
*
|
4
|
* Copyright © 2021 jahoti <jahoti@tilde.team>
|
5
|
*
|
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
* you may not use this file except in compliance with the License.
|
8
|
* You may obtain a copy of the License at
|
9
|
*
|
10
|
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
*
|
12
|
* Unless required by applicable law or agreed to in writing, software
|
13
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
* See the License for the specific language governing permissions and
|
16
|
* limitations under the License.
|
17
|
*/
|
18
|
|
19
|
var pathParts = location.pathname.split('/'), itemRef = pathParts[pathParts.length - 1];
|
20
|
|
21
|
// Generate a function which, when invoked, loads the catalog holdings starting at i (one-indexed) focused on loc
|
22
|
function generateGoTo(i, set_loc) {
|
23
|
return function () {
|
24
|
; // If this is a new search, "set_loc" won't be set; set it
|
25
|
var xhr = new content.XMLHttpRequest(), loc = set_loc || encodeURIComponent(locInput.value);
|
26
|
xhr.onreadystatechange = function () {
|
27
|
if (this.readyState === 4) {
|
28
|
if (this.status === 200) {
|
29
|
retrieved.innerHTML = this.responseText;
|
30
|
|
31
|
var i, node = document.getElementById('libslocator');
|
32
|
node.parentNode.removeChild(node);
|
33
|
for (node of retrieved.querySelectorAll('a[href^="javascript:findLibs(\'\', "]')) {
|
34
|
i = parseInt(node.href.split(',', 2)[1]);
|
35
|
node.onclick = generateGoTo(i, loc);
|
36
|
}
|
37
|
}
|
38
|
else alert('Search failed: response code ' + this.status);
|
39
|
}
|
40
|
}
|
41
|
|
42
|
xhr.open('GET', 'https://www.worldcat.org/wcpa/servlet/org.oclc.lac.ui.ajax.ServiceServlet?wcoclcnum=' + itemRef + '&start_holding='
|
43
|
+ i + '&serviceCommand=holdingsdata&loc=' + loc, true);
|
44
|
xhr.send();
|
45
|
return false; // Make sure the browser doesn't try to submit any holding form
|
46
|
};
|
47
|
}
|
48
|
|
49
|
|
50
|
var retriever = document.querySelector('.retrieving'), retrieved = document.getElementById('donelocator');
|
51
|
|
52
|
var locForm = document.createElement('form'), locLabel = document.createElement('label'), locInput = document.createElement('input'),
|
53
|
locSubmit = document.createElement('input');
|
54
|
|
55
|
locForm.appendChild(locLabel);
|
56
|
locForm.appendChild(locInput);
|
57
|
locForm.appendChild(locSubmit);
|
58
|
|
59
|
locInput.name = locLabel.htmlFor = 'cat_location';
|
60
|
locInput.type = 'text';
|
61
|
locInput.required = 'yes';
|
62
|
locLabel.innerText = 'Find copies closest to: ';
|
63
|
locSubmit.value = 'Go';
|
64
|
locSubmit.type = 'submit';
|
65
|
locForm.onsubmit = generateGoTo(1);
|
66
|
|
67
|
retriever.parentNode.replaceChild(locForm, retriever);
|