Lucas shares 5 easy tips for adding jquery, CSS, and HTML to your Koha system.
Use an Array to only show certain values on ALL OPAC Advanced Search dropdowns
/*Use an Array to only show certain values on ALL OPAC Advanced Search dropdowns*/
$(document).ready(function () {
if ( $('#advsearch').length ) {
$('[id^=search-field_] option').hide();
let values = ['kw' ,'su,wrdl', 'ti' , 'se,wrdl', 'callnum' , 'au,wrdl' , 'pb,wrdl']
$('[id^=search-field_] option').each( function() {
if( $.inArray ($(this).val(), values) !== -1) {
$(this).show();
}
})
}
});
Use a JS Object to make groups in OPAC Advanced Search
/*USe a JS Object to make groups in OPAC Advanced Search*/
$(document).ready(function () {
if ( $('#advsearch').length ) {
const groupValues = {
Video: ['mc-ccode:DVD' , 'mc-ccode:EDDVD' , 'mc-ccode:VIDEO' , 'mc-ccode:SPECVID' , 'mc-ccode:EVIDEO'],
Theses: ['mc-ccode:THESES'],
Technology: ['mc-ccode:ROOM57', 'mc-ccode:TECH', 'mc-ccode:CIRCDESK'],
"Streaming Media": ['mc-ccode:AV' , 'mc-ccode:EVIDEO' , 'mc-ccode:WWW' , 'mc-ccode:EAUDIO'],
"Special Collections": ['mc-ccode:CC' , 'mc-ccode:COLORADO' , 'mc-ccode:CCO', 'mc-ccode:COFOLIO' , 'mc-ccode:COO' , 'mc-ccode:RARE' , 'mc-ccode:RAREFOLIO' , 'mc-ccode:COP' , 'mc-ccode:ECC' , 'mc-ccode:MANUSCRIPT' , 'mc-ccode:PHOTO' , 'mc-ccode:RAREO' , 'mc-ccode:RARES' , 'mc-ccode:SLIDE' , 'mc-ccode:SPECED' , 'mc-ccode:SPECEDF' , 'mc-ccode:SPECEDO' , 'mc-ccode:SPECVID' , 'mc-ccode:SPECEDS' , 'mc-ccode:SPECEDF'],
Scores: ['mc-ccode:MINISCORE', 'mc-ccode:ORCHESTRA', 'mc-ccode:SCORES'],
Reference: ['mc-ccode:EREF' , 'mc-ccode:REF'],
Periodicals: ['mc-ccode:PERIODICAL' , 'mc-ccode:EPER' , 'mc-ccode:COP'],
Newspapers: ['mc-ccode:Newspapers'],
Maps: ['mc-ccode:MAPS', 'mc-ccode:USFMAP', 'mc-ccode:USMAP'],
"Government Documents": ['mc-ccode:EAUDIO' , 'mc-ccode:COMICRO' , 'mc-ccode:USDOC' , 'mc-ccode:USCD' , 'mc-ccode:USINDEX' , 'mc-ccode:USMICRO' , 'mc-ccode:USDOCO' , 'mc-ccode:USCENSUS' , 'mc-ccode:USOMAP' , 'mc-ccode:USFMAP'],
eBooks: ['mc-ccode:EREF' , 'mc-ccode:EBOOK'],
Books: ['mc-ccode:ART', 'mc-ccode:Art Folio' , 'mc-ccode:BOOKS' , 'value="mc-ccode:SCORES' , 'mc-ccode:CURRICULUM', 'mc-ccode:EDSCORE' , 'mc-ccode:FOLIO' , 'mc-ccode:LEISURE' , 'mc-ccode:MAIN' , 'mc-ccode:NEW' , 'mc-ccode:OVERSIZE' , 'mc-ccode:REF' , 'mc-ccode:LIT'],
Audio: ['mc-ccode:AUDIO' , 'mc-ccode:CASSETTE' , 'mc-ccode:TUTTCD' , 'mc-ccode:SEAYCD' , 'mc-ccode:LP' , 'mc-ccode:EAUDIO']
}
$('#advsearch-ccode').prepend('<fieldset class="groups"></fieldset>')
$('#advsearch-ccode .groups').prepend('<hr><legend>Limit by collection group:</legend>');
let currentGroups = Object.keys(groupValues);
function buildChecks(values) {
$('#advsearch-ccode .groups').prepend(
'<div class="span3" style="margin-left:0;">' +
'<input type="checkbox" id="'+values+'" class="group">' +
'<label"> '+values+'' +
'</label"></div>'
)
}
currentGroups.forEach(buildChecks);
function addGroups(values) {
$('input[value="'+values+'"]').prop('checked' , true);
$('input[value="'+values+'"]').parent().addClass('cGroup');
}
function removeGroups(values) {
$('input[value="'+values+'"]').prop('checked' , false);
$('input[value="'+values+'"]').parent().removeClass('cGroup');
}
$( ".group" ).change( function () {
let currentID = $(this).attr('id');
let currentValues = Object.values(groupValues[currentID]);
if ( $(this).is(':checked') ) {
currentValues.forEach(addGroups);
} else {
currentValues.forEach(removeGroups);
}
})
}
});
Change Material Type Icons into Font Awesome on OPAC
/*Change Material Type Icons into Font Awesome on OPAC*/
$(document).ready(function () {
if ( $('#results').length || $('#opac-detail').length ) {
/*list the icon to replace by class name and the name of the fa icon class*/
const listOfIcons = {
article: ['mt_icon_AR' , 'fa-book'],
book: ['mt_icon_BK', 'fa-book'],
kit: ['mt_icon_MM', 'fa-balance-scale'],
computer: ['mt_icon_CS', 'fa-laptop'],
map: ['mt_icon_MP' , 'fa-map'],
visual: ['mt_icon_VM' , 'fa-film'],
picture: ['mt_icon_GR', 'fa-picture-o'],
pictures: ['.format[src=""/opac-tmpl/lib/famfamfam/pictures.png""]' , 'fa-picture-o'],
object: ['mt_icon_OB' , 'fa-cube'],
score: ['mt_icon_PR' , 'fa-music'],
sound: ['mt_icon_MU' , 'fa-music'],
music: ['mt_icon_PR', 'fa-music'],
continueresource: ['mt_icon_SE' , 'fa-newspaper-o'],
biography: ['natureofcontents[alt="biography"]', 'fa-user'],
cd: ['format[src="/opac-tmpl/lib/famfamfam/cd.png"]', 'fa-dot-circle-o'],
dvd: ['format[src="/opac-tmpl/lib/famfamfam/dvd.png"]' , 'fa-dot-circle'],
globe: ['format[src="/opac-tmpl/lib/famfamfam/world.png"]', 'fa-globe'],
chart: ['format[src="/opac-tmpl/lib/famfamfam/chart_curve.png"]', 'fa-line-chart'],
pencil: ['format[src="/opac-tmpl/lib/famfamfam/pencil.png"]', 'fa-pencil'],
note: ['format[src="/opac-tmpl/lib/famfamfam/note.png"]' , 'fa-sticky-note-o' ],
paint: ['format[src="/opac-tmpl/lib/famfamfam/paintbrush.png"]' , 'fa-paint-brush'],
magnify: ['format[src=""/opac-tmpl/lib/famfamfam/magnifier.png""]' , 'fa-search '],
}
function makeIconsFA(className, faIcon) {
$(`.${className}`).each( function() {
$(this).replaceWith(`<i class="fa ${faIcon} ${className}" aria-hidden="true"></i>`)
} )
}
Object.keys(listOfIcons).forEach(function (item) {
let array = listOfIcons[item];
makeIconsFA(array[0], array[1])
});
}
});
Remove A Column from a DataTable
/*Remove A Column from a DataTable*/
$(document).ready(function () {
if ( $('#catalog_detail').length ) {
$( document ).ajaxComplete(function() {
var table = $('#holdings_table').DataTable();
let date_accessioned_column = $('#holdings_table th:contains("Date accessioned")').index();
table.columns( [date_accessioned_column] ).visible(false ).draw();
})
}
});
Re-order a column from a DataTable
/*Re-order a column from a DataTable*/
$(document).ready(function () {
if ( $('#catalog_detail').length ) {
$(window).load(function () {
var table = $('#holdings_table').DataTable();
let last_seen_column = $('#holdings_table th:contains("Last seen")').index();
table
.order( [ last_seen_column, 'asc' ] )
.draw()
})
}
});
Webinar
Presenter: Lucas Gass, Web Design and Developer
When: Monday, April 20, 2020
Time: 1:30 PM - 2:00 PM Eastern Time (US and Canada)
Register in Advance for this webinar.
After registering, you will receive a confirmation email containing information about joining the webinar. We will be recording this town hall and make it available on-demand after the LIVE presentation.
Read more by Lucas Gass