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.
109 lines
4.5 KiB
109 lines
4.5 KiB
12 years ago
|
Drupal.behaviors.roblib_search_eds = {
|
||
8 years ago
|
attach: function (context, settings) {
|
||
|
$url = settings.roblib_search_eds.search_url;
|
||
7 years ago
|
profile = settings.roblib_search_eds.eds_profile;
|
||
3 years ago
|
proxy_url = "https://proxy.library.upei.ca/login?url=";
|
||
8 years ago
|
jQuery.getJSON($url, function (data) {
|
||
|
var items = [];
|
||
|
var numberOfDocs = 0;
|
||
|
try {
|
||
7 years ago
|
numberOfDocs = data.numFound;
|
||
8 years ago
|
} 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();
|
||
7 years ago
|
var queries = [];
|
||
|
jQuery.each(data.queries, function (key7, query) {
|
||
|
queries.push(query.query);
|
||
|
})
|
||
6 years ago
|
var query_str = encodeURI(data.queries[0].query);
|
||
7 years ago
|
var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profid=lite&mode=bool&lang=en&bquery=';
|
||
7 years ago
|
|
||
7 years ago
|
jQuery.each(data.documents, function (key, val) {
|
||
8 years ago
|
id = 'roblib-search-eds-' + counter;
|
||
|
divs[counter++] = id;
|
||
|
if (typeof val.Items !== 'undefined') {
|
||
|
items.push('<div class ="roblib-search-row" id="' + id + '">');
|
||
7 years ago
|
if (typeof val.Items.Title !== 'undefined') {
|
||
|
items.push('<div class="roblib-title eds">');
|
||
7 years ago
|
items.push('<a href="' + proxy_url + val.PLink + '&scope=site">' + val.Items.Title.Data + '</a></div>');
|
||
11 years ago
|
}
|
||
7 years ago
|
val.PubType == 'Book' ? pubType = 'Print Book' : pubType = val.PubType;
|
||
8 years ago
|
|
||
8 years ago
|
pubYear = val.RecordInfo.BibRelationships.IsPartOfRelationships["date"];
|
||
|
!pubYear ? pubYear = " " : pubYear = pubYear[0]["Y"];
|
||
8 years ago
|
|
||
8 years ago
|
items.push('<div class="eds-type"><span class="eds-pubyear">' + pubYear + '</span> - ' + pubType + '</div>');
|
||
|
|
||
8 years ago
|
var roblib_authors =[];
|
||
8 years ago
|
jQuery.each(val.RecordInfo.BibRelationships.HasContributorRelationships, function (key3, author) {
|
||
8 years ago
|
roblib_authors.push(author.NameFull);
|
||
8 years ago
|
})
|
||
8 years ago
|
|
||
|
items.push('<div class="eds-sor">');
|
||
|
roblib_authors = roblib_shorten(roblib_authors.join('; '), 50, " ");
|
||
8 years ago
|
items.push(roblib_authors);
|
||
|
items.push('</div>');
|
||
8 years ago
|
|
||
|
var url;
|
||
7 years ago
|
!val.Items.URL ? url = " " : url = val.Items.URL.Data;
|
||
8 years ago
|
if(url) {
|
||
|
items.push('<div class="eds-url">' + url + '</div>');
|
||
|
}
|
||
12 years ago
|
|
||
8 years ago
|
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>';
|
||
|
items.push('<div class="eds-catalog-link">' + catalogUrl + '</div>');
|
||
|
}
|
||
|
}
|
||
8 years ago
|
items.push('</div>');
|
||
7 years ago
|
} else {
|
||
3 years ago
|
items.push('<div class ="roblib-search-row roblib-eds-unauthorized" id="\' + id + \'">You must login to view this result, <a href="https://proxy.library.upei.ca/login?url=' + href_str + query_str + '" id="eds-unauthorized-result">click here to login</a></div>' );
|
||
8 years ago
|
}
|
||
12 years ago
|
});
|
||
8 years ago
|
jQuery('#' + 'roblib-search-content-eds').empty().append(items.join(''));
|
||
|
}
|
||
7 years ago
|
var non_upei_link = '';
|
||
7 years ago
|
var upei_link = '<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results">SEE ALL (' + data.recordCount + ')</a> ';
|
||
7 years ago
|
if(!data.is_local_ip) {
|
||
6 years ago
|
non_upei_link = '<a href="' + href_str + query_str + '&authtype=ip,guest" id="eds-non-upei-see_all_results">[Non-UPEI]</a>';
|
||
7 years ago
|
upei_link = upei_link + non_upei_link;
|
||
7 years ago
|
}
|
||
|
jQuery('#roblib-search-eds-more').empty().append(upei_link);
|
||
|
jQuery('#roblib-eds-books-more-results').empty().append(upei_link);
|
||
7 years ago
|
jQuery('#roblib-eds-books-toc').empty().append('<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results-toc">Books (' + data.recordCount + ')</a>');
|
||
8 years ago
|
|
||
|
});
|
||
|
}
|
||
12 years ago
|
}
|
||
11 years ago
|
|
||
7 years ago
|
|
||
8 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;
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
function roblib_shorten(str, maxLen, separator) {
|
||
|
if (str.length <= maxLen) return str;
|
||
|
return str.substr(0, str.lastIndexOf(separator, maxLen)) + ' et al.';
|
||
|
}
|
||
|
|
||
|
|