This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathschemas.js
307 lines (294 loc) · 25 KB
/
schemas.js
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
(function($) {
if (!jQuery.microdata) {
console.error('jQuery Microdata plugin has not been loaded prior to loading this script!');
return;
}
var validators = $.microdata.validators;
function extend(base, additions) {
var ret = base.fields.slice();
for (var i = 0; i < additions.length; i++) {
if (!findField(additions[i].name))
ret.push(additions[i]);
}
return ret;
function findField(name) {
for (var i = 0; i < ret.length; i++) {
if (ret[i].name.toLowerCase() == name.toLowerCase()) return ret[i];
}
return false;
}
}
function findByUrl(source, url) {
for (var i = 0; i < source.length; i++) {
if (source[i].url == url) return source[i];
}
return null;
}
// A partial implementation of data-vocabulary.org schemas
var dataVocabulary = [
{
url: "http://data-vocabulary.org/Event",
fields: [
{ name: "summary", required: true, type: "text", validator: validators.text },
{ name: "url", required: false, type: "url", validator: validators.url },
{ name: "location", required: false, type: "complex", validator: validators.complex }, // optionally represented by data-vocabulary.org/Organization or data-vocabulary.org/Address
{ name: "description", required: false, type: "text", validator: validators.text },
{ name: "startdate", required: true, type: "datetime", validator: validators.datetime },
{ name: "enddate", required: false, type: "datetime", validator: validators.datetime },
{ name: "duration", required: false, type: "duration", validator: validators.duration },
{ name: "eventtype", required: false, type: "text", validator: validators.text },
{ name: "geo", required: false, type: "complex", validator: validators.complex }, // represented by itemscope with two properties: latitude and longitude
{ name: "photo", required: false, type: "url", validator: validators.url }
]
},
{
url: "http://data-vocabulary.org/Person",
fields: [
{ name: "name", required: false, type: "text", validator: validators.text },
{ name: "fn", required: false, type: "text", validator: validators.text }, // alias for "name"
{ name: "nickname", required: false, type: "text", validator: validators.text },
{ name: "photo", required: false, type: "url", validator: validators.url },
{ name: "title", required: false, type: "text", validator: validators.text },
{ name: "role", required: false, type: "text", validator: validators.text },
{ name: "url", required: false, type: "url", validator: validators.url },
{ name: "affiliation", required: false, type: "text", validator: validators.text },
{ name: "org", required: false, type: "text", validator: validators.text }, // alias for "affiliation"
{ name: "address", required: false, type: "complex", validator: validators.complex }, // can have subproperties street-address, city, region, postal-code, country-name
{ name: "adr", required: false, type: "complex", validator: validators.complex }, // alias for "address"
{ name: "friend", required: false, type: "url", validator: validators.url },
{ name: "contact", required: false, type: "url", validator: validators.url },
{ name: "acquaintance", required: false, type: "url", validator: validators.url }
// NOTE: to define "friend", "contact" or "acquaintance", you can also use XFN rel="..."
]
},
{
url: "http://data-vocabulary.org/Organization",
fields: [
{ name: "name", required: false, type: "text", validator: validators.text },
{ name: "fn", required: false, type: "text", validator: validators.text }, // alias for "name"
{ name: "org", required: false, type: "text", validator: validators.text }, // alias for "name"
{ name: "url", required: false, type: "url", validator: validators.url },
{ name: "address", required: false, type: "complex", validator: validators.complex },
{ name: "adr", required: false, type: "complex", validator: validators.complex }, // alias for "address"
{ name: "tel", required: false, type: "text", validator: validators.text },
{ name: "geo", required: false, type: "complex", validator: validators.complex }
]
},
{
url: "http://data-vocabulary.org/Offer",
fields: [
{ name: "price", required: false, type: "float", validator: validators.float },
{ name: "currency", required: false, type: "text", validator: validators.currency },
{ name: "pricevaliduntil", required: false, type: "datetime", validator: validators.datetime },
{ name: "seller", required: false, type: "complex", validator: validators.complex }, // can contain a Person or Organization
{
name: "condition", required: false, type: "complex",
validator: function(value, el) {
return $(el).hasAttr('content') && $.inArray($(el).attr('content').toLowerCase(), ["new", "used", "refurbished"]);
}
},
{
name: "availability", required: false, type: "complex",
validator: function(value, el) {
return $(el).hasAttr('content') && $.inArray($(el).attr('content').toLowerCase(), ["out_of_stock", "in_stock", "instore_only", "preorder"]);
}
},
{ name: "offerurl", required: false, type: "url", validator: validators.url }, // points to a product web page that includes the offer
{ name: "identifier", required: false, type: "text", validator: validators.text }, // recognizes ASIN, ISBN, MPN, UPC, SKU; suggests including product prand and at least one of the identifiers
{ name: "itemoffered", required: false, type: "complex", validator: validators.complex } // can contain free text, a Product or other item types
]
}
];
// add the data-vocabulary.org validators to the plugin
for (var i = 0; i < dataVocabulary.length; i++) {
$.microdata.addDefinition(dataVocabulary[i].url, dataVocabulary[i].fields);
}
// This section pertains to the schema.org definitions
var schemaOrg = [
{
url: "http://schema.org/Thing",
fields: [
{ name: "description", required: false, type: "text", validator: validators.text },
{ name: "image", required: false, type: "url", validator: validators.url },
{ name: "name", required: false, type: "text", validator: validators.text },
{ name: "url", required: false, type: "url", validator: validators.url }
]
}
];
schemaOrg.push({
url: "http://schema.org/Event",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Thing"), [
{ name: "attendees", required: false, type: "complex", validator: validators.complex }, // child elements of type Person or Organization
{ name: "duration", required: false, type: "duration", validator: validators.duration },
{ name: "endDate", required: false, type: "datetime", validator: validators.datetime },
{ name: "location", required: false, type: "complex", validator: validators.complex }, // child elements of type Place or PostalAddress
{ name: "offers", required: false, type: "complex", validator: validators.complex }, // child elements of type Offer
{ name: "performers", required: false, type: "complex", validator: validators.complex }, // child elements of type Person or Organization
{ name: "startDate", required: false, type: "datetime", validator: validators.datetime },
{ name: "subEvents", required: false, type: "complex", validator: validators.complex }, // child elements of type Event
{ name: "superEvent", required: false, type: "complex", validator: validators.complex } // a child element of type Event
])
});
schemaOrg.push({
url: "http://schema.org/Organization",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Thing"), [
{ name: "address", required: false, type: "complex", validator: validators.complex }, // a child element of PostalAddress
{ name: "aggregatRating", required: false, type: "complex", validator: validators.complex }, // a child element of AggregateRating
{ name: "contactPoints", required: false, type: "complex", validator: validators.complex }, // child elements of ContactPoint
{ name: "email", required: false, type: "text", validator: validators.email },
{ name: "employees", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "events", required: false, type: "complex", validator: validators.complex }, // a child element of Event
{ name: "faxNumber", required: false, type: "text", validator: validators.text },
{ name: "founders", required: false, type: "complex", validator: validators.complex }, // child elements of type Person
{ name: "foundingDate", required: false, type: "datetime", validator: validators.datetime },
{ name: "interactionCount", required: false, type: "text", validator: validators.text }, // should be one of the types of UserInteraction
{ name: "location", required: false, type: "complex", validator: validators.complex }, // a child element of Place or PostalAddress
{ name: "members", required: false, type: "complex", validator: validators.complex }, // child elements of Person or Organization
{ name: "reviews", required: false, type: "complex", validator: validators.complex }, // child elements of Review
{ name: "telephone", required: false, type: "text", validator: validators.text }
])
});
schemaOrg.push({
url: "http://schema.org/Intangible",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Thing"), [])
});
schemaOrg.push({
url: "http://schema.org/Product",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Thing"), [
{ name: "aggregateRating", required: false, type: "complex", validator: validators.complex }, // a child element of AggregateRating
{ name: "brand", required: false, type: "complex", validator: validators.complex }, // a child element of Organization
{ name: "manufacturer", required: false, type: "complex", validator: validators.complex }, // a child element of Organization
{ name: "model", required: false, type: "text", validator: validators.text },
{ name: "offers", required: false, type: "complex", validator: validators.complex }, // child elements of Offer
{ name: "productId", required: false, type: "text", validator: validators.text },
{ name: "reviews", required: false, type: "complex", validator: validators.complex } // child elements of Review
])
});
schemaOrg.push({
url: "http://schema.org/CreativeWork",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Thing"), [
{name: "about", required: false, type: "complex", validator: validators.text },
{name: "accountablePerson", required: false, type: "complex", validator: validators.text },
{name: "aggregateRating", required: false, type: "complex", validator: validators.text },
{name: "alternativeHeadline", required: false, type: "text", validator: validators.text },
{name: "associatedMedia", required: false, type: "complex", validator: validators.text },
{name: "audience", required: false, type: "complex", validator: validators.text },
{name: "audio", required: false, type: "complex", validator: validators.complex },
{name: "author", required: false, type: "complex", validator: validators.complex },
{name: "award", required: false, type: "text", validator: validators.text },
{name: "awards", required: false, type: "text", validator: validators.text },
{name: "comment", required: false, type: "complex", validator: validators.complex },
{name: "contentLocation", required: false, type: "complex", validator: validators.complex },
{name: "contentRating", required: false, type: "text", validator: validators.text },
{name: "contributor", required: false, type: "complex", validator: validators.complex },
{name: "copyrightHolder", required: false, type: "complex", validator: validators.complex },
{name: "copyrightYear", required: false, type: "number", validator: validators.number },
{name: "creator", required: false, type: "complex", validator: validators.complex },
{name: "dateCreated", required: false, type: "datetime", validator: validators.datetime },
{name: "dateModified", required: false, type: "datetime", validator: validators.datetime },
{name: "datePublished", required: false, type: "datetime", validator: validators.datetime },
{name: "discussionUrl", required: false, type: "url", validator: validators.url },
{name: "editor", required: false, type: "complex", validator: validators.complex },
{name: "educationalAlignment", required: false, type: "complex", validator: validators.complex },
{name: "educationalUse", required: false, type: "text", validator: validators.text },
{name: "encoding", required: false, type: "complex", validator: validators.complex },
{name: "encodings", required: false, type: "complex", validator: validators.complex },
{name: "genre", required: false, type: "text", validator: validators.text },
{name: "headline", required: false, type: "text", validator: validators.text },
{name: "inLanguage", required: false, type: "text", validator: validators.text },
{name: "interactionCount", required: false, type: "text", validator: validators.text },
{name: "interactivityType", required: false, type: "text", validator: validators.text },
{name: "isBasedOnUrl", required: false, type: "url", validator: validators.url },
{name: "isFamilyFriendly", required: false, type: "boolean", validator: validators.boolean },
{name: "keywords", required: false, type: "text", validator: validators.text },
{name: "learningResourceType", required: false, type: "text", validator: validators.text },
{name: "mentions", required: false, type: "complex", validator: validators.complex },
{name: "offers", required: false, type: "complex", validator: validators.complex },
{name: "provider", required: false, type: "complex", validator: validators.complex },
{name: "publisher", required: false, type: "complex", validator: validators.complex },
{name: "publishingPrinciples", required: false, type: "url", validator: validators.url },
{name: "review", required: false, type: "complex", validator: validators.complex },
{name: "reviews", required: false, type: "complex", validator: validators.complex },
{name: "sourceOrganization", required: false, type: "complex", validator: validators.complex },
{name: "text", required: false, type: "text", validator: validators.text },
{name: "thumbnailUrl", required: false, type: "url", validator: validators.url },
{name: "timeRequired", required: false, type: "duration", validator: validators.duration },
{name: "typicalAgeRange", required: false, type: "text", validator: validators.text },
{name: "version", required: false, type: "number", validator: validators.number },
{name: "video" , required: false, type: "complex", validator: validators.complex }
])
});
schemaOrg.push({
url: "http://schema.org/Book",
fields: extend(findByUrl(schemaOrg, "http://schema.org/CreativeWork"), [
{ name: "bookEdition", required: false, type: "text", validator: validators.text },
{ name: "bookFormat", required: false, type: "complex", validator: validators.complex },
{ name: "illustrator", required: false, type: "complex", validator: validators.complex },
{ name: "isbn", required: false, type: "text", validator: validators.text },
{ name: "numberOfPages", required: false, type: "int", validator: validators.int }
])
});
schemaOrg.push({
url: "http://schema.org/Person",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Thing"), [
{ name: "additionalName", required: false, type: "text", validator: validators.text },
{ name: "address", required: false, type: "complex", validator: validators.complex }, // a child element of PostalAddress
{ name: "affiliation", required: false, type: "complex", validator: validators.complex }, // a child element of Organization
{ name: "alumniOf", required: false, type: "complex", validator: validators.complex }, // a child element of EducationalOrganization
{ name: "awards", required: false, type: "text", validator: validators.text },
{ name: "birthDate", required: false, type: "datetime", validator: validators.datetime },
{ name: "children", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "colleagues", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "contactPoints", required: false, type: "complex", validator: validators.complex }, // child elements of ContactPoint
{ name: "deathDate", required: false, type: "datetime", validator: validators.datetime }, // hopefully null
{ name: "email", required: false, type: "email", validator: validators.email },
{ name: "familyName", required: false, type: "text", validator: validators.text },
{ name: "faxNumber", required: false, type: "text", validator: validators.text },
{ name: "follows", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "gender", required: false, type: "text", validator: validators.text }, // oddly enough, does not enumerate valid values
{ name: "givenName", required: false, type: "text", validator: validators.text },
{ name: "homeLocation", required: false, type: "complex", validator: validators.complex }, // a child element of Place or ContactPoint
{ name: "honorificPrefix", required: false, type: "text", validator: validators.text }, // something along the lines of Mr., Mrs., etc.
{ name: "honorificSuffix", required: false, type: "text", validator: validators.text }, // similarly, M.D., PhD., etc.
{ name: "interactionCount", required: false, type: "text", validator: validators.text }, // example: "20 UserLikes, 5 UserComments"
{ name: "jobTitle", required: false, type: "text", validator: validators.text }, // example: "Lion tamer"
{ name: "knows", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "memberOf", required: false, type: "complex", validator: validators.complex }, // child elements of Organization
{ name: "nationality", required: false, type: "complex", validator: validators.complex }, // a child element of Country
{ name: "parents", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "performerIn", required: false, type: "complex", validator: validators.complex }, // child elements of Event
{ name: "relatedTo", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "siblings", required: false, type: "complex", validator: validators.complex }, // child elements of Person
{ name: "spouse", required: false, type: "complex", validator: validators.complex }, // a child element of Person (as wrong as that sounds)
{ name: "telephone", required: false, type: "text", validator: validators.text },
{ name: "workLocation", required: false, type: "complex", validator: validators.complex }, // a child element of Location or ContactPoint
{ name: "worksFor", required: false, type: "complex", validator: validators.complex } // a child element of Organization
])
});
schemaOrg.push({
url: "http://schema.org/Offer",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Intangible"), [
{ name: "aggregateRating", required: false, type: "complex", validator: validators.complex }, // AggregateRating schema child element
{ name: "availability", required: false, type: "complex", validator: validators.complex }, // ItemAvailability schema child element
{ name: "itemCondition", required: false, type: "complex", validator: validators.complex }, // OfferItemCondition schema child element
{ name: "itemOffered", required: false, type: "complex", validator: validators.complex }, // Product schema child element
{ name: "price", required: false, type: "text", validator: validators.text },
{ name: "priceCurrency", required: false, type: "text", validator: validators.text },
{ name: "priceValidUntil", required: false, type: "text", validator: validators.text },
{ name: "reviews", required: false, type: "complex", validator: validators.complex }, // Review schema child element
{ name: "seller", required: false, type: "complex", validator: validators.complex } // Organization schema child element
])
});
schemaOrg.push({
url: "http://schema.org/AggregateOffer",
fields: extend(findByUrl(schemaOrg, "http://schema.org/Offer"), [
{ name: "highPrice", required: false, type: "text", validator: validators.text },
{ name: "lowPrice", required: false, type: "text", validator: validators.text },
{ name: "offerCount", required: false, type: "text", validator: validators.text }
])
});
// add schema.org to the roster
for (var i = 0; i < schemaOrg.length; i++) {
$.microdata.addDefinition(schemaOrg[i].url, schemaOrg[i].fields);
}
})(jQuery);