JQuery Library
From Koha Wiki
JQuery modifications are a great way to customize the look and feel of your Koha install. There are a few tips to remember when writing JQuery modifications:
- For the staff side, all JQuery statements go in the IntranetUserJS system preference
- For the OPAC, all JQuery statements go in the OPACUserJS system preference
- You must include inside the preference, around your statements. Examples listed below are considered "statements."
$(document).ready(function(){ <multiple statements go here> });
- Clients must have Javascript enabled in their browsers for these changes to take effect.
Template
Developers: Please use the following template to add your JQuery statements to the wiki.
JQuery Title
- Developer: Name of JQuery developer
- Creation Date: the date you entered the script (YYYY-MM-DD)
- Purpose: Purpose of the JQuery script
- Status: Completed / In progress
- Intranet or OPAC?:
- Version: (The Koha version you are using this with, or Any, if applicable)
Some JQuery code
Intranet JQuery Statements
Modify Labels on memberentry.pl (Patron edit screen)
- Developer: Liz Rea (NEKLS)
- Purpose: To change phone/email labels from Home/Mobile Phone to Phone/Email (primary) and Phone/Email (secondary). Also adds a helpful tip as to which field will be printed on transit slips.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
$("#memberentry_contact label[for='phone']").html("Primary Phone :"); $("#memberentry_contact label[for='email']").html("Primary Email :"); $("#memberentry_contact label[for='emailpro']").html("Alternate Email :"); $("#memberentry_contact li:contains('Primary Phone')").append("<strong><em> Shows on transit slips</em></strong>"); $("#memberentry_contact li:contains('Primary Email')").append("<strong><em> Shows on transit slips</em></strong>");
This second bit changes the labels on the patron detail page:
$("#patron-information .label:contains('Home:')").html('Primary Phone:'); $("#patron-information .label:contains('Work:')").html('Alternate Phone:'); $("#patron-information .label:contains('Email (work):')").html('Alternate Email:'); $("#patron-information .label:contains('Email (home):')").html('Primary Email:');
Remove Upcoming Events row from the messaging preferences table
- Developer: Liz Rea (NEKLS)
- Purpose: Remove the Upcoming Events row from the messaging prefs table. This was confusing because upcoming events notification requires additional software, but was always offered even if the additional software wasn't installed. This JQuery removes that row in the preferences table.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
$("#memberentry_messaging_prefs tr:contains('Upcoming Events')").empty(); $("#patron-messaging-prefs tr:contains('Upcoming Events')").empty();
Remove Return All functionality from check out screen/Patron Detail page
- Developer: Liz Rea (NEKLS)
- Purpose: Since the Return All functionality is only partially complete (it doesn't process holds correctly when used, a big problem in our system) we have chosen to remove the column for Return all, and the associated button.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
$("#finesholdsissues #issuest").find("tbody td:last-child,thead th:last-child").hide(); $("#finesholdsissues").find('input[id=return_all]').hide(); $("#patronlists #issuest").find("tbody td:last-child,thead th:last-child").hide();
Remove Delete link from the News items on the Staff home screen
- Developer: Liz Rea (NEKLS)
- Purpose: Some of our librarians were deleting news items, we wanted to remove the link.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
$(".newsfooter a:contains('Delete')").hide();
Adds Focus to Cataloging Search
- Developer: Liz Rea (NEKLS)
- Purpose: The cataloging search didn't seem to get focus after adding a bib. This adds that functionality.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.0.x (afaik)
$("#addbooks_search input[name=q]:eq(0)").focus();
Hide a field on Patron detail screen
- Developer: Liz Rea (NEKLS)
- Purpose: Hide a desired field on the Patron detail screen
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
$("#patron-information li:contains('Mobile:')").hide();
- Developer: Marc Véron
- Purpose: Hide th menu in the left column to get more space for big table e.g. in Administration->Circulation and fine rules
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
if ((""+window.location).indexOf("smart-rules.pl")>=0) {
$("#navmenu").hide();
$(".yui-t1 #yui-main .yui-b").css("margin-left", "1em");
}
Change the staff client's "Change Password" field to password type input
- Developer: Owen Leonard (Nelsonville Public Library)
- Purpose: Change the staff client's "Change Password" field to password type input. Useful if your staff client terminal is viewable by the public. This also removes Koha's default "suggested password" from the field.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.2
$(document).ready(function(){ $("#newpassword").parent().append("<input type=\"password\" value=\"\" size=\"20\" id=\"newpassword\" name=\"newpassword\">").end().remove(); });
Add additional searches to Intranet
- Developer: Magnus Enger, but based on "Add additional searches to OPAC" by Jared Camins-Esakov above
- Purpose: Adds additional searches to the Intranet Search type dropdown, in a specific place in the drop down
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
- Note: The goal here is to add the Dewey index after the "Subject as Phrase" index, and indent it to the same level as that index. Since matching is done on the values of elements in the list of options (and not on the text labels) this should work across translations too.
$('option[value="su,phr"]').after("<option value='Dewey-classification'> Dewey</option>");
Remove link to Holds to pull page
- Developer: Ian Walls
- Purpose: Removes "Holds to pull" link from the circulation page
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
- Note: Often, the Holds to pull list is deprecated for library use vs. the Holds Queue. This query removes the link in an effort to remove staff confusion. Sponsored by MassCat.
$("ul li:contains('Holds to pull')").remove();
Streamline Import Patrons page
- Developer: Daniel Grobani
- Purpose: removes unneeded fields and sets desired values
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: LLEK 4.0200019
// remove "default values" fieldset $('form[action] legend:contains("Default values")').parent().remove(); // set record matching field to ID $('fieldset:has(legend:contains("Field to use for record matching")) #matchpoint').val("ID"); // overwrite matching record $('#overwrite_cardnumberno').attr('checked', 'false'); $('#overwrite_cardnumberyes').attr('checked', 'true'); // replace only included extended attributes $('#ext_preserve_0').attr('checked', 'false'); $('#ext_preserve_1').attr('checked', 'true');
Point out there is a button for renewing items at bottom of patron page
- Developer: Jared Camins-Esakov, ByWater Solutions
- Purpose: Alerting staff to the fact that they can renew/return items directly from the patron record; particularly relevant for patrons with huge numbers of items checked out, where staff might forget about the renewal button at the bottom
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.4
$("#issuest").parent().prepend("<div id='renewref'>See below to renew all or selected items.</div>");
Don't Allow Checkout Overrides
- Developer: Scott Merrill , CAUSE
- Purpose: Removes the override option for circulation rules that block checkouts... right now, if you have a maximum line of X item type out to a patron type, you'll always get a prompt asking if you want to override, this removes the prompt
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.4+
$("#circ_needsconfirmation ul li:contains('This patron can\'t check out this item per library circulation policy')").parent().siblings().hide();
Hide Streetnumber field on Patron edit screen
- Developer: Joy Nelson, ByWater Solutions
- Purpose: Remove the Street Number field from the patron edit screen.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.6+
$("#entryform #streetnumber").parent().hide();
Hide the Patron column in the Holds Que report
- Developer: Ed Veal, ByWater Solutions
- Purpose: Hides the Patron column in the Holds Que report but could be changed to hide any column within the report.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.6+
$("#holdst .hq-patron").hide();
Add a link to self checkout on intranet login screen
- Developer: Koha Community
- Purpose: Add a link to the built-in self checkout function to the intranet login screen
- Status: Completed
- Intranet
- Version: Any
$("#login .submit").parent().after("<p><a href=\"http://YOUR_KOHA_OPAC_URL/cgi-bin/koha/sco/sco-main.pl\" target=\"_blank\">Self-Checkout</a></p>");
Keyboard shortcuts to quickly change tab while showing or editing MARC records
- Developer: Stefano Bargioni (Pontificia Università della Santa Croce) - 2012-04-26
- Purpose: Keyboard shortcuts to change tab while showing or editing MARC records
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
// MARC bib edit if (location.pathname.indexOf('cataloguing/addbiblio.pl')>-1) { $(document).keydown(function(e) { if (e.target.tagName == 'INPUT') return; if (e.target.tagName == 'TEXTAREA') return; var f = 0; // flag var c = e.which; // code key pressed if (c>=48 && c<=57) {f=1; c-=48;} // 0..9 keyboard if (c>=96 && c<=105) {f=1; c-=96;} // 0..9 keypad if (f==0) return; var marc_sections = $('#addbibliotabs ul li a').text().replace(/[^0-9]/g,''); var marc_section = marc_sections.indexOf(c); if (marc_section == -1) return; $($('#addbibliotabs ul li a')[marc_section]).click(); }); } // MARC bib show if (location.pathname.indexOf('catalogue/MARCdetail.pl')>-1) { $(document).keydown(function(e) { if (e.target.tagName == 'INPUT') return; if (e.target.tagName == 'TEXTAREA') return; var f = 0; // flag var c = e.which; // code key pressed if (c>=48 && c<=57) {f=1; c-=48;} // 0..9 keyboard if (c>=96 && c<=105) {f=1; c-=96;} // 0..9 keypad if (f==0) return; var marc_sections = $('#bibliotabs ul li a').text().replace(/[^0-9]/g,''); var marc_section = marc_sections.indexOf(c); if (marc_section == -1) return; $($('#bibliotabs ul li a')[marc_section]).click(); }); } // MARC auth show if (location.pathname.indexOf('authorities/detail.pl')>-1) { $(document).keydown(function(e) { if (e.target.tagName == 'INPUT') return; if (e.target.tagName == 'TEXTAREA') return; var f = 0; // flag var c = e.which; // code key pressed if (c>=48 && c<=57) {f=1; c-=48;} // 0..9 keyboard if (c>=96 && c<=105) {f=1; c-=96;} // 0..9 keypad if (f==0) return; var marc_sections = $('#authoritiestabs ul li a').text().replace(/[^0-9]/g,''); var marc_section = marc_sections.indexOf(c); if (marc_section == -1) return; $($('#authoritiestabs ul li a')[marc_section]).click(); }); } // MARC auth edit if (location.pathname.indexOf('authorities/authorities.pl')>-1) { $(document).keydown(function(e) { if (e.target.tagName == 'INPUT') return; if (e.target.tagName == 'TEXTAREA') return; var f = 0; // flag var c = e.which; // code key pressed if (c>=48 && c<=57) {f=1; c-=48;} // 0..9 keyboard if (c>=96 && c<=105) {f=1; c-=96;} // 0..9 keypad if (f==0) return; var marc_sections = $('#authoritytabs ul li a').text().replace(/[^0-9]/g,''); var marc_section = marc_sections.indexOf(c); if (marc_section == -1) return; $($('#authoritytabs ul li a')[marc_section]).click(); }); }
Hide SQL statement when running guided report
- Developer: Galen Charlton
- Purpose: Hide the SQL query when running a guided report
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.4.x and later
$("#sql_output").hide();
Set sort order to ascending call number if selecting call number search in the staff interface
- Developer: Galen Charlton
- Purpose: Set sort order to ascending call number if selecting call number search in the staff interface
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.0.x and later (tested in 3.8.x)
$("select.advsearch").change(function() { var idx = $(this).val(); if (idx.substring(0, 7) == 'callnum') { $("select#sort_by").val('call_number_asc'); } });
Add a filter to the patron various tables in staff interface
- Developer: Christopher Brannon (Coeur d'Alene Public Library), based of original code by Kobi Lidershnider at http://kobikobi.wordpress.com/2008/09/15/using-jquery-to-filter-table-rows/
- Purpose: To help find information in various tables, such as the Account and Pay fines portions of patron Fines, Edit items in cataloging, or the details screen for a bib in the staff catalog.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
//Add filter to various tables $("#yui-main div[class='tabs-container'] table").attr("class","filterable"); //filter for fines $("#yui-main div[id='cataloguing_additem_itemlist'] table").attr("class","filterable"); //filter for Edit items in cataloging $("#yui-main div[id='bibliodetails'] table").attr("class","filterable"); //filter for bib items in staff catalog $("<i>Filter: </i><input type='text' id='FilterTextBox' name='FilterTextBox' /><a href='#' class='clear' rel='nofollow'> Clear</a></p>").insertBefore("#yui-main table[class='filterable']"); $(".filterable tr:has(td)").each(function(){var t = $(this).text().toLowerCase(); $("<td class='indexColumn'></td>").hide().text(t).appendTo(this); });//each tr $("#FilterTextBox").keyup(function(){ var s = $(this).val().toLowerCase().split(" "); //show all rows. $(".filterable tr:hidden").show(); $.each(s, function(){ $(".filterable tr:visible .indexColumn:not(:contains('" + this + "'))").parent().hide(); });//each });//key up. $(".clear").click(function(){ $("#FilterTextBox").val("").keyup(); return false; }); //end filters
Clean up patron details screen
- Developer: Christopher Brannon (Coeur d'Alene Public Library)
- Purpose: Remove unused lines in the Alternate address or Alternative contact sections of the Patron Details screen.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
//Condense Patron Display $("#patron-alternate-address,#patron-alternative-contact").find("li").hide(); $("#patron-alternate-address li,#patron-alternative-contact li") .contents() .filter(function() { return this.nodeType == Node.TEXT_NODE; }).wrap("<span class='availablecontent'/>"); $("#patron-alternate-address,#patron-alternative-contact").find(".availablecontent").each(function() { $(this).parent("li").show(); }); //end Condense Patron Display
Alert staff about missing email or phone upon checkout
- Developer: Paul Landers - Texas Tech University Health Sciences Center
- Purpose: Alert staff about missing email or phone upon checkout.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
- Note: Alert staff upon item checkout that a patron's email or phone is blank.
// Confirm that we're on the "Checking Out" page myvar0 = $('title:contains("Checking out")').length; // is there a mailto: link on this page? myvar1 = $('a[href*="mailto"]').length; myvar2 = $("#nophonestored").length; if(myvar0 != 0 && myvar1 == 0) { alert('Patron email is blank!'); } if(myvar0 != 0 && myvar2 != 0) { alert('Phone number is missing!'); }
Alert inattentive staff to read patron notes
- Developer: Paul Landers - Texas Tech University Health Sciences Center
- Purpose: Alert staff about blank email upon checkout.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
- Note: Alert inattentive staff to read and resolve patron notes upon item checkout. This alert is repeated upon every page reload.
noteVar = $('.circ-hlt').length; if (noteVar != 0) { alert('READ Circulation Note!'); }
Add 'Hide/Unhide $0.00 balances' toggle button to fines screen
- Developer: George H. Williams
- Purpose: Creates a toggle button that hides or shows any lines from the patron fines table that have been paid in full.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.8
- Note: The button requires 2 parts. The first part adds a Jquery selector called 'contentIs.' The second statement creates the toggle button. For the button to work correctly you must include the statement to create the 'contentIs' selector.
//add the “contentIs” selector to return exact matches $.expr[':'].contentIs = function(el, idx, meta) { return $(el).text() === meta[3]; }; //end “contentIs” selector //begin Zero Balance Button //Adds a toggle button to the account tab on the patron fines screen that hides or shows any lines in a patron's account with an outstanding balance of zero var new_btn = $('<button id="0hide">Hide/Unhide $0.00 balances</button>'); new_btn.insertBefore('#PatronAccountTable:first'); $('#0hide').click(function() { $(".credit:contentIs(0.00)").parents("tr").toggle(); }); //end Zero Balance Button
Change Manual Credit to Add Note
- Developer: Paul Landers - Texas Tech University Health Sciences Center
- Purpose: Change the Manual Credit function to an Add Note function.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: Any
- Note: Manual Credit was problematic for us, especially in reporting. Our staff used it only because of the notes field in order to give a reason when writing off a fine. Since the form assumes $0.00 upon submission, we just hide the amount field and then change the text on various elements.
//rename the tab from "Create manual credit" to "Add note" $('a[href*="mancredit"]').text('Add note'); // Also if we're on the "Create manual credit" subpage: myvar0 = $('title:contains("Create manual credit")').length; if(myvar0 != 0) { $("li:contains('Amount: ')").hide(); $("legend:contains('Manual credit')").text('Add note'); $("input[name='add']").val('Create note'); }
Remove 23:59 time dues from Circ and Catalogue when hourly loans are not in use
- Developer: Liz Rea (Catalyst IT)
- Purpose: Remove the time due from intranet detail and circulation pages.
- Intranet or OPAC?: Intranet
- Version: 3.8+
$("#issuest td:contains('23:59')").each(function() { var text = $(this).text().replace('23:59', ''); $(this).text(text); }); $(".datedue:contains('23:59')").each(function() { var text = $(this).text().replace('23:59', ''); $(this).text(text); });
Force Staff to use Datepicker when altering due dates, renewal dates, and suspend until dates
- Developer: George H. Williams - Latah County Library District
- Purpose: Since incorrectly formatted due dates can be entered in the "specify due date", "renewal date", and "suspend until" input boxes (and incorrectly formatted dates can cause system errors), this jQuery forces staff to use the calendar datepicker to choose dates for these options.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.8
//BEGIN Force staff to use datepicker for altering due dates, renewal dates, and suspend unitl dates $("#duedatespec").attr("readonly", "readonly"); $("#newduedate").attr("readonly", "readonly"); $("#suspend_until").attr("readonly", "readonly"); $(".hint:contains('Specify due date (MM/DD/YYYY):')").text('Use calendar button to choose new Due Date'); $("p:contains(Renewal due date:)").prepend('Use calendar button to choose '); $(".hint:contains('Specify date on which to resume (MM/DD/YYYY):')").text('Use calendar button to specify the date when holds will resume'); //END Force staff to use datepicker for altering due dates, renewal dates, and suspend unitl dates
Hide some of the displayed fields when adding or editing an item
- Developer: George H. Williams - Latah County Library District
- Purpose: Hides selected fields in the "Add item" and "Edit item" pages.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.10
- Note: Catalogers in our consortium want the default display of these screens to be shorter but they also need the ability to look at all fields if necessary. This example hides the 0, 1, 4, f, and j subfields. To remove different fields from the default display when the page loads add "li:contains(SUBFIELD -)" to the selector.
//BEGIN Hide and Show All Fields buttons for Catalogers $(".yui-u #cataloguing_additem_newitem .rows li:contains('0 - '), li:contains('1 - '), li:contains('4 - '), li:contains('f - '), li:contains('j - ')").hide(); var new_btn = $('<button id="cataddhide">Show all fields</button>'); new_btn.prependTo('.yui-u #cataloguing_additem_newitem .rows'); $('#cataddhide').click(function(e) { e.preventDefault(); $(".yui-u #cataloguing_additem_newitem .rows li:contains(' ')").show(); $('#cataddhide').fadeOut(); }); //END Show All Fields buttons for Catalogers
Preview OPAC syspref changes
- Developer: Jared Camins-Esakov, C & P Bibliography Services
- Purpose: Provides a preview for basic OPAC customizations on the OPAC syspref page.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.10+ with bug 10405 and a special web server configuration
- Note: You will need to adjust the preview URLs for your particular installation. The URLs used in this sample were especially configured so that /cgi-bin/koha/opac/ would be forwarded to the OPAC. Also be aware that only part of the script goes in $(document).ready(..). To make this clear, I have included the $(document).ready(...) in the script.
function showPreview(url) { document.getElementById('opac-preview').src = url; $('#preview-loading').show(); $('#opac-preview').load(function () { $('#opac-preview').show(); $('#region-opaccredits', $('#opac-preview').contents()).html($('#pref_opaccredits').val()); $('#region-opacheader', $('#opac-preview').contents()).html($('#pref_opacheader').val()); $('#opacmainuserblock', $('#opac-preview').contents()).html($('#pref_OpacMainUserBlock').val()); $('#opacmainuserblockmobile', $('#opac-preview').contents()).html($('#pref_OpacMainUserBlockMobile').val()); $('#region-opacnav', $('#opac-preview').contents()).html($('#pref_OpacNav').val()); $('#region-opacnavbottom', $('#opac-preview').contents()).html($('#pref_OpacNavBottom').val()); $('#opacrightsidebar', $('#opac-preview').contents()).html($('#pref_OpacNavRight').val()); $('#noresultsfound', $('#opac-preview').contents()).html($('#pref_OPACNoResultsFound').val()); $('#opacresultssidebar', $('#opac-preview').contents()).html($('#pref_OPACResultsSidebar').val()); $('#region-opacusercss', $('#opac-preview').contents()).replaceWith('<style id="region-opacusercss" type="text/css">' + $('#pref_OPACUserCSS').val() + '</style>'); $('#region-opacuserjs', $('#opac-preview').contents()).replaceWith('<' + 'script id="region-opacuserjs" type="text/javascript">' + $('#pref_opacuserjs').val() + '<' + '/script>'); $('#preview-loading').hide(); }); } $(document).ready(function () { if ($('#pref_OpacNav').size() > 0) { $('#doc3').after('<div class="navbar navbar-fixed-bottom" style="z-index: 10000;"><div id="preview-pane" class="navbar-inner"><h4 style="float: left; margin-right: 2em;">Preview changes</h4><div class="btn-group" data-toggle="buttons-radio"><button type="button" class="btn" id="preview-main">Main page</button><button type="button" class="btn" id="preview-results">Results</button><button type="button" class="btn" id="preview-details">Details</button><button type="button" class="btn active" id="preview-hide">Hide</button></div><img id="preview-loading" style="display: none;" src="/intranet-tmpl/prog/img/loading-small.gif"/><iframe id="opac-preview" style="height: 20em; width: 100%; display: none;"></iframe></div></div>'); $('#preview-main').click(function () { showPreview('/cgi-bin/koha/opac/opac-main.pl'); }); $('#preview-results').click(function () { showPreview('/cgi-bin/koha/opac/opac-search.pl?idx=&q=pqf%3D%40attr+1%3D_ALLRECORDS+%40attr+2%3D103+%22%22&branch_group_limit='); }); $('#preview-details').click(function () { showPreview('/cgi-bin/koha/opac/opac-detail.pl?biblionumber=1'); }); $('#preview-hide').click(function () { $('#opac-preview').hide(); }); } });
Validate patron data fields
- Developer: Paul Landers - Texas Tech University Health Sciences Center
- Purpose: Validate data when creating or editing patron records.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.10+
- Note: Koha performs only basic validation (i.e. required fields). This jQuery script replaces the default SAVE button with a VALIDATE button which runs a custom validation using regular expressions. Upon successful validation it submits the form data. NOTE - this script is very large and will require additional customization to fit your library, since it contains our library's unique patron categorycodes and our validation definitions. For example, we require 2 email addresses for all patrons, but allow the 2 addresses to be the same for only some categorycodes, while requiring them to be different for other categorycodes.
//hide the miniature EDIT links on the patron details screen $("#patron-alternate-address").next('div').hide(); $("#patron-alternative-contact").next('div').hide(); $("#patron-messaging-prefs").next('div').hide(); $('div.yui-u div.action a:contains("Edit")').hide(); $('#patron-information a:contains("Edit")').hide(); // validate data when creating or editing patrons by hiding the SAVE button, running an inline validation script, then submitting the form if it passes validation. // create the validation function patronValidate = function () { //start with an empty alert message var mes = ""; //get all our variables var surname = $('input[id=surname]').val(); var firstname = $('input[id=firstname]').val(); var address = $('input[id=address]').val(); var city = $('input[id=city]').val(); var state = $('input[id=state]').val(); var zipcode = $('input[id=zipcode]').val(); var phone = $('input[id=phone]').val(); var phonepro = $('input[id=phonepro]').val(); var email = $('input[id=email]').val(); var emailpro = $('input[id=emailpro]').val(); var cardnumber = $('input[id=cardnumber]').val(); var categorycode = $('select[id=categorycode]').val(); var dateexpiry = $('input[id=to]').val(); var userid = $('input[id=userid]').val(); var school = $('select[id=patron_attr_3]').val(); //create our arrays for validating expiration dates var fullYear = ['ADMIN', 'EMPLOYEE', 'FACULTY', 'RETIRED', 'STAFF']; var nonTTUHSC = ['CLINFAC', 'CONTRACTS', 'DEBTORS', 'FRIEND', 'PRECEPTOR']; //create our regexes var cardnumberReg = /(^P[A-Z0-9]{5}$)|(^R[0-9]{8}$)/; var stateReg = /^([A-Z]{2}$)/; var useridReg = /^([a-z0-9_]{3,8})$/; var surnameReg = /^[a-zA-Z\-\(\)\ ]+$/; var firstnameReg = /^[a-zA-Z]+$/; var cityReg = /^[a-zA-Z ]+$/; var addressReg = /^([1-9])/; var zipReg = /(^[0-9]{5}(-[0-9]{4})?$)/; var phoneReg = /^([2-9][0-9]{2}-[0-9]{3}-[0-9]{4})$/; var emailReg = /^([a-z0-9\-]+\.([a-z]\.)?[a-z\-]+@ttuhsc\.edu)$/i; var emailReg2 = /^(.+@.+\.[a-z]{2,3})$/i; var alumniReg = /^((11\/30\/20[0-9]{2})|(02\/15\/20[0-9]{2})|(06\/30\/20[0-9]{2}))$/; var clinfacReg = /^(08\/15\/20[0-9]{2}$)/; var higheredReg = /^(06\/30\/20[0-9]{2}$)/; var hospitalReg = /^(12\/31\/20[0-8][0-9]$)/; var studentReg = /^((05\/31\/20[0-9]{2})|(08\/15\/20[0-9]{2})|(12\/31\/20[0-8][0-9]))$/; // validate surname if (!surnameReg.test(surname)) { mes = mes + "\nLast name contains invalid characters.\n"; } // validate firstname if (!firstnameReg.test(firstname)) { mes = mes + "\nFirst name contains invalid characters (e.g. spaces).\n"; } // validate city if (!cityReg.test(city)) { mes = mes + "\nCity contains invalid characters.\n"; } // validate street address if (!addressReg.test(address)) { mes = mes + "\nStreet address must begin with a number.\n"; } // validate state if (!stateReg.test(state)) { mes = mes + "\nState abbreviation must be exactly 2 uppercase characters.\n"; } // validate zipcode if (!zipReg.test(zipcode)) { mes = mes + "\nZip code looks invalid.\n"; } // validate primary phone if (!phoneReg.test(phone)) { mes = mes + "\nPrimary phone must be exactly XXX-XXX-XXXX\n"; } // validate secondary phone if (!phoneReg.test(phonepro)) { mes = mes + "\nSecondary phone must be exactly XXX-XXX-XXXX\n"; } // validate both email addresses if (!emailReg2.test(email)) { mes = mes + "\nPrimary email looks invalid.\n"; } if (!emailReg2.test(emailpro)) { mes = mes + "\nSecondary email looks invalid.\n"; } // some categorycodes require 2 email addresses if ((nonTTUHSC.indexOf(categorycode) == -1 || categorycode == 'ALUMNI' ) && email == emailpro) { mes = mes + "\nPatron class \'" + categorycode + "\' requires 2 distinct email addresses.\n"; } //validate the cardnumber if (!cardnumberReg.test(cardnumber)) { mes = mes + "\nCardnumber is invalid.\n"; } //validate the userid if (!useridReg.test(userid)) { mes = mes + "\nUsername \(eRaider\) must be lowercase letters and numbers only.\n"; } //validate the school if (school == '') { mes = mes + "\nYou must chose a school or choose \'none\'.\n"; } //set or check dateexpiry based upon categorycode if (fullYear.indexOf(categorycode) != -1) { $('input[id=to]').val('12/31/2099'); } if (categorycode == 'CLINFAC' && !clinfacReg.test(dateexpiry)) { mes = mes + "\nClinical Faculty must expire on exactly 08\/15\/20xx.\n"; } if (categorycode == 'HIGHERED' && !higheredReg.test(dateexpiry)) { mes = mes + "\nResidents and Fellows must expire on exactly 06\/30\/20xx.\n"; } if (categorycode == 'HOSPITAL' && !hospitalReg.test(dateexpiry)) { mes = mes + "\nHospital employees must expire on exactly 12\/31\/20xx.\n"; } if (categorycode == 'ALUMNI' && !alumniReg.test(dateexpiry)) { mes = mes + "\nAlumni must expire on exactly 02\/15\/20xx, or 06\/30\/20xx, or 11\/30\/20xx.\n"; } if (categorycode == 'STUDENT' && !studentReg.test(dateexpiry)) { mes = mes + "\nStudents must expire on exactly 05\/31\/20xx, or 08\/15\/20xx, or 12\/31\/20xx.\n"; } // display an alert if (mes != "") { alert(mes); return false; } else { alert("All data looks good!"); } // submit the form check_form_borrowers(); }; // Hide the SAVE button, create the VALIDATE button $('#entryform > fieldset.action').prepend('<input id="validate" type="button" value="Validate" onclick="patronValidate()" name="validate">'); $('#entryform input[name=save]').hide(); });
OPAC JQuery Statements
Changing the logo in Koha’s OPAC
- Developer: Koustubha Kale (anantcorp.com)
- Purpose: Changing the logo in Koha’s OPAC
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
A jquery based script that can be used in “opacuserjs” syspref which overcomes the image size limitation of "opacsmallimage" syspref. This script allows you to put your own logo in place of the default Koha logo while it shifts the Koha logo, prepending it with text “Powered by :” and a link back to the koha-community.org site, at the bottom of the page. The script takes care to add it below any credits you might have added by using the “opaccredits” syspref.
var logo='http://www.anantcorp.com/images/resized/anant-logo.gif'; var bkgnd=$("#opac-main-search").css("background-color"); var frgnd=$("#moresearches").css("color"); $("#opac-main-search").find("h1").remove(); $("#opac-main-search").prepend("<a id='#libraryname' href='/cgi-bin/koha/opac-main.pl' style='float: left; padding: 0pt; display: inline; margin: 0em 1em 0.3em 0.1em;'><img src="+logo+" /></a>"); $("#fluid-offset").css({ "float":"left","width":"75%" }); if($(".ft").length != 0) { $(".ft").after("<div id='kohacredit'><center><b style='color:"+frgnd+";'>Powered By :</b><a href='http://www.koha-community.org' style='text-decoration:none;' target='_blank' > <img src='/opac-tmpl/prog/images/koha-logo.gif' alt='Koha' ALIGN='ABSMIDDLE' style='background:"+bkgnd+";'/> </a></center></div>"); } else { $("div#bd").after("<div id='kohacredit'><center><b style='color:"+frgnd+";'>Powered By :</b><a href='http://www.koha-community.org' style='text-decoration:none;' target='_blank' > <img src='/opac-tmpl/prog/images/koha-logo.gif' alt='Koha' ALIGN='ABSMIDDLE' style='background:"+bkgnd+";'/> </a></center></div>"); }
On line number one of the script you can give link to your logo. On line two you can set the background color for the transparent Koha logo image and on line three the color of the words “Powered by :” is set. I have tried to read in the values of Koha OPAC’s search block’s background and text color here but you can simply replace these with your favorite colors.
Don't forget to surround the code above in$(document).ready(function(){ and });
Change the text of the OPAC login link
- Developer: Owen Leonard (Nelsonville Public Library)
- Purpose: Change the text of the OPAC login link
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
$("#members a:contains('Log in to Your Account')").text("Log In");
Rename 'Place Hold' in OPAC to 'Get It Now!'
- Developer: Owen Leonard (Nelsonville Public Library)
- Purpose: Change the 'Place Hold' text throuhgout the OPAC with 'Get it Now!'
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.2
$(document).ready(function(){ var holdlinks = $("a:contains('Place Hold'),a:contains('Place hold')"); $(holdlinks).text("Get It Now!"); }); $(window).load(function(){ $("input[value='Place Hold']").attr("value","Get It Now!"); });
Rename 'Browse Shelf' in OPAC to 'See Similar Items'
- Developer: Ian Walls (ByWater Solutions)
- Purpose: Change the 'Browse Shelf' text after the callnumber in opac-detail to 'See Similar Items'
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.4
$(document).ready(function(){ $("a:contains('Browse Shelf')").text("See Similar Items"); });
Add a link to the header only if a patron is logged into the OPAC
- Developer: Galen Charlton
- Purpose: Adds a link to the OPAC masthead only if the patron is logged into the OPAC.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
- Note: This can be generalized to alter behavior or display when a patron is logged in. For this specific example, note that somebody viewing source can see the link's URL, so be careful if using this to present super-sekrit (sic) stuff only to logged-in patrons.
if ($("#logout").length) { $("#moresearches").append("<span class=\"pipe\"> | </span><a href=\"http://bursar.example.edu/\">Pay fines</a>"); }
Change where the header logo link goes
- Developer: D Ruth Bavousett, ByWater Solutions
- Purpose: Reroute the link on the logo to someplace other than opac-main
- Status: Completed /
- Intranet or OPAC?: OPAC
- Version: 3.2+, but will probably work way, way back.
$("#libraryname a").attr('href','http://your.link.here');
Remove the textual item type description from the OPAC holdings table
- Developer: Jared Camins-Esakov (ByWater Solutions)
- Purpose: Remove the textual item type description from the OPAC holdings table
- Status: Completed /
- Intranet or OPAC?: OPAC
- Version: 3.2+
- Programming notes: The magic number '3' is used instead of Node.TEXT_NODE because Internet Explorer apparently does not export that constant into the global namespace.
$("#holdingst tbody tr td:nth-child(1)").contents().filter(function() { return this.nodeType == 3; }).remove();
Replace '--' with carriage returns in title notes on OPAC details
- Developer: D Ruth Bavousett, ByWater Solutions
- Purpose: formatting/layout hack for Title Notes section
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
$("#descriptions .content_set").html($("#descriptions .content_set").html().replace(/--/g,'<br />'));
Force suggestions table in OPAC to show "Library Staff" as manager
- Developer: D Ruth Bavousett, ByWater Solutions
- Purpose: Library desires to not name names for who managed suggestions--"Library Staff" should be shown for all
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.4
$('#suggestt tr').each(function() { $(this).find("td:nth-child(4)").html("Library Staff"); });
Change "Available for reference" note in search results to something more appropriate to ebooks
- Developer: Jared Camins-Esakov, ByWater Solutions
- Purpose: Change the text of the "Available for reference" note in OPAC search results to something more appropriate for ebooks, which may not actually be available as a physical book in the library at all.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.2+
$(".available b:contains('reference')").text("View e-resources online; If available in print, one or more copies may only be used in: ");
Hide 'Save Record' Box in OPAC
- Developer: Joy Nelson, ByWater Solutions
- Purpose: Remove the 'Save Record' box on the bib detail in the OPAC.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.4+
$(document).ready(function(){ $("#export").remove(); });
Change Text in Drop Down list for 'Save Record'
- Developer: Joy Nelson, ByWater Solutions
- Purpose: Change Text in Drop Down list for 'Save Record' from BIBTEX to Endnote
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.4+
$('#export option[value="bibtex"]').text('EndNote');
Break OPAC SearchForTitleIn out of dropdown
- Developer: Ian Walls, ByWater Solutions
- Purpose: Make the content in SearchForTitleIn always visible, instead of appearing only when the "more searches" button is clicked
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.4+
$("#furthersearches").parent().hide(); $("#furtherm").attr("class","").attr("style",""); $("#furtherm div ul li").attr("style", "list-style:none");
Hiding a library from the list in the drop-down in the OPAC
- Developer: Ed Veal, ByWater Solutions
- Purpose: This hides a library branch from the drop-down selection on the search main screen. You will need to identify the branch code and replace "CODE" with the appropriate code for the branch you wish to hide.
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: 3.6+
$("#select_library option[value='branch:CODE']").hide();
- Developer: Elliott Davis (UT Tyler)
- Purpose: Move Navigation Menu Below OpacMainSearch
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: All
$('#header-wrapper').append($('#navigation'));
Move List Dropdown
- Developer: Elliott Davis (UT Tyler)
- Purpose: Move lists dropdown to main menu
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: All
$('#listsmenulink').appendTo('.main-menu > .last');
Opac Search Results Sort
- Developer: Elliott Davis (UT Tyler)
- Purpose: Change wording in call number sort
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: All
$("option[value='call_number_asc']").html("Call Number Ascending"); $("option[value='call_number_dsc']").html("Call Number Descending");
Add a bookplate when cover images are not found
- Developer: Jared Camins-Esakov, C & P Bibliography Services
- Purpose: Replace the "No cover image" message on the OPAC with a custom bookplate
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: All
- Note: Replace "bookplate.jpg" in the script with the URL to the image you want to use
$('.no-image').css('background-image','url(bookplate.jpg)');
Show nothing when cover images are not found
- Developer: Nicole C. Engard, ByWater Solutions
- Purpose: Remove the "No cover image" message on the OPAC
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: All
$(document).ready(function(){ $('.no-image').remove(); });
Alert patrons about exhausting their renewals early when they login to the OPAC
- Developer: Paul Landers - Texas Tech University Health Sciences Center
- Purpose: Adds an alert to the top of the OPAC only if the patron is logged into the OPAC.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
- Note: When the OPAC RenewalPeriodBase preference is set to the current date, patrons can accidently exhaust their renewals early. This code will place a prominent alert at the top of the OPAC upon patron login. This code is a modified version of Galen Charlton's code Add a link to the header only if a patron is logged into the OPAC
if ($("#logout").length) { $("#members").prepend("<p style=\"text-align:center;font-size:20px;background:red;color:white;margin-right:25%;margin-left:25%\">ALERT - renewing your items early or clicking 'renew' more than once will reduce your total checkout time.</p>"); }
Move OPACResultsSidebar to the top
- Developer: Derryn Jones
- Purpose: Moves the OPACResultsSidebar to the top
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any (Tested on 3.6 - 3.10)
$("#facetcontainer.container").prepend($("#opacresultssidebar"));
Remove all links on SCO (Self-Checkout)
- Developer: Derryn Jones
- Creation Date: 2013-03-26
- Purpose: Removes all links on SCO page to stop people using the SCO as a browser (Very useful if you're using a kiosk with no back/forward buttons)
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any (Tested on 3.10)
if(/sco-main/.test(self.location.href)) { $('a').removeAttr('href') }
Hiding a library from the pickup location drop-down in the OPAC "Place Hold" screen
- Developer: George H. Williams, Latah County Library District
- Purpose: This hides a library branch from the pickup location drop-down in the "Place Hold" screen in the OPAC. This prevents patrons from having a hold delivered to the branch you specify unless that branch is their home library. Replace "BRANCHCODE" with the code for the branch you wish to remove from the drop-down.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.8
$("#bibitemloop option[value='BRANCHCODE']").hide();
Hide the CART button
- Developer: Paul Landers - Texas Tech University Health Sciences Center
- Purpose: Hide the CART button.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
- Note: Hide the CART button.
$('#cmspan').hide();
Change Browse Authorities to say Search
- Developer: Nicole C. Engard, ByWater Solutions
- Purpose: The link to search the authorities says 'browse' but it's a search, so this changes it to be clearer.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
$("a:contains('Browse by author or subject')").text("Search authorities");
Make the opac more multilingual
- Developer: Jonathan Druart, Gaetan Boisson, BibLibre
- Creation Date: (2013-06-06)
- Purpose: The system preferences for customizing OPAC regions only allow for one language, so an opac with several languages will always show the same text here whatever the language selected by the user. This allows for switching to a different language when using the selector at the bottom of the screen. To achieve this, you will need to put each language in a separate div in the concerned system preference, each div will have a class named after the value the KohaOpacLanguage cookie will take when this language is selected. You will also need to add a bit of css so that all those divs are hidden by default. (Such as "div.en, div.ar-Arab {display:none;}"). If not language is set, the default is set to english, be sure to change this if your opac doesn't use this language, as it will be used when a user first land on the website.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.10.04
$(document).ready(function(){ var url = 'https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js'; $.getScript( url, function(){ var myLang = jQuery.cookie('KohaOpacLanguage'); if(!myLang) myLang = "en"; $("div."+myLang).show(); }); });
Hide Location Column
- Developer: Nicole C. Engard, ByWater Solutions
- Purpose: This hides the location column in the holdings table in the OPAC.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.10.x
//Hide Location Column $("th#item_location").hide(); $("td.location").hide();
Hide Collection Column
- Developer: Nicole C. Engard, ByWater Solutions
- Purpose: This hides the collection column in the holdings table in the OPAC.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.10.x
//Hide Collection Column $("th#item_ccode").hide(); $("td.collection").hide();
Add additional searches to OPAC
- Developer: Jared Camins-Esakov
- Purpose: Adds additional searches to the OPAC Search type dropdown
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
- Note: Both indexes used here are custom. In order to use the Auction date index, MARC21 field 033$a would need to be indexed and linked to CCL search prefix 'adate:'. In order to use the Journal title index, MARC21 field 773$t would need to be indexed and linked to CCL search prefix 'Host-item:'.
$("select[name='idx']").append("<option value='adate'>Auction date</option><option value='Host-item,wrdl'>Journal title</option>");
Add focus to OPAC Search
- Developer: Jared Camins-Esakov
- Purpose: The opac search didn't seem to get focus. This adds that functionality.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.2.x (afaik)
$("#transl1").focus();
Append text to the OPAC search results
- Developer: Owen Leonard (Nelsonville Public Library)
- Purpose: Append text to the OPAC search results. Useful if you want to promote an alternate means of finding results (interlibrary loan?) or point the user to more resources (chat with a librarian?).
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
$(".searchresults").after("<p>Not finding what you\'re looking for? Make a <a href=\"http://koha.example.org/cgi-bin/koha/opac-suggestions.pl\">purchase suggestion</a></p>");
Change "Library Catalog" to "Keyword" in OPAC main search
- Developer: Jared Camins-Esakov
- Purpose: Changes the string "Library Catalog" to "Keyword" in the OPAC main search.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: Any
$("select[name='idx'] option:first").text('Keyword');
Remove language selection fieldset from OPAC advanced Search
- Developer: Liz Rea
- Purpose: remove language selection fieldset from OPAC advanced search
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: tested 3.4
$("#advsearch legend:contains('Language')").parent().hide();
Remove Subtype Limits from OPAC Advanced Search
- Developer: Nicole Engard
- Purpose: remove subtype selection fieldset from OPAC advanced search
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: tested 3.4
$("#advsearch legend:contains('Subtype limits')").parent().hide();
Enhanced content for the OPAC
Add direct export to RefWorks link to OPAC
- Developer: Jared Camins-Esakov, ByWater Solutions
- Purpose: Add a link to directly export a citation to RefWorks
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.2+
function getParameterByName( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } $(document).ready(function(){ $("<div id='refworks'><a href='http://www.refworks.com/express/expressimport.asp?vendor=Koha&filter=RIS%20Format&encoding=65001&url=http%3A%2F%2F" + location.host + "%2Fcgi-bin%2Fkoha%2Fopac-export.pl%3Fop%3Dexport%26format%3Dris%26bib%3D" + getParameterByName('biblionumber') + "' target='RefWorksMain'>Export to RefWorks</a></div>").appendTo("#export"); $("#userbasket #toolbar .download").parent().after("<li><a class='download' href='http://www.refworks.com/express/expressimport.asp?vendor=Koha&filter=RIS%20Format&encoding=65001&url=http%3A%2F%2F" + location.host + "%2Fcgi-bin%2Fkoha%2Fopac-downloadcart.pl%3Fformat%3Dris%26bib_list%3D" + encodeURIComponent(getParameterByName('bib_list')) + "' target='RefWorksMain'>Export to RefWorks</a></li>") $("#usershelves #toolbar .download").after("<span id='refworks'><a class='download tag_hides' href='http://www.refworks.com/express/expressimport.asp?vendor=Koha&filter=RIS%20Format&encoding=65001&url=http%3A%2F%2F" + location.host + "%2Fcgi-bin%2Fkoha%2Fopac-downloadshelf.pl%3Fformat%3Dris%26shelfid%3D" + encodeURIComponent(getParameterByName('viewshelf')) + "' target='RefWorksMain'>Export to RefWorks</a></span>"); });
Add a link to map the publisher's location
- Developer: Jared Camins-Esakov, C & P Bibliography Services
- Purpose: Add a link to map the publisher's location.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: All
- Note: This particular implementation is for MARC21, and retrieves the location from an authority-controlled 751. In order to identify the correct 751, it looks for the relator code 'pup' (place of publication).
$.get("/cgi-bin/koha/opac-export.pl", { bib: $("input[name='bib']").val(), format: "marcxml" }, function(data){ $(".publisher > span[class='label']:first").append("<a target='_blank' href='http://maps.google.com/maps?q=" + $(data).find("datafield[tag='751'] > subfield[code='4']:contains('pup')").parent().find("subfield[code='a']").text() + "'><img src='/opac-tmpl/prog/famfamfam/MP.png' alt='Show publisher on map' title='Show publisher on map' /></a>"); } );
- Note: This particular implementation is for MARC21, and retrieves the location from the 260$a, then removes any trailing punctuation. For all but the most recent of books, this is likely to result in an inaccurate (or useless) map.
$.get("/cgi-bin/koha/opac-export.pl", { bib: $("input[name='bib']").val(), format: "marcxml" }, function(data){ $(".publisher > span[class='label']:first").append("<a target='_blank' href='http://maps.google.com/maps?q=" + $(data).find("datafield[tag='260'] > subfield[code='a']").text().replace(/\W+$/, '') + "'><img src='/opac-tmpl/prog/famfamfam/MP.png' alt='Show publisher on map' title='Show publisher on map' /></a>"); } );
Add links out to Wikipedia for authors
- Developer: Jared Camins-Esakov, C & P Bibliography Services
- Purpose: Add a link for each author to bring the user to a Wikipedia search
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: All
$("h5.author > a").each(function() { $("<a href='http://en.wikipedia.org/wiki/Special:Search?search=" + encodeURI($(this).text().replace(/\[.*\]/g, '').replace(/[\W\d]+$/, '')) + "' title='Search for this person in Wikipedia'><img src='http://upload.wikimedia.org/wikipedia/commons/b/b0/Wikipedia-favicon.png'/></a>").insertAfter($(this)); });
Add iDreamBooks.com Readometer to OPAC
- Developer: C & P Bibliography Services
- Purpose: Add a "Readometer" from iDreamBooks.com to the OPAC to show aggregated information about reviews of the book by professional critics.
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.6+ with XSLT enabled for the OPAC details page
- Note: This is an updated version that offers better web browser compatibility. Anyone using the iFrame version originally posted should switch.
var isbn = $(".isbn:last").text().split(" ")[1]; if (isbn) { isbn = isbn.replace(/\W*$/, ''); if ($.browser.msie && parseInt($.browser.version, 10) >= 8 && window.XDomainRequest) { // Use Microsoft XDR for IE version 8 or above var xdr = new XDomainRequest(); xdr.open("get", "http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e"); xdr.onload = function() { if (! typeof(json) == 'undefined') { json = 'json = '+xdr.responseText; // the string now looks like.. json = { ... }; eval(json); // json is now a regular JSON object $(".title").append('<a href="'+json.book.detail_link+'" id="idreambooksreadometer"><img src="http://idreambooks.com/remotereadometer/'+isbn+'.jpg" alt="'+json.book.title+' by '+json.book.author+'" title="Rating based on reviews of '+json.book.title+'"></a>'); } } xdr.send(); } else { $.getJSON("http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e", function(json){ if (! typeof(json) == 'undefined') { $(".title").append('<a href="'+json.book.detail_link+'" id="idreambooksreadometer"><img src="http://idreambooks.com/remotereadometer/'+isbn+'.jpg" alt="'+json.book.title+' by '+json.book.author+'" title="Rating based on reviews of '+json.book.title+'"></a>'); } }); } }
You will also need the following line of CSS in your OPACUserCSS:
#idreambooksreadometer { float: right; }
Add iDreamBooks.com reviews tab to OPAC (3.6-3.8)
- Developer: C & P Bibliography Services
- Purpose: Add a tab with snippets of reviews from iDreamBooks.com to the OPAC
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.6-3.8 with XSLT enabled for the OPAC details page (3.10 script below)
var isbn = $(".isbn:last").text().split(" ")[1]; if (isbn) { isbn = isbn.replace(/\W*$/, ''); if ($.browser.msie && parseInt($.browser.version, 10) >= 8 && window.XDomainRequest) { // Use Microsoft XDR for IE version 8 or above var xdr = new XDomainRequest(); xdr.open("get", "http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e"); xdr.onload = function() { json = 'json = '+xdr.responseText; // the string now looks like.. json = { ... }; eval(json); // json is now a regular JSON object parseIDBJSON(json); // parse using same function as for jQuery's success event } xdr.send(); } else { $.getJSON("http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e", function(json){ parseIDBJSON(json); }); } } // NOTE THAT THE CODE BELOW SHOULD NOT GO IN $(document).ready. function parseIDBJSON( json ) { if(json.total_results > 0 && json.book.rating > 0){ var isbn = $(".isbn:last").text().split(" ")[1]; //build new tab for critic reviews $("#bibliodescriptions").append('<div id="idb_critic_reviews"><div id="idb_review_snippets"></div><span><a id="seemoreidb">More book reviews at iDreamBooks.com</a></span></div>'); $("#bibliodescriptions ul").tabs('add', '#idb_critic_reviews', 'Book reviews by critics ( '+json.book.review_count+' )'); //append happy-sad cloud review $("#catalogue_detail_biblio").append("<span class='idreambookssummary results_summary'><a href='"+json.book.detail_link+"'><img src='"+json.book.to_read_or_not_small+"' alt='"+json.book.title+" by "+json.book.author+"' title='Rating based on reviews of "+json.book.title+"'>"+json.book.rating+"%</a> <a href='http://www.idreambooks.com/'>rating based on reviews at iDreamBooks.com</a></span>"); //insert data into Book reviews tab $.each(json.book.critic_reviews, function(){ $("#idb_review_snippets").append("<div class='review'><div><a href='"+this.review_link+"'>"+this.source+"</a></div><div>\"..."+this.snippet+"...\"</div><div>Review date: "+this.review_date+"</div><div><a class='reviewlink' href='"+json.book.detail_link+"'>Review result: "+this.pos_or_neg+" <img src='"+this.smiley_or_sad_small+"' alt='iDreamBooks.com rating' title='"+this.pos_or_neg+"' /></a></div></div>"); }); $("#seemoreidb").attr('href', json.book.detail_link); } }
You will also need the following CSS added to your OPACUserCSS syspref:
.review { margin-bottom: 20px; } a.idreambooksrating { font-size: 30px; color: #29ADE4; padding-left: 85px; line-height: 30px; text-decoration: none; } .idreambookslegend { font-size: small; } a.reviewlink,a.reviewlink:visited { text-decoration: none; color: black; font-weight: normal; } .idreambookssummary a { color: #707070; text-decoration: none; } .idreambookssummary img, .idbresult img { vertical-align: middle; } .idbresult { color: #29ADE4; text-align: center; margin: 0.5em; padding: 0.5em; } .idbresult a, .idbresult a:visited { text-decoration: none; color: #29ADE4; } .idbresult img { padding-right: 6px; }
Add iDreamBooks.com reviews tab to OPAC (3.10+)
- Developer: C & P Bibliography Services
- Purpose: Add a tab with snippets of reviews from iDreamBooks.com to the OPAC
- Status: Completed
- Intranet or OPAC?: OPAC
- Version: 3.10+ with XSLT enabled for the OPAC details page (3.6-3.8 script above)
var isbn = $(".isbn:last").text().split(" ")[1]; if (isbn) { isbn = isbn.replace(/\W*$/, ''); if ($.browser.msie && parseInt($.browser.version, 10) >= 8 && window.XDomainRequest) { // Use Microsoft XDR for IE version 8 or above var xdr = new XDomainRequest(); xdr.open("get", "http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e"); xdr.onload = function() { json = 'json = '+xdr.responseText; // the string now looks like.. json = { ... }; eval(json); // json is now a regular JSON object parseIDBJSON(json); // parse using same function as for jQuery's success event } xdr.send(); } else { $.getJSON("http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e", function(json){ parseIDBJSON(json); }); } } function parseIDBJSON( json ) { if(json.total_results > 0 && json.book.rating > 0){ var isbn = $(".isbn:last").text().split(" ")[1]; //build new tab for critic reviews $("#bibliodescriptions").append('<div id="idb_critic_reviews"><div id="idb_review_snippets"></div><span><a id="seemoreidb">More book reviews at iDreamBooks.com</a></span></div>'); $("#bibliodescriptions").tabs('add', '#idb_critic_reviews', 'Book reviews by critics ( '+json.book.review_count+' )'); //append happy-sad cloud review $("#catalogue_detail_biblio").append("<span class='idreambookssummary results_summary'><a href='"+json.book.detail_link+"'><img src='"+json.book.to_read_or_not_small+"' alt='"+json.book.title+" by "+json.book.author+"' title='Rating based on reviews of "+json.book.title+"'>"+json.book.rating+"%</a> <a href='http://www.idreambooks.com/'>rating based on reviews at iDreamBooks.com</a></span>"); //insert data into Book reviews tab $.each(json.book.critic_reviews, function(){ $("#idb_review_snippets").append("<div class='review'><div><a href='"+this.review_link+"'>"+this.source+"</a></div><div>\"..."+this.snippet+"...\"</div><div>Review date: "+this.review_date+"</div><div><a class='reviewlink' href='"+json.book.detail_link+"'>Review result: "+this.pos_or_neg+" <img src='"+this.smiley_or_sad_small+"' alt='iDreamBooks.com rating' title='"+this.pos_or_neg+"' /></a></div></div>"); }); $("#seemoreidb").attr('href', json.book.detail_link); $("#tab_idb_critic_reviews").show(); } }
You will also need the following CSS added to your OPACUserCSS syspref:
.review { margin-bottom: 20px; } a.idreambooksrating { font-size: 30px; color: #29ADE4; padding-left: 85px; line-height: 30px; text-decoration: none; } .idreambookslegend { font-size: small; } a.reviewlink,a.reviewlink:visited { text-decoration: none; color: black; font-weight: normal; } .idreambookssummary a { color: #707070; text-decoration: none; } .idreambookssummary img, .idbresult img { vertical-align: middle; } .idbresult { color: #29ADE4; text-align: center; margin: 0.5em; padding: 0.5em; } .idbresult a, .idbresult a:visited { text-decoration: none; color: #29ADE4; } .idbresult img { padding-right: 6px; }
Enhanced content for the Staff
Add VIAF autosuggest for new NAME authorities
- Developer: Stefano Bargioni (Pontificia Università della Santa Croce) - 2012-06-22
- Purpose: Allow cataloguers to search VIAF database while creating new NAME authorities
- Status: Completed
- Intranet or OPAC?: Intranet
- Version: tested on Koha 3.2
if (document.location.href.indexOf('_NAME') == document.location.href.length-5 || // match /cgi-bin/koha/authorities/authorities.pl?authtypecode=....._NAME document.location.href.indexOf('authorities/authorities.pl?authid=')>-1) { if (document.location.href.indexOf('authorities/authorities.pl?authid=')>-1) { var title = $('h1').text(); if (title.indexOf('Name')!=title.length-4) return; // not available for non-NAME headings } function myUpperCase(s) { if (s.indexOf('nli')>-1) return 'NLI'+s.substr(3); return s.toUpperCase(); } function autoComplete() { $('head').append('<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/base/jquery.ui.all.css">'); $($('ul.toolbar')[0]).append('\ <div class="ui-widget" style="margin-top:5px">\ <label for="viaf">VIAF Autosuggest:</label> <input type="text" style="font-size:0.9em" id="viaf" size="80" title="digitare almeno i primi 3 caratteri di un nome">\ </div>\ '); $(function() { $( "#viaf" ).autocomplete({ source: function( request, response ) { $.ajax({ url: "http://viaf.org/viaf/AutoSuggest", dataType: "jsonp", data: { query: request.term }, success: function( data ) { if (!data.result) return false; response( $.map( data.result, function( item ) { return { label: item.term, value: item.term, item: item } })); } }); }, minLength: 3, select: function( event, ui ) { $('#viaf_table').remove(); var H = new Array; H.push('<table id="viaf_table">'); H.push('<tr><td colspan="3">'+ui.item.item.term); var viafid = ui.item.item.viafid; // VIAF permalink H.push('<tr><td><a target="viaf" href="http://viaf.org/viaf/'+viafid+'"><img src="http://viaf.org/viaf/images/viaf-link.png" class="viaf_flag"></a><td>VIAF<td>'+viafid); for (var i in ui.item.item) { var flag = '<img src="http://viaf.org/viaf/images/flags/'+myUpperCase(i)+'.png" class="viaf_flag">'; if (i!='viafid' && i!='term') { if (myUpperCase(i)=='LC') { // LoC permalink H.push('<tr><td><a target="loc" href="http://lccn.loc.gov/'+ui.item.item[i]+'">'+flag+'</a><td>'+myUpperCase(i)+'<td>'+ui.item.item[i]); } else { H.push('<tr><td>'+flag+'<td>'+myUpperCase(i)+'<td>'+ui.item.item[i]); } } } H.push('</table>'); $('#viaf').after(H.join('')); $('#viaf_table').css('margin-top','5px'); $('.viaf_flag').css('border','0'); }, open: function() {$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); $('ul li').css('list-style-type','none'); }, close: function() {$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );} }); }); } // load jquery-ui to get autocomplete method $.ajax({ url: 'http://code.jquery.com/ui/1.8.19/jquery-ui.min.js', dataType: "script", success: autoComplete }); }
Change the default view on OPAC detail pages
- Developer: Owen Leonard
- Creation Date: 2012-10-19
- Purpose: to change the default view on OPAC or Intranet detail pages from holdings to, in this case, the title notes tab. The "1" indicates the number of the tab, starting with 0, so for title notes, you would need tab 1.
- Status: Completed
- Intranet or OPAC?: OPAC or Intranet
- Version:3.8. This code will not work with 3.10+
$('#bibliodescriptions > ul').tabs('select', 1);