aboutsummaryrefslogtreecommitdiff
path: root/content/sworldcat_library_holdings
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-08-15 00:00:00 +0000
committerjahoti <jahoti@tilde.team>2021-08-15 00:00:00 +0000
commitd104aaf3ebcddfbda495bdfe3ba3a905f75b936f (patch)
treef617204baeb4919cd1bad2cf3e302acf3ef7116f /content/sworldcat_library_holdings
parent428c474c4c71ef4c7961070d4246017d15aa0c0c (diff)
downloadhaketilo-fixes-demo-d104aaf3ebcddfbda495bdfe3ba3a905f75b936f.tar.gz
haketilo-fixes-demo-d104aaf3ebcddfbda495bdfe3ba3a905f75b936f.zip
Port existing fixes from hachette_fixes_tmp to Hydrilla format
Diffstat (limited to 'content/sworldcat_library_holdings')
-rw-r--r--content/sworldcat_library_holdings/index.json6
-rw-r--r--content/sworldcat_library_holdings/library_holdings.js65
2 files changed, 71 insertions, 0 deletions
diff --git a/content/sworldcat_library_holdings/index.json b/content/sworldcat_library_holdings/index.json
new file mode 100644
index 0000000..f2f3a39
--- /dev/null
+++ b/content/sworldcat_library_holdings/index.json
@@ -0,0 +1,6 @@
+{
+"type" : "script",
+"name" : "worldcat (library holdings)",
+"sha256" : "b1ffa6162dc9f68e2bfb1d4b6adaeac850c23bcfcc86162a2d4450aecc22f7fd",
+"location" : "library_holdings.js"
+}
diff --git a/content/sworldcat_library_holdings/library_holdings.js b/content/sworldcat_library_holdings/library_holdings.js
new file mode 100644
index 0000000..3a30b2b
--- /dev/null
+++ b/content/sworldcat_library_holdings/library_holdings.js
@@ -0,0 +1,65 @@
+/*
+ Copyright © 2021 jahoti (jahoti@tilde.team)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+var pathParts = location.pathname.split('/'), itemRef = pathParts[pathParts.length - 1];
+
+// Generate a function which, when invoked, loads the catalog holdings starting at i (one-indexed) focused on loc
+function generateGoTo(i, set_loc) {
+ return function () {
+ ; // If this is a new search, "set_loc" won't be set; set it
+ var xhr = new content.XMLHttpRequest(), loc = set_loc || encodeURIComponent(locInput.value);
+ xhr.onreadystatechange = function () {
+ if (this.readyState === 4) {
+ if (this.status === 200) {
+ retrieved.innerHTML = this.responseText;
+
+ var i, node = document.getElementById('libslocator');
+ node.parentNode.removeChild(node);
+ for (node of retrieved.querySelectorAll('a[href^="javascript:findLibs(\'\', "]')) {
+ i = parseInt(node.href.split(',', 2)[1]);
+ node.onclick = generateGoTo(i, loc);
+ }
+ }
+ else alert('Search failed: response code ' + this.status);
+ }
+ }
+
+ xhr.open('GET', 'https://www.worldcat.org/wcpa/servlet/org.oclc.lac.ui.ajax.ServiceServlet?wcoclcnum=' + itemRef + '&start_holding='
+ + i + '&serviceCommand=holdingsdata&loc=' + loc, true);
+ xhr.send();
+ return false; // Make sure the browser doesn't try to submit any holding form
+ };
+}
+
+
+var retriever = document.querySelector('.retrieving'), retrieved = document.getElementById('donelocator');
+
+var locForm = document.createElement('form'), locLabel = document.createElement('label'), locInput = document.createElement('input'),
+ locSubmit = document.createElement('input');
+
+locForm.appendChild(locLabel);
+locForm.appendChild(locInput);
+locForm.appendChild(locSubmit);
+
+locInput.name = locLabel.htmlFor = 'cat_location';
+locInput.type = 'text';
+locInput.required = 'yes';
+locLabel.innerText = 'Find copies closest to: ';
+locSubmit.value = 'Go';
+locSubmit.type = 'submit';
+locForm.onsubmit = generateGoTo(1);
+
+retriever.parentNode.replaceChild(locForm, retriever); \ No newline at end of file