Drupal.behaviors.roblib_search_evergreen = {
attach: function(context, settings) {
url = settings.roblib_search_evergreen.search_url;
jQuery.getJSON(url, function(data) {
var items = [];
var numberOfDocs = 0;
try {
numberOfDocs = data.numberOfRecords;
} catch (err) {
numberOfDocs = 0;
}
if(numberOfDocs === undefined || numberOfDocs < 1){
jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results');
jQuery('.pane-roblib-search-evergreen-roblib-search-evergreen-results').hide();
} else {
var counter = 0;
var divs = new Array();
var content = new Array();
jQuery.each(data, function(key, val) {
id = 'roblib_search_evergreen_' + counter;
populatePopupDivs(content, val, counter);
divs[counter++] = id;
items.push('
');
items.push('
');
if (typeof val.sor !== 'undefined') {
items.push('
' + val.sor +'
');
}
if (typeof val.date !== 'undefined') {
items.push('
' + val.date + '
')
}
if(typeof val.holdings !== 'undefined'){
items.push('
');
jQuery.each(val.holdings, function(key2, val2){
roblibEvergreenAddHoldings(val2, items);
})
items.push('
')
}
if(typeof val.electronic_holdings !== 'undefined'){
items.push('
');
jQuery.each(val.electronic_holdings, function(key2, val2){
roblibEvergreenAddElectronicHoldings(val2, items);
})
items.push('
')
}
items.push('
');
});
jQuery('#roblib-search-content-evergreen').empty().append(items.join(''));
qtipify(divs, content, 'More Info');
}
jQuery('#roblib-search-evergreen-more').empty().append('See all results');
});
}
}
function populatePopupDivs(content, val, counter){
content[counter] = '';
var placeOfPublication = '';
if(typeof val.pop !== 'undefined'){
content[counter] += 'Publisher: ' + val.pop ;
placeOfPublication = '
';
}
if(typeof val.pop !== 'undefined' ){
placeOfPublication = val.publisher + ' ' +placeOfPublication;
}
content[counter] += placeOfPublication;
if(typeof val.numofpages !== 'undefined'){
content[counter] += 'Number of Pages: ' + val.numofpages +'
';
}
if(typeof val.date !== 'undefined'){
content[counter] += '';
}
var subjects = '';
if(typeof val.subjectsa !== 'undefined'){
subjects += val.subjectsa;
}
if(typeof val.subjectsb !== 'undefined'){
subjects += ' ' + val.subjectsb;
}
if(typeof val.subjectsc !== 'undefined'){
subjects += ' ' + val.subjectsc;
}
if(subjects){
content[counter] += 'Subjects: ' + subjects + '
';
}
}
function roblibEvergreenAddHoldings(holdings, items){
items.push('' + holdings.call_number + ' - ' + holdings.location +' (' + holdings.availability + ')
');
}
function roblibEvergreenAddElectronicHoldings(holdings, items){
items.push('');
}