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