-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.html
71 lines (61 loc) · 1.8 KB
/
index.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Elm + Intl</title>
<script type="text/javascript" src="elm.js"></script>
</head>
<body>
<div id="myapp"></div>
</body>
<script type="text/javascript">
// Create a function that that formats text as you need. Here we have
// a function to localize dates:
//
// localizeDate('sr-RS', 12, 5) == "петак, 1. јун 2012."
// localizeDate('en-GB', 12, 5) == "Friday, 1 June 2012"
// localizeDate('en-US', 12, 5) == "Friday, June 1, 2012"
//
function localizeDate(lang, year, month)
{
const dateTimeFormat = new Intl.DateTimeFormat(lang, {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
return dateTimeFormat.format(new Date(year, month));
}
// Define a Custom Element that uses this function. Here we make it
// possible to define nodes like this:
//
// <intl-date lang="sr-RS" year="2012" month="5">
// <intl-date lang="en-GB" year="2012" month="5">
// <intl-date lang="en-US" year="2012" month="5">
//
// Check out src/Main.elm to see how you use this on the Elm side.
//
customElements.define('intl-date',
class extends HTMLElement {
// things required by Custom Elements
constructor() { super(); }
connectedCallback() { this.setTextContent(); }
attributeChangedCallback() { this.setTextContent(); }
static get observedAttributes() { return ['lang','year','month']; }
// Our function to set the textContent based on attributes.
setTextContent()
{
const lang = this.getAttribute('lang');
const year = this.getAttribute('year');
const month = this.getAttribute('month');
this.textContent = localizeDate(lang, year, month);
}
}
);
// Start the Elm application that uses the <intl-date> node.
//
var app = Elm.Main.init({
node: document.getElementById('myapp')
});
</script>
</html>