From 9c7c5c1ba51111521f23b7293dfab4659f49e201 Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Mon, 27 May 2013 20:46:23 -0500 Subject: [PATCH] [Cell Press] Add support for supplementary data --- Cell Press.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/Cell Press.js b/Cell Press.js index 9a79ac1eeaa..7a6e4d45cac 100644 --- a/Cell Press.js +++ b/Cell Press.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2013-01-25 22:40:39" + "lastUpdated": "2013-05-28 01:31:45" } /* @@ -83,6 +83,7 @@ function scrape(doc, url) { i--; } } + if(pdfUrl) { ZU.doGet(pdfUrl, function(text) { if(text.indexOf('onload="javascript:redirectToScienceURL();"') != -1) { @@ -94,21 +95,101 @@ function scrape(doc, url) { pdfUrl += (pdfUrl.indexOf('?') != -1 ? '&' : '?') + 'intermediate=true'; } + item.attachments.push({ title: 'Full Text PDF', url: pdfUrl, mimeType: 'application/pdf' }); - item.complete(); + + finalize(item, doc, url, pdfUrl); }); } else { - item.complete(); + finalize(item, doc, url, pdfUrl); } }); translator.translate(); } +//mimetype map for supplementary attachments +//intentionally excluding potentially large files like videos and zip files +var suppTypeMap = { + 'pdf': 'application/pdf', + 'doc': 'application/msword', + 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'xls': 'application/vnd.ms-excel', + 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' +}; + +function finalize(item, doc, url, pdfUrl) { + if(Z.getHiddenPref && Z.getHiddenPref('attachSupplementary')) { + try { + //check if there is supplementary data + var tabs = doc.getElementById('aotftabs'); + var suppLink; + if(tabs) { + //enhanced view (AJAX driven), but let's see if we even have supp. data + suppLink = ZU.xpath(tabs, './/a[@href="#suppinfo"]')[0]; + if(suppLink) { + //construct a link to the standard view of supp. data + suppLink = url.replace(/[^\/]+(?=\/[^\/]*$)/, 'supplemental') + .replace(/[?#].*/, ''); + } + } else if(tabs = doc.getElementById('article_options')) { + //standard view + suppLink = ZU.xpathText(tabs, './/a[text()="Supplemental Data"]/@href'); + } + if(suppLink) { + if(Z.getHiddenPref('supplementaryAsLink')) { + item.attachments.push({ + title: 'Supplementary Data', + url: suppLink, + mimeType: 'text/html', + snapshot: false + }); + } else { + ZU.processDocuments(suppLink, function(suppDoc) { + var suppEntries = ZU.xpath(suppDoc, '//div[@id="main_supp"]/dl/dt'); + for(var i=0, n=suppEntries.length; i