Last active
February 8, 2017 09:53
-
-
Save SydneyUni-Jim/ab330825b2cd1839f8e2166e883c1647 to your computer and use it in GitHub Desktop.
Workaround for not being able to request after a keyword search in Sierra 3.0's opac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script> | |
<script> | |
"use strict" | |
/* | |
Copyright 2017 Jim Nicholls, The University of Sydney. | |
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. | |
*/ | |
// Workaround for bug introduced by Sierra 3.0. | |
jQuery(function($) { | |
(function () { | |
var searchInfo = getSearchInfo(); | |
if (!searchInfo || searchInfo.searchType !== 'X') { | |
return; | |
} | |
var requestButton = getRequestButton(); | |
if (!requestButton) { | |
return; | |
} | |
var bib = | |
findBibNumberInRequstButton(requestButton) || | |
findBibNumberInOtherButtons() || | |
findBibNumberInBibRecordLinks(); | |
if (!bib) { | |
console.log("Couldn't get the bib record number from anywhere, so can't re-write the request buttons's url."); | |
return; | |
} | |
requestButton.href = constructBibRecordRequestUrl(searchInfo, bib); | |
console.log("Re-wrote the request button's url."); | |
})(); | |
function constructBibRecordRequestUrl(searchInfo, bib) { | |
return '/search' + searchInfo.scope + '?/.' + bib + '/.' + bib + '/' + searchInfo.commaJank + '/request~' + bib; | |
} | |
function getRequestButton() { | |
var c = $('a[href*="/search"][href*="/request"]'); | |
return c && c[0]; | |
} | |
function getSearchInfo() { | |
var m = window.location.href.match(/\/search(~S\d)?\?\/(.).*\/([A-Z0-9]+(%2C[A-Z0-9]+)+)\//); | |
if (m === null) { return; } | |
return { | |
'scope': m[1] || '', | |
'searchType': m[2], | |
'commaJank': m[3] | |
}; | |
} | |
function findBibNumberInBibRecordLinks() { | |
var r; | |
$('.bibRecordLink, #bibRecordLink').each(function () { | |
var m = this.innerHTML.match(/\/record=(b\d+)/); | |
r = m && m[1]; | |
return !m; | |
}); | |
return r; | |
} | |
function findBibNumberInOtherButtons() { | |
var r; | |
$('a[href*="save=b"]').each(function () { | |
var m = this.href.match(/save=(b\d+)+/); | |
r = m && m[1]; | |
return !m; | |
}); | |
return r; | |
} | |
// If the patron is logged in, the bib number is NOT in the request button's url. | |
function findBibNumberInRequstButton(requestButton) { | |
var m = requestButton.href.match(/\/request~(b\d+)/) | |
return m && m[1]; | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not do the workaround in pverify3_web.html?
Actually, this is where I started trying to code the workaround. Putting the workaround here would have meant any request button would work, not just the request button on bib_display.html.
The problem I faced is that when doing the workaround in pverify3_web.html, I can only get the bib record number from the request url.
Inexplicably, when a patron is already logged in, Sierra doesn't include the bib record number in the request url. 😖
The University of Sydney doesn't have request buttons outside of bib_display.html, so I went with a workaround in bib_display.html. Otherwise I would have need some kind of fallback for when a patron is already logged in.