Last active
August 29, 2015 14:21
-
-
Save happyrainb/e0f546390436a1c26ac2 to your computer and use it in GitHub Desktop.
Add license links to Summon 2.0 user interface using "Source"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Script to customize Summon UI ver 2 made by Wittawat Meesangnil | |
* Hi SerSol, this seems safe enough, if you think this script breaks anything - let us know. | |
* Many thanks to @daveyp, @mreidsma, and @godmarback | |
*/ | |
//fixing OCT 15 2014 - Summon now load stuffs from CDN with LAB.js, everything is async, non-blocking | |
//think of this as a wake up call, and learn how to "hacking Summon - the elegant way" | |
//our custom translation here - they've finally fixed it | |
__translations["Chat with a Librarian"] = "Ask a Librarian"; | |
//part of the chat hack, make it say we're online even when the main queue is not | |
__translations["Chat is offline"] = "Ask Us 24/7"; | |
var APIArticle = {}; | |
APIArticle.key='dw2zn6fm9z'; | |
APIArticle.queensUrl= 'http://'+APIArticle.key+'.openurl.xml.serialssolutions.com'; | |
APIArticle.baseUrl = 'http://'+APIArticle.key+'.openurl.xml.serialssolutions.com/openurlxml'; | |
APIArticle.resultContainer = 'body'; | |
APIArticle.initialized = false; | |
APIArticle.init = function(options){ | |
APIArticle.issn = options.issn; | |
APIArticle.volumn = options.volumn; | |
APIArticle.title = options.title; | |
APIArticle.doi = options.doi; | |
APIArticle.initialized = true; | |
} | |
APIArticle.makeRequest = function(){ | |
if(!APIArticle.initialized){ | |
return null; | |
} | |
var fields = { | |
'version': '1.0', | |
'issn': APIArticle.issn, | |
'volumn': APIArticle.volumn, | |
'doi': APIArticle.doi | |
} | |
return $.get( APIArticle.baseUrl, fields, APIArticle.processXML, "xml" ); | |
} | |
APIArticle.processXML = function(xml){ | |
if(xml.find('linkGroup').first()){ | |
var results = {}; | |
xml.find('linkGroup').each(function(group_index, dataGroup){ | |
var item = APIArticle.extractResult(dataGroup); | |
results.push(item); | |
}); | |
} else { | |
// no results found display appropriate message | |
var message = 'Title <b>'+APIArticle.title+'</b> is not available please use ILL form below'; | |
$(APIArticle.resultContainer).append(message); | |
} | |
} | |
APIArticle.extractResult = function(dataGroup){ | |
var article_url = ''; | |
var url_elements = dataGroup.find('url'); | |
var item = { | |
'journal_url':'', | |
'article_url':'', | |
'databaseName':'', | |
'dateAvailable':'', | |
'databaseId':'', | |
'source':'', | |
'journal':'' | |
}; | |
url_elements.each(function(url_index, element){ | |
if(element.attr('type') == 'article'){ | |
item.article_url = element.text(); | |
} | |
if(element.attr('type') == 'journal'){ | |
item.journal_url = element.text(); | |
} | |
}); | |
var holdingData = dataGroup.find('holdingData').first(); | |
item.databaseName = holdingData.find('databaseName').first().text(); | |
var startDate = holdingData.find('startDate').first().text(); | |
var endDate = ''; | |
if(holdingData.find('endDate').size() > 0){ | |
holdingData.find('endDate').first().text(); | |
} | |
item.dateAvailable = startDate + " " + endDate; | |
item.databaseId = holdingData.find('databaseId').first().text(); | |
url_elements.each(function(item, nodedata){ | |
var url_type = nodedata.attr('type'); | |
if(url_type == 'source'){ | |
item.source = '&U=' + nodedata.text(); | |
} | |
if(url_type == 'journal'){ | |
item.journal = nodedata.text(); | |
} | |
}); | |
return item; | |
} | |
APIArticle.appendResult = function(item){ | |
var popup = '<div class="preview " id="177255960" style="display: block;">'+item.databaseName+'</div>'; | |
$(APIArticle.resultContainer).append(popup); | |
} | |
$(document).ready(function() { | |
if (window.location.hostname.indexOf('queensu.preview.summon.serialssolutions.com') != -1) { //edit the address here | |
console.log('it\'s 2.0 Live Site'); | |
//get Angular $Scope | |
//myscope = angular.element('[ng-app=summonApp]').scope(); | |
//new get Angular $Scope - since it's loading async, have to delay everything a sec | |
setTimeout(function() { | |
myscope = angular.element('html').scope(); | |
//watchRouteChange(); | |
watchFeedChange(); | |
//miscHack(); | |
}, 1000); | |
//watch for route change and do something | |
function watchRouteChange( ) { | |
myscope.$on('$routeChangeSuccess', function(current) { | |
//console.log("routeChangeSuccess current route: %o", current); | |
//TODO: need to learn how to get a route name, ok? | |
// if its a detail page for citation only, remove any previous hack | |
if (window.location.hash.substring(1).indexOf('FETCHMERGED-LOGICAL') != -1) { | |
$('#dnlClickHere').remove(); | |
$('#dnlCustom856').remove(); | |
$('#dnlMillRequest').remove(); | |
} | |
//if its catalog details page - add all the hacks | |
if (window.location.hash.substring(1).indexOf('FETCHMERGED-fairfield_catalog') != -1) { | |
//if (myscope.docDetail.visible) { | |
console.log("catalog details page open"); | |
millBibMatch = window.location.hash.match(/fairfield_catalog_b(\d{7})/); | |
console.log("Mill bib num is " + millBibMatch[1]); | |
dnlItemLoc = $('strong:contains("Library Location")').next().html(); | |
//remove any previously added click here to view button | |
if($('#dnlClickHere').size() > 0){ | |
$('#dnlClickHere').remove(); | |
} | |
if (dnlItemLoc && dnlItemLoc.indexOf("Online") !== -1) { | |
console.log("this item is e-resourece"); | |
//add click here to view button | |
$('div.documentActionsContainer div.documentActions').prepend('<a id="dnlClickHere" class="primary btn ng-binding" href="http://library2.fairfield.edu/mill856link.php?bibnum=' + millBibMatch[1] + '" target="_blank" style="display: block;">Click Here to View</a>'); | |
} | |
//console.log($('strong:contains("Library Location")').next().html()); | |
//remove previously added custom 856 | |
if($('#dnlCustom856').size() > 0){ | |
$('#dnlCustom856').remove(); | |
} | |
//remove previously added request it button | |
if($('#dnlMillRequest').size() > 0){ | |
$('#dnlMillRequest').remove(); | |
} | |
//get 856 links from WebPac - this is JSONP | |
$.getJSON( | |
'http://library2.fairfield.edu/summonjs/get856json.php?bibnum=' + millBibMatch[1] +'&callback=?', | |
function(data){ | |
try{ | |
var Status = data.status; | |
var BibInfo = data.bibinfo; | |
var requestAble = data.requestable; | |
//console.log(Status); | |
//console.log(BibInfo); | |
if(Status && Status == "hasLink") { | |
$('div.fixed.fullDialog.detailPage div.detailSummary div.summary').append('<div id="dnlCustom856"><ul>' + BibInfo + '</ul></div>'); | |
} | |
//add request it button | |
if(requestAble) { | |
//console.log("this item is requestable: " + data.requestable); | |
$('div.documentActionsContainer div.documentActions').prepend('<a id="dnlMillRequest" class="primary btn ng-binding" href="http://library2.fairfield.edu/millrequest.php?bibnum=' + millBibMatch[1] + '" target="_blank" style="display: block;">Request It!</a>'); | |
} | |
} catch(err){ | |
console.log(err); | |
} | |
} | |
); | |
} | |
}); | |
} | |
var dnlBookEbookCount; | |
//watch feed change, add license links | |
function watchFeedChange( ) { | |
myscope.$watchCollection('feed', function(){ | |
//delay 1 sec. to wait for DOM to actually finish loading | |
setTimeout(function (){ | |
$("a.availabilityLink").mouseover(function(e) { | |
var issn = myscope.preview.doc.issns; | |
var eissn = myscope.preview.doc.eissns; | |
var doi = myscope.preview.doc.dois; | |
var resulting_issn = issn; | |
if(resulting_issn == undefined){ | |
resulting_issn = eissn; | |
} | |
var options = { | |
'issn' : resulting_issn, | |
'doi' : doi, | |
'volumn': '', | |
'title': '' | |
} | |
APIArticle.init(options); | |
APIArticle.makeRequest(); | |
}); | |
//for each content type display, do these | |
$(".contentType.ng-scope span[bo-bind='doc.content_type | translate']").each(function(){ | |
//if it's journal article AND hasn't been processed by our custom script | |
if($(this).text().indexOf('Journal Article') != -1 && $(this).not('.processed').size() > 0 ) { | |
//add a class called processed so we can keep track, then add a custom link | |
$(this).addClass('processed').parent().append('<br/><span class="icon sprite-s format-sprite format--generic_16px format-journal_article_16px"></span> Source: <a class="mycustomlink" href="#" target="_blank"> [License Information]</a>'); | |
} | |
}); | |
function getContainerValue(){ | |
if(myscope.preview.doc.databases.length > 0){ | |
return myscope.preview.doc.databases[0].name; | |
} else { | |
return myscope.preview.doc.publisher; | |
} | |
} | |
function buildUrl(source_name){ | |
return "http://baseURL/licenselink.php?provider="+source_name; | |
} | |
$("a.mycustomlink").click( | |
function(){ | |
if( $(this).parent().children('div.license_popup').length ){ | |
$(this).parent().children('div.license_popup').remove(); | |
} else { | |
if(myscope.preview.doc.databases && myscope.preview.doc.databases.length > 0){ | |
var new_node = '<div class="license_popup">'; | |
for (var i = 0; i < myscope.preview.doc.databases.length; i++) { | |
new_node += '<span class="icon sprite-s format-sprite format--generic_16px format-journal_article_16px"></span>'; | |
new_node += '<a class="mycustomlink2" href="' + buildUrl(myscope.preview.doc.databases[i].name) + '" target="_blank"> ['+ myscope.preview.doc.databases[i].name +']</a>'; | |
new_node += '<br />'; | |
}; | |
new_node += '</div>'; | |
$(this).parent().append(new_node); | |
} else { | |
window.location.href = "http://library.queensu.ca/360Link/360sample.htm"; | |
} | |
} | |
return false; | |
} | |
); | |
},1000); | |
}); | |
} //watch feed chage() | |
function miscHack() { | |
//add links and css | |
$('.siteLinks .help').parent().parent().before('<div id="webpaclink" class="ng-scope" dynamic-link="" ng-repeat="link in links.links" no-ellipsis="true" link-class="" is-internal="true" link="" click="link.click(link.type)" text="Library Account" ng-switch="isInternal"><a href="http://libcat.fairfield.edu" class="ng-scope ng-binding" ellipsis="" ng-switch-when="true" ng-class="linkClass" ng-click="click()" ng-bind-html-unsafe="text">Classic Catalog</a></div>'); | |
$('div.languageSwitcher.clickable').hide(); | |
$('head').append('<link rel="stylesheet" href="http://mlib.fairfield.edu/summonjs/dnlsummon2.css" type="text/css" />'); | |
//a horrible libraryh3lp chat hack. We're ACJU vir ref member, so basically we have 2 queues | |
$('div.chat.right.nonImage').on('click', function() { | |
console.log("chat button clicked"); | |
if(!myscope.chat.isAvailable) { | |
console.log("DNL ref offline - switch to AJCU"); | |
$('iframe.libraryh3lpWidget').attr('src','https://libraryh3lp.com/chat/[email protected]?skin=22723&identity=Librarian&profile=cs-fairfield'); | |
$('button[ng-click="switchView(\'chat\')"]').trigger('click'); | |
} | |
}); | |
//Track what type of content user actually click on (with GA) | |
//main col | |
$('div.inner').on('click','a[ng-class="linkClass"] , a.availabilityLink', function() { | |
var myContentType = $(this).closest('div.summary').find('div.contentType span.ng-binding').text(); | |
//console.log('Main Col: Clicked on ' + myContentType); | |
_gaq.push(['_trackEvent', 'dnlCustomClick', 'clickOnMainResult', 'contentType:' + myContentType]); | |
}); | |
//preview pane - can't think of less stupid way to do this | |
var contentTypeOfLastHoveredOn; | |
$('div.inner').on('mouseenter','div.documentSummary', function() { | |
contentTypeOfLastHoveredOn = $(this).find('div.contentType span.ng-binding').text(); | |
//console.log('contentTypeOfLastHoveredOn ' + contentTypeOfLastHoveredOn); | |
}); | |
$('div#previewMenu').on('click','a[ng-class="linkClass"] , div.previewOptions a.btn:first', function() { | |
//console.log('preview pane link or read onlnie btn clicked. contentype is ' + contentTypeOfLastHoveredOn); | |
_gaq.push(['_trackEvent', 'dnlCustomClick', 'clickOnPreview', 'contentType:' + contentTypeOfLastHoveredOn]); | |
}); | |
//saved item dialog | |
$('div.savedItemsDialog').on('click','a[ng-class="linkClass"] , a.availabilityLink', function() { | |
var myContentType = $(this).closest('div.summary').find('div.contentType span.ng-binding').text(); | |
//console.log('Saved Item: Clicked on ' + myContentType); | |
_gaq.push(['_trackEvent', 'dnlCustomClick', 'clickOnSavedItem', 'contentType:' + myContentType]); | |
}); | |
} //miscHack() | |
} else if (window.location.hostname.indexOf('fairfield.preview.summon.serialssolutions.com') != -1) { | |
console.log("Preview Site"); | |
} //end if preview site | |
}); //end doc ready | |
function dnlSearchPrintBookOnly() { | |
var dnlQuery = $('input[name=q]').val(); | |
var dnlUrl = $(location).attr('href'); | |
//"toggle" the "print book only" facet | |
if (dnlUrl.indexOf('Library,Reference%20Online,t%7CLibrary,Online,t') != -1) { | |
var dnlPrintBookOnlyHash = "!/search?ho=t&fvf=SourceType,Library%20Catalog,f%7CContentType,Book%20%2F%20eBook,f&l=en&q=" + dnlQuery; | |
//var dnlPrintBookOnlyHash = "!/search?ho=t&fvf=f%7CContentType,Book%20%2F%20eBook,f&l=en&q=" + dnlQuery; | |
} else { | |
var dnlPrintBookOnlyHash = "!/search?ho=t&fvf=Library,Reference%20Online,t%7CLibrary,Online,t%7CSourceType,Library%20Catalog,f%7CContentType,Book%20%2F%20eBook,f&l=en&q=" + dnlQuery; | |
} | |
window.location.hash = dnlPrintBookOnlyHash; | |
} | |
//preview site | |
if (window.location.hostname.indexOf('fairfield.preview.summon.serialssolutions.com') != -1) { | |
angular.module('summonApp').run(function(){ | |
console.log('this still gets called back before DOM is actually populated'); | |
$('.languageSwitcher').hide(); | |
$('.Logo').hide(); | |
console.log('welp! it\'s still there isn\'t it'); | |
}); | |
} //if preview site |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment