2008-09-11 04:40:07 +00:00
{
2011-07-01 05:15:39 +00:00
"translatorID" : "05d07af9-105a-4572-99f6-a8e231c0daef" ,
"label" : "COinS" ,
"creator" : "Simon Kornblith" ,
"target" : "" ,
2011-07-01 19:39:06 +00:00
"minVersion" : "2.1" ,
2011-07-01 05:15:39 +00:00
"maxVersion" : "" ,
"priority" : 300 ,
"inRepository" : true ,
"translatorType" : 4 ,
"browserSupport" : "gcs" ,
2011-07-01 19:39:06 +00:00
"lastUpdated" : "2011-07-01 19:16:28"
2008-09-11 04:40:07 +00:00
}
function detectWeb ( doc , url ) {
var spanTags = doc . getElementsByTagName ( "span" ) ;
var encounteredType = false ;
2010-09-15 18:43:52 +00:00
// This and the x: prefix in the XPath are to work around an issue with pages
// served as application/xhtml+xml
//
// https://developer.mozilla.org/en/Introduction_to_using_XPath_in_JavaScript#Implementing_a_default_namespace_for_XML_documents
function nsResolver ( ) {
return 'http://www.w3.org/1999/xhtml' ;
}
var spans = doc . evaluate ( '//x:span[contains(@class, " Z3988") or contains(@class, "Z3988 ") or @class="Z3988"][@title]' , doc , nsResolver , XPathResult . ANY _TYPE , null ) ;
2010-06-16 07:44:31 +00:00
var span ;
while ( span = spans . iterateNext ( ) ) {
// determine if it's a valid type
var item = new Zotero . Item ;
var success = Zotero . Utilities . parseContextObject ( span . title , item ) ;
if ( item . itemType ) {
if ( encounteredType ) {
return "multiple" ;
} else {
encounteredType = item . itemType ;
2008-09-11 04:40:07 +00:00
}
}
}
return encounteredType ;
}
// used to retrieve next COinS object when asynchronously parsing COinS objects
// on a page
function retrieveNextCOinS ( needFullItems , newItems , couldUseFullItems , doc ) {
if ( needFullItems . length ) {
var item = needFullItems . shift ( ) ;
Zotero . debug ( "looking up contextObject" ) ;
var search = Zotero . loadTranslator ( "search" ) ;
search . setHandler ( "itemDone" , function ( obj , item ) {
newItems . push ( item ) ;
} ) ;
search . setHandler ( "done" , function ( ) {
retrieveNextCOinS ( needFullItems , newItems , couldUseFullItems , doc ) ;
} ) ;
// look for translators
2011-07-01 19:39:06 +00:00
search . setHandler ( "translators" , function ( obj , translators ) {
2011-07-01 05:15:39 +00:00
if ( translators . length ) {
search . setTranslator ( translators ) ;
search . translate ( ) ;
} else {
retrieveNextCOinS ( needFullItems , newItems , couldUseFullItems , doc ) ;
}
} ) ;
2011-07-01 19:39:06 +00:00
search . setSearch ( item ) ;
search . getTranslators ( ) ;
2008-09-11 04:40:07 +00:00
} else {
completeCOinS ( newItems , couldUseFullItems , doc ) ;
Zotero . done ( ) ;
}
}
// saves all COinS objects
function completeCOinS ( newItems , couldUseFullItems , doc ) {
if ( newItems . length > 1 ) {
2011-07-01 05:15:39 +00:00
var selectArray = new Array ( newItems . length ) ;
2008-09-11 04:40:07 +00:00
for ( var i in newItems ) {
selectArray [ i ] = newItems [ i ] . title ;
}
2011-07-01 05:15:39 +00:00
Zotero . selectItems ( selectArray , function ( selectArray ) {
var useIndices = new Array ( ) ;
for ( var i in selectArray ) {
useIndices . push ( i ) ;
}
completeItems ( newItems , useIndices , couldUseFullItems ) ;
} ) ;
2008-09-11 04:40:07 +00:00
} else if ( newItems . length ) {
completeItems ( newItems , [ 0 ] , couldUseFullItems ) ;
}
}
function completeItems ( newItems , useIndices , couldUseFullItems , doc ) {
if ( ! useIndices . length ) {
return ;
}
var i = useIndices . shift ( ) ;
// grab full item if the COinS was missing an author
if ( couldUseFullItems [ i ] ) {
Zotero . debug ( "looking up contextObject" ) ;
var search = Zotero . loadTranslator ( "search" ) ;
var firstItem = false ;
search . setHandler ( "itemDone" , function ( obj , newItem ) {
if ( ! firstItem ) {
// add doc as attachment
newItem . attachments . push ( { document : doc } ) ;
newItem . complete ( ) ;
firstItem = true ;
}
} ) ;
search . setHandler ( "done" , function ( obj ) {
// if we didn't find anything, use what we had before (even if it
// lacks the creator)
if ( ! firstItem ) {
newItems [ i ] . complete ( ) ;
}
// call next
completeItems ( newItems , useIndices , couldUseFullItems ) ;
} ) ;
2011-07-01 19:39:06 +00:00
search . setHandler ( "translators" , function ( obj , translators ) {
2011-07-01 05:15:39 +00:00
if ( translators . length ) {
search . setTranslator ( translators ) ;
search . translate ( ) ;
} else {
// add doc as attachment
newItems [ i ] . attachments . push ( { document : doc } ) ;
newItems [ i ] . complete ( ) ;
// call next
completeItems ( newItems , useIndices , couldUseFullItems ) ;
}
} ) ;
2011-07-01 19:39:06 +00:00
search . setSearch ( newItems [ i ] ) ;
search . getTranslators ( ) ;
2008-09-11 04:40:07 +00:00
} else {
// add doc as attachment
newItems [ i ] . attachments . push ( { document : doc } ) ;
newItems [ i ] . complete ( ) ;
// call next
completeItems ( newItems , useIndices , couldUseFullItems ) ;
}
}
function doWeb ( doc , url ) {
var newItems = new Array ( ) ;
var needFullItems = new Array ( ) ;
var couldUseFullItems = new Array ( ) ;
2010-09-15 18:43:52 +00:00
// See note in detectWeb()
function nsResolver ( ) {
return 'http://www.w3.org/1999/xhtml' ;
}
var spans = doc . evaluate ( '//x:span[contains(@class, " Z3988") or contains(@class, "Z3988 ") or @class="Z3988"][@title]' , doc , nsResolver , XPathResult . ANY _TYPE , null ) ;
2010-06-16 07:44:31 +00:00
var span ;
while ( span = spans . iterateNext ( ) ) {
var spanTitle = span . title ;
var newItem = new Zotero . Item ( ) ;
newItem . repository = false ; // do not save repository
if ( Zotero . Utilities . parseContextObject ( spanTitle , newItem ) ) {
if ( newItem . title ) {
if ( ! newItem . creators . length ) {
// if we have a title but little other identifying
// information, say we'll get full item later
newItem . contextObject = spanTitle ;
couldUseFullItems [ newItems . length ] = true ;
2008-09-11 04:40:07 +00:00
}
2010-06-16 07:44:31 +00:00
// title and creators are minimum data to avoid looking up
newItems . push ( newItem ) ;
} else {
// retrieve full item
newItem . contextObject = spanTitle ;
needFullItems . push ( newItem ) ;
2008-09-11 04:40:07 +00:00
}
}
}
Zotero . debug ( needFullItems ) ;
if ( needFullItems . length ) {
// retrieve full items asynchronously
Zotero . wait ( ) ;
retrieveNextCOinS ( needFullItems , newItems , couldUseFullItems , doc ) ;
} else {
completeCOinS ( newItems , couldUseFullItems , doc ) ;
}
2011-07-01 05:15:39 +00:00
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type" : "web" ,
"url" : "http://www.husdal.com/2011/06/19/disruptions-in-supply-networks/" ,
"items" : [
{
"itemType" : "journalArticle" ,
"creators" : [
{
"firstName" : "Phil" ,
"lastName" : "Greening" ,
"creatorType" : "author"
} ,
{
"firstName" : "Christine" ,
"lastName" : "Rutherford" ,
"creatorType" : "author"
}
] ,
"notes" : [ ] ,
"tags" : [ ] ,
"seeAlso" : [ ] ,
"attachments" : [
{ }
] ,
"publicationTitle" : "International Journal of Logistics Management" ,
"title" : "Disruptions and supply networks: a multi-level, multi-theoretical relational perspective" ,
"date" : "2011" ,
"volume" : "22" ,
"issue" : "1" ,
"pages" : "104-126" ,
"libraryCatalog" : false ,
"shortTitle" : "Disruptions and supply networks"
}
]
} ,
{
"type" : "web" ,
"url" : "http://gamblershouse.wordpress.com/2011/06/19/the-view-from-dolores/" ,
"items" : "multiple"
} ,
{
"type" : "web" ,
"url" : "http://www.hubmed.org/display.cgi?uids=21665052" ,
"items" : [
{
"itemType" : "journalArticle" ,
"creators" : [
{
"creatorType" : "author" ,
"firstName" : "Hui-Wen Vivian" ,
"lastName" : "Tang"
}
] ,
"notes" : [ ] ,
"tags" : [ ] ,
"seeAlso" : [ ] ,
"attachments" : [
{ }
] ,
"publicationTitle" : "Evaluation and Program Planning" ,
"volume" : "34" ,
"ISSN" : "01497189" ,
"date" : "11/2011" ,
"pages" : "343-352" ,
"DOI" : "10.1016/j.evalprogplan.2011.04.002" ,
"url" : "http://linkinghub.elsevier.com/retrieve/pii/S0149718911000449" ,
"title" : "Optimizing an immersion ESL curriculum using analytic hierarchy process" ,
"libraryCatalog" : "CrossRef"
}
]
}
]
/** END TEST CASES **/