@websy/websy-designs 1.2.6 → 1.2.7
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/dist/websy-designs-es6.debug.js +81 -20
- package/dist/websy-designs-es6.js +309 -228
- package/dist/websy-designs-es6.min.js +1 -1
- package/dist/websy-designs.debug.js +81 -20
- package/dist/websy-designs.js +309 -228
- package/dist/websy-designs.min.css +1 -1
- package/dist/websy-designs.min.js +1 -1
- package/package.json +1 -1
|
@@ -205,18 +205,20 @@ class WebsyDatePicker {
|
|
|
205
205
|
this.currentselection = []
|
|
206
206
|
this.validDates = []
|
|
207
207
|
this.validYears = []
|
|
208
|
+
this.validHours = []
|
|
208
209
|
this.customRangeSelected = true
|
|
209
210
|
this.shiftPressed = false
|
|
210
211
|
const DEFAULTS = {
|
|
211
212
|
defaultRange: 0,
|
|
212
213
|
allowClear: true,
|
|
214
|
+
hideRanges: false,
|
|
213
215
|
minAllowedDate: this.floorDate(new Date(new Date((new Date().setFullYear(new Date().getFullYear() - 1))).setDate(1))),
|
|
214
216
|
maxAllowedDate: this.floorDate(new Date((new Date()))),
|
|
215
217
|
minAllowedYear: 1970,
|
|
216
218
|
maxAllowedYear: new Date().getFullYear(),
|
|
217
219
|
daysOfWeek: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
|
|
218
220
|
monthsOfYear: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
|
219
|
-
hours: new Array(24).fill(0).map((d, i) => (i < 10 ? '0' : '') + i + ':00'),
|
|
221
|
+
hours: new Array(24).fill(0).map((d, i) => ({text: (i < 10 ? '0' : '') + i + ':00', num: (1 / 24 * i)})),
|
|
220
222
|
mode: 'date',
|
|
221
223
|
monthMap: {
|
|
222
224
|
0: 'Jan',
|
|
@@ -301,7 +303,12 @@ class WebsyDatePicker {
|
|
|
301
303
|
range: [this.floorDate(new Date(new Date(new Date().setDate(1)).setMonth(new Date().getMonth() - 24))), this.floorDate(new Date(new Date().setDate(1)))]
|
|
302
304
|
}
|
|
303
305
|
],
|
|
304
|
-
hour: [
|
|
306
|
+
hour: [
|
|
307
|
+
{
|
|
308
|
+
label: 'All',
|
|
309
|
+
range: ['00:00', '23:00']
|
|
310
|
+
}
|
|
311
|
+
]
|
|
305
312
|
}
|
|
306
313
|
this.options = Object.assign({}, DEFAULTS, options)
|
|
307
314
|
this.selectedRange = this.options.defaultRange || 0
|
|
@@ -337,8 +344,8 @@ class WebsyDatePicker {
|
|
|
337
344
|
html += `
|
|
338
345
|
</div>
|
|
339
346
|
<div id='${this.elementId}_mask' class='websy-date-picker-mask'></div>
|
|
340
|
-
<div id='${this.elementId}_content' class='websy-date-picker-content'>
|
|
341
|
-
<div class='websy-date-picker-ranges'>
|
|
347
|
+
<div id='${this.elementId}_content' class='websy-date-picker-content ${this.options.hideRanges === true ? 'hide-ranges' : ''}'>
|
|
348
|
+
<div class='websy-date-picker-ranges' >
|
|
342
349
|
<ul id='${this.elementId}_rangelist'>
|
|
343
350
|
${this.renderRanges()}
|
|
344
351
|
</ul>
|
|
@@ -376,11 +383,26 @@ class WebsyDatePicker {
|
|
|
376
383
|
if (this.options.onChange) {
|
|
377
384
|
console.log('confirm', this.selectedRangeDates)
|
|
378
385
|
console.log('confirm', this.currentselection)
|
|
379
|
-
if (this.customRangeSelected === true) {
|
|
380
|
-
this.options.
|
|
386
|
+
if (this.customRangeSelected === true) {
|
|
387
|
+
if (this.options.mode === 'hour') {
|
|
388
|
+
let hoursOut = []
|
|
389
|
+
for (let i = this.selectedRangeDates[0]; i < this.selectedRangeDates[1] + 1; i++) {
|
|
390
|
+
hoursOut.push(this.options.hours[i])
|
|
391
|
+
}
|
|
392
|
+
this.options.onChange(hoursOut, true)
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
this.options.onChange(this.selectedRangeDates, true)
|
|
396
|
+
}
|
|
381
397
|
}
|
|
382
398
|
else {
|
|
383
|
-
this.options.
|
|
399
|
+
if (this.options.mode === 'hour') {
|
|
400
|
+
let hoursOut = this.selectedRangeDates.map(h => this.options.hours[h])
|
|
401
|
+
this.options.onChange(hoursOut, true)
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
this.options.onChange(this.currentselection, false)
|
|
405
|
+
}
|
|
384
406
|
}
|
|
385
407
|
}
|
|
386
408
|
this.updateRange()
|
|
@@ -515,7 +537,7 @@ class WebsyDatePicker {
|
|
|
515
537
|
console.log('diff', diff)
|
|
516
538
|
}
|
|
517
539
|
else if (this.options.mode === 'hour') {
|
|
518
|
-
|
|
540
|
+
diff = this.selectedRangeDates[this.selectedRangeDates.length - 1] - this.selectedRangeDates[0]
|
|
519
541
|
}
|
|
520
542
|
for (let i = 0; i < diff + 1; i++) {
|
|
521
543
|
let d
|
|
@@ -538,7 +560,9 @@ class WebsyDatePicker {
|
|
|
538
560
|
rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1].getTime()
|
|
539
561
|
}
|
|
540
562
|
else if (this.options.mode === 'hour') {
|
|
541
|
-
|
|
563
|
+
d = this.selectedRangeDates[0] + i
|
|
564
|
+
rangeStart = this.selectedRangeDates[0]
|
|
565
|
+
rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1]
|
|
542
566
|
}
|
|
543
567
|
let dateEl
|
|
544
568
|
if (this.options.mode === 'date') {
|
|
@@ -554,7 +578,7 @@ class WebsyDatePicker {
|
|
|
554
578
|
dateEl = document.getElementById(`${this.elementId}_${d}_monthyear`)
|
|
555
579
|
}
|
|
556
580
|
else if (this.options.mode === 'hour') {
|
|
557
|
-
|
|
581
|
+
dateEl = document.getElementById(`${this.elementId}_${d}_hour`)
|
|
558
582
|
}
|
|
559
583
|
if (dateEl) {
|
|
560
584
|
dateEl.classList.add('selected')
|
|
@@ -580,7 +604,7 @@ class WebsyDatePicker {
|
|
|
580
604
|
dateEl = document.getElementById(`${this.elementId}_${d}_monthyear`)
|
|
581
605
|
}
|
|
582
606
|
else if (this.options.mode === 'hour') {
|
|
583
|
-
|
|
607
|
+
dateEl = document.getElementById(`${this.elementId}_${d}_hour`)
|
|
584
608
|
}
|
|
585
609
|
dateEl.classList.add('selected')
|
|
586
610
|
dateEl.classList.add('first')
|
|
@@ -622,6 +646,7 @@ class WebsyDatePicker {
|
|
|
622
646
|
let disabled = []
|
|
623
647
|
this.validDates = []
|
|
624
648
|
this.validYears = []
|
|
649
|
+
this.validHours = []
|
|
625
650
|
this.monthYears = {}
|
|
626
651
|
this.monthYearMonths = []
|
|
627
652
|
if (disabledDates) {
|
|
@@ -636,7 +661,7 @@ class WebsyDatePicker {
|
|
|
636
661
|
//
|
|
637
662
|
}
|
|
638
663
|
else if (this.options.mode === 'hour') {
|
|
639
|
-
|
|
664
|
+
return d
|
|
640
665
|
}
|
|
641
666
|
return d.getTime()
|
|
642
667
|
})
|
|
@@ -654,7 +679,7 @@ class WebsyDatePicker {
|
|
|
654
679
|
diff = Math.ceil((this.options.maxAllowedDate.getTime() - this.options.minAllowedDate.getTime()) / this.oneDay) + 1
|
|
655
680
|
}
|
|
656
681
|
else if (this.options.mode === 'hour') {
|
|
657
|
-
|
|
682
|
+
diff = 24
|
|
658
683
|
}
|
|
659
684
|
let months = {}
|
|
660
685
|
let yearList = []
|
|
@@ -691,9 +716,16 @@ class WebsyDatePicker {
|
|
|
691
716
|
}
|
|
692
717
|
}
|
|
693
718
|
else if (this.options.mode === 'hour') {
|
|
694
|
-
//
|
|
719
|
+
//
|
|
695
720
|
}
|
|
696
721
|
}
|
|
722
|
+
if (this.options.mode === 'hour') {
|
|
723
|
+
this.options.hours.forEach(h => {
|
|
724
|
+
if (disabled.indexOf(h.text) === -1) {
|
|
725
|
+
this.validHours.push(h)
|
|
726
|
+
}
|
|
727
|
+
})
|
|
728
|
+
}
|
|
697
729
|
// check each range to see if it can be enabled
|
|
698
730
|
for (let i = 0; i < this.options.ranges[this.options.mode].length; i++) {
|
|
699
731
|
const r = this.options.ranges[this.options.mode][i]
|
|
@@ -742,7 +774,23 @@ class WebsyDatePicker {
|
|
|
742
774
|
//
|
|
743
775
|
}
|
|
744
776
|
else if (this.options.mode === 'hour') {
|
|
745
|
-
|
|
777
|
+
if (this.validDates.indexOf(r.range[0]) !== -1) {
|
|
778
|
+
r.disabled = false
|
|
779
|
+
}
|
|
780
|
+
else if (r.range[1]) {
|
|
781
|
+
if (this.validDates.indexOf(r.range[1]) !== -1) {
|
|
782
|
+
r.disabled = false
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
// check the full range until a match is found
|
|
786
|
+
for (let i = r.range[0]; i <= r.range[1]; i++) {
|
|
787
|
+
if (this.validDates.indexOf(r.range[0] + i) !== -1) {
|
|
788
|
+
r.disabled = false
|
|
789
|
+
break
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
746
794
|
}
|
|
747
795
|
}
|
|
748
796
|
let html = ''
|
|
@@ -804,7 +852,9 @@ class WebsyDatePicker {
|
|
|
804
852
|
html += `</div>`
|
|
805
853
|
}
|
|
806
854
|
else if (this.options.mode === 'hour') {
|
|
807
|
-
|
|
855
|
+
html += `<div id='${this.elementId}_dateList' class='websy-dp-date-list'><ul>`
|
|
856
|
+
html += this.options.hours.map(h => `<li id='${this.elementId}_${+h.text.split(':')[0]}_hour' data-hour='${h.text}' class='websy-dp-date websy-dp-hour'>${h.text}</li>`).join('')
|
|
857
|
+
html += `</ul></div>`
|
|
808
858
|
}
|
|
809
859
|
return html
|
|
810
860
|
}
|
|
@@ -856,7 +906,13 @@ class WebsyDatePicker {
|
|
|
856
906
|
console.log('current selection', this.currentselection)
|
|
857
907
|
}
|
|
858
908
|
else {
|
|
859
|
-
this.currentselection.
|
|
909
|
+
let index = this.currentselection.indexOf(timestamp)
|
|
910
|
+
if (index !== -1) {
|
|
911
|
+
this.currentselection.splice(index, 1)
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
this.currentselection.push(timestamp)
|
|
915
|
+
}
|
|
860
916
|
this.currentselection.sort((a, b) => a - b)
|
|
861
917
|
this.customRangeSelected = false
|
|
862
918
|
}
|
|
@@ -872,7 +928,7 @@ class WebsyDatePicker {
|
|
|
872
928
|
//
|
|
873
929
|
}
|
|
874
930
|
else if (this.options.mode === 'hour') {
|
|
875
|
-
|
|
931
|
+
this.selectedRangeDates = [this.currentselection[0], this.currentselection[1] || this.currentselection[0]]
|
|
876
932
|
}
|
|
877
933
|
// if (this.currentselection.length === 2) {
|
|
878
934
|
// this.currentselection = []
|
|
@@ -936,7 +992,8 @@ class WebsyDatePicker {
|
|
|
936
992
|
this.options.maxAllowedDate = range[1] || range[0]
|
|
937
993
|
}
|
|
938
994
|
else if (this.options.mode === 'hour') {
|
|
939
|
-
|
|
995
|
+
this.options.minAllowedHour = range[0]
|
|
996
|
+
this.options.maxAllowedHour = range[1] || range[0]
|
|
940
997
|
}
|
|
941
998
|
}
|
|
942
999
|
updateRange () {
|
|
@@ -959,7 +1016,7 @@ class WebsyDatePicker {
|
|
|
959
1016
|
return `${this.options.monthMap[d.getMonth()]} ${d.getFullYear()}`
|
|
960
1017
|
}
|
|
961
1018
|
else if (this.options.mode === 'hour') {
|
|
962
|
-
|
|
1019
|
+
return d
|
|
963
1020
|
}
|
|
964
1021
|
})
|
|
965
1022
|
let start = list[0]
|
|
@@ -970,6 +1027,10 @@ class WebsyDatePicker {
|
|
|
970
1027
|
else {
|
|
971
1028
|
start = `${list.length} selected`
|
|
972
1029
|
}
|
|
1030
|
+
if (this.options.mode === 'hour') {
|
|
1031
|
+
start = this.options.hours[start].text
|
|
1032
|
+
end = `${this.customRangeSelected === true ? ' - ' : ''}${this.options.hours[list[list.length - 1]].text}`
|
|
1033
|
+
}
|
|
973
1034
|
range = { label: `${start}${end}` }
|
|
974
1035
|
}
|
|
975
1036
|
else {
|