add-to-calendar-button 2.2.0 → 2.2.2
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/atcb.js +3 -3
- package/dist/commonjs/index.js +119 -161
- package/dist/module/index.js +119 -161
- package/package.json +1 -1
package/dist/module/index.js
CHANGED
|
@@ -6,15 +6,15 @@ import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'tim
|
|
|
6
6
|
* Add to Calendar Button
|
|
7
7
|
* ++++++++++++++++++++++
|
|
8
8
|
*
|
|
9
|
-
* Version: 2.2.
|
|
9
|
+
* Version: 2.2.2
|
|
10
10
|
* Creator: Jens Kuerschner (https://jenskuerschner.de)
|
|
11
11
|
* Project: https://github.com/add2cal/add-to-calendar-button
|
|
12
12
|
* License: Elastic License 2.0 (ELv2) (https://github.com/add2cal/add-to-calendar-button/blob/main/LICENSE.txt)
|
|
13
13
|
* Note: DO NOT REMOVE THE COPYRIGHT NOTICE ABOVE!
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
-
const atcbVersion = '2.2.
|
|
17
|
-
const atcbCssTemplate = {
|
|
16
|
+
const atcbVersion = '2.2.2';
|
|
17
|
+
const atcbCssTemplate = {
|
|
18
18
|
if (typeof window === 'undefined') {
|
|
19
19
|
return false;
|
|
20
20
|
} else {
|
|
@@ -172,7 +172,8 @@ const atcbWcBooleanParams = [
|
|
|
172
172
|
'disabled',
|
|
173
173
|
'hidden',
|
|
174
174
|
];
|
|
175
|
-
const atcbWcObjectParams = ['
|
|
175
|
+
const atcbWcObjectParams = ['customLabels', 'ty', 'rsvp'];
|
|
176
|
+
const atcbWcObjectArrayParams = ['dates'];
|
|
176
177
|
const atcbWcArrayParams = ['images', 'options'];
|
|
177
178
|
const atcbIcon = {
|
|
178
179
|
trigger:
|
|
@@ -525,15 +526,19 @@ function atcb_date_specials_calculation(type, dateString, timeString = null, tim
|
|
|
525
526
|
if (type === 'timestamp') {
|
|
526
527
|
return tmpDate.getTime();
|
|
527
528
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
529
|
+
try {
|
|
530
|
+
let isoString = tmpDate.toISOString();
|
|
531
|
+
if (timeString && timeZone) {
|
|
532
|
+
const offsetEnd = tzlib_get_offset(timeZone, dateString, timeString);
|
|
533
|
+
const formattedOffsetEnd = offsetEnd.slice(0, 3) + ':' + offsetEnd.slice(3);
|
|
534
|
+
isoString.replace('.000Z', formattedOffsetEnd);
|
|
535
|
+
}
|
|
536
|
+
const utcEndDate = new Date(isoString);
|
|
537
|
+
const currentUtcDate = new Date(Date.now()).toUTCString();
|
|
538
|
+
return utcEndDate.getTime() < new Date(currentUtcDate).getTime();
|
|
539
|
+
} catch (e) {
|
|
540
|
+
return false;
|
|
533
541
|
}
|
|
534
|
-
const utcEndDate = new Date(isoString);
|
|
535
|
-
const currentUtcDate = new Date(Date.now()).toUTCString();
|
|
536
|
-
return utcEndDate.getTime() < new Date(currentUtcDate).getTime();
|
|
537
542
|
}
|
|
538
543
|
function atcb_date_calculation(dateString) {
|
|
539
544
|
const today = new Date();
|
|
@@ -550,7 +555,11 @@ function atcb_date_calculation(dateString) {
|
|
|
550
555
|
if (dateStringParts[1] != null && dateStringParts[1] > 0) {
|
|
551
556
|
newDate.setDate(newDate.getDate() + parseInt(dateStringParts[1]));
|
|
552
557
|
}
|
|
553
|
-
|
|
558
|
+
try {
|
|
559
|
+
return newDate.toISOString().replace(/T(\d{2}:\d{2}:\d{2}\.\d{3})Z/g, '');
|
|
560
|
+
} catch (e) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
554
563
|
}
|
|
555
564
|
function atcb_decorate_data_button_status_handling(data) {
|
|
556
565
|
if (data.pastDateHandling == null || (data.pastDateHandling != 'disable' && data.pastDateHandling != 'hide')) {
|
|
@@ -581,17 +590,16 @@ function atcb_decorate_data_button_status_handling(data) {
|
|
|
581
590
|
}
|
|
582
591
|
|
|
583
592
|
|
|
584
|
-
function atcb_check_required(data
|
|
593
|
+
function atcb_check_required(data) {
|
|
594
|
+
if (data.validationError) {
|
|
595
|
+
data.validationError = null;
|
|
596
|
+
}
|
|
585
597
|
if (data.options == null || data.options.length < 1) {
|
|
586
|
-
|
|
587
|
-
throw new Error('Add to Calendar Button generation failed: no valid options set');
|
|
588
|
-
}
|
|
598
|
+
data.validationError = 'Add to Calendar Button generation failed: no valid options set';
|
|
589
599
|
return false;
|
|
590
600
|
}
|
|
591
601
|
if (data.name == null || data.name == '') {
|
|
592
|
-
|
|
593
|
-
throw new Error('Add to Calendar Button generation failed: required name information missing');
|
|
594
|
-
}
|
|
602
|
+
data.validationError = 'Add to Calendar Button generation failed: required name information missing';
|
|
595
603
|
return false;
|
|
596
604
|
}
|
|
597
605
|
if (data.dates != null && data.dates.length > 0) {
|
|
@@ -603,9 +611,7 @@ function atcb_check_required(data, throwError = true) {
|
|
|
603
611
|
(!requiredMultiFieldFlex.includes(`${field}`) && (data.dates[`${i}`][`${field}`] == null || data.dates[`${i}`][`${field}`] == '')) ||
|
|
604
612
|
(requiredMultiFieldFlex.includes(`${field}`) && (data.dates[`${i}`][`${field}`] == null || data.dates[`${i}`][`${field}`] == '') && (data[`${field}`] == null || data[`${field}`] == ''))
|
|
605
613
|
) {
|
|
606
|
-
|
|
607
|
-
throw new Error('Add to Calendar Button generation failed: required setting missing [dates array object #' + (i + 1) + '/' + data.dates.length + '] => [' + field + ']');
|
|
608
|
-
}
|
|
614
|
+
data.validationError = 'Add to Calendar Button generation failed: required setting missing [dates array object #' + (i + 1) + '/' + data.dates.length + '] => [' + field + ']';
|
|
609
615
|
return false;
|
|
610
616
|
}
|
|
611
617
|
}
|
|
@@ -615,9 +621,7 @@ function atcb_check_required(data, throwError = true) {
|
|
|
615
621
|
const requiredSingleField = ['startDate'];
|
|
616
622
|
return requiredSingleField.every(function (field) {
|
|
617
623
|
if (data[`${field}`] == null || data[`${field}`] == '') {
|
|
618
|
-
|
|
619
|
-
throw new Error('Add to Calendar Button generation failed: required setting missing [' + field + ']');
|
|
620
|
-
}
|
|
624
|
+
data.validationError = 'Add to Calendar Button generation failed: required setting missing [' + field + ']';
|
|
621
625
|
return false;
|
|
622
626
|
}
|
|
623
627
|
return true;
|
|
@@ -625,6 +629,9 @@ function atcb_check_required(data, throwError = true) {
|
|
|
625
629
|
}
|
|
626
630
|
}
|
|
627
631
|
function atcb_validate(data) {
|
|
632
|
+
if (data.validationError) {
|
|
633
|
+
data.validationError = null;
|
|
634
|
+
}
|
|
628
635
|
const msgPrefix = 'Add to Calendar Button generation (' + data.identifier + ')';
|
|
629
636
|
if (!atcb_validate_icsFile(data, msgPrefix)) return false;
|
|
630
637
|
if (!atcb_validate_buttonStyle(data, msgPrefix)) return false;
|
|
@@ -651,9 +658,7 @@ function atcb_validate_icsFile(data, msgPrefix, i = '', msgSuffix = '') {
|
|
|
651
658
|
})();
|
|
652
659
|
if (icsFileStr != '') {
|
|
653
660
|
if (!atcb_secure_url(icsFileStr, false) || !data.icsFile.startsWith('https://')) {
|
|
654
|
-
|
|
655
|
-
console.error(msgPrefix + ' failed: explicit ics file path not valid' + msgSuffix);
|
|
656
|
-
}
|
|
661
|
+
data.validationError = msgPrefix + ' failed: explicit ics file path not valid' + msgSuffix;
|
|
657
662
|
return false;
|
|
658
663
|
}
|
|
659
664
|
}
|
|
@@ -662,48 +667,36 @@ function atcb_validate_icsFile(data, msgPrefix, i = '', msgSuffix = '') {
|
|
|
662
667
|
function atcb_validate_buttonStyle(data, msgPrefix) {
|
|
663
668
|
const availableStyles = ['default', '3d', 'flat', 'round', 'neumorphism', 'text', 'date', 'custom', 'none'];
|
|
664
669
|
if (!availableStyles.includes(data.buttonStyle)) {
|
|
665
|
-
|
|
666
|
-
console.error(msgPrefix + ' failed: provided buttonStyle invalid');
|
|
667
|
-
}
|
|
670
|
+
data.validationError = msgPrefix + ' failed: provided buttonStyle invalid';
|
|
668
671
|
return false;
|
|
669
672
|
}
|
|
670
673
|
if (data.customCss != null && data.customCss != '' && (!atcb_secure_url(data.customCss, false) || !/\.css$/m.test(data.customCss))) {
|
|
671
|
-
|
|
672
|
-
console.error(msgPrefix + ' failed: customCss provided, but no valid url');
|
|
673
|
-
}
|
|
674
|
+
data.validationError = msgPrefix + ' failed: customCss provided, but no valid url';
|
|
674
675
|
return false;
|
|
675
676
|
}
|
|
676
677
|
if ((data.customCss == null || data.customCss == '') && data.buttonStyle == 'custom') {
|
|
677
|
-
|
|
678
|
-
console.error(msgPrefix + ' failed: buttonStyle "custom" selected, but no customCss file provided');
|
|
679
|
-
}
|
|
678
|
+
data.validationError = msgPrefix + ' failed: buttonStyle "custom" selected, but no customCss file provided';
|
|
680
679
|
return false;
|
|
681
680
|
}
|
|
682
681
|
return true;
|
|
683
682
|
}
|
|
684
683
|
function atcb_validate_subscribe(data, msgPrefix) {
|
|
685
684
|
if (data.subscribe == true && (data.icsFile == null || data.icsFile == '')) {
|
|
686
|
-
|
|
687
|
-
console.error(msgPrefix + ' failed: a subscription calendar requires a valid explicit ics file as well');
|
|
688
|
-
}
|
|
685
|
+
data.validationError = msgPrefix + ' failed: a subscription calendar requires a valid explicit ics file as well';
|
|
689
686
|
return false;
|
|
690
687
|
}
|
|
691
688
|
return true;
|
|
692
689
|
}
|
|
693
690
|
function atcb_validate_created(data, msgPrefix) {
|
|
694
691
|
if (!/^\d{8}T\d{6}Z$/.test(data.created)) {
|
|
695
|
-
|
|
696
|
-
console.error(msgPrefix + ' failed: created date format not valid. Needs to be a full ISO-8601 UTC date and time string, formatted YYYYMMDDTHHMMSSZ');
|
|
697
|
-
}
|
|
692
|
+
data.validationError = msgPrefix + ' failed: created date format not valid. Needs to be a full ISO-8601 UTC date and time string, formatted YYYYMMDDTHHMMSSZ';
|
|
698
693
|
return false;
|
|
699
694
|
}
|
|
700
695
|
return true;
|
|
701
696
|
}
|
|
702
697
|
function atcb_validate_updated(data, msgPrefix) {
|
|
703
698
|
if (!/^\d{8}T\d{6}Z$/.test(data.updated)) {
|
|
704
|
-
|
|
705
|
-
console.error(msgPrefix + ' failed: updated date format not valid. Needs to be a full ISO-8601 UTC date and time string, formatted YYYYMMDDTHHMMSSZ');
|
|
706
|
-
}
|
|
699
|
+
data.validationError = msgPrefix + ' failed: updated date format not valid. Needs to be a full ISO-8601 UTC date and time string, formatted YYYYMMDDTHHMMSSZ';
|
|
707
700
|
return false;
|
|
708
701
|
}
|
|
709
702
|
return true;
|
|
@@ -712,9 +705,7 @@ function atcb_validate_options(data, msgPrefix) {
|
|
|
712
705
|
if (
|
|
713
706
|
!data.options.every(function (option) {
|
|
714
707
|
if (!atcbOptions.includes(option)) {
|
|
715
|
-
|
|
716
|
-
console.error(msgPrefix + ' failed: invalid option [' + option + ']');
|
|
717
|
-
}
|
|
708
|
+
data.validationError = msgPrefix + ' failed: invalid option [' + option + ']';
|
|
718
709
|
return false;
|
|
719
710
|
}
|
|
720
711
|
return true;
|
|
@@ -747,18 +738,14 @@ function atcb_validate_date_blocks(data, msgPrefix) {
|
|
|
747
738
|
}
|
|
748
739
|
function atcb_validate_status(data, msgPrefix, i, msgSuffix) {
|
|
749
740
|
if (data.dates[`${i}`].status != 'TENTATIVE' && data.dates[`${i}`].status != 'CONFIRMED' && data.dates[`${i}`].status != 'CANCELLED') {
|
|
750
|
-
|
|
751
|
-
console.error(msgPrefix + ' failed: event status needs to be TENTATIVE, CONFIRMED, or CANCELLED' + msgSuffix);
|
|
752
|
-
}
|
|
741
|
+
data.validationError = msgPrefix + ' failed: event status needs to be TENTATIVE, CONFIRMED, or CANCELLED' + msgSuffix;
|
|
753
742
|
return false;
|
|
754
743
|
}
|
|
755
744
|
return true;
|
|
756
745
|
}
|
|
757
746
|
function atcb_validate_availability(data, msgPrefix, i, msgSuffix) {
|
|
758
747
|
if (data.dates[`${i}`].availability != null && data.dates[`${i}`].availability != '' && data.dates[`${i}`].availability != 'free' && data.dates[`${i}`].availability != 'busy') {
|
|
759
|
-
|
|
760
|
-
console.error(msgPrefix + ' failed: event availability needs to be "free" or "busy"' + msgSuffix);
|
|
761
|
-
}
|
|
748
|
+
data.validationError = msgPrefix + ' failed: event availability needs to be "free" or "busy"' + msgSuffix;
|
|
762
749
|
return false;
|
|
763
750
|
}
|
|
764
751
|
return true;
|
|
@@ -767,9 +754,7 @@ function atcb_validate_organizer(data, msgPrefix, i, msgSuffix) {
|
|
|
767
754
|
if (data.dates[`${i}`].organizer != null && data.dates[`${i}`].organizer != '') {
|
|
768
755
|
const organizerParts = data.dates[`${i}`].organizer.split('|');
|
|
769
756
|
if (organizerParts.length != 2 || organizerParts[0].length > 50 || organizerParts[1].length > 80 || !atcb_validEmail(organizerParts[1])) {
|
|
770
|
-
|
|
771
|
-
console.error(msgPrefix + ' failed: organizer needs to match the schema "NAME|EMAIL" with a valid email address' + msgSuffix);
|
|
772
|
-
}
|
|
757
|
+
data.validationError = msgPrefix + ' failed: organizer needs to match the schema "NAME|EMAIL" with a valid email address' + msgSuffix;
|
|
773
758
|
return false;
|
|
774
759
|
}
|
|
775
760
|
}
|
|
@@ -778,16 +763,12 @@ function atcb_validate_organizer(data, msgPrefix, i, msgSuffix) {
|
|
|
778
763
|
function atcb_validate_attendee(data, msgPrefix, i, msgSuffix) {
|
|
779
764
|
if (data.dates[`${i}`].attendee != null && data.dates[`${i}`].attendee != '') {
|
|
780
765
|
if (data.dates[`${i}`].organizer == null || data.dates[`${i}`].organizer == '') {
|
|
781
|
-
|
|
782
|
-
console.error(msgPrefix + ' failed: if an attendee is set, you also need to set the organizer' + msgSuffix);
|
|
783
|
-
}
|
|
766
|
+
data.validationError = msgPrefix + ' failed: if an attendee is set, you also need to set the organizer' + msgSuffix;
|
|
784
767
|
return false;
|
|
785
768
|
}
|
|
786
769
|
const attendeeParts = data.dates[`${i}`].attendee.split('|');
|
|
787
770
|
if (attendeeParts.length != 2 || attendeeParts[0].length > 50 || attendeeParts[1].length > 80 || !atcb_validEmail(attendeeParts[1])) {
|
|
788
|
-
|
|
789
|
-
console.error(msgPrefix + ' failed: attendee needs to match the schema "NAME|EMAIL" with a valid email address' + msgSuffix);
|
|
790
|
-
}
|
|
771
|
+
data.validationError = msgPrefix + ' failed: attendee needs to match the schema "NAME|EMAIL" with a valid email address' + msgSuffix;
|
|
791
772
|
return false;
|
|
792
773
|
}
|
|
793
774
|
}
|
|
@@ -818,9 +799,7 @@ function atcb_validate_timezone(data, msgPrefix, i, msgSuffix) {
|
|
|
818
799
|
if (data.dates[`${i}`].timeZone != null && data.dates[`${i}`].timeZone != '') {
|
|
819
800
|
const validTimeZones = tzlib_get_timezones();
|
|
820
801
|
if (!validTimeZones.includes(data.dates[`${i}`].timeZone)) {
|
|
821
|
-
|
|
822
|
-
console.error(msgPrefix + ' failed: invalid time zone given' + msgSuffix);
|
|
823
|
-
}
|
|
802
|
+
data.validationError = msgPrefix + ' failed: invalid time zone given' + msgSuffix;
|
|
824
803
|
return false;
|
|
825
804
|
}
|
|
826
805
|
}
|
|
@@ -832,16 +811,12 @@ function atcb_validate_datetime(data, msgPrefix, i, msgSuffix) {
|
|
|
832
811
|
if (
|
|
833
812
|
!dates.every(function (date) {
|
|
834
813
|
if (data.dates[`${i}`][`${date}`].length !== 10) {
|
|
835
|
-
|
|
836
|
-
console.error(msgPrefix + ' failed: date misspelled [-> YYYY-MM-DD]' + msgSuffix);
|
|
837
|
-
}
|
|
814
|
+
data.validationError = msgPrefix + ' failed: date misspelled [-> YYYY-MM-DD]' + msgSuffix;
|
|
838
815
|
return false;
|
|
839
816
|
}
|
|
840
817
|
const dateParts = data.dates[`${i}`][`${date}`].split('-');
|
|
841
818
|
if (dateParts.length < 3 || dateParts.length > 3) {
|
|
842
|
-
|
|
843
|
-
console.error(msgPrefix + ' failed: date misspelled [' + date + ': ' + data.dates[`${i}`][`${date}`] + ']' + msgSuffix);
|
|
844
|
-
}
|
|
819
|
+
data.validationError = msgPrefix + ' failed: date misspelled [' + date + ': ' + data.dates[`${i}`][`${date}`] + ']' + msgSuffix;
|
|
845
820
|
return false;
|
|
846
821
|
}
|
|
847
822
|
newDate[`${date}`] = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);
|
|
@@ -855,28 +830,20 @@ function atcb_validate_datetime(data, msgPrefix, i, msgSuffix) {
|
|
|
855
830
|
!times.every(function (time) {
|
|
856
831
|
if (data.dates[`${i}`][`${time}`] != null) {
|
|
857
832
|
if (data.dates[`${i}`][`${time}`].length !== 5) {
|
|
858
|
-
|
|
859
|
-
console.error(msgPrefix + ' failed: time misspelled [-> HH:MM]' + msgSuffix);
|
|
860
|
-
}
|
|
833
|
+
data.validationError = msgPrefix + ' failed: time misspelled [-> HH:MM]' + msgSuffix;
|
|
861
834
|
return false;
|
|
862
835
|
}
|
|
863
836
|
const timeParts = data.dates[`${i}`][`${time}`].split(':');
|
|
864
837
|
if (timeParts.length < 2 || timeParts.length > 2) {
|
|
865
|
-
|
|
866
|
-
console.error(msgPrefix + ' failed: time misspelled [' + time + ': ' + data.dates[`${i}`][`${time}`] + ']' + msgSuffix);
|
|
867
|
-
}
|
|
838
|
+
data.validationError = msgPrefix + ' failed: time misspelled [' + time + ': ' + data.dates[`${i}`][`${time}`] + ']' + msgSuffix;
|
|
868
839
|
return false;
|
|
869
840
|
}
|
|
870
841
|
if (timeParts[0] > 23) {
|
|
871
|
-
|
|
872
|
-
console.error(msgPrefix + ' failed: time misspelled - hours number too high [' + time + ': ' + timeParts[0] + ']' + msgSuffix);
|
|
873
|
-
}
|
|
842
|
+
data.validationError = msgPrefix + ' failed: time misspelled - hours number too high [' + time + ': ' + timeParts[0] + ']' + msgSuffix;
|
|
874
843
|
return false;
|
|
875
844
|
}
|
|
876
845
|
if (timeParts[1] > 59) {
|
|
877
|
-
|
|
878
|
-
console.error(msgPrefix + ' failed: time misspelled - minutes number too high [' + time + ': ' + timeParts[1] + ']' + msgSuffix);
|
|
879
|
-
}
|
|
846
|
+
data.validationError = msgPrefix + ' failed: time misspelled - minutes number too high [' + time + ': ' + timeParts[1] + ']' + msgSuffix;
|
|
880
847
|
return false;
|
|
881
848
|
}
|
|
882
849
|
if (time == 'startTime') {
|
|
@@ -892,75 +859,53 @@ function atcb_validate_datetime(data, msgPrefix, i, msgSuffix) {
|
|
|
892
859
|
return false;
|
|
893
860
|
}
|
|
894
861
|
if ((data.dates[`${i}`].startTime != null && data.dates[`${i}`].endTime == null) || (data.dates[`${i}`].startTime == null && data.dates[`${i}`].endTime != null)) {
|
|
895
|
-
|
|
896
|
-
console.error(msgPrefix + ' failed: if you set a starting or end time, the respective other one also needs to be defined' + msgSuffix);
|
|
897
|
-
}
|
|
862
|
+
data.validationError = msgPrefix + ' failed: if you set a starting or end time, the respective other one also needs to be defined' + msgSuffix;
|
|
898
863
|
return false;
|
|
899
864
|
}
|
|
900
865
|
if (newDate.endDate < newDate.startDate) {
|
|
901
|
-
|
|
902
|
-
console.error(msgPrefix + ' failed: end date before start date' + msgSuffix);
|
|
903
|
-
}
|
|
866
|
+
data.validationError = msgPrefix + ' failed: end date before start date' + msgSuffix;
|
|
904
867
|
return false;
|
|
905
868
|
}
|
|
906
869
|
return true;
|
|
907
870
|
}
|
|
908
871
|
function atcb_validate_rrule(data, msgPrefix) {
|
|
909
872
|
if (data.recurrence != null && data.recurrence != '' && data.dates.length > 1) {
|
|
910
|
-
|
|
911
|
-
console.error(msgPrefix + ' failed: RRULE and multi-date set at the same time');
|
|
912
|
-
}
|
|
873
|
+
data.validationError = msgPrefix + ' failed: RRULE and multi-date set at the same time';
|
|
913
874
|
return false;
|
|
914
875
|
}
|
|
915
876
|
if (data.recurrence != null && data.recurrence != '' && !/^RRULE:[\w=;,:+-/\\]+$/i.test(data.recurrence)) {
|
|
916
|
-
|
|
917
|
-
console.error(msgPrefix + ' failed: RRULE data misspelled');
|
|
918
|
-
}
|
|
877
|
+
data.validationError = msgPrefix + ' failed: RRULE data misspelled';
|
|
919
878
|
return false;
|
|
920
879
|
}
|
|
921
880
|
return true;
|
|
922
881
|
}
|
|
923
882
|
function atcb_validate_rrule_simplyfied(data, msgPrefix) {
|
|
924
883
|
if (data.recurrence_interval != null && data.recurrence_interval != '' && !/^\d+$/.test(data.recurrence_interval)) {
|
|
925
|
-
|
|
926
|
-
console.error(msgPrefix + ' failed: recurrence data (interval) misspelled');
|
|
927
|
-
}
|
|
884
|
+
data.validationError = msgPrefix + ' failed: recurrence data (interval) misspelled';
|
|
928
885
|
return false;
|
|
929
886
|
}
|
|
930
887
|
if (data.recurrence_until != null && data.recurrence_until != '' && !/^(\d|-|:)+$/i.test(data.recurrence_until)) {
|
|
931
|
-
|
|
932
|
-
console.error(msgPrefix + ' failed: recurrence data (until) misspelled');
|
|
933
|
-
}
|
|
888
|
+
data.validationError = msgPrefix + ' failed: recurrence data (until) misspelled';
|
|
934
889
|
return false;
|
|
935
890
|
}
|
|
936
891
|
if (data.recurrence_count != null && data.recurrence_count != '' && !/^\d+$/.test(data.recurrence_count)) {
|
|
937
|
-
|
|
938
|
-
console.error(msgPrefix + ' failed: recurrence data (interval) misspelled');
|
|
939
|
-
}
|
|
892
|
+
data.validationError = msgPrefix + ' failed: recurrence data (interval) misspelled';
|
|
940
893
|
return false;
|
|
941
894
|
}
|
|
942
895
|
if (data.recurrence_byMonth != null && data.recurrence_byMonth != '' && !/^(\d|,)+$/.test(data.recurrence_byMonth)) {
|
|
943
|
-
|
|
944
|
-
console.error(msgPrefix + ' failed: recurrence data (byMonth) misspelled');
|
|
945
|
-
}
|
|
896
|
+
data.validationError = msgPrefix + ' failed: recurrence data (byMonth) misspelled';
|
|
946
897
|
return false;
|
|
947
898
|
}
|
|
948
899
|
if (data.recurrence_byMonthDay != null && data.recurrence_byMonthDay != '' && !/^(\d|,)+$/.test(data.recurrence_byMonthDay)) {
|
|
949
|
-
|
|
950
|
-
console.error(msgPrefix + ' failed: recurrence data (byMonthDay) misspelled');
|
|
951
|
-
}
|
|
900
|
+
data.validationError = msgPrefix + ' failed: recurrence data (byMonthDay) misspelled';
|
|
952
901
|
return false;
|
|
953
902
|
}
|
|
954
903
|
if (data.recurrence_byDay != null && data.recurrence_byDay != '' && !/^(\d|-|MO|TU|WE|TH|FR|SA|SU|,)+$/im.test(data.recurrence_byDay)) {
|
|
955
|
-
|
|
956
|
-
console.error(msgPrefix + ' failed: recurrence data (byDay) misspelled');
|
|
957
|
-
}
|
|
904
|
+
data.validationError = msgPrefix + ' failed: recurrence data (byDay) misspelled';
|
|
958
905
|
return false;
|
|
959
906
|
}
|
|
960
907
|
if (data.recurrence_weekstart != null && data.recurrence_weekstart != '' && !/^(MO|TU|WE|TH|FR|SA|SU)$/im.test(data.recurrence_weekstart)) {
|
|
961
|
-
|
|
962
|
-
console.error(msgPrefix + ' failed: recurrence data (weekstart) misspelled');
|
|
963
|
-
}
|
|
908
|
+
data.validationError = msgPrefix + ' failed: recurrence data (weekstart) misspelled';
|
|
964
909
|
return false;
|
|
965
910
|
}
|
|
966
911
|
return true;
|
|
@@ -2514,22 +2459,30 @@ function atcb_rewrite_html_elements(content, clear = false) {
|
|
|
2514
2459
|
content = content.replace(/<br\s*\/?>/gi, '\n');
|
|
2515
2460
|
if (clear) {
|
|
2516
2461
|
content = content.replace(/\[(|\/)(url|br|hr|p|b|strong|u|i|em|li|ul|ol|h\d)\]|((\|.*)\[\/url\])/gi, '');
|
|
2462
|
+
content = content.replace(/\{(|\/)(url|br|hr|p|b|strong|u|i|em|li|ul|ol|h\d)\}|((\|.*)\{\/url\})/gi, '');
|
|
2517
2463
|
} else {
|
|
2518
2464
|
content = content.replace(/\[(\/|)(br|hr|p|b|strong|u|i|em|li|ul|ol|h\d)\]/gi, '<$1$2>');
|
|
2465
|
+
content = content.replace(/\{(\/|)(br|hr|p|b|strong|u|i|em|li|ul|ol|h\d)\}/gi, '<$1$2>');
|
|
2519
2466
|
content = content.replace(/\[url\]([\w&$+.,:;=~!*'?@^%#|\s\-()/]*)\[\/url\]/gi, function (match, p1) {
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
} else {
|
|
2525
|
-
return urlText[0];
|
|
2526
|
-
}
|
|
2527
|
-
})();
|
|
2528
|
-
return '<a href="' + urlText[0] + '" target="' + atcbDefaultTarget + '" rel="noopener">' + text + '</a>';
|
|
2467
|
+
return atcb_parse_url_code(p1);
|
|
2468
|
+
});
|
|
2469
|
+
content = content.replace(/\{url\}([\w&$+.,:;=~!*'?@^%#|\s\-()/]*)\{\/url\}/gi, function (match, p1) {
|
|
2470
|
+
return atcb_parse_url_code(p1);
|
|
2529
2471
|
});
|
|
2530
2472
|
}
|
|
2531
2473
|
return content;
|
|
2532
2474
|
}
|
|
2475
|
+
function atcb_parse_url_code(input) {
|
|
2476
|
+
const urlText = input.split('|');
|
|
2477
|
+
const text = (function () {
|
|
2478
|
+
if (urlText.length > 1 && urlText[1] != '') {
|
|
2479
|
+
return urlText[1];
|
|
2480
|
+
} else {
|
|
2481
|
+
return urlText[0];
|
|
2482
|
+
}
|
|
2483
|
+
})();
|
|
2484
|
+
return '<a href="' + urlText[0] + '" target="' + atcbDefaultTarget + '" rel="noopener">' + text + '</a>';
|
|
2485
|
+
}
|
|
2533
2486
|
function atcb_position_list(host, trigger, list, blockUpwards = false, resize = false) {
|
|
2534
2487
|
let anchorSet = false;
|
|
2535
2488
|
const originalTrigger = trigger;
|
|
@@ -3148,9 +3101,8 @@ const i18nStrings = {
|
|
|
3148
3101
|
};
|
|
3149
3102
|
const availableLanguages = Object.keys(i18nStrings);
|
|
3150
3103
|
function atcb_translate_hook(identifier, data) {
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
return atcb_rewrite_html_elements(data.customLabels[`${searchKey}`]);
|
|
3104
|
+
if (data.customLabels != null && data.customLabels[`${identifier}`] != null && data.customLabels[`${identifier}`] != '') {
|
|
3105
|
+
return atcb_rewrite_html_elements(data.customLabels[`${identifier}`]);
|
|
3154
3106
|
} else {
|
|
3155
3107
|
return atcb_translate(identifier, data.language);
|
|
3156
3108
|
}
|
|
@@ -3193,9 +3145,8 @@ if (isBrowser()) {
|
|
|
3193
3145
|
} catch (e) {
|
|
3194
3146
|
if (this.debug) {
|
|
3195
3147
|
atcb_render_debug_msg(this.shadowRoot, e);
|
|
3196
|
-
console.error(e);
|
|
3197
|
-
return;
|
|
3198
3148
|
}
|
|
3149
|
+
return;
|
|
3199
3150
|
}
|
|
3200
3151
|
this.data.proKey = '';
|
|
3201
3152
|
}
|
|
@@ -3225,9 +3176,8 @@ if (isBrowser()) {
|
|
|
3225
3176
|
} catch (e) {
|
|
3226
3177
|
if (this.debug) {
|
|
3227
3178
|
atcb_render_debug_msg(this.shadowRoot, e);
|
|
3228
|
-
console.error(e);
|
|
3229
|
-
return;
|
|
3230
3179
|
}
|
|
3180
|
+
return;
|
|
3231
3181
|
}
|
|
3232
3182
|
}
|
|
3233
3183
|
disconnectedCallback() {
|
|
@@ -3268,9 +3218,8 @@ if (isBrowser()) {
|
|
|
3268
3218
|
} catch (e) {
|
|
3269
3219
|
if (this.debug) {
|
|
3270
3220
|
atcb_render_debug_msg(this.shadowRoot, e);
|
|
3271
|
-
console.error(e);
|
|
3272
|
-
return;
|
|
3273
3221
|
}
|
|
3222
|
+
return;
|
|
3274
3223
|
}
|
|
3275
3224
|
this.data.identifier = this.identifier;
|
|
3276
3225
|
try {
|
|
@@ -3278,9 +3227,8 @@ if (isBrowser()) {
|
|
|
3278
3227
|
} catch (e) {
|
|
3279
3228
|
if (this.debug) {
|
|
3280
3229
|
atcb_render_debug_msg(this.shadowRoot, e);
|
|
3281
|
-
console.error(e);
|
|
3282
|
-
return;
|
|
3283
3230
|
}
|
|
3231
|
+
return;
|
|
3284
3232
|
}
|
|
3285
3233
|
}
|
|
3286
3234
|
}
|
|
@@ -3304,6 +3252,14 @@ function atcb_read_attributes(el) {
|
|
|
3304
3252
|
}
|
|
3305
3253
|
} else if (atcbWcObjectParams.includes(attr)) {
|
|
3306
3254
|
val = JSON.parse(inputVal);
|
|
3255
|
+
} else if (atcbWcObjectArrayParams.includes(attr)) {
|
|
3256
|
+
const cleanedInput = (function () {
|
|
3257
|
+
if (inputVal.substring(0, 1) != '[') {
|
|
3258
|
+
return '[' + inputVal + ']';
|
|
3259
|
+
}
|
|
3260
|
+
return inputVal;
|
|
3261
|
+
})();
|
|
3262
|
+
val = JSON.parse(cleanedInput);
|
|
3307
3263
|
} else if (atcbWcArrayParams.includes(attr)) {
|
|
3308
3264
|
const cleanedInput = (function () {
|
|
3309
3265
|
let newVal = inputVal;
|
|
@@ -3334,7 +3290,7 @@ function atcb_read_attributes(el) {
|
|
|
3334
3290
|
data['identifier'] = atcb_secure_content(identifierAttr.replace(/(\r\n|\n|\r)/g, ''), false);
|
|
3335
3291
|
}
|
|
3336
3292
|
}
|
|
3337
|
-
if (!atcb_check_required(data
|
|
3293
|
+
if (!atcb_check_required(data)) {
|
|
3338
3294
|
const slotInput = el.innerHTML;
|
|
3339
3295
|
const atcbJsonInput = (function () {
|
|
3340
3296
|
if (slotInput != '') {
|
|
@@ -3347,6 +3303,7 @@ function atcb_read_attributes(el) {
|
|
|
3347
3303
|
return '';
|
|
3348
3304
|
})();
|
|
3349
3305
|
if (atcbJsonInput.length == 0) {
|
|
3306
|
+
console.error(data.validationError);
|
|
3350
3307
|
throw new Error('Add to Calendar Button generation failed: no data provided or missing required fields - see console logs for details');
|
|
3351
3308
|
}
|
|
3352
3309
|
data = atcbJsonInput;
|
|
@@ -3354,25 +3311,24 @@ function atcb_read_attributes(el) {
|
|
|
3354
3311
|
return data;
|
|
3355
3312
|
}
|
|
3356
3313
|
function atcb_build_button(host, data, debug = false) {
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
}
|
|
3314
|
+
data = atcb_decorate_data(data);
|
|
3315
|
+
if (atcb_validate(data)) {
|
|
3316
|
+
const rootObj = host.querySelector('.atcb-initialized');
|
|
3317
|
+
atcb_set_light_mode(host, data);
|
|
3318
|
+
rootObj.setAttribute('lang', data.language);
|
|
3319
|
+
atcb_load_css(host, rootObj, data.buttonStyle, data.inline, data.buttonsList, data.customCss);
|
|
3320
|
+
atcb_setup_state_management(data);
|
|
3321
|
+
atcb_set_global_event_listener(host, data);
|
|
3322
|
+
atcb_init_log(data.proKey, debug);
|
|
3323
|
+
atcb_generate_button(host, rootObj, data, debug);
|
|
3324
|
+
if (!data.hideRichData && data.name && data.dates[0].location && data.dates[0].startDate) {
|
|
3325
|
+
atcb_generate_rich_data(data, host.host);
|
|
3326
|
+
data.schemaEl = host.host.previousSibling;
|
|
3327
|
+
}
|
|
3328
|
+
atcb_log_event('initialization', data.identifier, data.identifier);
|
|
3329
|
+
} else if (debug) {
|
|
3330
|
+
console.error(data.validationError);
|
|
3331
|
+
throw new Error(data.validationError);
|
|
3376
3332
|
}
|
|
3377
3333
|
}
|
|
3378
3334
|
function atcb_cleanup(host, data) {
|
|
@@ -3498,7 +3454,8 @@ function atcb_action(data, triggerElement, keyboardTrigger = false) {
|
|
|
3498
3454
|
}
|
|
3499
3455
|
data.debug = data.debug === 'true';
|
|
3500
3456
|
if (!atcb_check_required(data)) {
|
|
3501
|
-
|
|
3457
|
+
console.error(data.validationError);
|
|
3458
|
+
return;
|
|
3502
3459
|
}
|
|
3503
3460
|
data = atcb_decorate_data(data);
|
|
3504
3461
|
let root = document.body;
|
|
@@ -3523,7 +3480,8 @@ function atcb_action(data, triggerElement, keyboardTrigger = false) {
|
|
|
3523
3480
|
data.listStyle = 'modal';
|
|
3524
3481
|
}
|
|
3525
3482
|
if (!atcb_validate(data)) {
|
|
3526
|
-
|
|
3483
|
+
console.error(data.validationError);
|
|
3484
|
+
return;
|
|
3527
3485
|
}
|
|
3528
3486
|
const oneOption = (function () {
|
|
3529
3487
|
if (data.options.length === 1) {
|