input-duration 2.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +358 -0
- package/docs/chrono.js.html +742 -0
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/global.html +253 -0
- package/docs/global.html#ChronlyHMS +224 -0
- package/docs/index.html +66 -0
- package/docs/module-ChronlyHMS%20Module-ChronlyHMS.html +1745 -0
- package/docs/module-ChronlyHMS%20Module.html +145 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/styles/jsdoc-default.css +358 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/index.js +710 -0
- package/package.json +25 -0
- package/readme/html.png +0 -0
- package/readme/logo.svg +5 -0
- package/readme/safariBad.png +0 -0
- package/webpack.config.js +39 -0
package/index.js
ADDED
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
class ChronlyHMS extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
|
|
4
|
+
super();
|
|
5
|
+
|
|
6
|
+
this.myElement = this.attachShadow({ mode: 'open' });
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// needed for setting inputs when value attribute is added to chronlyHMS
|
|
10
|
+
// <chronly-hms id="bobPrepop" value="99:09:09.999"></chronly-hms>
|
|
11
|
+
|
|
12
|
+
this.value = this.getAttribute('value');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
this.boot();
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
} // end constructor
|
|
19
|
+
|
|
20
|
+
get value() {
|
|
21
|
+
|
|
22
|
+
// return this.getAttribute('value');
|
|
23
|
+
|
|
24
|
+
if (this.myElement.querySelector('input[name="startHours"]') !== null) {
|
|
25
|
+
|
|
26
|
+
return this.myElement.querySelector('input[name="startHours"]').value +
|
|
27
|
+
':' + this.myElement.querySelector('input[name="startMinutes"]').value +
|
|
28
|
+
':' + this.myElement.querySelector('input[name="startSeconds"]').value +
|
|
29
|
+
'.' + this.myElement.querySelector('input[name="startMilliSecs"]').value;
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
|
|
34
|
+
return null;
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
set value(val) {
|
|
40
|
+
|
|
41
|
+
// for setting the value in js (like document.querySelector("#bobPrepop").value = "05:05:05.005")
|
|
42
|
+
if (val) {
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
console.log(val);
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if (/(^[0-9][0-9]):([0-5][0-9]):([0-5][0-9])\.([0-9][0-9][0-9]$)/.exec(val)) {
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// split val
|
|
52
|
+
|
|
53
|
+
var timeArray = val.split(/[.:]+/);
|
|
54
|
+
|
|
55
|
+
console.log('time array is ' + timeArray[0] + ':' + timeArray[1] + ':' + timeArray[2] + ':' + timeArray[3]);
|
|
56
|
+
|
|
57
|
+
console.log('this.id = ' + this.id);
|
|
58
|
+
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
|
|
61
|
+
this.myElement.querySelector('input[name="startHours"]').value = timeArray[0];
|
|
62
|
+
this.myElement.querySelector('input[name="startMinutes"]').value = timeArray[1];
|
|
63
|
+
this.myElement.querySelector('input[name="startSeconds"]').value = timeArray[2];
|
|
64
|
+
this.myElement.querySelector('input[name="startMilliSecs"]').value = timeArray[3];
|
|
65
|
+
}, 0);
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
this.setAttribute('value', val);
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
|
|
74
|
+
console.warn(`The specified value ${val} does not conform to the required format. The format is "HH:mm:ss.SSS" where HH is 00-99, mm is 00-59, ss is 00-59, and SSS is 000-999.`);
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// I think this is for empty string to clear value
|
|
79
|
+
// gives a False bool and removes value from Webcomponent chronlyHMS
|
|
80
|
+
} else {
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
setTimeout(() => {
|
|
84
|
+
|
|
85
|
+
this.myElement.querySelector('input[name="startHours"]').value = '00';
|
|
86
|
+
this.myElement.querySelector('input[name="startMinutes"]').value = '00';
|
|
87
|
+
this.myElement.querySelector('input[name="startSeconds"]').value = '00';
|
|
88
|
+
this.myElement.querySelector('input[name="startMilliSecs"]').value = '000';
|
|
89
|
+
|
|
90
|
+
}, 0);
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
this.removeAttribute('value');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* eventlistener that adds arrow key input of values (up/down) and place toggling (left/right) triggered by
|
|
99
|
+
* the change event of the input
|
|
100
|
+
* @method
|
|
101
|
+
* @see boot()
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
addArrowKeyInput() {
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
console.log('1 this: ' + this);
|
|
108
|
+
console.log('1 this.myElement: ' + this.myElement);
|
|
109
|
+
console.log('1 this.myElement active: ' + this.myElement);
|
|
110
|
+
|
|
111
|
+
var mE = this.myElement;
|
|
112
|
+
|
|
113
|
+
// Left and Right arrow key toggle between HMSmS
|
|
114
|
+
// this depends on data-attributes ex. data-tp="1" in HTML
|
|
115
|
+
|
|
116
|
+
this.myElement.querySelector("div.timeCase")
|
|
117
|
+
.addEventListener('keydown', function (event) {
|
|
118
|
+
|
|
119
|
+
var et = event.target;
|
|
120
|
+
var tp_active = mE.activeElement.dataset.tp;
|
|
121
|
+
|
|
122
|
+
switch (true) {
|
|
123
|
+
|
|
124
|
+
case event.key == "ArrowLeft":
|
|
125
|
+
|
|
126
|
+
if (tp_active >= 2) {
|
|
127
|
+
tp_active--;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
et.parentElement.querySelector("[data-tp='" + tp_active + "']").focus();
|
|
131
|
+
setTimeout(function () { et.parentElement.querySelector("[data-tp='" + tp_active + "']").select(); }, 5);
|
|
132
|
+
|
|
133
|
+
break;
|
|
134
|
+
|
|
135
|
+
case event.key == "ArrowRight":
|
|
136
|
+
// tp_active = this.myElement.shadowRoot.activeElement.dataset.tp;
|
|
137
|
+
|
|
138
|
+
if (tp_active <= 3) {
|
|
139
|
+
tp_active++;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
et.parentElement.querySelector("[data-tp='" + tp_active + "']").focus();
|
|
143
|
+
setTimeout(function () { et.parentElement.querySelector("[data-tp='" + tp_active + "']").select(); }, 5);
|
|
144
|
+
|
|
145
|
+
break;
|
|
146
|
+
|
|
147
|
+
// these keep the input selected
|
|
148
|
+
case event.key == "ArrowUp":
|
|
149
|
+
|
|
150
|
+
setTimeout(function () { mE.activeElement.select(); }, 5);
|
|
151
|
+
|
|
152
|
+
break;
|
|
153
|
+
|
|
154
|
+
case event.key == "ArrowDown":
|
|
155
|
+
|
|
156
|
+
setTimeout(function () { mE.activeElement.select(); }, 5);
|
|
157
|
+
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
// this is good for testing, to determine whether a key press is detected
|
|
161
|
+
case /^([0-9]?)$/.test(event.key):
|
|
162
|
+
|
|
163
|
+
break;
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* used by boot() to update inputs marked with data-univHMS
|
|
171
|
+
* @method
|
|
172
|
+
* @see boot()
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
addHTML() {
|
|
176
|
+
|
|
177
|
+
var spanIn = document.createElement("div");
|
|
178
|
+
|
|
179
|
+
spanIn.classList.add('timeCase');
|
|
180
|
+
|
|
181
|
+
var template = document.createElement('template');
|
|
182
|
+
|
|
183
|
+
template.innerHTML = `
|
|
184
|
+
<input id="inShadow" type="number" class="sH D2 ts_digit" name="startHours" data-tp="1" min="-1" max="100" value="00" >
|
|
185
|
+
<span class="bds-h">:</span>
|
|
186
|
+
<input type="number" class="sM D2 ts_digit" name="startMinutes" data-tp="2" min="-1" max="60" value="00">
|
|
187
|
+
<span class="bds-m">:</span>
|
|
188
|
+
<input type="number" class="sS D2 ts_digit" name="startSeconds" data-tp="3" min="-1" max="60" value="00">
|
|
189
|
+
<span class="bds-s">.</span>
|
|
190
|
+
<input type="number" class="sMS D3 ts_digit" name="startMilliSecs" data-tp="4" min="-10" max="1010" step="10" value="000">
|
|
191
|
+
<div id="svgContainer">
|
|
192
|
+
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true"
|
|
193
|
+
focusable="false" data-prefix="fal" data-icon="stopwatch" class="svg-inline--fa fa-stopwatch fa-w-14"
|
|
194
|
+
role="img" viewBox="0 0 448 512">
|
|
195
|
+
<path xmlns="http://www.w3.org/2000/svg" fill="currentColor" d="M393.9 184l22.6-22.6c4.7-4.7 4.7-12.3 0-17l-17-17c-4.7-4.7-12.3-4.7-17 0l-20.7 20.7c-31.1-27.5-70.4-45.9-113.8-50.8V48h28c6.6 0 12-5.4 12-12V12c0-6.6-5.4-12-12-12H172c-6.6 0-12 5.4-12 12v24c0 6.6 5.4 12 12 12h28v49.4C96.4 109.3 16 197.2 16 304c0 114.9 93.1 208 208 208s208-93.1 208-208c0-44.7-14.1-86.1-38.1-120zM224 464c-88.4 0-160-71.6-160-160s71.6-160 160-160 160 71.6 160 160-71.6 160-160 160zm12-112h-24c-6.6 0-12-5.4-12-12V204c0-6.6 5.4-12 12-12h24c6.6 0 12 5.4 12 12v136c0 6.6-5.4 12-12 12z"/>
|
|
196
|
+
</svg>
|
|
197
|
+
</div>
|
|
198
|
+
<style>
|
|
199
|
+
*:focus {
|
|
200
|
+
outline: none;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
div.timeCase{
|
|
205
|
+
display: inline-flex;
|
|
206
|
+
flex-direction: row;
|
|
207
|
+
max-width: 300px;
|
|
208
|
+
padding: 3px;
|
|
209
|
+
border-style: solid;
|
|
210
|
+
border-width: 1px;
|
|
211
|
+
border-radius: 2px;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
/* Each input width set and blinking cursor 'caret' removed */
|
|
216
|
+
div.timeCase input{
|
|
217
|
+
caret-color: transparent;
|
|
218
|
+
width: 15px;
|
|
219
|
+
padding-top:1px;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
div.timeCase .D3{
|
|
224
|
+
width: 25px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
/* Hiding the up and down arrow */
|
|
229
|
+
/*https://www.w3schools.com/howto/howto_css_hide_arrow_number.asp*/
|
|
230
|
+
/* Chrome, Safari, Edge, Opera */
|
|
231
|
+
|
|
232
|
+
input::-webkit-outer-spin-button,
|
|
233
|
+
input::-webkit-inner-spin-button {
|
|
234
|
+
-webkit-appearance: none;
|
|
235
|
+
margin: 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
/* Firefox */
|
|
240
|
+
|
|
241
|
+
input[type=number] {
|
|
242
|
+
/* -moz-appearance: textfield; */
|
|
243
|
+
-moz-appearance: textarea;
|
|
244
|
+
-webkit-appearance: textarea;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
div.timeCase:focus-within {
|
|
249
|
+
border: 2px solid black;
|
|
250
|
+
padding: 2px;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
.ts_digit {
|
|
255
|
+
border: none;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* between digit span */
|
|
259
|
+
.bds{
|
|
260
|
+
padding-bottom: 1px;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
#svgContainer {
|
|
264
|
+
width: 12px;
|
|
265
|
+
height: 12px;
|
|
266
|
+
padding-top: 1px;
|
|
267
|
+
padding-right: 2px;
|
|
268
|
+
color: black;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
*:disabled {
|
|
272
|
+
background-color: grey;
|
|
273
|
+
color: lightgrey;
|
|
274
|
+
opacity: .6;
|
|
275
|
+
}
|
|
276
|
+
</style> `
|
|
277
|
+
|
|
278
|
+
spanIn.appendChild(template.content);
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
// const chronlyCssLink = document.createElement('link');
|
|
282
|
+
// let link = document.createElement('link');
|
|
283
|
+
// chronlyCssLink.setAttribute('rel', 'stylesheet');
|
|
284
|
+
// chronlyCssLink.setAttribute('href', 'chronlyWebComponent.css');
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
this.myElement.appendChild(spanIn);
|
|
292
|
+
|
|
293
|
+
// this.myElement.appendChild(chronlyCssLink);
|
|
294
|
+
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* eventlistener that adds number looping for up and down keys triggered by
|
|
300
|
+
* the change event of the input
|
|
301
|
+
* @method
|
|
302
|
+
* @see boot()
|
|
303
|
+
*/
|
|
304
|
+
|
|
305
|
+
addNumberLooping() {
|
|
306
|
+
|
|
307
|
+
// Numeric Value looping (eventually this can be 'parameterised' refactored)
|
|
308
|
+
// ex. 99 uparrow to 0 hours, 59 uparrow to 0 minutes and seconds, 990 uparrow to 010, downarrow 000 milliseconds
|
|
309
|
+
|
|
310
|
+
const sH = this.myElement.querySelector("input.sH");
|
|
311
|
+
sH.addEventListener('change', function (event) {
|
|
312
|
+
|
|
313
|
+
if (sH.value == 100) {
|
|
314
|
+
sH.value = '00';
|
|
315
|
+
}
|
|
316
|
+
if (sH.value == -1) {
|
|
317
|
+
sH.value = 99;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
const sM = this.myElement.querySelector("input.sM");
|
|
323
|
+
sM.addEventListener('change', function (event) {
|
|
324
|
+
|
|
325
|
+
if (sM.value == 60) {
|
|
326
|
+
sM.value = '00';
|
|
327
|
+
}
|
|
328
|
+
if (sM.value == -1) {
|
|
329
|
+
sM.value = 59;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const sS = this.myElement.querySelector("input.sS");
|
|
335
|
+
sS.addEventListener('change', function (event) {
|
|
336
|
+
|
|
337
|
+
if (sS.value == 60) {
|
|
338
|
+
sS.value = '00';
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (sS.value == -1) {
|
|
342
|
+
sS.value = 59;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
const sMS = this.myElement.querySelector("input.sMS");
|
|
349
|
+
sMS.addEventListener('change', function (event) {
|
|
350
|
+
|
|
351
|
+
if (sMS.value == 1000) {
|
|
352
|
+
sMS.value = "010";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (sMS.value == -10) {
|
|
356
|
+
sMS.value = 990;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (sMS.value == 0) {
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
addNumericInput() {
|
|
366
|
+
|
|
367
|
+
const mE = this.myElement;
|
|
368
|
+
|
|
369
|
+
// https://stackoverflow.com/questions/469357/html-text-input-allow-only-numeric-input
|
|
370
|
+
// Digit input 0-9 (typed in by user)
|
|
371
|
+
|
|
372
|
+
function setInputFilter(inputElement, inputFilter) {
|
|
373
|
+
// this sets a listener and immediately updates the value of the input number (note: can update this from input text, like by removing setSelectionRange )
|
|
374
|
+
|
|
375
|
+
console.log('inputElement: ' + inputElement);
|
|
376
|
+
window.inputElement = inputElement;
|
|
377
|
+
|
|
378
|
+
inputElement.addEventListener('keyup', function (event) {
|
|
379
|
+
|
|
380
|
+
window.kue = event;
|
|
381
|
+
|
|
382
|
+
if (/^([0-9]?)$/.test(event.key)) {
|
|
383
|
+
if (inputFilter(this.value)) {
|
|
384
|
+
this.oldValue = this.value;
|
|
385
|
+
this.oldSelectionStart = this.selectionStart;
|
|
386
|
+
this.oldSelectionEnd = this.selectionEnd;
|
|
387
|
+
} else if (this.hasOwnProperty("oldValue")) {
|
|
388
|
+
this.value = this.oldValue;
|
|
389
|
+
// this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
|
|
390
|
+
} else {
|
|
391
|
+
this.value = "";
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
// three boxes, hours or minutes and seconds (are the same) but milliseconds is different
|
|
399
|
+
|
|
400
|
+
// sH
|
|
401
|
+
var sH = this.myElement.querySelector('input.sH');
|
|
402
|
+
|
|
403
|
+
setInputFilter(sH, function (value) {
|
|
404
|
+
|
|
405
|
+
var newV = /^([0-9]?|[0-9][0-9]?)$/.test(value);
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
if (value.length === 2) {
|
|
409
|
+
|
|
410
|
+
mE.querySelector('input.sM').focus();
|
|
411
|
+
mE.querySelector('input.sM').select();
|
|
412
|
+
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return newV;
|
|
416
|
+
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
var sM = this.myElement.querySelector('input.sM');
|
|
420
|
+
setInputFilter(sM, function (value) {
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
var newV = /^([0-9]?|[0-5][0-9]?)$/.test(value);
|
|
424
|
+
|
|
425
|
+
if (value > 5 || value.length === 2) {
|
|
426
|
+
|
|
427
|
+
mE.querySelector('input.sS').focus();
|
|
428
|
+
mE.querySelector('input.sS').select();
|
|
429
|
+
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
return newV;
|
|
433
|
+
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
var sS = this.myElement.querySelector('input.sS');
|
|
437
|
+
setInputFilter(sS, function (value) {
|
|
438
|
+
|
|
439
|
+
var newV = /^([0-9]?|[0-5][0-9]?)$/.test(value);
|
|
440
|
+
|
|
441
|
+
if (value > 5 || value.length === 2) {
|
|
442
|
+
|
|
443
|
+
mE.querySelector('input.sMS').focus();
|
|
444
|
+
mE.querySelector('input.sMS').select();
|
|
445
|
+
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return newV;
|
|
449
|
+
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
var sMS = this.myElement.querySelector('input.sMS');
|
|
454
|
+
setInputFilter(sMS, function (value) {
|
|
455
|
+
|
|
456
|
+
var newV = /^([0-9]?|[0-9][0-9]?|[0-9][0-9][0-9]?)$/.test(value);
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
if (value.length === 3) {
|
|
460
|
+
|
|
461
|
+
mE.querySelector('input.sMS').blur();
|
|
462
|
+
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return newV;
|
|
466
|
+
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* each time Chronly is newed up, the constructor uses checkBoot() to
|
|
474
|
+
* 1) check for an existing window.ChronlyFlag if there is one
|
|
475
|
+
* 2) clear events a) named events, b) remove
|
|
476
|
+
* 3) add events
|
|
477
|
+
* @method
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
checkBoot() {
|
|
481
|
+
|
|
482
|
+
this.boot();
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
// if (window.ChronlyFlag) {
|
|
486
|
+
// this.reboot();
|
|
487
|
+
// }
|
|
488
|
+
// else {
|
|
489
|
+
// this.boot();
|
|
490
|
+
// }
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* used by checkBoot() and externally exposed for user
|
|
497
|
+
* @method
|
|
498
|
+
*
|
|
499
|
+
*/
|
|
500
|
+
|
|
501
|
+
boot() {
|
|
502
|
+
|
|
503
|
+
this.addHTML();
|
|
504
|
+
// this.addCSS();
|
|
505
|
+
this.blockNonNumberInput();
|
|
506
|
+
|
|
507
|
+
// // set up event listeners
|
|
508
|
+
this.add0s();
|
|
509
|
+
this.addNumberLooping();
|
|
510
|
+
this.addArrowKeyInput();
|
|
511
|
+
this.addNumericInput();
|
|
512
|
+
this.addClicksToActivate();
|
|
513
|
+
this.nonNumericBugInHTML();
|
|
514
|
+
// this.updatePrototype();
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* window.ChronlyFlag declared here
|
|
519
|
+
* @global
|
|
520
|
+
*/
|
|
521
|
+
// this.ChronlyFlag = true;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
disable() {
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
var closure = this;
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
// disable chronly inputs on page
|
|
533
|
+
|
|
534
|
+
closure.shadowRoot.querySelectorAll(".timeCase input").forEach(el => el.disabled = 'true')
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* method adds the necessary CSS
|
|
541
|
+
* @method
|
|
542
|
+
* @see boot()
|
|
543
|
+
* /
|
|
544
|
+
|
|
545
|
+
addCSS(){
|
|
546
|
+
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* eventlistener that adds 0s to preface numbers less than 10 triggered by
|
|
552
|
+
* the change event of the input
|
|
553
|
+
* @method
|
|
554
|
+
* @see boot()
|
|
555
|
+
*/
|
|
556
|
+
|
|
557
|
+
add0s() {
|
|
558
|
+
|
|
559
|
+
// input for hours, minutes, seconds
|
|
560
|
+
this.myElement.querySelectorAll('input').forEach(i => i.addEventListener('change', function () {
|
|
561
|
+
if (!isNaN(this.value) && this.value.length === 1) {
|
|
562
|
+
this.value = '0' + this.value;
|
|
563
|
+
}
|
|
564
|
+
}));
|
|
565
|
+
|
|
566
|
+
// milliseconds
|
|
567
|
+
this.myElement.querySelectorAll("input.sMS").forEach(i => i.addEventListener('change', function () {
|
|
568
|
+
|
|
569
|
+
if (!isNaN(this.value) && this.value.length === 2) {
|
|
570
|
+
this.value = '0' + this.value;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
}));
|
|
574
|
+
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
// this needs to be updated or removed, test
|
|
579
|
+
|
|
580
|
+
blockNonNumberInput() {
|
|
581
|
+
|
|
582
|
+
document.querySelectorAll(".timeCase input").forEach(item =>
|
|
583
|
+
|
|
584
|
+
item.addEventListener('keypress', function (e) {
|
|
585
|
+
|
|
586
|
+
e = e || window.event;
|
|
587
|
+
var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
|
|
588
|
+
var charStr = String.fromCharCode(charCode);
|
|
589
|
+
|
|
590
|
+
if (!charStr.match(/^[0-9]+$/))
|
|
591
|
+
e.preventDefault();
|
|
592
|
+
|
|
593
|
+
}));
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
// second idea is to update prototype of ChronlyInputElement (class)
|
|
598
|
+
|
|
599
|
+
updatePrototype() {
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
ChronlyHMSElement.prototype.__defineGetter__('value', function () {
|
|
603
|
+
|
|
604
|
+
if (this.myElement.querySelector('input[name="startHours"]') !== null) {
|
|
605
|
+
|
|
606
|
+
return this.myElement.querySelector('input[name="startHours"]').value +
|
|
607
|
+
':' + this.myElement.querySelector('input[name="startMinutes"]').value +
|
|
608
|
+
':' + this.myElement.querySelector('input[name="startSeconds"]').value +
|
|
609
|
+
'.' + this.myElement.querySelector('input[name="startMilliSecs"]').value;
|
|
610
|
+
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
|
|
614
|
+
return null;
|
|
615
|
+
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
ChronlyHMSElement.prototype.__defineSetter__('value', function (timeString) {
|
|
622
|
+
|
|
623
|
+
// will need warning about timeString format (like input type='time')
|
|
624
|
+
|
|
625
|
+
if (/(^[0-9][0-9]):([0-5][0-9]):([0-5][0-9])\.([0-9][0-9][0-9]$)/.exec(timeString)) {
|
|
626
|
+
|
|
627
|
+
// split val
|
|
628
|
+
|
|
629
|
+
var timeArray = timeString.split(/[.:]+/);
|
|
630
|
+
|
|
631
|
+
this.myElement.querySelector('input[name="startHours"]').value = timeArray[0];
|
|
632
|
+
this.myElement.querySelector('input[name="startMinutes"]').value = timeArray[1];
|
|
633
|
+
this.myElement.querySelector('input[name="startSeconds"]').value = timeArray[2];
|
|
634
|
+
this.myElement.querySelector('input[name="startMilliSecs"]').value = timeArray[3];
|
|
635
|
+
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
|
|
639
|
+
console.warn(`The specified value ${timeString} does not conform to the required format. The format is "HH:mm:ss.SSS" where HH is 00-99, mm is 00-59, ss is 00-59, and SSS is 000-999.`);
|
|
640
|
+
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* eventlistener that adds click to activate input of values by the keyboard triggered by
|
|
648
|
+
* the click event of the input
|
|
649
|
+
* @method
|
|
650
|
+
* @see boot()
|
|
651
|
+
*/
|
|
652
|
+
|
|
653
|
+
addClicksToActivate() {
|
|
654
|
+
|
|
655
|
+
this.myElement.querySelectorAll('input').forEach(i => i.addEventListener("click", function () { this.select(); }))
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
noHours() {
|
|
660
|
+
|
|
661
|
+
var closure = this;
|
|
662
|
+
|
|
663
|
+
// hide chronly hours inputs on page
|
|
664
|
+
|
|
665
|
+
closure.shadowRoot.querySelectorAll(".timeCase input.sH").forEach(el => el.style.display = 'none');
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
// hide the hours colon on page
|
|
669
|
+
|
|
670
|
+
closure.shadowRoot.querySelectorAll(".timeCase span.bds-h").forEach(el => el.style.display = 'none');
|
|
671
|
+
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* eventlistener that adds key filtering to stop letters (or other non-numerics) from being input triggered by
|
|
682
|
+
* the keypress event of the input
|
|
683
|
+
* @method
|
|
684
|
+
* @see boot()
|
|
685
|
+
*/
|
|
686
|
+
|
|
687
|
+
nonNumericBugInHTML() {
|
|
688
|
+
|
|
689
|
+
this.myElement.querySelectorAll(".timeCase input").forEach(item =>
|
|
690
|
+
|
|
691
|
+
item.addEventListener('keypress', function (e) {
|
|
692
|
+
|
|
693
|
+
e = e || window.event;
|
|
694
|
+
var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
|
|
695
|
+
var charStr = String.fromCharCode(charCode);
|
|
696
|
+
|
|
697
|
+
if (!charStr.match(/^[0-9]+$/))
|
|
698
|
+
e.preventDefault();
|
|
699
|
+
|
|
700
|
+
}));
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
} // end class
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
// page script (try making this auto instantiate in module like PM does)
|
|
709
|
+
|
|
710
|
+
export default customElements.define('chronly-hms', ChronlyHMS);
|