Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Summon1-use360API.js: The orginal script is called Summon-clicks.js which is made by Matthew Reidsma & Adam Luckenbaugh. You need to save this javascript on you web server and put the ULR to: ProQuest’s Client Center>Summon Admin>Custom Link> URL. You will need another file (apiArticle.php) to be stored in the same directory on your web server.
/*
* Script to log summon usage statistics & customize Summon UI
* http://gvsu.summon.serialssolutions.com/search?s.cmd=nextPage%28%29&s.light=t&s.pn=4&s.q=test
* Authors: Matthew Reidsma & Adam Luckenbaugh
* Version 1.2
* Last Edited by: Jenny Jing & Sharifi Ahmed, 05/24/2015
* Function: find the ISSN and DOI in each record displayed in Summon result page, and use them as the input for 360Link API, in order to generate the links in the mini-popup window.
*/
$(document).ready(function() {
// Since we use the link text to insert this script, add an actual link to the DOM
$("#topbar").find(".link").prepend('<a href="http://gvsu.edu/chat">Get Help Now</a>');
// Include helper text if you get a lot of results
// Hat tip to Dave Pattern (@daveyp) of University of Huddersfield for this bit
var count = $('#summary .highlight:last').html();
if(count) {
count = count.replace(/[^0-9]/g,'');
if( count > 50000 ){
$('#summary').append('<div style="margin-top:5px;"><span id="refineSeachHelp" style="display:none; font-size:90%; font-style:italic;">Too many results? Use the options below to refine your search...</span>&nbsp;</div>');
$('#refineSeachHelp').delay(1000).fadeIn(1000);
}
}
// Assign unique IDs to each link in place
var i=1, j=1, m=1,t=1, x=1, path="http://gvsulib.com/summon-stats/", search_metadata_str, search_metadata_obj, ts=0, searchClicks=1,clicked, contentType, availabilityText, page;
search_metadata_str = cleanJSON(/[0-9A-Za-z]+((:|,)|[\n])\s/g, /[0-9A-Za-z]+((:|,)|[\n])\s/, $("#search-metadata").text()).replace(/[\s]*[\n]/g, "");
query_metadata_str = cleanJSON(/[0-9A-Za-z]+((:|,)|[\n])\s/g, /[0-9A-Za-z]+((:|,)|[\n])\s/, $("#query-metadata").text()).replace(/[\s]*[\n]/g, "");
//parse the fixed-up string as a JSON object and deal with it from there. This handles any errors that arise during and after JSON parsing.
try
{
search_metadata_obj = jQuery.parseJSON(search_metadata_str);
query_metadata_obj = jQuery.parseJSON(query_metadata_str);
$.post(path + "write_metadata.php", search_metadata_obj.clusters);
$.post(path + "write_metadata.php", query_metadata_obj);
}
catch(err)
{
//err.message
console.log("JavaScript error: \"" + err.message + "\"");
}
// Page navigation fix for pages without navigation by Michael Oehrlich of Thüringer Universitäts- und Landesbibliothek Jena
if($("#pageNavigation").length){
page = $("#pageNavigation").find("li:not(:has(a))").text();
} else {
page = '1';
}
$("h3 a.documentLink").each(function(){
$(this).attr("data-click", i + "/docLink/" + page + "/").addClass("gvsuTest");
i=i+1;
});
// This fix thanks to Ben Elwell!
$("div.document").each(function(){
$(this).attr("data-click", j + "/summaryLink/" + page + "/");
j=j+1;
});
$(".thumbnail").find("a").each(function(){
$(this).attr("data-click", t + "/imgLink/" + page + "/").addClass("gvsuTest");
t=t+1;
availabilityText = $(this).find('div.format').attr("class");
var availability = availabilityText.split(" ");
if((availability[2]== "format_book_lg") || (availability[2] == "format_video_recording_lg")) {
var searchTitle = $(this).closest(".document").find(".title").find("h3").text();
searchTitle = encodeURIComponent(searchTitle);
$(this).closest("table").find(".metadata").find(".Availability").append('<br /><p style="clear: left; padding-top:1em;">Not available? <a href="http://elibrary.mel.org/search/a?searchtype=t&searcharg=' + searchTitle + '&SORT=D" target="_blank">Find this at another Michigan library</a></p>');
}
});
$("div.section").each(function(){
$(this).attr("data-click", m + "/sectionLink/" + page + "/");
m=m+1;
});
////////////////////////////// License code -- new test, find the ISSN and DOI in each record and use them as the input for 360Link API, to generate the links in the mini-popup window.
$('#resultPage').find(".document").each (
function()
{
var publicationLocation = $(this).find(".document-summary");
var thumbnail = $(this).find(".thumbnail").find('div.format');
if (thumbnail.hasClass("format_journal_article_lg") || thumbnail.hasClass("format_generic_lg"))
{
sections = $(this).find('div.previewDocumentContent').find(".section");
var issn = '';
var doi = '';
$(sections).each (
function()
{
if ($(this).find('.title').text() == 'ISSN')
{
issn = $(this).contents().filter(function() {
return this.nodeType == 3;
}).text();
}
if ($(this).find('.title').text() == 'DOI')
{
doi = $(this).find('.title').next().text();
}
}
);
// if it is not an ebook then we create the 360Link mini-popup window.
if( ! thumbnail.hasClass("format_ebook_lg") ){
provider='';
$.post('apiArticle.php', { 'issn': issn, 'doi' : doi}, function(data)
{
$(publicationLocation).find(".summary").append('<div style="display:none;">'+data+'</div>');
$(publicationLocation).find(".summary").children('div').first().mouseover(function(){$(this).stop(true,true).show();}).mouseout(function(){$(this).stop(true,true).fadeOut();});
$(publicationLocation).find(".summary").children('div').first().find('.theme-close').click(function(){$(this).parents('div.summary').children('div').first().hide();});
});
$(publicationLocation).find(".summary").children('a').first().mouseover(function(){$(this).next('div').stop(true,true).show();}).mouseout(function(){$(this).next('div').stop(true,true).fadeOut();});
}
}
}
);
///////////////////////////////////////
$(".previewDocumentTitle").find("a").each(function(){
$(this).attr("data-click", x + "/previewLink/" + page + "/").addClass("gvsuTest");
x=x+1;
});
// Now set a click handler to capture that data when an item is clicked
$("a.gvsuTest").click(function() {
clicked = $(this).attr("data-click");
// Thanks for Matt Matchell (@shuckle) for the tip on .closest()
contentType = escape($(this).closest('div.document').attr("type"));
ts = Math.round((new Date()).getTime() / 1000); // Timestamp
var url = path + "standard/" + ts + "/" + clicked + contentType + "/" + searchClicks;
$("body").append('<iframe src="' + url + '" height="0" width="0" style="visibility:hidden;"></iframe>');
// Add one to number of clicks for this search
searchClicks = searchClicks + 1;
});
// This fix thanks to Ben Elwell! Delegate the clickability of the summary link, since it often doesn't exist yet when this script runs.
$("div.document").on('click', '.summary a', function() {
clicked = $(this).closest("div.document").attr("data-click");
// Thanks for Matt Matchell (@shuckle) for the tip on .closest()
contentType = escape($(this).closest('div.document').attr("type"));
ts = Math.round((new Date()).getTime() / 1000); // Timestamp
var url = path + ts + "/" + clicked + contentType + "/" + searchClicks;
$("body").append('<iframe src="' + url + '" height="0" width="0" style="visibility:hidden;"></iframe>');
// Add one to number of clicks for this search
searchClicks = searchClicks + 1;
});
// Make useful but ugly best bets look better
if($(".best-bet-list").length > 0) {
var bbTitle = $(".best-bet-title").text();
var bbURL = $(".best-bet").find(".more").find("a").attr("href");
var bbDesc = $(".best-bet-body").find(".detail").text();
if(bbDesc === ".") {
$("li.best-bet").html('<div class="theme-best-bet-icon"></div><div class="best-bet-title"><a href="' + bbURL + '">' + bbTitle + '</a></div>');
} else { // Has a description
$("li.best-bet").html('<div class="theme-best-bet-icon"></div><div class="best-bet-title"><a href="' + bbURL + '">' + bbTitle + '</a></div><div class="best-bet-body" style="margin-top: 0 !important; padding-left: 0 !important;"><div class="detail"><p>' + bbDesc + '</p></div>');
}
}
// Fix the positioning problem on the #dock-container
//console.log($("#dock-container").length);
if($("#dock-container").length > 0) {
$("body").append('<style>#dock-container{position:fixed !important;}</style>');
}
});
function cleanJSON(glob_expr, sing_expr, str)
{
str = str.replace(/[,](?=[ 0-9A-Za-z]+["])/g, "`");
var matches = str.match(glob_expr);
var i;
for(i = 0; i < matches.length; i++)
{
var tmp_str = "\"" + matches[i].replace(/((:|,)|\n)/, "\"$& ");
str = str.replace(sing_expr, tmp_str);
}
return str.replace(/[`](?=[ 0-9A-Za-z]+["])/g, ",");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.