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
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: chrono.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: chrono.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>/**
|
|
30
|
+
* This import of this module self-news a ChronlyHMS class, it requires import of chrono.css
|
|
31
|
+
* and the addition of a data-univHMS attibute on html (time) input tags
|
|
32
|
+
* @module ChronlyHMS Module
|
|
33
|
+
* @requires ./chrono.css
|
|
34
|
+
* @requires data-univHMS#
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Import the required css
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import './chrono.css'
|
|
42
|
+
|
|
43
|
+
// A HH:MM:SS.mmm control that is unaffected by OSX and works on 'all' browsers.
|
|
44
|
+
// ChronlyHMS requires an input element with the attribute 'data-univHMS'
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A single class plugin
|
|
48
|
+
* @class ChronlyHMS Class
|
|
49
|
+
* @property {method} checkboot() - checks ChronlyHMS presence on page through window.ChronlyFlag
|
|
50
|
+
* @property {declaration} querySelectorAll - determines which inputs to update
|
|
51
|
+
* @property {global} globals - instantiates window.ChronlyHMS and window.ChronlyFlag
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ChronlyHMS {
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The contructor creates two window variables
|
|
59
|
+
* window.ChronlyHMS a global ChronlyHMS instance and
|
|
60
|
+
* window.ChronlyFlag for determining re-boot status
|
|
61
|
+
* @constructor
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
constructor() {
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
this.checkBoot();
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A window.ChronlyHMS instance.
|
|
72
|
+
* @global
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
window.ChronlyHMS = this;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A loose method (codeblock) that scans for existing ChronlyHMS html
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
document.querySelectorAll(".timeCase input").forEach(item =>
|
|
84
|
+
|
|
85
|
+
item.addEventListener('keypress', function (e) {
|
|
86
|
+
|
|
87
|
+
e = e || window.event;
|
|
88
|
+
var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
|
|
89
|
+
var charStr = String.fromCharCode(charCode);
|
|
90
|
+
|
|
91
|
+
if (!charStr.match(/^[0-9]+$/))
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
// run checkboot again
|
|
97
|
+
this.checkBoot()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* each time Chronly is newed up, the constructor uses checkBoot() to
|
|
106
|
+
* 1) check for an existing window.ChronlyFlag if there is one
|
|
107
|
+
* 2) clear events a) named events, b) remove
|
|
108
|
+
* 3) add events
|
|
109
|
+
* @method
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
checkBoot() {
|
|
113
|
+
|
|
114
|
+
if (window.ChronlyFlag) {
|
|
115
|
+
this.reboot();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.boot();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* used by checkBoot() and externally exposed for user
|
|
126
|
+
* @method
|
|
127
|
+
*
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
boot() {
|
|
131
|
+
|
|
132
|
+
this.addHTML();
|
|
133
|
+
|
|
134
|
+
// set up event listeners
|
|
135
|
+
this.add0s();
|
|
136
|
+
this.addNumberLooping();
|
|
137
|
+
this.addArrowKeyInput();
|
|
138
|
+
this.addNumericInput();
|
|
139
|
+
this.addClicksToActivate();
|
|
140
|
+
this.nonNumericBugInHTML();
|
|
141
|
+
this.updateDivPrototype();
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* window.ChronlyFlag declared here
|
|
146
|
+
* @global
|
|
147
|
+
*/
|
|
148
|
+
window.ChronlyFlag = true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* used by checkBoot() and externally exposed for user
|
|
155
|
+
* @method
|
|
156
|
+
* @see boot()
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
reboot() {
|
|
160
|
+
|
|
161
|
+
// for each input in the timeCase replace it with (the original/ an) input
|
|
162
|
+
|
|
163
|
+
var elements = document.querySelectorAll('.timeCase');
|
|
164
|
+
|
|
165
|
+
elements.forEach(element => {
|
|
166
|
+
|
|
167
|
+
var replaceElement = document.createElement('input');
|
|
168
|
+
|
|
169
|
+
[...element.attributes].forEach(attr => { replaceElement.setAttribute(attr.nodeName, attr.nodeValue) });
|
|
170
|
+
|
|
171
|
+
element.parentElement.insertBefore(replaceElement, element);
|
|
172
|
+
|
|
173
|
+
element.remove();
|
|
174
|
+
|
|
175
|
+
// removes eventlisters
|
|
176
|
+
element = ''
|
|
177
|
+
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
this.boot();
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* this removes the elements and removes their events
|
|
188
|
+
* @todo Remove next refactoring/ version
|
|
189
|
+
* @deprecated
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
refreshChronlyHMS() {
|
|
193
|
+
|
|
194
|
+
var chronoInputs = document.querySelectorAll('.timeCase').forEach(tc => {
|
|
195
|
+
|
|
196
|
+
tc.querySelectorAll('input').forEach(input => {
|
|
197
|
+
|
|
198
|
+
input.remove();
|
|
199
|
+
input = '';
|
|
200
|
+
|
|
201
|
+
this.addInputs(input);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* removes hours display, so only minutes, seconds, and microseconds are displayed
|
|
211
|
+
* @method
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
noHours() {
|
|
215
|
+
|
|
216
|
+
// hide chronly hours inputs on page
|
|
217
|
+
|
|
218
|
+
document.querySelectorAll(".timeCase input.sH").forEach(el => el.style.display = 'none');
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
// hide the hours colon on page
|
|
222
|
+
|
|
223
|
+
document.querySelectorAll(".timeCase span.bds-h").forEach(el => el.style.display = 'none');
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* disables all chronlyHMS inputs to user, does not change their js get/set()
|
|
231
|
+
* @method
|
|
232
|
+
* @todo create an id sepcific selector method that calls this method
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
disableInputs() {
|
|
236
|
+
|
|
237
|
+
// disable chronly inputs on page
|
|
238
|
+
|
|
239
|
+
document.querySelectorAll(".timeCase input").forEach(el => el.disabled = 'true')
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* used by boot() to update inputs marked with data-univHMS
|
|
247
|
+
* @method
|
|
248
|
+
* @see boot()
|
|
249
|
+
*/
|
|
250
|
+
|
|
251
|
+
addHTML() {
|
|
252
|
+
|
|
253
|
+
const univHMSinp = document.querySelectorAll("input[data-univHMS]");
|
|
254
|
+
|
|
255
|
+
univHMSinp.forEach(el => {
|
|
256
|
+
// code
|
|
257
|
+
|
|
258
|
+
var spanIn = document.createElement("div");
|
|
259
|
+
|
|
260
|
+
[...el.attributes].forEach(attr => { spanIn.setAttribute(attr.nodeName, attr.nodeValue) });
|
|
261
|
+
|
|
262
|
+
el.replaceWith(spanIn);
|
|
263
|
+
|
|
264
|
+
spanIn.classList.add('timeCase');
|
|
265
|
+
|
|
266
|
+
var template = document.createElement('template');
|
|
267
|
+
|
|
268
|
+
template.innerHTML = `
|
|
269
|
+
<input type="number" class="sH D2 ts_digit" name="startHours" data-tp="1" min="-1" max="100" value="00" >
|
|
270
|
+
<span class="bds-h">:</span>
|
|
271
|
+
<input type="number" class="sM D2 ts_digit" name="startMinutes" data-tp="2" min="-1" max="60" value="00">
|
|
272
|
+
<span class="bds-m">:</span>
|
|
273
|
+
<input type="number" class="sS D2 ts_digit" name="startSeconds" data-tp="3" min="-1" max="60" value="00">
|
|
274
|
+
<span class="bds-s">.</span>
|
|
275
|
+
<input type="number" class="sMS D3 ts_digit" name="startMilliSecs" data-tp="4" min="-10" max="1010" step="10" value="000">
|
|
276
|
+
<div id="svgContainer">
|
|
277
|
+
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true"
|
|
278
|
+
focusable="false" data-prefix="fal" data-icon="stopwatch" class="svg-inline--fa fa-stopwatch fa-w-14"
|
|
279
|
+
role="img" viewBox="0 0 448 512">
|
|
280
|
+
<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"/>
|
|
281
|
+
</svg>
|
|
282
|
+
</div>
|
|
283
|
+
`
|
|
284
|
+
|
|
285
|
+
spanIn.appendChild(template.content)
|
|
286
|
+
console.log(el);
|
|
287
|
+
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* used by refreshChronlyHMS() to add inputs without time case
|
|
293
|
+
* @method
|
|
294
|
+
* @param {element} el HTML input element
|
|
295
|
+
* @see refreshChronlyHMS()
|
|
296
|
+
*/
|
|
297
|
+
|
|
298
|
+
addInputs(el) {
|
|
299
|
+
|
|
300
|
+
var template = document.createElement('template');
|
|
301
|
+
|
|
302
|
+
template.innerHTML = `
|
|
303
|
+
<input type="number" class="sH D2 ts_digit" name="startHours" data-tp="1" min="-1" max="100" value="00" >
|
|
304
|
+
<span class="bds">:</span>
|
|
305
|
+
<input type="number" class="sM D2 ts_digit" name="startMinutes" data-tp="2" min="-1" max="60" value="00">
|
|
306
|
+
<span class="bds">:</span>
|
|
307
|
+
<input type="number" class="sS D2 ts_digit" name="startSeconds" data-tp="3" min="-1" max="60" value="00">
|
|
308
|
+
<span class="bds">.</span>
|
|
309
|
+
<input type="number" class="sMS D3 ts_digit" name="startMilliSecs" data-tp="4" min="-10" max="1010" step="10" value="000">
|
|
310
|
+
<div id="svgContainer">
|
|
311
|
+
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true"
|
|
312
|
+
focusable="false" data-prefix="fal" data-icon="stopwatch" class="svg-inline--fa fa-stopwatch fa-w-14"
|
|
313
|
+
role="img" viewBox="0 0 448 512">
|
|
314
|
+
<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"/>
|
|
315
|
+
</svg>
|
|
316
|
+
</div>
|
|
317
|
+
`
|
|
318
|
+
|
|
319
|
+
el.appendChild(template.content)
|
|
320
|
+
console.log(el);
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* eventlistener that adds 0s to preface numbers less than 10 triggered by
|
|
328
|
+
* the change event of the input
|
|
329
|
+
* @method
|
|
330
|
+
* @see boot()
|
|
331
|
+
*/
|
|
332
|
+
|
|
333
|
+
add0s() {
|
|
334
|
+
|
|
335
|
+
// input for hours, minutes, seconds
|
|
336
|
+
document.querySelectorAll("div.timeCase input").forEach(i => i.addEventListener('change', function () {
|
|
337
|
+
if (!isNaN(this.value) && this.value.length === 1) {
|
|
338
|
+
this.value = '0' + this.value;
|
|
339
|
+
}
|
|
340
|
+
}));
|
|
341
|
+
|
|
342
|
+
// milliseconds
|
|
343
|
+
document.querySelectorAll("input.sMS").forEach(i => i.addEventListener('change', function () {
|
|
344
|
+
|
|
345
|
+
if (!isNaN(this.value) && this.value.length === 2) {
|
|
346
|
+
this.value = '0' + this.value;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
}));
|
|
350
|
+
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* eventlistener that adds number looping for up and down keys triggered by
|
|
357
|
+
* the change event of the input
|
|
358
|
+
* @method
|
|
359
|
+
* @see boot()
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
addNumberLooping() {
|
|
363
|
+
// Numeric Value looping (eventually this can be 'parameterised' refactored)
|
|
364
|
+
// ex. 99 uparrow to 0 hours, 59 uparrow to 0 minutes and seconds, 990 uparrow to 010, downarrow 000 milliseconds
|
|
365
|
+
|
|
366
|
+
document.querySelectorAll("input.sH").forEach(i =>
|
|
367
|
+
i.addEventListener('change', function (event) {
|
|
368
|
+
|
|
369
|
+
if (i.value == 100) {
|
|
370
|
+
i.value = '00';
|
|
371
|
+
}
|
|
372
|
+
if (i.value == -1) {
|
|
373
|
+
i.value = 99;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
}));
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
document.querySelectorAll("input.sM").forEach(i =>
|
|
380
|
+
i.addEventListener('change', function (event) {
|
|
381
|
+
|
|
382
|
+
if (i.value == 60) {
|
|
383
|
+
i.value = '00';
|
|
384
|
+
}
|
|
385
|
+
if (i.value == -1) {
|
|
386
|
+
i.value = 59;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
}));
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
document.querySelectorAll("input.sS").forEach(i =>
|
|
393
|
+
i.addEventListener('change', function (event) {
|
|
394
|
+
|
|
395
|
+
if (i.value == 60) {
|
|
396
|
+
i.value = '00';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (i.value == -1) {
|
|
400
|
+
i.value = 59;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
}));
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
document.querySelectorAll("input.sMS").forEach(i =>
|
|
407
|
+
i.addEventListener('change', function (event) {
|
|
408
|
+
|
|
409
|
+
if (i.value == 1000) {
|
|
410
|
+
i.value = "010";
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (i.value == -10) {
|
|
414
|
+
i.value = 990;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (i.value == 0) {
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
}));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* eventlistener that adds arrow key input of values (up/down) and place toggling (left/right) triggered by
|
|
427
|
+
* the change event of the input
|
|
428
|
+
* @method
|
|
429
|
+
* @see boot()
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
addArrowKeyInput() {
|
|
433
|
+
|
|
434
|
+
// Left and Right arrow key toggle between HMSmS
|
|
435
|
+
// this depends on data-attributes ex. data-tp="1" in HTML
|
|
436
|
+
|
|
437
|
+
document.querySelectorAll("div.timeCase").forEach(d =>
|
|
438
|
+
d.addEventListener('keydown', function (event) {
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
var et = event.target;
|
|
442
|
+
var dId = d.id;
|
|
443
|
+
var tp_active;
|
|
444
|
+
|
|
445
|
+
// these help manual testing by posting to the webapge
|
|
446
|
+
var el_disp = document.querySelector("#keyHolder");
|
|
447
|
+
el_disp.innerHTML = "None";
|
|
448
|
+
|
|
449
|
+
switch (true) {
|
|
450
|
+
|
|
451
|
+
case event.key == "ArrowLeft":
|
|
452
|
+
tp_active = document.activeElement.dataset.tp;
|
|
453
|
+
|
|
454
|
+
if (tp_active >= 2) {
|
|
455
|
+
tp_active--;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
document.querySelector('#' + dId).querySelector("[data-tp='" + tp_active + "']").focus();
|
|
459
|
+
setTimeout(function () { document.querySelector('#' + dId).querySelector("[data-tp='" + tp_active + "']").select(); }, 5);
|
|
460
|
+
el_disp.innerHTML = event.key;
|
|
461
|
+
|
|
462
|
+
break;
|
|
463
|
+
|
|
464
|
+
case event.key == "ArrowRight":
|
|
465
|
+
tp_active = document.activeElement.dataset.tp;
|
|
466
|
+
|
|
467
|
+
if (tp_active <= 3) {
|
|
468
|
+
tp_active++;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
document.querySelector('#' + dId).querySelector("[data-tp='" + tp_active + "']").focus();
|
|
472
|
+
setTimeout(function () { document.querySelector('#' + dId).querySelector("[data-tp='" + tp_active + "']").select(); }, 5);
|
|
473
|
+
el_disp.innerHTML = event.key;
|
|
474
|
+
|
|
475
|
+
break;
|
|
476
|
+
|
|
477
|
+
// these keep the input selected
|
|
478
|
+
case event.key == "ArrowUp":
|
|
479
|
+
el_disp.innerHTML = event.key;
|
|
480
|
+
setTimeout(function () { document.activeElement.select(); }, 5);
|
|
481
|
+
|
|
482
|
+
break;
|
|
483
|
+
|
|
484
|
+
case event.key == "ArrowDown":
|
|
485
|
+
el_disp.innerHTML = event.key;
|
|
486
|
+
|
|
487
|
+
setTimeout(function () { document.activeElement.select(); }, 5);
|
|
488
|
+
|
|
489
|
+
break;
|
|
490
|
+
|
|
491
|
+
// this is good for testing, to determine whether a key press is detected
|
|
492
|
+
case /^([0-9]?)$/.test(event.key):
|
|
493
|
+
|
|
494
|
+
el_disp.innerHTML = event.key;
|
|
495
|
+
|
|
496
|
+
break;
|
|
497
|
+
|
|
498
|
+
}
|
|
499
|
+
}));
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* eventlistener that adds number input filtering for keys triggered by
|
|
506
|
+
* the key event of the input
|
|
507
|
+
* @method
|
|
508
|
+
* @see boot()
|
|
509
|
+
*/
|
|
510
|
+
|
|
511
|
+
addNumericInput() {
|
|
512
|
+
|
|
513
|
+
// https://stackoverflow.com/questions/469357/html-text-input-allow-only-numeric-input
|
|
514
|
+
// Digit input 0-9 (typed in by user)
|
|
515
|
+
|
|
516
|
+
function setInputFilter(textbox, inputFilter) {
|
|
517
|
+
// this sets a listener and immediately updates the value of the input number (note: can update this from input text, like by removing setSelectionRange )
|
|
518
|
+
|
|
519
|
+
textbox.addEventListener('keyup', function () {
|
|
520
|
+
if (/^([0-9]?)$/.test(event.key)) {
|
|
521
|
+
if (inputFilter(this.value)) {
|
|
522
|
+
this.oldValue = this.value;
|
|
523
|
+
this.oldSelectionStart = this.selectionStart;
|
|
524
|
+
this.oldSelectionEnd = this.selectionEnd;
|
|
525
|
+
} else if (this.hasOwnProperty("oldValue")) {
|
|
526
|
+
this.value = this.oldValue;
|
|
527
|
+
// this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
|
|
528
|
+
} else {
|
|
529
|
+
this.value = "";
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
// three boxes, hours or minutes and seconds (are the same) but milliseconds is different
|
|
537
|
+
|
|
538
|
+
// sH
|
|
539
|
+
document.querySelectorAll('input.sH').forEach(i => setInputFilter(i, function (value) {
|
|
540
|
+
|
|
541
|
+
var newV = /^([0-9]?|[0-9][0-9]?)$/.test(value);
|
|
542
|
+
|
|
543
|
+
if (value.length === 2) {
|
|
544
|
+
|
|
545
|
+
i.parentNode.querySelector('input.sM').focus();
|
|
546
|
+
i.parentNode.querySelector('input.sM').select();
|
|
547
|
+
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return newV;
|
|
551
|
+
|
|
552
|
+
}));
|
|
553
|
+
|
|
554
|
+
document.querySelectorAll('input.sM').forEach(i => setInputFilter(i, function (value) {
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
var newV = /^([0-9]?|[0-5][0-9]?)$/.test(value);
|
|
558
|
+
|
|
559
|
+
if (value > 5 || value.length === 2) {
|
|
560
|
+
|
|
561
|
+
i.parentNode.querySelector('input.sS').focus();
|
|
562
|
+
i.parentNode.querySelector('input.sS').select();
|
|
563
|
+
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return newV;
|
|
567
|
+
|
|
568
|
+
}));
|
|
569
|
+
|
|
570
|
+
document.querySelectorAll('input.sS').forEach(i => setInputFilter(i, function (value) {
|
|
571
|
+
|
|
572
|
+
var newV = /^([0-9]?|[0-5][0-9]?)$/.test(value);
|
|
573
|
+
|
|
574
|
+
if (value > 5 || value.length === 2) {
|
|
575
|
+
|
|
576
|
+
i.parentNode.querySelector('input.sMS').focus();
|
|
577
|
+
i.parentNode.querySelector('input.sMS').select();
|
|
578
|
+
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return newV;
|
|
582
|
+
|
|
583
|
+
}));
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
document.querySelectorAll('input.sMS').forEach(i => setInputFilter(i, function (value) {
|
|
587
|
+
|
|
588
|
+
var newV = /^([0-9]?|[0-9][0-9]?|[0-9][0-9][0-9]?)$/.test(value);
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
if (value.length === 3) {
|
|
592
|
+
|
|
593
|
+
i.parentNode.querySelector('input.sMS').blur();
|
|
594
|
+
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return newV;
|
|
598
|
+
|
|
599
|
+
}));
|
|
600
|
+
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* eventlistener that adds click to activate input of values by the keyboard triggered by
|
|
608
|
+
* the click event of the input
|
|
609
|
+
* @method
|
|
610
|
+
* @see boot()
|
|
611
|
+
*/
|
|
612
|
+
|
|
613
|
+
addClicksToActivate() {
|
|
614
|
+
|
|
615
|
+
document.querySelectorAll('input[name="startHours"]').forEach(
|
|
616
|
+
item => item.addEventListener("click", function () { this.select(); })
|
|
617
|
+
);
|
|
618
|
+
|
|
619
|
+
document.querySelectorAll('input[name="startMinutes"]').forEach(
|
|
620
|
+
item => item.addEventListener("click", function () { this.select(); })
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
document.querySelectorAll('input[name="startSeconds"]').forEach(
|
|
624
|
+
item => item.addEventListener("click", function () { this.select(); })
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
document.querySelectorAll('input[name="startMilliSecs"]').forEach(
|
|
628
|
+
item => item.addEventListener("click", function () { this.select(); })
|
|
629
|
+
)
|
|
630
|
+
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* eventlistener that adds key filtering to stop letters (or other non-numerics) from being input triggered by
|
|
637
|
+
* the keypress event of the input
|
|
638
|
+
* @method
|
|
639
|
+
* @see boot()
|
|
640
|
+
*/
|
|
641
|
+
|
|
642
|
+
nonNumericBugInHTML() {
|
|
643
|
+
|
|
644
|
+
document.querySelectorAll(".timeCase input").forEach(item =>
|
|
645
|
+
|
|
646
|
+
item.addEventListener('keypress', function (e) {
|
|
647
|
+
|
|
648
|
+
e = e || window.event;
|
|
649
|
+
var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
|
|
650
|
+
var charStr = String.fromCharCode(charCode);
|
|
651
|
+
|
|
652
|
+
if (!charStr.match(/^[0-9]+$/))
|
|
653
|
+
e.preventDefault();
|
|
654
|
+
|
|
655
|
+
}));
|
|
656
|
+
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* updates HTMLDivElement.prototype so that values can read from and set for the .timecase div
|
|
663
|
+
* so it functions as a single element,
|
|
664
|
+
* allows for getting and setting of values like document.querySelector('#bob').value = "08:04:05.002"
|
|
665
|
+
* @method
|
|
666
|
+
* @see boot()
|
|
667
|
+
*/
|
|
668
|
+
|
|
669
|
+
updateDivPrototype() {
|
|
670
|
+
|
|
671
|
+
HTMLDivElement.prototype.__defineGetter__('value', function () {
|
|
672
|
+
|
|
673
|
+
if (this.querySelector('input[name="startHours"]') !== null) {
|
|
674
|
+
|
|
675
|
+
return this.querySelector('input[name="startHours"]').value +
|
|
676
|
+
':' + this.querySelector('input[name="startMinutes"]').value +
|
|
677
|
+
':' + this.querySelector('input[name="startSeconds"]').value +
|
|
678
|
+
'.' + this.querySelector('input[name="startMilliSecs"]').value;
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
|
|
683
|
+
return null;
|
|
684
|
+
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
HTMLDivElement.prototype.__defineSetter__('value', function (timeString) {
|
|
691
|
+
|
|
692
|
+
// will need warning about timeString format (like input type='time')
|
|
693
|
+
|
|
694
|
+
if (/(^[0-9][0-9]):([0-5][0-9]):([0-5][0-9])\.([0-9][0-9][0-9]$)/.exec(timeString)) {
|
|
695
|
+
|
|
696
|
+
// split val
|
|
697
|
+
|
|
698
|
+
var timeArray = timeString.split(/[.:]+/);
|
|
699
|
+
|
|
700
|
+
this.querySelector('input[name="startHours"]').value = timeArray[0];
|
|
701
|
+
this.querySelector('input[name="startMinutes"]').value = timeArray[1];
|
|
702
|
+
this.querySelector('input[name="startSeconds"]').value = timeArray[2];
|
|
703
|
+
this.querySelector('input[name="startMilliSecs"]').value = timeArray[3];
|
|
704
|
+
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
|
|
708
|
+
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.`);
|
|
709
|
+
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
export default new ChronlyHMS;
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
</code></pre>
|
|
721
|
+
</article>
|
|
722
|
+
</section>
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
</div>
|
|
728
|
+
|
|
729
|
+
<nav>
|
|
730
|
+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ChronlyHMS%2520Module.html">ChronlyHMS Module</a></li></ul><h3>Classes</h3><ul><li><a href="module-ChronlyHMS%2520Module-ChronlyHMS.html">ChronlyHMS</a></li></ul><h3>Global</h3><ul><li><a href="global.html#ChronlyFlag">ChronlyFlag</a></li><li><a href="global.html#ChronlyHMS">ChronlyHMS</a></li></ul>
|
|
731
|
+
</nav>
|
|
732
|
+
|
|
733
|
+
<br class="clear">
|
|
734
|
+
|
|
735
|
+
<footer>
|
|
736
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Fri Jan 20 2023 10:29:02 GMT+0000 (Coordinated Universal Time)
|
|
737
|
+
</footer>
|
|
738
|
+
|
|
739
|
+
<script> prettyPrint(); </script>
|
|
740
|
+
<script src="scripts/linenumber.js"> </script>
|
|
741
|
+
</body>
|
|
742
|
+
</html>
|