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.

104 lines
4.3 KiB

Drupal.behaviors.roblib_search_eds = {
7 years ago
attach: function (context, settings) {
$url = settings.roblib_search_eds.search_url;
profile = 'eds'; //settings.roblib_search_eds.eds_profile;
jQuery.getJSON($url, function (data) {
var items = [];
var numberOfDocs = 0;
try {
numberOfDocs = data.records.length;
} catch (err) {
// do nothing leave docLength at 0
}
if (numberOfDocs < 1) {
jQuery('#' + 'roblib-search-content-eds').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-eds-roblib-search-eds-results').hide();
} else {
var counter = 0;
var divs = new Array();
var content = new Array();
jQuery.each(data.records, function (key, val) {
id = 'roblib-search-eds-' + counter;
divs[counter++] = id;
if (typeof val.Items !== 'undefined') {
items.push('<div class ="roblib-search-row" id="' + id + '">');
if (typeof val.Items.Ti !== 'undefined') {
jQuery.each(val.RecordInfo.BibEntity.Titles, function (key2, val2) {
7 years ago
items.push('<div class="roblib-title eds">');
items.push('<a href="http://proxy.library.upei.ca/login?url=' + val.PLink + '&scope=site">' + val2.TitleFull + '</a></div>');
7 years ago
})
}
pubType = val.pubType;
7 years ago
pubYear = val.RecordInfo.BibRelationships.IsPartOfRelationships["date"];
!pubYear ? pubYear = " " : pubYear = pubYear[0]["Y"];
items.push('<div class="eds-type"><span class="eds-pubyear">' + pubYear + '</span> - ' + pubType + '</div>');
var roblib_authors =[];
7 years ago
jQuery.each(val.RecordInfo.BibRelationships.HasContributorRelationships, function (key3, author) {
roblib_authors.push(author.NameFull);
})
items.push('<div class="eds-sor">');
roblib_authors = roblib_shorten(roblib_authors.join('; '), 50, " ");
7 years ago
items.push(roblib_authors);
items.push('</div>');
var url;
!val.Items.URL ? url = " " : url = val.Items.URL[0].Data;
if(url) {
items.push('<div class="eds-url">' + url + '</div>');
}
if(pubType == "Print Book") {
anNumber = val.An.split(".");
if (anNumber[0] && anNumber[0] == 'upei') {
catalogUrl = '<a href="http://islandpines.roblib.upei.ca/eg/opac/record/' + anNumber[1] +
'">View in UPEI Catalogue</a>';
}
if (catalogUrl) {
items.push('<div class="eds-catalog-link">' + catalogUrl + '</div>');
}
}
7 years ago
items.push('</div>');
}
});
7 years ago
jQuery('#' + 'roblib-search-content-eds').empty().append(items.join(''));
}
var queries = [];
jQuery.each(data.queries, function (key7, query) {
queries.push(query.query);
})
var query_str = data.queries[0].query;
//var host = "http://eds-api.ebscohost.com";
//var get = "/edsapi/rest/Search?query=history&searchmode=all&resultsperpage=20&pagenumber=1&sort=relevance&highlight=y&includefacets=y&facetfilter=1%2cSourceType%3aMagazines%2cSourceType%3aNews%2cSourceType%3aAcademic+Journals%2cSourceType%3aConference+Materials&view=detailed";
var href_str = 'http://search.ebscohost.com/login.aspx?direct=true&site=ehost-live&scope=site&type=1&custid=uprince&groupid=main&profid=' + profile + '&mode=bool&lang=en&bquery=';
jQuery('#roblib-search-eds-more').empty().append('<a href="http://proxy.library.upei.ca/login?url=' + href_str + query_str + '" id="see_all_results">See all results (' + data.recordCount + ')</a>');
jQuery('#roblib-eds-books-more-results').empty().append('<a href="http://proxy.library.upei.ca/login?url=' + href_str + query_str + '" id="see_all_results">See all results (' + data.recordCount + ')</a>');
7 years ago
});
}
}
function roblib_intersects(a, b) {
var d = {};
var results = [];
for (var i = 0; i < b.length; i++) {
d[b[i]] = true;
}
for (var j = 0; j < a.length; j++) {
if (d[a[j]])
results.push(a[j]);
}
return results;
}
function roblib_shorten(str, maxLen, separator) {
if (str.length <= maxLen) return str;
return str.substr(0, str.lastIndexOf(separator, maxLen)) + ' et al.';
}