Skip to content

Commit

Permalink
refactor: no more 'path' alias for location.pathname
Browse files Browse the repository at this point in the history
this was always sort of hacky and it's weird to rely on the scripts
to be concatenated in a particular order
plus it made copy-pasting any single script not work because you
needed to define path = location.pathname first
  • Loading branch information
phette23 committed Oct 3, 2024
1 parent 43486fc commit 071bf09
Show file tree
Hide file tree
Showing 33 changed files with 45 additions and 50 deletions.
2 changes: 0 additions & 2 deletions admin-js/_path.js

This file was deleted.

2 changes: 1 addition & 1 deletion admin-js/acq-neworder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// set notforloan = "ordered" for new orders
// NOTE: the pattern below matches multiple paths
// e.g. acqui/neworderempty.pl, acqui/neworderbiblio.pl, acqui/newordersuggestion.pl
if (path.match('/cgi-bin/koha/acqui/neworder')) {
if (location.pathname.match('/cgi-bin/koha/acqui/neworder')) {
$(() => {
function set_defaults () {
let select = $('#subfield7 select')
Expand Down
2 changes: 1 addition & 1 deletion admin-js/acq-orderreceive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// on the Acquisitions "receive items" page
// check the "Received?" box by default & fill in actual price
if (path === '/cgi-bin/koha/acqui/orderreceive.pl') {
if (location.pathname === '/cgi-bin/koha/acqui/orderreceive.pl') {
// run after document load
$(()=>{
// almost no classees or other good selector hooks on this page
Expand Down
2 changes: 1 addition & 1 deletion admin-js/catalog-additem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// replacementpricedate is a date field but inexplicably doesn't use a datepicker
if (path.match('/cgi-bin/koha/cataloguing/additem.pl')) {
if (location.pathname.match('/cgi-bin/koha/cataloguing/additem.pl')) {
$( // run a second after DOM load, hopefully form is present
setTimeout(
function () {
Expand Down
2 changes: 1 addition & 1 deletion admin-js/catalog-home.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// hide "new from z39.50/SRU" while it's broken
// https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37947
if (path.match('/cgi-bin/koha/cataloguing/cataloging-home.pl')) {
if (location.pathname.match('/cgi-bin/koha/cataloguing/cataloging-home.pl')) {
$('#z3950search').parent().hide()
}
2 changes: 1 addition & 1 deletion admin-js/circ-holds.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// "place a hold" page, accessible from multiple places
if (path.match('/cgi-bin/koha/reserve/request.pl')) {
if (location.pathname.match('/cgi-bin/koha/reserve/request.pl')) {
$(()=>{
// uncheck "hold next avail. item" on holds page
// we don't want people placing bib-level holds by accident
Expand Down
2 changes: 1 addition & 1 deletion admin-js/circ-returns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run only on the checkin page
if (path.match('/cgi-bin/koha/circ/returns.pl')) {
if (location.pathname.match('/cgi-bin/koha/circ/returns.pl')) {
// run on document load
$(function(){
// loop over each row in the checkin table
Expand Down
2 changes: 1 addition & 1 deletion admin-js/course-reserves.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// If you delete a course reserve without first removing all items from it
// the item fields get all messed up, this stops us from doing that.
if (path.match('/cgi-bin/koha/course_reserves/course-details.pl')) {
if (location.pathname.match('/cgi-bin/koha/course_reserves/course-details.pl')) {
let num_items = $('#course_reserves_table tbody tr').length
if (num_items > 0) {
// disable Delete Course button
Expand Down
2 changes: 1 addition & 1 deletion admin-js/mainpage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// modifications to the "main page" — page staff see right after logging in
if (path.match('/cgi-bin/koha/mainpage.pl')) {
if (location.pathname.match('/cgi-bin/koha/mainpage.pl')) {
$(()=>{
// add new module buttons for pending article/purchase requests
let $menu = $('.biglinks-list')
Expand Down
2 changes: 1 addition & 1 deletion admin-js/paycollect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (path.match('/cgi-bin/koha/members/paycollect.pl')) {
if (location.pathname.match('/cgi-bin/koha/members/paycollect.pl')) {
// append payment type to notes field, see https://github.com/cca/koha_snippets/issues/20
// and https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21791
let $note = $('#selected_accts_notes')
Expand Down
2 changes: 1 addition & 1 deletion admin-js/serials-edit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// serials receive default values & form simplification
if (path.match('/cgi-bin/koha/serials/serials-edit.pl')) {
if (location.pathname.match('/cgi-bin/koha/serials/serials-edit.pl')) {
// run on document load
$(() => {
function fixForm() {
Expand Down
2 changes: 1 addition & 1 deletion admin-js/serials-menu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// modify the links listed in the main menu of the Serials module
// on all pages beginning with path /cgi-bin/koha/serials/
if (path.match('/cgi-bin/koha/serials/')) {
if (location.pathname.match('/cgi-bin/koha/serials/')) {
// execute once document has loaded
$(() => {
let menu_list = $('#navmenulist ul').eq(0)
Expand Down
3 changes: 0 additions & 3 deletions catalog-js/_globals.js

This file was deleted.

2 changes: 1 addition & 1 deletion catalog-js/account.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// show on 1) "charges" tab, and 2) "summary" if there's a secondary "charges" tab
if (path.match('/cgi-bin/koha/opac-account.pl') || (path.match('/cgi-bin/koha/opac-user.pl') && $('#opac-user-fines').length)) {
if (location.pathname.match('/cgi-bin/koha/opac-account.pl') || (location.pathname.match('/cgi-bin/koha/opac-user.pl') && $('#opac-user-fines').length)) {
let html = '<p><a href="https://secure.touchnet.net/C20080_ustores/web/product_detail.jsp?PRODUCTID=210&SINGLESTORE=true" class="btn btn-warning" style="color:white;" target="_blank">Pay fines online</a></p><p>Please allow up to 24 hours for online payments to be processed in your library account.</p>'
// only show on charges tab if the user has fine
if (parseFloat($('.sum').eq(1).text())) {
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/article-request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (path.match('/cgi-bin/koha/opac-request-article.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-request-article.pl')) {
// SF is only valid pickup location for us so hide the pickup library menu,
// remove the other options, & ensure SF is selected (it should be)
$('#branchcode').parent().hide()
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/comics-plus-cover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// scrape the book cover image URL from the 856$u field and add it as a Koha cover image
if (path.match('/cgi-bin/koha/opac-detail.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-detail.pl')) {
let hasCover = () => !!$('.cover-image').length

const addCPCover = function () {
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/course-reserves.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// treat search filter on Course Reserves like every other form input
if (path.match('/cgi-bin/koha/opac-course-reserves.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-course-reserves.pl')) {
$('#course_reserves_table_wrapper input[type=search]').addClass('form-control')
}
2 changes: 1 addition & 1 deletion catalog-js/details-actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// changes to the right-side #action menu of bib detail page
if (path.match('/cgi-bin/koha/opac-detail.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-detail.pl')) {
$(()=>{
// Customizations to the right-side "Actions" menu
// remove "print", "suggest for purchase", & "save record" links
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/details.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// all our customizations to the bib details display in one place
if (path.match('/cgi-bin/koha/opac-detail.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-detail.pl')) {
// extra commas in 700 "contributor" field display
// like MARC of 700 __ ‡a Brundige, James, ‡e director, ‡e editor.
// => "Brundige, James [director,, editor.]"
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/holdings-table-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ex: https://library.cca.edu/cgi-bin/koha/opac-detail.pl?biblionumber=55280&viewallitems=1

// we're on a details page & there are more than 4 rows of holdings (not counting header row)
if (path === '/cgi-bin/koha/opac-detail.pl' && $('#holdingst tr').length > 5) {
if (location.pathname === '/cgi-bin/koha/opac-detail.pl' && $('#holdingst tr').length > 5) {
// Rolling our own search input is easier than trying to destory and rebuild the datatable
// to change its config and add one, which has some kind of race condition that can break
// the table entirely.
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/holds.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (path.match('/cgi-bin/koha/opac-reserve.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-reserve.pl')) {
// changes per Paul's request on 2022-09-07
// https://ccaweb.slack.com/archives/C01V8JTGRD2/p1662570492099079

Expand Down
2 changes: 1 addition & 1 deletion catalog-js/home-search.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// better home page column layout, simpler search form

// run only on home pg (could be at domain root or its own path)
if (path.match('cgi-bin/koha/opac-main.pl') || path === '/') {
if (location.pathname.match('cgi-bin/koha/opac-main.pl') || path === '/') {
// we want no form controls over than text input & search button
// we hide most with CSS but the library branch selector has a parent
// element with only layout classes so it's easier to remove with JS
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/item-type-icons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// use our custom-made icons instead of default theme Koha ones
if (path.match('/cgi-bin/koha/opac-search.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-search.pl')) {
let icon_map = {
'book': 'book.svg',
'continuing resource': 'periodical.svg',
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/librarian-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let paths = [
'/cgi-bin/koha/opac-messaging.pl',
'/cgi-bin/koha/opac-shelves.pl?op=list&category=1'
]
if (paths.some(page => path.match(page))) {
if (paths.some(page => location.pathname.match(page))) {
// use libraryh3lp Presence API https://dev.libraryh3lp.com/presence.html
fetch('https://libraryh3lp.com/presence/jid/cca-libraries-queue/chat.libraryh3lp.com/text')
.then(resp => resp.text())
Expand Down
18 changes: 9 additions & 9 deletions catalog-js/login-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ let onLoginScreen = !!$('#opac-login-page').length
}

// 1) record bib number when we're trying to place a hold but not logged in
if (onLoginScreen && path.match('/cgi-bin/koha/opac-reserve.pl')) {
if (onLoginScreen && location.pathname.match('/cgi-bin/koha/opac-reserve.pl')) {
// we always clear storage first in case multiple actions build up
// e.g. first they place hold, sign out, request article in same session
clearCCAStorage()
// URL structure is slightly different for multiple holds, biblionumbers
// are listed in one parameter and forward-slash separated
sessionStorage.setItem('cca_bib_hold', search.get('biblionumber'))
sessionStorage.setItem('cca_bib_holds', search.get('biblionumbers'))
} else if (path.match('/cgi-bin/koha/opac-user.pl') && (sessionStorage.getItem('cca_bib_hold') || sessionStorage.getItem('cca_bib_holds'))) {
} else if (location.pathname.match('/cgi-bin/koha/opac-user.pl') && (sessionStorage.getItem('cca_bib_hold') || sessionStorage.getItem('cca_bib_holds'))) {
bib = sessionStorage.getItem('cca_bib_hold')
bibs = sessionStorage.getItem('cca_bib_holds')
// clear storage then go to appropriate reserve page
Expand All @@ -47,38 +47,38 @@ if (onLoginScreen && path.match('/cgi-bin/koha/opac-reserve.pl')) {
if (onLoginScreen && location.href.match(/\/cgi-bin\/koha\/opac-suggestions.pl\?op=add/)) {
clearCCAStorage()
sessionStorage.setItem('cca_suggestion', true)
} else if (path.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_suggestion')) {
} else if (location.pathname.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_suggestion')) {
// clear storage, go to purchase suggestions form
sessionStorage.removeItem('cca_suggestion')
location = '/cgi-bin/koha/opac-suggestions.pl?op=add'
}

// 3) we're trying to make an article request but we're not logged in
if (onLoginScreen && path.match('/cgi-bin/koha/opac-request-article.pl')) {
if (onLoginScreen && location.pathname.match('/cgi-bin/koha/opac-request-article.pl')) {
clearCCAStorage()
sessionStorage.setItem('cca_article_request', search.get('biblionumber'))
} else if (path.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_article_request')) {
} else if (location.pathname.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_article_request')) {
bib = sessionStorage.getItem('cca_article_request')
// clear storage, go to appropriate article requests page
sessionStorage.removeItem('cca_article_request')
location = '/cgi-bin/koha/opac-request-article.pl?biblionumber=' + bib
}

// 4) we're trying to access the resticted page
if (onLoginScreen && path.match('/cgi-bin/koha/opac-restrictedpage.pl')) {
if (onLoginScreen && location.pathname.match('/cgi-bin/koha/opac-restrictedpage.pl')) {
clearCCAStorage()
sessionStorage.setItem('cca_restricted_page', true)
} else if (path.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_restricted_page')) {
} else if (location.pathname.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_restricted_page')) {
// clear storage, return to restricted page
clearCCAStorage()
location = '/cgi-bin/koha/opac-restrictedpage.pl'
}

// 4) we're trying to report a problem
if (onLoginScreen && path.match('/cgi-bin/koha/opac-reportproblem.pl')) {
if (onLoginScreen && location.pathname.match('/cgi-bin/koha/opac-reportproblem.pl')) {
clearCCAStorage()
sessionStorage.setItem('cca_report_problem', true)
} else if (path.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_report_problem')) {
} else if (location.pathname.match('/cgi-bin/koha/opac-user.pl') && sessionStorage.getItem('cca_report_problem')) {
// clear storage, return to restricted page
clearCCAStorage()
location = '/cgi-bin/koha/opac-reportproblem.pl'
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/mat-lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// custom display for Materials Library samples
if (path.match('/cgi-bin/koha/opac-detail.pl') &&
if (location.pathname.match('/cgi-bin/koha/opac-detail.pl') &&
$('td.itype').eq(0).text().trim() === 'Material Sample') {
// mat lib labels
let newLabel = (selector, label) => {
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/memberentry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// "Your personal details" user account page
if (path.match('/cgi-bin/koha/opac-memberentry.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-memberentry.pl')) {
// only allow SF to be home branch
$('#borrower_branchcode option[value="SF"]').prop('selected', true)
$('#borrower_branchcode').prop('disabled', true)
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/passwd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// "change your password" page, currently only Alumni have access
if (path.match('/cgi-bin/koha/opac-passwd.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-passwd.pl')) {
let msg = `<br>Note that this page only changes your Library Catalog password.
Some Alumni may sign in with their CCA password; this page does not reset that
password, instead see <a href="https://accounts.cca.edu/reset_password/">
Expand Down
2 changes: 1 addition & 1 deletion catalog-js/reserves.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (path.match('/cgi-bin/koha/opac-course-reserves.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-course-reserves.pl')) {
let html = '<p><b>Instructors</b>: add to your reserves list by filling out our <a href="https://docs.google.com/forms/d/e/1FAIpQLScq7SDjDi6bzu7OcHdI-4ec3CdKvmWLpcv8oxdwr7IksUYiKw/viewform">Course Reserves Request Form</a>.</p>'
$('h1').after(html)
}
12 changes: 6 additions & 6 deletions catalog-js/save-to-lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function addSaveToListBtn(target, wrapper, large=false) {
}

if (!loggedIn) {
if (path.match('/cgi-bin/koha/opac-detail.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-detail.pl')) {
// bib detail page & not logged in, add to right-side Actions menu
addSaveToListBtn('#action > li:first-child', 'li', true)
} else if (path.match('/cgi-bin/koha/opac-search.pl')) {
} else if (location.pathname.match('/cgi-bin/koha/opac-search.pl')) {
// search results page, add to each "actions" row at bottom of result
addSaveToListBtn('.actions-menu span.actions:nth-last-child(2)', 'span class="actions"')
}
Expand All @@ -34,21 +34,21 @@ if (!loggedIn) {
// we are logged in _and_ have data but were we on a search or details page?
if (sessionStorage.cca_search_url) {
// we started on a search page
if (path.match('/cgi-bin/koha/opac-user.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-user.pl')) {
// step 1) user page, so we just signed in, redirect to saved search
location = sessionStorage.cca_search_url
} else if (path.match('/cgi-bin/koha/opac-search.pl')) {
} else if (location.pathname.match('/cgi-bin/koha/opac-search.pl')) {
// step 2) find bib, click "save to lists" action then clear data
$('#title_summary_' + bib).find('.actions [href^="/cgi-bin/koha/opac-addbybiblionumber.pl"]').click()
sessionStorage.removeItem('cca_save_to_list')
sessionStorage.removeItem('cca_search_url')
}
} else {
// we start on a details page, simpler process
if (path.match('/cgi-bin/koha/opac-user.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-user.pl')) {
// step 1) user page, so we just signed in, redirect to bib
location = '/cgi-bin/koha/opac-detail.pl?biblionumber=' + bib
} else if (path.match('/cgi-bin/koha/opac-detail.pl')) {
} else if (location.pathname.match('/cgi-bin/koha/opac-detail.pl')) {
// step 2) click the "save to lists" link then clear data
$(addToShelfAction).click()
sessionStorage.removeItem('cca_save_to_list')
Expand Down
4 changes: 2 additions & 2 deletions catalog-js/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// on specific searches for the Artists' Books collection, show a link to the
// previews in VAULT
if (path.match('/cgi-bin/koha/opac-search.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-search.pl')) {
let qs = new URLSearchParams(location.search)
let q = qs.get('q') && qs.get('q').toLowerCase()
let limit = qs.get('limit')
Expand All @@ -9,7 +9,7 @@ if (path.match('/cgi-bin/koha/opac-search.pl')) {
let abHtml = '<div class="alert alert-error">View previews of the Artists\' Books Collection <a href="https://vault.cca.edu/logon.do?.page=/hierarchy.do?topic=a7b976d5-5316-44da-b06e-7374cd100075">in VAULT</a> (login required).</div>'
if (q && q.match(/artists?'? book/) || limit && limit.match('ARTIST')) {
$('#numresults').before(abHtml)
} else if (path.match('opac-shelves.pl') && qs.get('op') == 'view' && qs.get('shelfnumber') == '481') {
} else if (location.pathname.match('opac-shelves.pl') && qs.get('op') == 'view' && qs.get('shelfnumber') == '481') {
$('#usershelves').before(abHtml)
}

Expand Down
2 changes: 1 addition & 1 deletion catalog-js/serials-solutions-holdings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// - African arts (0001-9933) several holdings including print
// - ARTMargins (2162-2574) one online holding & print
// - Art & artists (0004-3001) has only a print holding
if (path.match('/cgi-bin/koha/opac-detail.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-detail.pl')) {
// do we have an ISSN? use 360 Link API to see if we have online holdings
let issn = $('.results_summary.issn').find('span[property="issn"]')

Expand Down
2 changes: 1 addition & 1 deletion catalog-js/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// user's "summary" page immediately after logging in
if (path.match('/cgi-bin/koha/opac-user.pl')) {
if (location.pathname.match('/cgi-bin/koha/opac-user.pl')) {
// edit (On hold) text in the "Renew" column to indicate a recall & make more prominent
$('.renew .renewals:contains("(On hold)")')
.css('font-weight', 'bold').text('Item recalled - please return')
Expand Down

0 comments on commit 071bf09

Please sign in to comment.