@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
|
@@ -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 = []
|
|
@@ -670,12 +695,13 @@ class WebsyDatePicker {
|
|
|
670
695
|
}
|
|
671
696
|
if (this.monthYearMonths.indexOf(`${d.getMonth()}-${d.getFullYear()}`) === -1) {
|
|
672
697
|
this.monthYearMonths.push(`${d.getMonth()}-${d.getFullYear()}`)
|
|
698
|
+
let firstOfMonth = new Date(new Date(d).setDate(1))
|
|
673
699
|
this.monthYears[d.getFullYear()].push({
|
|
674
|
-
date:
|
|
700
|
+
date: firstOfMonth,
|
|
675
701
|
month: this.options.monthMap[d.getMonth()],
|
|
676
702
|
monthNum: d.getMonth(),
|
|
677
703
|
year: d.getFullYear(),
|
|
678
|
-
id:
|
|
704
|
+
id: firstOfMonth.getTime()
|
|
679
705
|
})
|
|
680
706
|
}
|
|
681
707
|
if (disabled.indexOf(d.getTime()) === -1) {
|
|
@@ -691,9 +717,16 @@ class WebsyDatePicker {
|
|
|
691
717
|
}
|
|
692
718
|
}
|
|
693
719
|
else if (this.options.mode === 'hour') {
|
|
694
|
-
//
|
|
720
|
+
//
|
|
695
721
|
}
|
|
696
722
|
}
|
|
723
|
+
if (this.options.mode === 'hour') {
|
|
724
|
+
this.options.hours.forEach(h => {
|
|
725
|
+
if (disabled.indexOf(h.text) === -1) {
|
|
726
|
+
this.validHours.push(h)
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
}
|
|
697
730
|
// check each range to see if it can be enabled
|
|
698
731
|
for (let i = 0; i < this.options.ranges[this.options.mode].length; i++) {
|
|
699
732
|
const r = this.options.ranges[this.options.mode][i]
|
|
@@ -742,7 +775,23 @@ class WebsyDatePicker {
|
|
|
742
775
|
//
|
|
743
776
|
}
|
|
744
777
|
else if (this.options.mode === 'hour') {
|
|
745
|
-
|
|
778
|
+
if (this.validDates.indexOf(r.range[0]) !== -1) {
|
|
779
|
+
r.disabled = false
|
|
780
|
+
}
|
|
781
|
+
else if (r.range[1]) {
|
|
782
|
+
if (this.validDates.indexOf(r.range[1]) !== -1) {
|
|
783
|
+
r.disabled = false
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
// check the full range until a match is found
|
|
787
|
+
for (let i = r.range[0]; i <= r.range[1]; i++) {
|
|
788
|
+
if (this.validDates.indexOf(r.range[0] + i) !== -1) {
|
|
789
|
+
r.disabled = false
|
|
790
|
+
break
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
746
795
|
}
|
|
747
796
|
}
|
|
748
797
|
let html = ''
|
|
@@ -804,7 +853,9 @@ class WebsyDatePicker {
|
|
|
804
853
|
html += `</div>`
|
|
805
854
|
}
|
|
806
855
|
else if (this.options.mode === 'hour') {
|
|
807
|
-
|
|
856
|
+
html += `<div id='${this.elementId}_dateList' class='websy-dp-date-list'><ul>`
|
|
857
|
+
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('')
|
|
858
|
+
html += `</ul></div>`
|
|
808
859
|
}
|
|
809
860
|
return html
|
|
810
861
|
}
|
|
@@ -856,7 +907,13 @@ class WebsyDatePicker {
|
|
|
856
907
|
console.log('current selection', this.currentselection)
|
|
857
908
|
}
|
|
858
909
|
else {
|
|
859
|
-
this.currentselection.
|
|
910
|
+
let index = this.currentselection.indexOf(timestamp)
|
|
911
|
+
if (index !== -1) {
|
|
912
|
+
this.currentselection.splice(index, 1)
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
this.currentselection.push(timestamp)
|
|
916
|
+
}
|
|
860
917
|
this.currentselection.sort((a, b) => a - b)
|
|
861
918
|
this.customRangeSelected = false
|
|
862
919
|
}
|
|
@@ -872,7 +929,7 @@ class WebsyDatePicker {
|
|
|
872
929
|
//
|
|
873
930
|
}
|
|
874
931
|
else if (this.options.mode === 'hour') {
|
|
875
|
-
|
|
932
|
+
this.selectedRangeDates = [this.currentselection[0], this.currentselection[1] || this.currentselection[0]]
|
|
876
933
|
}
|
|
877
934
|
// if (this.currentselection.length === 2) {
|
|
878
935
|
// this.currentselection = []
|
|
@@ -936,7 +993,8 @@ class WebsyDatePicker {
|
|
|
936
993
|
this.options.maxAllowedDate = range[1] || range[0]
|
|
937
994
|
}
|
|
938
995
|
else if (this.options.mode === 'hour') {
|
|
939
|
-
|
|
996
|
+
this.options.minAllowedHour = range[0]
|
|
997
|
+
this.options.maxAllowedHour = range[1] || range[0]
|
|
940
998
|
}
|
|
941
999
|
}
|
|
942
1000
|
updateRange () {
|
|
@@ -959,7 +1017,7 @@ class WebsyDatePicker {
|
|
|
959
1017
|
return `${this.options.monthMap[d.getMonth()]} ${d.getFullYear()}`
|
|
960
1018
|
}
|
|
961
1019
|
else if (this.options.mode === 'hour') {
|
|
962
|
-
|
|
1020
|
+
return d
|
|
963
1021
|
}
|
|
964
1022
|
})
|
|
965
1023
|
let start = list[0]
|
|
@@ -970,6 +1028,10 @@ class WebsyDatePicker {
|
|
|
970
1028
|
else {
|
|
971
1029
|
start = `${list.length} selected`
|
|
972
1030
|
}
|
|
1031
|
+
if (this.options.mode === 'hour') {
|
|
1032
|
+
start = this.options.hours[start].text
|
|
1033
|
+
end = `${this.customRangeSelected === true ? ' - ' : ''}${this.options.hours[list[list.length - 1]].text}`
|
|
1034
|
+
}
|
|
973
1035
|
range = { label: `${start}${end}` }
|
|
974
1036
|
}
|
|
975
1037
|
else {
|