-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjob-posting.js
More file actions
101 lines (93 loc) · 3.52 KB
/
job-posting.js
File metadata and controls
101 lines (93 loc) · 3.52 KB
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
window.onload = function () {
var tmpl = "\u003Cscript type=\"application/ld+json\"> {\n" +
" \"@context\" : \"http://schema.org/\",\n" +
" \"@type\" : \"JobPosting\",\n" +
" \"title\" : \"{{title}}\",\n" +
" \"description\" : \"{{description}}\",\n" +
" \"identifier\": {\n" +
" \"@type\" : \"PropertyValue\",\n" +
" \"name\" : \"Kaimuki YMCA\",\n" +
" \"value\" : \"{{postingId}}\"\n" +
" },\n" +
" \"datePosted\" : \"{{datePosted}}\",\n" +
" \"validThrough\" : \"{{validThrough}}\",\n" +
" \"employmentType\" : \"{{employmentType}}\",\n" +
" \"hiringOrganization\" : {\n" +
" \"@type\" : \"Organization\",\n" +
" \"name\" : \"{{name}}\",\n" +
" \"sameAs\" : \"{{sameAs}}\",\n" +
" \"logo\" : \"{{logo}}\"\n" +
" },\n" +
" \"jobLocation\" : {\n" +
" \"@type\" : \"Place\",\n" +
" \"address\" : {\n" +
" \"@type\" : \"PostalAddress\",\n" +
" \"streetAddress\" : \"{{streetAddress}}\",\n" +
" \"addressLocality\" : \"{{addressLocality}}\",\n" +
" \"addressRegion\" : \"{{addressRegion}}\",\n" +
" \"postalCode\" : \"{{postalCode}}\",\n" +
" \"addressCountry\": \"US\"\n" +
" }\n" +
" }\n" +
"}\n" +
"\u003C/script>";
function spaces2html(line) {
// convert leading spaces to non-breaking space entities
return new Array(line.length + 1).join(' ')
}
function line2html(line) {
// convert line to HTML paragraph
return line.replace(/^(\s)+/, spaces2html);
}
function formatLineBreak(str) {
var lines = str.split("\n");
return lines.map(function (x) {return line2html(x) + "<br>"}).join("\n");
}
// handle no data and missing properties
var render = function (data) {
return data ?
tmpl.replace("{{name}}",data['name']||'')
.replace("{{sameAs}}",data['sameAs']||'')
.replace("{{logo}}",data['logo']||'')
.replace("{{title}}", data['title']||'')
.replace("{{description}}",data['description']||'')
.replace("{{postingId}}",data['postingId']||'')
.replace("{{datePosted}}",data['datePosted']||'')
.replace("{{validThrough}}",data['validThrough']||'')
.replace("{{employmentType}}",data['employmentType']||'')
.replace("{{streetAddress}}",data['streetAddress']||'')
.replace("{{addressLocality}}",data['addressLocality']||'')
.replace("{{addressRegion}}",data['addressRegion']||'')
.replace("{{postalCode}}",data['postalCode']||'')
:
{};
}
function getValue(elem) {
var item = document.getElementsByName(elem);
if (item.length < 1)
return '';
return item[0].value.trim();
}
var sbtn = document.getElementsByName("submit")[0];
sbtn.onclick = function () {
var data = {};
data.name = getValue("name");
data.sameAs = getValue("sameAs");
data.logo = getValue("logo");
data.title = getValue("title");
data.streetAddress = getValue("streetAddress");
data.addressLocality = getValue("addressLocality");
data.addressRegion = getValue("addressRegion");
data.postalCode = getValue("postalCode");
data.description = formatLineBreak(getValue("description"));
data.datePosted = getValue("datePosted");
data.validThrough = getValue("validThrough");
data.employmentType = getValue("employmentType");
data.postingId = getValue("postingId");
document.getElementsByTagName("pre")[0].innerText = render(data);
}
var cbtn = document.getElementsByName("clear")[0];
cbtn.onclick = function () {
document.getElementsByTagName("pre")[0].innerText = " ";
}
}