var ScapiURL="http://www.scopus.com/scsearchapi/"; var ScapiTimeout="40000"; var debug=new scapiDebug(); var scapi=new scapiInterface(); function scapiInterface(){ this._resultsValid=false; this._results=null; this._errors=null; this._warnings=null; this._search=null; this._callback=null; this._errorCallback=null; this.Backend=new scapiBackend(); this.Renderer=new scapiListRenderer(); var me=this; this._developerID=null; this.setDeveloperID=function(_2){ me._developerID=_2; }; this.setRenderer=function(_3){ if(_3!=null){ this.Renderer=_3; }else{ debug.write("setRenderer:no renderer specified"); } }; this.selectRenderer=function(_4){ if(_4=="list"){ this.Renderer=new scapiListRenderer(); } }; this.setRenderLocation=function(_5){ this.Renderer.setRenderLocation(_5); }; this.setCallback=function(_6){ if(_6!=null){ this._callback=_6; }else{ debug.write("setCallback:no callback specified"); } }; this.setErrorCallback=function(_7){ if(_7!=null){ this._errorCallback=_7; }else{ debug.write("setErrorCallback:no callback specified"); } }; this.runSearch=function(_8){ me._resultsValid=false; me._search=_8; me.Backend.submitSearch(_8,me._developerID,me.runSearchCallback); }; this.runSearchCallback=function(_9){ me._errors=null; me._warnings=null; me._results=null; me._resultsValid=false; if(_9=="timeout"){ debug.write("runSearch: search timed out"); if(me._errorCallback!=null){ me._errorCallback(); } }else{ if(_9.ERROR!=null){ debug.write("runSearch: error occured durring search"); me._errors=_9.ERROR.Errors; if(me._errorCallback!=null){ me._errorCallback(); } }else{ if(_9.PartOK!=null){ debug.write("runSearch: warnings occured durring search"); me._results=_9.PartOK; me._warnings=_9.PartOK.Warnings; me._resultsValid=true; }else{ if(_9.OK!=null){ debug.write("runSearch: search results are OK"); me._results=_9.OK; me._resultsValid=true; } } } } if(me._callback!=null){ me._callback(); }else{ debug.write("runSearch:no callback specified"); } }; this.search=function(_a){ me._resultsValid=false; me._search=_a; me.Backend.submitSearch(_a,me._developerID,me.searchCallback); }; this.searchCallback=function(_b){ me._errors=null; me._warnings=null; me._results=null; me._resultsValid=false; if(_b=="timeout"){ debug.write("runSearch: search timed out"); if(me._errorCallback!=null){ me._errorCallback(); } } if(_b.ERROR!=null){ debug.write("search: error occured durring search"); me.Renderer.renderErrors(_b.ERROR.Errors); if(me._errorCallback!=null){ me._errorCallback(); } me._errors=_b.ERROR.Errors; }else{ if(_b.PartOK!=null){ debug.write("search: warnings occured durring search"); me.Renderer.renderWarnings(_b); me._warnings=_b.PartOK.Warnings; me._results=_b.PartOK; me._resultsValid=true; }else{ if(_b.OK!=null){ debug.write("search: search results are OK"); me.Renderer.renderResults(_b.OK.Results); me._results=_b.OK; me._resultsValid=true; } } } if(me._callback!=null){ me._callback(); }else{ debug.write("search:no callback specified"); } }; this.areSearchResultsValid=function(){ return this._resultsValid; }; this.getSearchResults=function(){ if(this._resultsValid){ return this._results; }else{ debug.write("getSearchResults:results are not currently valid"); } }; this.renderDocument=function(_c){ this.Renderer.renderDocument(this._results,_c); }; this.renderField=function(_d,_e){ this.Renderer.renderField(this._results,_d,_e); }; this.getField=function(_f,_10){ return this._results.Results[_f][_10]; }; this.getTotalHits=function(){ return this._results.TotalResults; }; this.getNumResults=function(){ return this._results.ReturnedResults; }; this.getPosition=function(){ return this._results.Position; }; this.getLastSearchRequest=function(){ return this._search; }; this.setDebug=function(_11){ debug.setDebug(_11); }; this.getDebug=function(){ return debug.getDebug(); }; } function scapiDebug(){ this._debug=false; this.setDebug=function(_12){ this._debug=_12; }; this.getDebug=function(){ return this._debug; }; this.write=function(_13){ if(this.getDebug()){ var _14=document.createElement("p"); var _15=document.createTextNode(_13); _14.appendChild(_15); document.getElementById("scapiDebugArea").appendChild(_14); } }; } function scapiListRenderer(){ this._renderLocation="scapi"; this._scapiURL=ScapiURL; this._contentProvidedByString="Content provided by "; this._resultsTableStart=""; this._resultsTableEnd="
 "+this._contentProvidedByString+"
"; this._errorTableStart=""; this._errorTableEnd="
"; this._errorRowStart1=" "; this._documentRowStart1=""; this._documentRowEnd=""; this._singlefieldtitle=" (found in Scopus)"; this._singlefieldcited=" in Scopus"; this._white="whitebg"; this._grey="greybg"; this._titleStart=""; this._titleEnd=""; this._errorStart=""; this._errorEnd=""; this._title="title"; this._firstAuth="firstauth"; this._firstAuthName="First Author"; this._authlist="authlist"; this._authlistName="Author(s)"; this._abstract="abstract"; this._abstractName="Abstract"; this._affiliations="affiliations"; this._affiliationsName="Affiliation"; this._doctype="doctype"; this._doctypeName="Document Type"; this._sourcetitle="sourcetitle"; this._sourcetitleName="Source title"; this._issn="issn"; this._issnName="ISSN"; this._vol="vol"; this._volName="Volume"; this._issue="issue"; this._issueName="Issue"; this._page="page"; this._pageName="Pages"; this._pubdate="pubdate"; this._pubdateName="Year"; this._eid="eid"; this._eidName="EID"; this._scp="scp"; this._scpName="Scopus ID"; this._doi="doi"; this._doiName="DOI"; this._citedbycount="citedbycount"; this._citedbycountStart="Cited "; this._citedbycountEnd=" times"; this._inwardurl="inwardurl"; this._inwardurlStart="View on Scopus "; this._fieldSeperator=": "; this._fieldStart=""; this._fieldEnd="
"; this._noResults="No results were found for this search"; this.setRenderLocation=function(_16){ if(_16!=null&&_16!=""){ this._renderLocation=_16; }else{ debug.write("scapiRenderer.setRenderLocation: no render location specified"); } }; this.renderErrors=function(_17){ var _18=this._resultsTableStart; var _19=false; for(i=0;i<_17.length;i++){ if(_19){ _18+=this._errorRowStart1+this._grey+this._errorRowStart2+this._grey+this._errorRowStart3; }else{ _18+=this._errorRowStart1+this._white+this._errorRowStart2+this._white+this._errorRowStart3; } error=_17[i].split("\n"); _18+=this._errorStart+error[0]+this._errorEnd+this._fieldEnd; _18+=error[1]; _18+=this._documentRowEnd; if(_19){ _19=false; }else{ _19=true; } } _18+=this._resultsTableEnd; this.writeString(_18); }; this.renderWarnings=function(_1a){ var _1b=""; _1b+=this.getAllRenderedWarningsString(_1a.PartOK.Warnings); _1b+=this.getAllRenderedResultsString(_1a.PartOK.Results); this.writeString(_1b); }; this.getAllRenderedWarningsString=function(_1c){ for(i=0;i<_1c.length;i++){ alert(_1c[i]); } return ""; }; this.renderResults=function(_1d){ var _1e=this._resultsTableStart; _1e+=this.getAllRenderedResultsString(_1d); this.writeString(_1e); }; this.getAllRenderedResultsString=function(_1f){ var _20=this._resultsTableStart; var _21=false; if(_1f.length>0){ for(var i in _1f){ _20+=this.getRenderedResultString(_1f[i],_21); if(_21){ _21=false; }else{ _21=true; } } }else{ _20+=this._documentRowStart1+this._white+this._documentRowStart2+this._white+this._documentRowStart3; _20+=this._noResults; _20+=this._documentRowEnd; } _20+=this._resultsTableEnd; return _20; }; this.renderDocument=function(_23,_24){ var _25=this._resultsTableStart; _25+=this.getRenderedResultString(_23.Results[_24],false); _25+=this._resultsTableEnd; this.writeString(_25); }; this.renderField=function(_26,_27,_28){ output=this.getRenderedFieldString(_28,_26.Results[_27][_28],true); this.writeString(output); }; this.getRenderedResultString=function(_29,_2a){ output=""; if(_2a){ output+=this._documentRowStart1+this._grey+this._documentRowStart2+this._grey+this._documentRowStart3; }else{ output+=this._documentRowStart1+this._white+this._documentRowStart2+this._white+this._documentRowStart3; } for(var i in _29){ output+=this.getRenderedFieldString(i,_29[i],false); } output+=this._documentRowEnd; return output; }; this.getRenderedFieldString=function(_2c,_2d,_2e){ output=""; if(_2c==this._title){ if(_2e){ output+=this._titleStart+_2d+this._singlefieldtitle+this._titleEnd; }else{ output+=this._titleStart+_2d+this._titleEnd; } }else{ if(_2c==this._doctype){ output+=this._doctypeName+this._fieldSeperator+_2d; }else{ if(_2c==this._citedbycount){ if(_2e){ output+=this._citedbycountStart+_2d+this._citedbycountEnd; }else{ output+=this._citedbycountStart+_2d+this._citedbycountEnd; } }else{ if(_2c==this._inwardurl){ output+=this._inwardurlStart+_2d+this._inwardurlEnd; }else{ if(_2c==this._sourcetitle){ output+=this._sourcetitleName+this._fieldSeperator+_2d; }else{ if(_2c==this._issn){ output+=this._issnName+this._fieldSeperator+_2d; }else{ if(_2c==this._vol){ output+=this._volName+this._fieldSeperator+_2d; }else{ if(_2c==this._issue){ output+=this._issueName+this._fieldSeperator+_2d; }else{ if(_2c==this._page){ output+=this._pageName+this._fieldSeperator+_2d; }else{ if(_2c==this._pubdate){ output+=this._pubdateName+this._fieldSeperator+_2d; }else{ if(_2c==this._eid){ output+=this._eidName+this._fieldSeperator+_2d; }else{ if(_2c==this._scp){ output+=this._scpName+this._fieldSeperator+_2d; }else{ if(_2c==this._doi){ output+=this._doiName+this._fieldSeperator+_2d; }else{ if(_2c==this._firstAuth){ output+=this._firstAuthName+this._fieldSeperator+_2d; }else{ if(_2c==this._authlist){ output+=this._authlistName+this._fieldSeperator+_2d; }else{ if(_2c==this._affiliations){ output+=this._affiliationsName+this._fieldSeperator+_2d; }else{ if(_2c==this._abstract){ output+=this._abstractName+this._fieldSeperator+_2d; } } } } } } } } } } } } } } } } } return output+this._fieldEnd; }; this.writeString=function(_2f){ document.getElementById(this._renderLocation).innerHTML=_2f; }; } function scapiBackend(){ this._busy=false; this._scapiCallback=null; this._reqCounter=0; this._requests={}; this._scapiURL=ScapiURL+"search.url"; this._timeoutVal=ScapiTimeout; this._preventCache="preventCache"; this._devID="devId"; this._search="search"; this._sort="sort"; this._sortDirection="sortDirection"; this._fields="fields"; this._numResults="numResults"; this._content="content"; this._offset="offset"; this._callback="callback"; this._callbackStringStart="scapi.Backend._requests."; this._callbackStringEnd=".callback"; this._equals="="; this._connector="&"; this._post="?"; this.submitSearch=function(_30,_31,_32){ if(this._busy==true){ debug.write("Search already in flight...ignoring search request"); return; }else{ this._busy=true; debug.write("Search submitted: query="+_30.getSearch()); this._scapiCallback=_32; var _33=this._scapiURL+this._post; _33=this.appendVarToURL(_33,this._preventCache,this.randomString()); _33=this.appendVarToURL(_33,this._devID,_31); _33=this.appendVarToURL(_33,this._search,_30.getSearch()); _33=this.appendVarToURL(_33,this._sort,_30.getSort()); _33=this.appendVarToURL(_33,this._sortDirection,_30.getSortDirection()); _33=this.appendVarToURL(_33,this._fields,_30.getFields()); _33=this.appendVarToURL(_33,this._numResults,_30.getNumResults()); _33=this.appendVarToURL(_33,this._content,_30.getContent()); _33=this.appendVarToURL(_33,this._offset,_30.getOffset()); var _34="search"+this._reqCounter++; var _35=this._callbackStringStart+_34; var _36=this._callbackStringStart+_34+this._callbackStringEnd; _33=this.appendVarToURL(_33,this._callback,_36); flight=new inflight(_34); this._requests[_34]=flight; this.addRequestToHeader(_33); setTimeout("scapi.Backend.timeout("+_35+")",this._timeoutVal); } }; this.appendVarToURL=function(url,_38,_39){ if(_39!=null&&_39!=""){ url+=this._connector+_38+this._equals+_39; return url; }else{ return url; } }; this.addRequestToHeader=function(_3a){ var _3b=document.getElementsByTagName("head")[0]; script=document.createElement("script"); script.id="scapiSearch"; script.type="text/javascript"; script.src=_3a; _3b.appendChild(script); }; this.randomString=function(){ var _3c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; var _3d=20; var _3e=""; for(var i=0;i<_3d;i++){ var _40=Math.floor(Math.random()*_3c.length); _3e+=_3c.substring(_40,_40+1); } return _3e; }; this.callback=function(_41,_42){ debug.write("Results recieved by callback..."); if(_41.inflight==false){ debug.write("...Javascript just recieved a response for a search that had timed out."); }else{ _41.inflight=false; debug.write("...looking good"); this._busy=false; this._scapiCallback(_42); } }; this.timeout=function(_43){ debug.write("Checking for timedout search..."); if(_43.inflight==true){ debug.write("...Search was timed out"); _43.inflight=false; this._busy=false; this._scapiCallback("timeout"); }else{ debug.write("...search had already compleated"); } }; } function inflight(id){ this.searchID=id; this.inflight=true; this.callback=function(_45){ scapi.Backend.callback(this,_45); }; } function searchObj(){ this._search=null; this._sort=null; this._sortDirection=null; this._fields=null; this._numResults=null; this._content=null; this._offset=null; this.setSearch=function(_46){ this._search=_46; }; this.getSearch=function(){ return this._search; }; this.setSort=function(_47){ this._sort=_47; }; this.getSort=function(){ return this._sort; }; this.setSortDirection=function(_48){ this._sortDirection=_48; }; this.getSortDirection=function(){ return this._sortDirection; }; this.setFields=function(_49){ this._fields=_49; }; this.getFields=function(){ return this._fields; }; this.setNumResults=function(_4a){ this._numResults=_4a; }; this.getNumResults=function(){ return this._numResults; }; this.setContent=function(_4b){ this._content=_4b; }; this.getContent=function(){ return this._content; }; this.setOffset=function(_4c){ this._offset=_4c; }; this.getOffset=function(){ return this._offset; }; }