summaryrefslogtreecommitdiff
path: root/Education Week.js
blob: cbffab09a1540e29f2b2d9e7dbe80b35465265fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{
	"translatorID": "7e51d3fb-082e-4063-8601-cda08f6004a3",
	"label": "Education Week",
	"creator": "Ben Parr",
	"target": "^https?://(?:www\\.|blogs\\.|www2\\.)?edweek",
	"minVersion": "1.0.0b4.r1",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2012-08-06 19:23:07"
}

function detectWeb(doc,url)
{
	   var namespace = doc.documentElement.namespaceURI;
	   var nsResolver = namespace ? function(prefix) {
	   if (prefix == 'x') return namespace; else return null;
	   } : null;

	   var xpath='//meta[@name="Story_type"]/@content';
	   var temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE,null).iterateNext();
	   if(temp)
	   {
			   if(temp.value=="Blog")
					   {return "blogPost";}
			   if(temp.value.indexOf("Story")>-1)
					   {return "magazineArticle";}
	   }
}

function associateMeta(newItem, metaTags, field, zoteroField) {
	  if(metaTags[field]) {
			  newItem[zoteroField] = metaTags[field];
	  }
}

function scrape(doc, url) {

	  var newItem = new Zotero.Item("magazineArticle");
	   if(url&&url.indexOf("blogs.edweek.org")>-1)
			   {newItem.itemType="blogPost";}

	  newItem.url = doc.location.href;

	  var metaTags = new Object();

	  var metaTagHTML = doc.getElementsByTagName("meta");
	  var i;
	  for (i = 0 ; i < metaTagHTML.length ; i++) {
			  metaTags[metaTagHTML[i].getAttribute("name")]=Zotero.Utilities.cleanTags(metaTagHTML[i].getAttribute("content"));
	  }
	  associateMeta(newItem, metaTags, "Title", "title");
	  associateMeta(newItem, metaTags, "Cover_date", "date");
	  associateMeta(newItem, metaTags, "Description", "abstractNote");
	  associateMeta(newItem, metaTags, "ArticleID", "accessionNumber");
	  associateMeta(newItem,metaTags,"Source","publicationTitle");


		if (metaTags["Authors"]) {
			  var author = Zotero.Utilities.trimInternal(metaTags["Authors"]);
			  if (author.substr(0,3).toLowerCase() == "by ") {
					  author = author.substr(3);
			  }

			  var authors = author.split(" and ");
			  for each(var author in authors) {
					  var words = author.split(" ");
					  for (var i in words) {
							  words[i] = words[i][0].toUpperCase() +words[i].substr(1).toLowerCase();
					  }
					  author = words.join(" ");

		newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author"));
			  }
	  }

	   newItem.complete();
}

function doWeb(doc,url)
{
	   var namespace = doc.documentElement.namespaceURI;
	   var nsResolver = namespace ? function(prefix) {
	   if (prefix == 'x') return namespace; else return null;
	   } : null;

	  var xpath='//meta[@name="Story_type"]/@content';
	  var temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE,null).iterateNext();
	  if(temp)
	  {
			 if(temp.value.indexOf("Story")>-1 || temp.value=="Blog")
					   {scrape(doc,url);}
	  }
}

/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.edweek.org/ew/articles/2011/10/28/10jobs.h31.html?tkn=PUOFjigAbQPNufjjHPxYeafVz7T5Tf16qNb4&cmp=clp-edweek",
		"items": [
			{
				"itemType": "magazineArticle",
				"creators": [
					{
						"firstName": "Michele",
						"lastName": "Mcneil",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [],
				"url": "http://www.edweek.org/ew/articles/2011/10/28/10jobs.h31.html?tkn=PUOFjigAbQPNufjjHPxYeafVz7T5Tf16qNb4&cmp=clp-edweek",
				"title": "Obama Using Education Issue as Political Sword",
				"date": "2011-11-02",
				"abstractNote": "The Obama administration highlights its education record, while drawing a sharp contrast with the GOP in Congress.",
				"publicationTitle": "Education Week",
				"libraryCatalog": "Education Week",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	}
]
/** END TEST CASES **/