@websy/websy-designs 1.2.6 → 1.2.8
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 +84 -22
- package/dist/websy-designs-es6.js +312 -230
- package/dist/websy-designs-es6.min.js +1 -1
- package/dist/websy-designs.debug.js +84 -22
- package/dist/websy-designs.js +312 -230
- package/dist/websy-designs.min.css +1 -1
- package/dist/websy-designs.min.js +1 -1
- package/package.json +1 -1
|
@@ -391,18 +391,20 @@ class WebsyDatePicker {
|
|
|
391
391
|
this.currentselection = []
|
|
392
392
|
this.validDates = []
|
|
393
393
|
this.validYears = []
|
|
394
|
+
this.validHours = []
|
|
394
395
|
this.customRangeSelected = true
|
|
395
396
|
this.shiftPressed = false
|
|
396
397
|
const DEFAULTS = {
|
|
397
398
|
defaultRange: 0,
|
|
398
399
|
allowClear: true,
|
|
400
|
+
hideRanges: false,
|
|
399
401
|
minAllowedDate: this.floorDate(new Date(new Date((new Date().setFullYear(new Date().getFullYear() - 1))).setDate(1))),
|
|
400
402
|
maxAllowedDate: this.floorDate(new Date((new Date()))),
|
|
401
403
|
minAllowedYear: 1970,
|
|
402
404
|
maxAllowedYear: new Date().getFullYear(),
|
|
403
405
|
daysOfWeek: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
|
|
404
406
|
monthsOfYear: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
|
405
|
-
hours: new Array(24).fill(0).map((d, i) => (i < 10 ? '0' : '') + i + ':00'),
|
|
407
|
+
hours: new Array(24).fill(0).map((d, i) => ({text: (i < 10 ? '0' : '') + i + ':00', num: (1 / 24 * i)})),
|
|
406
408
|
mode: 'date',
|
|
407
409
|
monthMap: {
|
|
408
410
|
0: 'Jan',
|
|
@@ -487,7 +489,12 @@ class WebsyDatePicker {
|
|
|
487
489
|
range: [this.floorDate(new Date(new Date(new Date().setDate(1)).setMonth(new Date().getMonth() - 24))), this.floorDate(new Date(new Date().setDate(1)))]
|
|
488
490
|
}
|
|
489
491
|
],
|
|
490
|
-
hour: [
|
|
492
|
+
hour: [
|
|
493
|
+
{
|
|
494
|
+
label: 'All',
|
|
495
|
+
range: ['00:00', '23:00']
|
|
496
|
+
}
|
|
497
|
+
]
|
|
491
498
|
}
|
|
492
499
|
this.options = Object.assign({}, DEFAULTS, options)
|
|
493
500
|
this.selectedRange = this.options.defaultRange || 0
|
|
@@ -523,8 +530,8 @@ class WebsyDatePicker {
|
|
|
523
530
|
html += `
|
|
524
531
|
</div>
|
|
525
532
|
<div id='${this.elementId}_mask' class='websy-date-picker-mask'></div>
|
|
526
|
-
<div id='${this.elementId}_content' class='websy-date-picker-content'>
|
|
527
|
-
<div class='websy-date-picker-ranges'>
|
|
533
|
+
<div id='${this.elementId}_content' class='websy-date-picker-content ${this.options.hideRanges === true ? 'hide-ranges' : ''}'>
|
|
534
|
+
<div class='websy-date-picker-ranges' >
|
|
528
535
|
<ul id='${this.elementId}_rangelist'>
|
|
529
536
|
${this.renderRanges()}
|
|
530
537
|
</ul>
|
|
@@ -562,11 +569,26 @@ class WebsyDatePicker {
|
|
|
562
569
|
if (this.options.onChange) {
|
|
563
570
|
console.log('confirm', this.selectedRangeDates)
|
|
564
571
|
console.log('confirm', this.currentselection)
|
|
565
|
-
if (this.customRangeSelected === true) {
|
|
566
|
-
this.options.
|
|
572
|
+
if (this.customRangeSelected === true) {
|
|
573
|
+
if (this.options.mode === 'hour') {
|
|
574
|
+
let hoursOut = []
|
|
575
|
+
for (let i = this.selectedRangeDates[0]; i < this.selectedRangeDates[1] + 1; i++) {
|
|
576
|
+
hoursOut.push(this.options.hours[i])
|
|
577
|
+
}
|
|
578
|
+
this.options.onChange(hoursOut, true)
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
this.options.onChange(this.selectedRangeDates, true)
|
|
582
|
+
}
|
|
567
583
|
}
|
|
568
584
|
else {
|
|
569
|
-
this.options.
|
|
585
|
+
if (this.options.mode === 'hour') {
|
|
586
|
+
let hoursOut = this.selectedRangeDates.map(h => this.options.hours[h])
|
|
587
|
+
this.options.onChange(hoursOut, true)
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
this.options.onChange(this.currentselection, false)
|
|
591
|
+
}
|
|
570
592
|
}
|
|
571
593
|
}
|
|
572
594
|
this.updateRange()
|
|
@@ -701,7 +723,7 @@ class WebsyDatePicker {
|
|
|
701
723
|
console.log('diff', diff)
|
|
702
724
|
}
|
|
703
725
|
else if (this.options.mode === 'hour') {
|
|
704
|
-
|
|
726
|
+
diff = this.selectedRangeDates[this.selectedRangeDates.length - 1] - this.selectedRangeDates[0]
|
|
705
727
|
}
|
|
706
728
|
for (let i = 0; i < diff + 1; i++) {
|
|
707
729
|
let d
|
|
@@ -724,7 +746,9 @@ class WebsyDatePicker {
|
|
|
724
746
|
rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1].getTime()
|
|
725
747
|
}
|
|
726
748
|
else if (this.options.mode === 'hour') {
|
|
727
|
-
|
|
749
|
+
d = this.selectedRangeDates[0] + i
|
|
750
|
+
rangeStart = this.selectedRangeDates[0]
|
|
751
|
+
rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1]
|
|
728
752
|
}
|
|
729
753
|
let dateEl
|
|
730
754
|
if (this.options.mode === 'date') {
|
|
@@ -740,7 +764,7 @@ class WebsyDatePicker {
|
|
|
740
764
|
dateEl = document.getElementById(`${this.elementId}_${d}_monthyear`)
|
|
741
765
|
}
|
|
742
766
|
else if (this.options.mode === 'hour') {
|
|
743
|
-
|
|
767
|
+
dateEl = document.getElementById(`${this.elementId}_${d}_hour`)
|
|
744
768
|
}
|
|
745
769
|
if (dateEl) {
|
|
746
770
|
dateEl.classList.add('selected')
|
|
@@ -766,7 +790,7 @@ class WebsyDatePicker {
|
|
|
766
790
|
dateEl = document.getElementById(`${this.elementId}_${d}_monthyear`)
|
|
767
791
|
}
|
|
768
792
|
else if (this.options.mode === 'hour') {
|
|
769
|
-
|
|
793
|
+
dateEl = document.getElementById(`${this.elementId}_${d}_hour`)
|
|
770
794
|
}
|
|
771
795
|
dateEl.classList.add('selected')
|
|
772
796
|
dateEl.classList.add('first')
|
|
@@ -808,6 +832,7 @@ class WebsyDatePicker {
|
|
|
808
832
|
let disabled = []
|
|
809
833
|
this.validDates = []
|
|
810
834
|
this.validYears = []
|
|
835
|
+
this.validHours = []
|
|
811
836
|
this.monthYears = {}
|
|
812
837
|
this.monthYearMonths = []
|
|
813
838
|
if (disabledDates) {
|
|
@@ -822,7 +847,7 @@ class WebsyDatePicker {
|
|
|
822
847
|
//
|
|
823
848
|
}
|
|
824
849
|
else if (this.options.mode === 'hour') {
|
|
825
|
-
|
|
850
|
+
return d
|
|
826
851
|
}
|
|
827
852
|
return d.getTime()
|
|
828
853
|
})
|
|
@@ -840,7 +865,7 @@ class WebsyDatePicker {
|
|
|
840
865
|
diff = Math.ceil((this.options.maxAllowedDate.getTime() - this.options.minAllowedDate.getTime()) / this.oneDay) + 1
|
|
841
866
|
}
|
|
842
867
|
else if (this.options.mode === 'hour') {
|
|
843
|
-
|
|
868
|
+
diff = 24
|
|
844
869
|
}
|
|
845
870
|
let months = {}
|
|
846
871
|
let yearList = []
|
|
@@ -856,12 +881,13 @@ class WebsyDatePicker {
|
|
|
856
881
|
}
|
|
857
882
|
if (this.monthYearMonths.indexOf(`${d.getMonth()}-${d.getFullYear()}`) === -1) {
|
|
858
883
|
this.monthYearMonths.push(`${d.getMonth()}-${d.getFullYear()}`)
|
|
884
|
+
let firstOfMonth = new Date(new Date(d).setDate(1))
|
|
859
885
|
this.monthYears[d.getFullYear()].push({
|
|
860
|
-
date:
|
|
886
|
+
date: firstOfMonth,
|
|
861
887
|
month: this.options.monthMap[d.getMonth()],
|
|
862
888
|
monthNum: d.getMonth(),
|
|
863
889
|
year: d.getFullYear(),
|
|
864
|
-
id:
|
|
890
|
+
id: firstOfMonth.getTime()
|
|
865
891
|
})
|
|
866
892
|
}
|
|
867
893
|
if (disabled.indexOf(d.getTime()) === -1) {
|
|
@@ -877,9 +903,16 @@ class WebsyDatePicker {
|
|
|
877
903
|
}
|
|
878
904
|
}
|
|
879
905
|
else if (this.options.mode === 'hour') {
|
|
880
|
-
//
|
|
906
|
+
//
|
|
881
907
|
}
|
|
882
908
|
}
|
|
909
|
+
if (this.options.mode === 'hour') {
|
|
910
|
+
this.options.hours.forEach(h => {
|
|
911
|
+
if (disabled.indexOf(h.text) === -1) {
|
|
912
|
+
this.validHours.push(h)
|
|
913
|
+
}
|
|
914
|
+
})
|
|
915
|
+
}
|
|
883
916
|
// check each range to see if it can be enabled
|
|
884
917
|
for (let i = 0; i < this.options.ranges[this.options.mode].length; i++) {
|
|
885
918
|
const r = this.options.ranges[this.options.mode][i]
|
|
@@ -928,7 +961,23 @@ class WebsyDatePicker {
|
|
|
928
961
|
//
|
|
929
962
|
}
|
|
930
963
|
else if (this.options.mode === 'hour') {
|
|
931
|
-
|
|
964
|
+
if (this.validDates.indexOf(r.range[0]) !== -1) {
|
|
965
|
+
r.disabled = false
|
|
966
|
+
}
|
|
967
|
+
else if (r.range[1]) {
|
|
968
|
+
if (this.validDates.indexOf(r.range[1]) !== -1) {
|
|
969
|
+
r.disabled = false
|
|
970
|
+
}
|
|
971
|
+
else {
|
|
972
|
+
// check the full range until a match is found
|
|
973
|
+
for (let i = r.range[0]; i <= r.range[1]; i++) {
|
|
974
|
+
if (this.validDates.indexOf(r.range[0] + i) !== -1) {
|
|
975
|
+
r.disabled = false
|
|
976
|
+
break
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
932
981
|
}
|
|
933
982
|
}
|
|
934
983
|
let html = ''
|
|
@@ -990,7 +1039,9 @@ class WebsyDatePicker {
|
|
|
990
1039
|
html += `</div>`
|
|
991
1040
|
}
|
|
992
1041
|
else if (this.options.mode === 'hour') {
|
|
993
|
-
|
|
1042
|
+
html += `<div id='${this.elementId}_dateList' class='websy-dp-date-list'><ul>`
|
|
1043
|
+
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('')
|
|
1044
|
+
html += `</ul></div>`
|
|
994
1045
|
}
|
|
995
1046
|
return html
|
|
996
1047
|
}
|
|
@@ -1042,7 +1093,13 @@ class WebsyDatePicker {
|
|
|
1042
1093
|
console.log('current selection', this.currentselection)
|
|
1043
1094
|
}
|
|
1044
1095
|
else {
|
|
1045
|
-
this.currentselection.
|
|
1096
|
+
let index = this.currentselection.indexOf(timestamp)
|
|
1097
|
+
if (index !== -1) {
|
|
1098
|
+
this.currentselection.splice(index, 1)
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
this.currentselection.push(timestamp)
|
|
1102
|
+
}
|
|
1046
1103
|
this.currentselection.sort((a, b) => a - b)
|
|
1047
1104
|
this.customRangeSelected = false
|
|
1048
1105
|
}
|
|
@@ -1058,7 +1115,7 @@ class WebsyDatePicker {
|
|
|
1058
1115
|
//
|
|
1059
1116
|
}
|
|
1060
1117
|
else if (this.options.mode === 'hour') {
|
|
1061
|
-
|
|
1118
|
+
this.selectedRangeDates = [this.currentselection[0], this.currentselection[1] || this.currentselection[0]]
|
|
1062
1119
|
}
|
|
1063
1120
|
// if (this.currentselection.length === 2) {
|
|
1064
1121
|
// this.currentselection = []
|
|
@@ -1122,7 +1179,8 @@ class WebsyDatePicker {
|
|
|
1122
1179
|
this.options.maxAllowedDate = range[1] || range[0]
|
|
1123
1180
|
}
|
|
1124
1181
|
else if (this.options.mode === 'hour') {
|
|
1125
|
-
|
|
1182
|
+
this.options.minAllowedHour = range[0]
|
|
1183
|
+
this.options.maxAllowedHour = range[1] || range[0]
|
|
1126
1184
|
}
|
|
1127
1185
|
}
|
|
1128
1186
|
updateRange () {
|
|
@@ -1145,7 +1203,7 @@ class WebsyDatePicker {
|
|
|
1145
1203
|
return `${this.options.monthMap[d.getMonth()]} ${d.getFullYear()}`
|
|
1146
1204
|
}
|
|
1147
1205
|
else if (this.options.mode === 'hour') {
|
|
1148
|
-
|
|
1206
|
+
return d
|
|
1149
1207
|
}
|
|
1150
1208
|
})
|
|
1151
1209
|
let start = list[0]
|
|
@@ -1156,6 +1214,10 @@ class WebsyDatePicker {
|
|
|
1156
1214
|
else {
|
|
1157
1215
|
start = `${list.length} selected`
|
|
1158
1216
|
}
|
|
1217
|
+
if (this.options.mode === 'hour') {
|
|
1218
|
+
start = this.options.hours[start].text
|
|
1219
|
+
end = `${this.customRangeSelected === true ? ' - ' : ''}${this.options.hours[list[list.length - 1]].text}`
|
|
1220
|
+
}
|
|
1159
1221
|
range = { label: `${start}${end}` }
|
|
1160
1222
|
}
|
|
1161
1223
|
else {
|