///////////////////////////////////// // CONFIG VARS ///////////////////////////////////// /** * Unless the client platform is hosting a resolver instance this should not be set */ if (!su_basepath) { var su_basepath = "http://api.scholaruniverse.com/"; } /** * The type of link style. The possible values are: * 0 = The author's name will be converted into a link with an image link is appended directly after - The results will be displayed in a DHTML popup * 1 = An image link is appended directly after the authors name - The results will be displayed in a DHTML popup * 2 = The author's name will be converted into a link - The results will be displayed in a DHTML popup */ if (!su_linkstyle) { var su_linkstyle = 0; } /** * This can be set to override the text for possible matches */ if (!su_linktext_possible) { var su_linktext_possible = "View Author Profile"; } /** * This can be set to override the image path for the link that will be created for possible matches using * su_linkstyle = 0 or 1 */ if (!su_linkimage_possible) { var su_linkimage_possible = su_basepath + "images/ar_button.gif"; } ///////////////////////////////////// // END CONFIG VARS ///////////////////////////////////// var su_stopwords = ["to","they","but","for","no","by","was","of","are","if","on","these","be","with","is", "it","such","or","a","into","at","as","the","in","and","not","that","t","s","there","then","an", "will","their","this"]; var su_r = new Array(); var su_auth = 'vHwMmDI1pkDw06efybPLN14Gvbn3rMPXkNb5Bvy01zrGb%2Bs%2BQu1KePIf2nZy1SGQLO%2B%2FlCzrPhYJ2iSH2cFV39Wukq%2FekQVwrwlut1tVVETMZOMLR4QDVwP6sn1f7roVlLtUl%2BzbD1YGc8pyioURvw%3D%3D'; var su_referer = 'null'; function startResolving() { window.setTimeout(makeRequests, 200); } function makeRequests() { loadStylesheet(); var citations = $$(".hcite"); for (var i = 0; i < citations.length; i++) { var citation = citations[i]; makeCitationRequest(citation); } } function loadStylesheet() { var stylesheetURL = su_basepath + "css/author-resolver4.css"; if(document.createStyleSheet) { document.createStyleSheet(stylesheetURL); } else { var stylesheet = $(document.createElement('link')); stylesheet.setAttribute("rel", "stylesheet"); stylesheet.setAttribute("href", stylesheetURL); document.getElementsByTagName("head")[0].appendChild(stylesheet); } } function makeCitationRequest(citation) { var authors = citation.select(".creator"); if (authors.length == 0) { return; } var baseParams = ""; baseParams += buildParam(citation, "t", ".title", -1, su_stopwords); baseParams += buildParam(citation, "ie", ".email", -1, null); baseParams += buildParam(citation, "caguid", ".su-caguid", -1, null); baseParams += buildParam(citation, "ion", ".org", -1, su_stopwords); var uids = citation.select(".uid"); if (uids) { for (var i = 0; i < uids.length; i++) { var uid = uids[i]; var type = findValue(uid, ".type"); var value = findValue(uid, ".value"); if (type && value) { if ('issn' == type) { baseParams += "&issn=" + encodeURIComponent(value); } else { baseParams += "&cuid=" + encodeURIComponent(type + ":" + value); } } } } var query = $("q"); if (query) { baseParams += "&uq=" + query.value; } else { query = $("query"); if (query) { baseParams += "&uq=" + query.value; } } var authorsParams = ""; var requestedAuthorIndex = 0; for (var i = 0; i < authors.length; i++) { if (i == 20) { //We are only going to try to resolver the first 20 authors for a citation //Even 20 is pretty high number of authors so we may want to lower this break; } var author = authors[i]; var isVerified = findValue(author, ".su-verified"); if (!isVerified) { authorsParams = appendAuthorParams(authors, baseParams, authorsParams, citation, author, requestedAuthorIndex, i); requestedAuthorIndex++; } else { // Add global caname for this verified author to baseparams baseParams += buildCoAuthorParam(author); } } if (authorsParams) { var allParams = authorsParams + baseParams; if (su_linktext_possible.indexOf("$MATCH_QUALITY") == -1) { allParams += "&mrq=2"; } var head = document.getElementsByTagName("head")[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = su_basepath + "v1/resolver/people?o=js/aar" + allParams + "&auth=" + su_auth; head.appendChild(script); // sends all citation info + all authors for each citation into ResolverService } } function getAllCoAuthors(authors, authorIndex) { var allCoAuthors = ""; var coAuthor = null; var canameCounter = 0; for (var i = 0; i < authors.length; i++) { if (i != authorIndex) { coAuthor = authors[i]; var ln = findValues(coAuthor, ".family-name")[0]; if (ln && ln.length > 0) { allCoAuthors += buildCoAuthorParam(coAuthor); } else { allCoAuthors += buildParam(coAuthor, "caname", ".fn", -1, null); } canameCounter++; } } return allCoAuthors; } function appendAuthorParams(authors, baseParams, authorsParams, citation, author, requestedAuthorIndex, allAuthorsIndex) { var authorParams = baseParams; var ln = findValues(author, ".family-name")[0]; if (ln) { authorsParams += buildParam(author, "ln", ".family-name", requestedAuthorIndex, null); authorParams += buildParam(author, "ln", ".family-name", -1, null); authorsParams += buildParam(author, "fn", ".given-name", requestedAuthorIndex, null); authorParams += buildParam(author, "fn", ".given-name", -1, null); authorsParams += buildParam(author, "mn", ".additional-name", requestedAuthorIndex, null); authorParams += buildParam(author, "mn", ".additional-name", -1, null); } else { authorsParams += buildParam(author, "n", ".fn", requestedAuthorIndex, null); authorParams += buildParam(author, "n", ".fn", -1, null); } authorsParams += buildParam(author, "e", ".email", requestedAuthorIndex, null); authorParams += buildParam(author, "e", ".email", -1, null); authorsParams += buildParam(author, "on", ".org", requestedAuthorIndex, su_stopwords); authorParams += buildParam(author, "on", ".org", -1, su_stopwords); var allAuthors = authorParams + getAllCoAuthors(authors, allAuthorsIndex); var resolvable = new Object(); resolvable.author = author; resolvable.citation = citation; resolvable.authorParams = allAuthors; // Add author + all coauthors to popup request resolvable.status = 0; su_r[su_r.length] = resolvable; var ri = su_r.length - 1; authorsParams += "&ri:" + requestedAuthorIndex + "=" + ri; return authorsParams; } function buildCoAuthorParam(element) { var lastName = findValue(element, ".family-name"); if (lastName) { lastName = lastName.strip(); } if (!lastName) { return ""; } var firstName = findValue(element, ".given-name"); if (firstName) { firstName = firstName.strip(); } if (!firstName) { return ""; } var middleName = findValue(element, ".additional-name"); if (middleName) { middleName = middleName.strip(); } var nameToken = ""; if (middleName && middleName.length > 0) { nameToken = lastName + "_" + firstName + "_" + middleName; } else { nameToken = lastName + "_" + firstName; } var param = "&caname=" + encodeURIComponent(nameToken); return param; } function buildParam(element, paramName, className, index, stopWords) { var param = ""; var values = findValues(element, className); if (values) { for (var i = 0; i < values.length; i++) { var value = values[i]; if (stopWords) { value = stripStopWords(value, stopWords); } if (index > -1) { param += "&" + paramName + ":" + index + "=" + encodeURIComponent(value); } else { param += "&" + paramName + "=" + encodeURIComponent(value); } } } return param; } function findValue(element, className) { var values = findValues(element, className); return values[0]; } function findValues(element, className) { var values = new Array(); var valueElements = element.select(className); for (var i = 0; i < valueElements.length; i++) { var valueElement = valueElements[i]; values[values.length] = getTextValue(valueElement); } return values; } function stripStopWords(value, stopWords) { var result = ""; var values = value.split(';'); var firstValue = true; for (var i = 0; i < values.length; i++) { var newvalue = values[i]; var words = newvalue.split(' '); if (firstValue) { firstValue = false; } else { result += ";"; } var firstWord = true; for (var j = 0; j < words.length; j++) { var word = words[j]; var index = stopWords.indexOf(word.toLowerCase()); if (index < 0) { if (firstWord) { firstWord = false; } else { result += " "; } result += word; } } } return result; } // Setup the popup so that when user clicks on link, they see the popup function p(ri, mq) { var r = su_r[ri]; if (!r) { return; } if (mq >= 1) { var popup = new Popup(su_basepath + "v1/resolver/people?o=html/su-popup" + r.authorParams + "&auth=" + su_auth + "&_fr=" + encodeURIComponent(su_referer)); var linkText = su_linktext_possible; linkText = linkText.replace("$MATCH_QUALITY", mq); if (su_linkstyle == 0 || su_linkstyle == 2) { var a = document.createElement("a"); a.setAttribute("alt", linkText); a.setAttribute("title", linkText); var authorText = getTextValue(r.author); for (var i = r.author.childNodes.length - 1; i >= 0; i--) { var child = r.author.childNodes[i]; r.author.removeChild(child); a.appendChild(child); } a.setAttribute("style", "font-style: italic;"); a.setAttribute("href", "#"); r.author.appendChild(a); popup.attach(a); } if (su_linkstyle == 0 || su_linkstyle == 1){ var a = document.createElement("a"); a.setAttribute("alt", linkText); a.setAttribute("title", linkText); var img = document.createElement("img"); img.setAttribute("src", su_linkimage_possible); img.setAttribute("width", "16"); img.setAttribute("height", "16"); img.setAttribute("border", "0"); img.setAttribute("style", "border: 0px;"); img.setAttribute("title", linkText); img.setAttribute("alt", linkText); a.appendChild(img); a.setAttribute("href", "#"); r.author.setAttribute("style", "white-space: nowrap;"); r.author.appendChild(document.createTextNode(" ")); r.author.appendChild(a); popup.attach(a); } } } function getTextValue(element){ if (element.textContent) { return element.textContent; } if (element.innerText) { return element.innerText; } var title = element.getAttribute("title"); if (title) { return title; } return element.innerHTML; } function removeChildrenFromNode(node) { if(!node) { return; } while (node.hasChildNodes()) { node.removeChild(node.firstChild); } } var Popup = Class.create( { displayResults: null, displayPtr: null, fadeOut: null, rptr: null, lptr: null, attachedElements: new Array(), initialize: function(src) { this.src = src; this.resultsLoaded = false; this.results = $(document.createElement("div")); this.results.addClassName("su-ar-popup-results"); this.results.hide(); document.body.appendChild(this.results); if (Popup.popup == null) { Popup.popup = $(document.createElement("div")); Popup.header = $(document.createElement("div")); Popup.logo = $(document.createElement("img")); Popup.close = $(document.createElement("img")); Popup.popupBody = $(document.createElement("div")); Popup.loading = $(document.createElement("div")); Popup.loadingProgress = $(document.createElement("img")); Popup.loadingMessage = $(document.createElement("span")); Popup.logo.setAttribute("src", su_basepath + "images/ar_popup_logo.png"); Popup.logo.setAttribute("alt", "Scholar Universe"); Popup.logo.addClassName("su-ar-popup-logo"); Popup.close.setAttribute("src", su_basepath + "images/ar_popup_close.gif"); Popup.close.setAttribute("alt", "Close"); Popup.close.setAttribute("title", "Close"); Popup.close.addClassName("su-ar-popup-close"); Popup.header.addClassName("su-ar-popup-header"); Popup.header.appendChild(Popup.logo); Popup.header.appendChild(Popup.close); Popup.popup.appendChild(Popup.header); Popup.loadingProgress.setAttribute("src", su_basepath + "images/loading.gif"); Popup.loadingProgress.setAttribute("alt", "progress"); Popup.loadingProgress.addClassName("su-ar-popup-loading-progress"); Popup.loadingMessage.addClassName("su-ar-popup-loading-message"); Popup.loadingMessage.appendChild(document.createTextNode("Loading Author Resolver Matches")); Popup.loading.addClassName("su-ar-popup-loading"); Popup.loading.appendChild(Popup.loadingProgress); Popup.loading.appendChild(Popup.loadingMessage); Popup.popupBody.addClassName("su-ar-popup-body"); Popup.popupBody.appendChild(Popup.loading); Popup.popup.addClassName("su-ar-popup"); Popup.popup.appendChild(Popup.popupBody); Popup.popup.hide(); document.body.appendChild(Popup.popup); } if( Popup.rptr == null ) { Popup.rptr = document.createElement( "img" ); Element.extend( Popup.rptr ); Popup.rptr.setAttribute( "id", "rt_img") Popup.rptr.setAttribute( "src", su_basepath + "images/ar_popup_right.gif" ); Popup.rptr.setAttribute( "alt", "Right Pointer" ); Popup.rptr.hide(); document.body.appendChild( Popup.rptr ); } if( Popup.lptr == null ) { Popup.lptr = document.createElement( "img" ); Element.extend( Popup.lptr ); Popup.lptr.setAttribute( "id", "lt_img") Popup.lptr.setAttribute( "src", su_basepath + "images/ar_popup_left.gif" ); Popup.lptr.setAttribute( "alt", "Left Pointer" ); Popup.lptr.hide(); document.body.appendChild( Popup.lptr ); } this.showPopup = this.showPopup.bindAsEventListener(this); this.fadePopup = this.fadePopup.bindAsEventListener(this); this.hidePopup = this.hidePopup.bindAsEventListener(this); this.clearFadeOut = this.clearFadeOut.bindAsEventListener(this); Event.observe( Popup.close, "click", this.hidePopup ); Event.observe( Popup.popup, "mouseover", this.clearFadeOut ); Event.observe( Popup.popup, "mouseout", this.fadePopup ); Event.observe( Popup.lptr, "mouseover", this.clearFadeOut ); Event.observe( Popup.rptr, "mouseover", this.clearFadeOut ); }, attach: function(element) { var e = $(element); this.attachedElements[this.attachedElements.length] = e; Event.observe(e, "click", this.showPopup); }, destroy: function() { for (var i = 0; i < this.attachedElements.length; i++) { Event.stopObserving(this.attachedElements[i], "click", this.showPopup ); } Event.stopObserving( Popup.close, "click", this.hidePopup ); Event.stopObserving( Popup.popup, "mouseover", this.clearFadeOut ); Event.stopObserving( Popup.popup, "mouseout", this.fadePopup ); Event.stopObserving( Popup.lptr, "mouseover", this.clearFadeOut ); Event.stopObserving( Popup.rptr, "mouseover", this.clearFadeOut ); if (this.resultsFrame) { Event.stopObserving( this.resultsFrame, "mouseover", this.clearFadeOut ); Event.stopObserving( this.resultsFrame, "mouseout", this.fadePopup); Event.stopObserving( this.resultsFrame, "onload", this.showResults()); } }, stylePopup: function( event ){ var parent = event.element(); var parDim = parent.getDimensions(); var parOff = parent.cumulativeOffset(); var toolDim = Element.getDimensions( Popup.popup ); //var bodyDim = document.viewport.getDimensions(); var bodyDim = { }; $w('width height').each(function(d) { var D = d.capitalize(); bodyDim[d] = self['inner' + D] || (document.documentElement['client' + D] || document.body['client' + D]); }); var arrow_loc; var ptr_y = parOff.top + 1; var tt_y = parOff.top - 5; if( ( parOff.left + parDim.width + toolDim.width ) >= bodyDim.width ) { ptr_x = parOff.left - 17; tt_x = ptr_x - toolDim.width - 1; Popup.displayPtr = Popup.rptr; } else { ptr_x = parOff.left + parDim.width + 10; tt_x = ptr_x + 14; Popup.displayPtr = Popup.lptr; } if( event.clientY > (bodyDim.height/2) ) { ptr_y = parOff.top - 2; tt_y = parOff.top - toolDim.height + 15; } Popup.popup.setStyle({ position: 'absolute', top: tt_y + "px", left: tt_x + "px", zIndex: 1000 }); this.results.setStyle({ position: 'absolute', top: tt_y + 71 + "px", left: tt_x + 11 + "px", zIndex: 1099 }); Popup.displayPtr.setStyle({ position: 'absolute', top: ptr_y + "px", left: ptr_x + "px", zIndex: 1099 }); }, stopEvent: function( event ) { Event.stop(event); }, showPopup: function( event ) { Event.stop(event); Popup.popup.hide(); if( Popup.displayPtr != null ) { Popup.displayPtr.hide(); Popup.displayPtr = null; } if(Popup.displayResults != null) { Popup.displayResults.hide(); Popup.displayResults = null; } this.stylePopup( event ); Popup.displayResults = this.results; Popup.popup.show(); Popup.displayPtr.show(); if (this.resultsLoaded) { this.results.show(); setTimeout(( function(){ this.setFocus() }).bind( this ), 100 ); } else { Popup.loading.show(); setTimeout(( function(){ this.loadResults() }).bind( this ), 1000 ); } this.clearFadeOut( event ); }, setFocus : function() { if (this.resultsFrame && this.resultsFrame.contentDocument) { try { var iframeDoc = this.resultsFrame.contentDocument; var firstMatch = $(iframeDoc.getElementById("firstMatch")); if (firstMatch && firstMatch.focus) { firstMatch.focus(); } } catch (err) { //this script may not have permission //to get an element from the popup's iframe } } }, loadResults : function() { if (!this.resultsLoaded) { this.resultsFrame = $(document.createElement("iframe")); this.resultsFrame.addClassName("su-ar-popup-results"); this.results.appendChild(this.resultsFrame); this.resultsFrame.setAttribute("src", this.src); Event.observe( this.resultsFrame, "mouseover", this.clearFadeOut ); Event.observe( this.resultsFrame, "mouseout", this.fadePopup); Event.observe( this.resultsFrame, "onload", this.showResults()); } }, showResults : function() { if(Popup.displayResults == this.results) { this.results.show(); Popup.loading.hide(); } this.resultsLoaded = true }, clearFadeOut: function( event ) { if( Popup.fadeOut != null ) { clearTimeout( Popup.fadeOut ); } }, fadePopup: function( event ){ this.clearFadeOut(); Popup.fadeOut = setTimeout(( function(){ this.hidePopup() } ).bind( this ), 3000 ); }, hidePopup: function( event ){ Popup.popup.hide(); Popup.loading.hide(); this.results.hide(); if(Popup.displayPtr != null) { Popup.displayPtr.hide(); Popup.displayPtr = null; } if(Popup.displayResults != null) { Popup.displayResults.hide(); Popup.displayResults = null; } } }); Event.observe( window.document, "load", startResolving());