Bento box search with multiple targets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.2 KiB

Drupal.behaviors.roblib_search_evergreen = {
attach: function(context, settings) {
url = settings.roblib_search_evergreen.search_url;
jQuery.getJSON(url, function(data) {
var items = [];
if(data.length < 1){
jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results');
} else {
jQuery.each(data, function(key, val) {
items.push('<div class ="roblib-search-row">');
items.push('<div class="roblib-title evergreen">');
if (typeof val.title !== 'undefined') {
items.push('<a href = "'+val.url+'">'+val.title);
}
if (typeof val.subtitle !== 'undefined') {
items.push(' ' + val.subtitle);
}
items.push('</a></div>');
if (typeof val.sor !== 'undefined') {
items.push('<div class="evergreen-sor">' + val.sor +'</div>');
}
if (typeof val.date !== 'undefined') {
items.push('<div class="evergreen-date">' + val.date + '</div>')
}
if(typeof val.holdings !== 'undefined'){
items.push('<div class="evergreen-holdings">');
jQuery.each(val.holdings, function(key2, val2){
roblibEvergreenAddHoldings(val2, items);
})
items.push('</div>')
}
items.push('</div>');
});
}
jQuery('#roblib-search-content-evergreen').empty().append(items.join(''));
jQuery('#roblib-search-evergreen-more').empty().append('<a href = "' + data.catalogBaseSearchUrl + '">See all ' + data.numberOfRecords + ' results</a>');
});
}
}
function roblibEvergreenAddHoldings(holdings, items){
items.push('<div class="evergreen-holdings-item">' + holdings.call_number + ' ' + holdings.availability + '</div>');
}