-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathindex.html
More file actions
251 lines (218 loc) · 7.15 KB
/
index.html
File metadata and controls
251 lines (218 loc) · 7.15 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>time elements</title>
</head>
<body>
<h2>Past Date</h2>
<h3>Format DateTime</h3>
<p>
Default:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime">
Jan 1 1970
</relative-time>
</p>
<p>
With time:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime" hour="numeric" minute="2-digit" second="2-digit">
Jan 1 1970
</relative-time>
</p>
<p>
No title attribute:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime" hour="numeric" minute="2-digit" second="2-digit"
no-title>
Jan 1 1970
</relative-time>
</p>
<p>
h12 cycle:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime" hour="numeric" minute="2-digit" second="2-digit" hour-cycle="h12">
Jan 1 1970
</relative-time>
</p>
<p>
h23 cycle:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime" hour="numeric" minute="2-digit" second="2-digit" hour-cycle="h23">
Jan 1 1970
</relative-time>
</p>
<p>
Customised options:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime" weekday="narrow" year="2-digit" month="narrow" day="numeric" hour="numeric" minute="2-digit" second="2-digit">
Jan 1 1970
</relative-time>
</p>
<h3>Format Relative</h3>
<p>
Default:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="relative">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Fixed to future tense:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="relative" tense="future">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<h3>Format Duration</h3>
<p>
Default:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="duration">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Month precision:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="duration" precision="month">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Fixed to future tense:
<relative-time datetime="1970-01-01T00:00:00.000Z" format="duration" tense="future">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<h2>Future Date</h2>
<h3>Format DateTime</h3>
<p>
Default:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="datetime">
Jan 1 2023
</relative-time>
</p>
<p>
With time:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="datetime" hour="numeric" minute="2-digit" second="2-digit">
Jan 1 2023
</relative-time>
</p>
<p>
Customised options:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="datetime" weekday="narrow" year="2-digit" month="narrow" day="numeric" hour="numeric" minute="2-digit" second="2-digit">
Jan 1 2023
</relative-time>
</p>
<h3>Format Relative</h3>
<p>
Default:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="relative">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Fixed to past tense:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="relative" tense="past">
Oops! This browser doesn't support Web Components.
</relative-time>
<p>
<h3>Format Duration</h3>
<p>
Default:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="duration">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Month precision:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="duration" precision="month">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Fixed to future tense:
<relative-time datetime="2038-01-01T00:00:00.000Z" format="duration" tense="future">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<h2>Dynamic Formats</h2>
<p>
Nearby, dynamic, relative time:
<relative-time datetime="2019-08-12T20:50:00.000Z" id="dynamic1">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Nearby, dynamic, relative time:
<relative-time datetime="2019-08-12T20:50:00.000Z" id="dynamic2">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Nearby, dynamic, relative time:
<relative-time datetime="2019-08-12T20:50:00.000Z" tense="past" id="dynamic3">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
How long you've been on this page
<relative-time id="dynamic4" format="elapsed">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Countdown timer until 2038 bug:
<relative-time datetime="2038-01-19T03:14:08Z" format="elapsed">
Oops! This browser doesn't support Web Components.
</time-until>
</p>
<h2>Localised Dates</h2>
<p>
Localised to Polish:
<relative-time datetime="2019-08-12T20:50:00.000Z" lang="pl" prefix="">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Localised to Hebrew with Format=DateTime
<relative-time datetime="2019-08-12T20:50:00.000Z" format="datetime" lang="he">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Localised to French with Format=Duration
<relative-time datetime="2019-08-12T20:50:00.000Z" format="duration" lang="fr">
Oops! This browser doesn't support Web Components.
</relative-time>
</p>
<p>
Lazily added datetime via setAttribute
<relative-time id="lazy" tense="past">
This will display in one second.
</relative-time>
</p>
<h2>With Aria Hidden</h2>
<button class="js-toggle-aria-hidden">
With aria-hidden
<relative-time aria-hidden="true" datetime="1970-01-01T00:00:00.000Z">
</relative-time>
</button>
<!-- <script type="module" src="../dist/index.js"></script> -->
<script type="module" src="https://unpkg.com/@github/relative-time-element@latest/dist/bundle.js"></script>
<script>
document.body.addEventListener('relative-time-updated', event => {
console.log('event from', event.target, event)
});
document.getElementById('dynamic1').date = new Date()
document.getElementById('dynamic2').date = new Date(Date.now() - 30000)
document.getElementById('dynamic3').date = new Date(Date.now() + 5000)
document.getElementById('dynamic4').date = new Date()
setTimeout(() => {
document.getElementById('lazy').setAttribute('datetime', new Date().toJSON())
}, 1000)
const toggleAriaHidden = (event) => {
const relativeTimeElement = event.currentTarget.querySelector('relative-time')
if (relativeTimeElement.getAttribute('aria-hidden') === 'true') {
relativeTimeElement.setAttribute('aria-hidden', 'false')
} else {
relativeTimeElement.setAttribute('aria-hidden', 'true')
}
}
const button = document.querySelector('.js-toggle-aria-hidden')
button.addEventListener('click', toggleAriaHidden)
</script>
</body>
</html>