add-to-calendar-button 2.6.21 → 2.7.1

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.
@@ -974,14 +974,14 @@ function tzlib_get_timezones(jsonType = false) {
974
974
  * Add to Calendar Button
975
975
  * ++++++++++++++++++++++
976
976
  *
977
- * Version: 2.6.21
977
+ * Version: 2.7.1
978
978
  * Creator: Jens Kuerschner (https://jekuer.com)
979
979
  * Project: https://github.com/add2cal/add-to-calendar-button
980
980
  * License: Elastic License 2.0 (ELv2) (https://github.com/add2cal/add-to-calendar-button/blob/main/LICENSE.txt)
981
981
  * Note: DO NOT REMOVE THE COPYRIGHT NOTICE ABOVE!
982
982
  *
983
983
  */
984
- const atcbVersion = '2.6.21';
984
+ const atcbVersion = '2.7.1';
985
985
  const atcbCssTemplate = {};
986
986
  const atcbIsBrowser = () => {
987
987
  if (typeof window === 'undefined') {
@@ -1516,8 +1516,9 @@ function atcb_decorate_data_description(data, i) {
1516
1516
  description = cleanDescription(description);
1517
1517
  if (data.customVar) {
1518
1518
  for (const key in data.customVar) {
1519
- const sanitizedKey = key.replace(/[^\w\-.]/g, '');
1520
- description = description.replace(new RegExp(`%%${sanitizedKey}%%`, 'g'), data.customVar[`${key}`]);
1519
+ const sanitizedKey = '%%' + key.replace(/[^\w\-.]/g, '') + '%%';
1520
+ // eslint-disable-next-line security/detect-non-literal-regexp
1521
+ description = description.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
1521
1522
  }
1522
1523
  }
1523
1524
  const descriptionHtmlFree = atcb_rewrite_html_elements(description, true);
@@ -1575,9 +1576,11 @@ function atcb_decorate_data_extend(data) {
1575
1576
  }
1576
1577
  if (data.customVar) {
1577
1578
  for (const key in data.customVar) {
1578
- const sanitizedKey = key.replace(/[^\w\-.]/g, '');
1579
- data.dates[`${i}`].name = data.dates[`${i}`].name.replace(new RegExp(`%%${sanitizedKey}%%`, 'g'), data.customVar[`${key}`]);
1580
- data.dates[`${i}`].location = data.dates[`${i}`].location.replace(new RegExp(`%%${sanitizedKey}%%`, 'g'), data.customVar[`${key}`]);
1579
+ const sanitizedKey = '%%' + key.replace(/[^\w\-.]/g, '') + '%%';
1580
+ // eslint-disable-next-line security/detect-non-literal-regexp
1581
+ data.dates[`${i}`].name = data.dates[`${i}`].name.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
1582
+ // eslint-disable-next-line security/detect-non-literal-regexp
1583
+ data.dates[`${i}`].location = data.dates[`${i}`].location.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
1581
1584
  }
1582
1585
  }
1583
1586
  }
@@ -1590,26 +1593,31 @@ function atcb_decorate_data_extend(data) {
1590
1593
  return data;
1591
1594
  }
1592
1595
  function atcb_date_cleanup(dateTimeData) {
1596
+ function isValidDateFormat(dateStr) {
1597
+ return /^\d\d\d\d-\d\d-\d\d(?:T\d\d:\d\d)?(?::\d\d)?(?:.\d\d\d)?Z?$/i.test(dateStr);
1598
+ }
1599
+ function isValidTodayFormat(dateStr) {
1600
+ return /^today(?:\+(?:\d|\d\d|\d\d\d|\d\d\d\d))?$/i.test(dateStr);
1601
+ }
1593
1602
  if (!dateTimeData.endDate || dateTimeData.endDate === '') {
1594
1603
  dateTimeData.endDate = dateTimeData.startDate;
1595
1604
  }
1596
1605
  const endpoints = ['start', 'end'];
1597
1606
  endpoints.forEach(function (point) {
1598
- if (!/^(?:\d{4}-\d{2}-\d{2}T?(?:\d{2}:\d{2})?Z?|today(?:\+\d{1,4})?)$/i.test(dateTimeData[point + 'Date'])) {
1607
+ const dateStr = dateTimeData[point + 'Date'];
1608
+ if (!isValidDateFormat(dateStr) && !isValidTodayFormat(dateStr)) {
1599
1609
  dateTimeData[point + 'Date'] = 'badly-formed';
1600
1610
  } else {
1601
- dateTimeData[point + 'Date'] = atcb_date_calculation(dateTimeData[point + 'Date']);
1611
+ if (isValidTodayFormat(dateStr)) dateTimeData[point + 'Date'] = atcb_date_calculation(dateStr);
1602
1612
  if (dateTimeData[point + 'Date']) {
1603
- dateTimeData[point + 'Date'] = dateTimeData[point + 'Date'].replace(/\.\d{3}/, '').replace('Z', '');
1604
1613
  const tmpSplitStartDate = dateTimeData[point + 'Date'].split('T');
1605
1614
  if (tmpSplitStartDate[1]) {
1606
1615
  dateTimeData[point + 'Date'] = tmpSplitStartDate[0];
1607
1616
  dateTimeData[point + 'Time'] = tmpSplitStartDate[1];
1608
1617
  }
1609
1618
  }
1610
- if (dateTimeData[point + 'Time'] && dateTimeData[point + 'Time'].length === 8) {
1611
- const timeStr = dateTimeData[point + 'Time'];
1612
- dateTimeData[point + 'Time'] = timeStr.substring(0, timeStr.length - 3);
1619
+ if (dateTimeData[point + 'Time'] && dateTimeData[point + 'Time'].length > 5) {
1620
+ dateTimeData[point + 'Time'] = dateTimeData[point + 'Time'].substring(0, 5);
1613
1621
  }
1614
1622
  }
1615
1623
  });
@@ -1654,12 +1662,7 @@ function atcb_date_calculation(dateString) {
1654
1662
  dateString = dateString.replace(/today/gi, todayString);
1655
1663
  const dateStringParts = dateString.split('+');
1656
1664
  const dateParts = dateStringParts[0].split('-');
1657
- let newDate = (function () {
1658
- if (dateParts[0].length < 4) {
1659
- return new Date(Date.UTC(dateParts[2], dateParts[0] - 1, dateParts[1]));
1660
- }
1661
- return new Date(Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2]));
1662
- })();
1665
+ const newDate = new Date(Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2].substring(0, 2)));
1663
1666
  if (dateStringParts[1] && dateStringParts[1] > 0) {
1664
1667
  newDate.setDate(newDate.getDate() + parseInt(dateStringParts[1]));
1665
1668
  }
@@ -1702,19 +1705,25 @@ function atcb_decorate_data_button_status_handling(data) {
1702
1705
  return data;
1703
1706
  }
1704
1707
  async function atcb_decorate_data_rsvp(data) {
1705
- if (typeof atcb_check_booked_out !== 'function' || !data.rsvp || Object.keys(data.rsvp).length === 0) return data;
1708
+ if (typeof atcb_check_bookings !== 'function' || !data.rsvp || !data.proKey || Object.keys(data.rsvp).length === 0) return data;
1706
1709
  data.rsvp.expired = (function () {
1707
1710
  if (data.rsvp && data.rsvp.expires && new Date(data.rsvp.expires) < new Date()) {
1708
1711
  return true;
1709
1712
  }
1710
1713
  return false;
1711
1714
  })();
1712
- data.rsvp.bookedOut = await atcb_check_booked_out(data);
1713
- if (data.rsvp.expired || data.rsvp.bookedOut) {
1714
- data.blockInteraction = true;
1715
- }
1716
- if (data.blockInteraction) {
1717
- data.disabled = true;
1715
+ if (data.rsvp.max) {
1716
+ const bookings = await atcb_check_bookings(data.proKey, data.dev);
1717
+ data.rsvp.seatsLeft = data.rsvp.max - bookings;
1718
+ if (data.rsvp.seatsLeft < 1) {
1719
+ data.rsvp.bookedOut = true;
1720
+ }
1721
+ if (data.rsvp.expired || data.rsvp.bookedOut) {
1722
+ data.blockInteraction = true;
1723
+ }
1724
+ if (data.blockInteraction) {
1725
+ data.disabled = true;
1726
+ }
1718
1727
  }
1719
1728
  return data;
1720
1729
  }
@@ -3108,7 +3117,7 @@ function atcb_generate_subscribe_links(host, linkType, data, keyboardTrigger) {
3108
3117
  atcb_subscribe_ical(data, data.icsFile);
3109
3118
  break;
3110
3119
  }
3111
- atcb_subscribe_ical(data, adjustedFileUrl);
3120
+ atcb_subscribe_ical(data, adjustedFileUrl, host, keyboardTrigger);
3112
3121
  break;
3113
3122
  case 'google':
3114
3123
  atcb_subscribe_google(data, adjustedFileUrl);
@@ -3177,7 +3186,11 @@ function atcb_set_fully_successful(host, data, multiDateModal = false) {
3177
3186
  atcb_toggle(host, 'close');
3178
3187
  }
3179
3188
  }
3180
- function atcb_subscribe_ical(data, fileUrl) {
3189
+ function atcb_subscribe_ical(data, fileUrl, host = null, keyboardTrigger = false) {
3190
+ if ((atcbIsiOS() || data.fakeIOS) && !atcbIsSafari()) {
3191
+ atcb_ical_copy_note(host, fileUrl, data, keyboardTrigger);
3192
+ return;
3193
+ }
3181
3194
  atcb_open_cal_url(data, 'ical', fileUrl, true);
3182
3195
  }
3183
3196
  function atcb_subscribe_google(data, fileUrl) {
@@ -3502,7 +3515,7 @@ function atcb_generate_ical(host, data, subEvent = 'all', keyboardTrigger = fals
3502
3515
  }
3503
3516
  return 'data:text/calendar;charset=utf-8,' + encodeURIComponent(ics_lines.join('\r\n'));
3504
3517
  })();
3505
- if ((atcbIsiOS() && !atcbIsSafari()) || (atcbIsWebView() && (atcbIsiOS() || (atcbIsAndroid() && atcbIsProblematicWebView())))) {
3518
+ if (((atcbIsiOS() || data.fakeIOS) && !atcbIsSafari()) || (atcbIsWebView() && (atcbIsiOS() || data.fakeIOS || ((atcbIsAndroid() || data.fakeAndroid) && atcbIsProblematicWebView())))) {
3506
3519
  atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger);
3507
3520
  return;
3508
3521
  }
@@ -3528,7 +3541,7 @@ function atcb_determine_ical_filename(data, subEvent) {
3528
3541
  }
3529
3542
  function atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger) {
3530
3543
  atcb_copy_to_clipboard(dataUrl);
3531
- if (atcbIsiOS() && !atcbIsSafari()) {
3544
+ if ((atcbIsiOS() || data.fakeIOS) && !atcbIsSafari()) {
3532
3545
  atcb_create_modal(
3533
3546
  host,
3534
3547
  data,
@@ -5045,27 +5058,26 @@ if (atcbIsBrowser()) {
5045
5058
  }
5046
5059
  this.proOverride = !proOverrideVal || proOverrideVal === 'true' || proOverrideVal === '' ? true : false;
5047
5060
  }
5048
- if ((this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') || (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '')) {
5049
- if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5050
- this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5061
+ try {
5062
+ if ((this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') || (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '')) {
5063
+ if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5064
+ this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5065
+ } else {
5066
+ this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5067
+ }
5068
+ if (this.data.proKey) this.proKey = this.data.proKey;
5051
5069
  } else {
5052
- this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5053
- }
5054
- if (this.data.proKey) this.proKey = this.data.proKey;
5055
- }
5056
- if (!this.data.name || this.data.name === '') {
5057
- this.data.proKey = '';
5058
- try {
5070
+ this.data.proKey = '';
5059
5071
  this.data = await atcb_process_inline_data(this, this.debug);
5060
- } catch (e) {
5061
- if (this.debug) {
5062
- console.error(e);
5063
- atcb_render_debug_msg(this.shadowRoot, e);
5064
- }
5065
- this.state.initializing = false;
5066
- this.state.ready = true;
5067
- return;
5068
5072
  }
5073
+ } catch (e) {
5074
+ if (this.debug) {
5075
+ console.error(e);
5076
+ atcb_render_debug_msg(this.shadowRoot, e);
5077
+ }
5078
+ this.state.initializing = false;
5079
+ this.state.ready = true;
5080
+ return;
5069
5081
  }
5070
5082
  await this.initButton();
5071
5083
  this.state.initializing = false;
@@ -5120,24 +5132,23 @@ if (atcbIsBrowser()) {
5120
5132
  const elem = document.createElement('template');
5121
5133
  elem.innerHTML = template;
5122
5134
  this.shadowRoot.append(elem.content.cloneNode(true));
5123
- if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5124
- this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5125
- if (this.data.proKey) this.proKey = this.data.proKey;
5126
- } else if (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '') {
5127
- this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5128
- if (this.data.proKey) this.proKey = this.data.proKey;
5129
- }
5130
- if (!this.data.name || this.data.name === '') {
5131
- try {
5135
+ try {
5136
+ if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5137
+ this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5138
+ if (this.data.proKey) this.proKey = this.data.proKey;
5139
+ } else if (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '') {
5140
+ this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5141
+ if (this.data.proKey) this.proKey = this.data.proKey;
5142
+ } else {
5132
5143
  this.data = await atcb_process_inline_data(this, this.debug);
5133
- } catch (e) {
5134
- if (this.debug) {
5135
- console.error(e);
5136
- atcb_render_debug_msg(this.shadowRoot, e);
5137
- }
5138
- this.updatePending = false;
5139
- return;
5140
5144
  }
5145
+ } catch (e) {
5146
+ if (this.debug) {
5147
+ console.error(e);
5148
+ atcb_render_debug_msg(this.shadowRoot, e);
5149
+ }
5150
+ this.updatePending = false;
5151
+ return;
5141
5152
  }
5142
5153
  atcb_cleanup(this.shadowRoot, this.identifier);
5143
5154
  await this.initButton();
@@ -5468,19 +5479,28 @@ async function atcb_action(inputData, triggerElement, keyboardTrigger = false) {
5468
5479
  if (!atcbIsBrowser()) {
5469
5480
  return;
5470
5481
  }
5471
- let data = await (async function () {
5472
- const cleanedInput = atcb_secure_content(inputData);
5473
- if (cleanedInput.prokey && cleanedInput.prokey !== '') {
5474
- cleanedInput.proKey = cleanedInput.prokey;
5475
- }
5476
- if (cleanedInput.proKey && cleanedInput.proKey !== '') {
5477
- const proData = await atcb_get_pro_data(cleanedInput.proKey, null, cleanedInput);
5478
- if (proData.name && proData.name != '') {
5479
- return proData;
5482
+ let data;
5483
+ try {
5484
+ data = await (async function () {
5485
+ const cleanedInput = atcb_secure_content(inputData);
5486
+ if (cleanedInput.prokey && cleanedInput.prokey !== '') {
5487
+ cleanedInput.proKey = cleanedInput.prokey;
5480
5488
  }
5481
- }
5482
- return cleanedInput;
5483
- })();
5489
+ if (cleanedInput.proKey && cleanedInput.proKey !== '') {
5490
+ try {
5491
+ const proData = await atcb_get_pro_data(cleanedInput.proKey, null, cleanedInput);
5492
+ return proData;
5493
+ } catch (e) {
5494
+ throw new Error(e.message);
5495
+ }
5496
+ } else {
5497
+ return cleanedInput;
5498
+ }
5499
+ })();
5500
+ } catch (e) {
5501
+ console.error(e);
5502
+ return;
5503
+ }
5484
5504
  data.debug = data.debug === 'true';
5485
5505
  try {
5486
5506
  await atcb_check_required(data);
@@ -5618,9 +5638,6 @@ async function atcb_get_pro_data(licenseKey, el = null, directData = {}) {
5618
5638
  const response = await fetch((dataOverrides.dev ? 'https://event-dev.caldn.net/' : 'https://event.caldn.net/') + licenseKey + '/config.json');
5619
5639
  if (response.ok) {
5620
5640
  const data = await response.json();
5621
- if (!data.name || data.name === '') {
5622
- throw new Error('Not possible to read proKey config from server...');
5623
- }
5624
5641
  if (proOverride) {
5625
5642
  atcbWcParams.forEach((key) => {
5626
5643
  if (Object.prototype.hasOwnProperty.call(dataOverrides, key) && ['hideBranding', 'hidebranding', 'rsvp', 'ty'].indexOf(key) === -1) {
@@ -5634,13 +5651,16 @@ async function atcb_get_pro_data(licenseKey, el = null, directData = {}) {
5634
5651
  }
5635
5652
  });
5636
5653
  }
5654
+ if (!data.name || data.name === '') {
5655
+ throw new Error('Not possible to read proKey config from server...');
5656
+ }
5637
5657
  data.proKey = licenseKey;
5638
5658
  data.identifier = licenseKey;
5639
5659
  return data;
5640
5660
  }
5641
5661
  throw new Error('Not possible to read proKey config from server...');
5642
5662
  } catch {
5643
- console.error('Add to Calendar Button proKey invalid or server not responding! Falling back to local data...');
5663
+ throw new Error('Add to Calendar Button proKey invalid or server not responding!');
5644
5664
  }
5645
5665
  }
5646
5666
  return {};
@@ -974,15 +974,15 @@ function tzlib_get_timezones(jsonType = false) {
974
974
  * Add to Calendar Button
975
975
  * ++++++++++++++++++++++
976
976
  *
977
- * Version: 2.6.21
977
+ * Version: 2.7.1
978
978
  * Creator: Jens Kuerschner (https://jekuer.com)
979
979
  * Project: https://github.com/add2cal/add-to-calendar-button
980
980
  * License: Elastic License 2.0 (ELv2) (https://github.com/add2cal/add-to-calendar-button/blob/main/LICENSE.txt)
981
981
  * Note: DO NOT REMOVE THE COPYRIGHT NOTICE ABOVE!
982
982
  *
983
983
  */
984
- const atcbVersion = '2.6.21';
985
- const atcbCssTemplate = {
984
+ const atcbVersion = '2.7.1';
985
+ const atcbCssTemplate = {
986
986
  if (typeof window === 'undefined') {
987
987
  return false;
988
988
  } else {
@@ -1515,8 +1515,9 @@ function atcb_decorate_data_description(data, i) {
1515
1515
  description = cleanDescription(description);
1516
1516
  if (data.customVar) {
1517
1517
  for (const key in data.customVar) {
1518
- const sanitizedKey = key.replace(/[^\w\-.]/g, '');
1519
- description = description.replace(new RegExp(`%%${sanitizedKey}%%`, 'g'), data.customVar[`${key}`]);
1518
+ const sanitizedKey = '%%' + key.replace(/[^\w\-.]/g, '') + '%%';
1519
+ // eslint-disable-next-line security/detect-non-literal-regexp
1520
+ description = description.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
1520
1521
  }
1521
1522
  }
1522
1523
  const descriptionHtmlFree = atcb_rewrite_html_elements(description, true);
@@ -1574,9 +1575,11 @@ function atcb_decorate_data_extend(data) {
1574
1575
  }
1575
1576
  if (data.customVar) {
1576
1577
  for (const key in data.customVar) {
1577
- const sanitizedKey = key.replace(/[^\w\-.]/g, '');
1578
- data.dates[`${i}`].name = data.dates[`${i}`].name.replace(new RegExp(`%%${sanitizedKey}%%`, 'g'), data.customVar[`${key}`]);
1579
- data.dates[`${i}`].location = data.dates[`${i}`].location.replace(new RegExp(`%%${sanitizedKey}%%`, 'g'), data.customVar[`${key}`]);
1578
+ const sanitizedKey = '%%' + key.replace(/[^\w\-.]/g, '') + '%%';
1579
+ // eslint-disable-next-line security/detect-non-literal-regexp
1580
+ data.dates[`${i}`].name = data.dates[`${i}`].name.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
1581
+ // eslint-disable-next-line security/detect-non-literal-regexp
1582
+ data.dates[`${i}`].location = data.dates[`${i}`].location.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
1580
1583
  }
1581
1584
  }
1582
1585
  }
@@ -1589,26 +1592,31 @@ function atcb_decorate_data_extend(data) {
1589
1592
  return data;
1590
1593
  }
1591
1594
  function atcb_date_cleanup(dateTimeData) {
1595
+ function isValidDateFormat(dateStr) {
1596
+ return /^\d\d\d\d-\d\d-\d\d(?:T\d\d:\d\d)?(?::\d\d)?(?:.\d\d\d)?Z?$/i.test(dateStr);
1597
+ }
1598
+ function isValidTodayFormat(dateStr) {
1599
+ return /^today(?:\+(?:\d|\d\d|\d\d\d|\d\d\d\d))?$/i.test(dateStr);
1600
+ }
1592
1601
  if (!dateTimeData.endDate || dateTimeData.endDate === '') {
1593
1602
  dateTimeData.endDate = dateTimeData.startDate;
1594
1603
  }
1595
1604
  const endpoints = ['start', 'end'];
1596
1605
  endpoints.forEach(function (point) {
1597
- if (!/^(?:\d{4}-\d{2}-\d{2}T?(?:\d{2}:\d{2})?Z?|today(?:\+\d{1,4})?)$/i.test(dateTimeData[point + 'Date'])) {
1606
+ const dateStr = dateTimeData[point + 'Date'];
1607
+ if (!isValidDateFormat(dateStr) && !isValidTodayFormat(dateStr)) {
1598
1608
  dateTimeData[point + 'Date'] = 'badly-formed';
1599
1609
  } else {
1600
- dateTimeData[point + 'Date'] = atcb_date_calculation(dateTimeData[point + 'Date']);
1610
+ if (isValidTodayFormat(dateStr)) dateTimeData[point + 'Date'] = atcb_date_calculation(dateStr);
1601
1611
  if (dateTimeData[point + 'Date']) {
1602
- dateTimeData[point + 'Date'] = dateTimeData[point + 'Date'].replace(/\.\d{3}/, '').replace('Z', '');
1603
1612
  const tmpSplitStartDate = dateTimeData[point + 'Date'].split('T');
1604
1613
  if (tmpSplitStartDate[1]) {
1605
1614
  dateTimeData[point + 'Date'] = tmpSplitStartDate[0];
1606
1615
  dateTimeData[point + 'Time'] = tmpSplitStartDate[1];
1607
1616
  }
1608
1617
  }
1609
- if (dateTimeData[point + 'Time'] && dateTimeData[point + 'Time'].length === 8) {
1610
- const timeStr = dateTimeData[point + 'Time'];
1611
- dateTimeData[point + 'Time'] = timeStr.substring(0, timeStr.length - 3);
1618
+ if (dateTimeData[point + 'Time'] && dateTimeData[point + 'Time'].length > 5) {
1619
+ dateTimeData[point + 'Time'] = dateTimeData[point + 'Time'].substring(0, 5);
1612
1620
  }
1613
1621
  }
1614
1622
  });
@@ -1653,12 +1661,7 @@ function atcb_date_calculation(dateString) {
1653
1661
  dateString = dateString.replace(/today/gi, todayString);
1654
1662
  const dateStringParts = dateString.split('+');
1655
1663
  const dateParts = dateStringParts[0].split('-');
1656
- let newDate = (function () {
1657
- if (dateParts[0].length < 4) {
1658
- return new Date(Date.UTC(dateParts[2], dateParts[0] - 1, dateParts[1]));
1659
- }
1660
- return new Date(Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2]));
1661
- })();
1664
+ const newDate = new Date(Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2].substring(0, 2)));
1662
1665
  if (dateStringParts[1] && dateStringParts[1] > 0) {
1663
1666
  newDate.setDate(newDate.getDate() + parseInt(dateStringParts[1]));
1664
1667
  }
@@ -1701,19 +1704,25 @@ function atcb_decorate_data_button_status_handling(data) {
1701
1704
  return data;
1702
1705
  }
1703
1706
  async function atcb_decorate_data_rsvp(data) {
1704
- if (typeof atcb_check_booked_out !== 'function' || !data.rsvp || Object.keys(data.rsvp).length === 0) return data;
1707
+ if (typeof atcb_check_bookings !== 'function' || !data.rsvp || !data.proKey || Object.keys(data.rsvp).length === 0) return data;
1705
1708
  data.rsvp.expired = (function () {
1706
1709
  if (data.rsvp && data.rsvp.expires && new Date(data.rsvp.expires) < new Date()) {
1707
1710
  return true;
1708
1711
  }
1709
1712
  return false;
1710
1713
  })();
1711
- data.rsvp.bookedOut = await atcb_check_booked_out(data);
1712
- if (data.rsvp.expired || data.rsvp.bookedOut) {
1713
- data.blockInteraction = true;
1714
- }
1715
- if (data.blockInteraction) {
1716
- data.disabled = true;
1714
+ if (data.rsvp.max) {
1715
+ const bookings = await atcb_check_bookings(data.proKey, data.dev);
1716
+ data.rsvp.seatsLeft = data.rsvp.max - bookings;
1717
+ if (data.rsvp.seatsLeft < 1) {
1718
+ data.rsvp.bookedOut = true;
1719
+ }
1720
+ if (data.rsvp.expired || data.rsvp.bookedOut) {
1721
+ data.blockInteraction = true;
1722
+ }
1723
+ if (data.blockInteraction) {
1724
+ data.disabled = true;
1725
+ }
1717
1726
  }
1718
1727
  return data;
1719
1728
  }
@@ -3107,7 +3116,7 @@ function atcb_generate_subscribe_links(host, linkType, data, keyboardTrigger) {
3107
3116
  atcb_subscribe_ical(data, data.icsFile);
3108
3117
  break;
3109
3118
  }
3110
- atcb_subscribe_ical(data, adjustedFileUrl);
3119
+ atcb_subscribe_ical(data, adjustedFileUrl, host, keyboardTrigger);
3111
3120
  break;
3112
3121
  case 'google':
3113
3122
  atcb_subscribe_google(data, adjustedFileUrl);
@@ -3176,7 +3185,11 @@ function atcb_set_fully_successful(host, data, multiDateModal = false) {
3176
3185
  atcb_toggle(host, 'close');
3177
3186
  }
3178
3187
  }
3179
- function atcb_subscribe_ical(data, fileUrl) {
3188
+ function atcb_subscribe_ical(data, fileUrl, host = null, keyboardTrigger = false) {
3189
+ if ((atcbIsiOS() || data.fakeIOS) && !atcbIsSafari()) {
3190
+ atcb_ical_copy_note(host, fileUrl, data, keyboardTrigger);
3191
+ return;
3192
+ }
3180
3193
  atcb_open_cal_url(data, 'ical', fileUrl, true);
3181
3194
  }
3182
3195
  function atcb_subscribe_google(data, fileUrl) {
@@ -3501,7 +3514,7 @@ function atcb_generate_ical(host, data, subEvent = 'all', keyboardTrigger = fals
3501
3514
  }
3502
3515
  return 'data:text/calendar;charset=utf-8,' + encodeURIComponent(ics_lines.join('\r\n'));
3503
3516
  })();
3504
- if ((atcbIsiOS() && !atcbIsSafari()) || (atcbIsWebView() && (atcbIsiOS() || (atcbIsAndroid() && atcbIsProblematicWebView())))) {
3517
+ if (((atcbIsiOS() || data.fakeIOS) && !atcbIsSafari()) || (atcbIsWebView() && (atcbIsiOS() || data.fakeIOS || ((atcbIsAndroid() || data.fakeAndroid) && atcbIsProblematicWebView())))) {
3505
3518
  atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger);
3506
3519
  return;
3507
3520
  }
@@ -3527,7 +3540,7 @@ function atcb_determine_ical_filename(data, subEvent) {
3527
3540
  }
3528
3541
  function atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger) {
3529
3542
  atcb_copy_to_clipboard(dataUrl);
3530
- if (atcbIsiOS() && !atcbIsSafari()) {
3543
+ if ((atcbIsiOS() || data.fakeIOS) && !atcbIsSafari()) {
3531
3544
  atcb_create_modal(
3532
3545
  host,
3533
3546
  data,
@@ -5044,27 +5057,26 @@ if (atcbIsBrowser()) {
5044
5057
  }
5045
5058
  this.proOverride = !proOverrideVal || proOverrideVal === 'true' || proOverrideVal === '' ? true : false;
5046
5059
  }
5047
- if ((this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') || (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '')) {
5048
- if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5049
- this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5060
+ try {
5061
+ if ((this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') || (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '')) {
5062
+ if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5063
+ this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5064
+ } else {
5065
+ this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5066
+ }
5067
+ if (this.data.proKey) this.proKey = this.data.proKey;
5050
5068
  } else {
5051
- this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5052
- }
5053
- if (this.data.proKey) this.proKey = this.data.proKey;
5054
- }
5055
- if (!this.data.name || this.data.name === '') {
5056
- this.data.proKey = '';
5057
- try {
5069
+ this.data.proKey = '';
5058
5070
  this.data = await atcb_process_inline_data(this, this.debug);
5059
- } catch (e) {
5060
- if (this.debug) {
5061
- console.error(e);
5062
- atcb_render_debug_msg(this.shadowRoot, e);
5063
- }
5064
- this.state.initializing = false;
5065
- this.state.ready = true;
5066
- return;
5067
5071
  }
5072
+ } catch (e) {
5073
+ if (this.debug) {
5074
+ console.error(e);
5075
+ atcb_render_debug_msg(this.shadowRoot, e);
5076
+ }
5077
+ this.state.initializing = false;
5078
+ this.state.ready = true;
5079
+ return;
5068
5080
  }
5069
5081
  await this.initButton();
5070
5082
  this.state.initializing = false;
@@ -5119,24 +5131,23 @@ if (atcbIsBrowser()) {
5119
5131
  const elem = document.createElement('template');
5120
5132
  elem.innerHTML = template;
5121
5133
  this.shadowRoot.append(elem.content.cloneNode(true));
5122
- if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5123
- this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5124
- if (this.data.proKey) this.proKey = this.data.proKey;
5125
- } else if (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '') {
5126
- this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5127
- if (this.data.proKey) this.proKey = this.data.proKey;
5128
- }
5129
- if (!this.data.name || this.data.name === '') {
5130
- try {
5134
+ try {
5135
+ if (this.hasAttribute('proKey') && this.getAttribute('proKey') !== '') {
5136
+ this.data = await atcb_get_pro_data(this.getAttribute('proKey'), this);
5137
+ if (this.data.proKey) this.proKey = this.data.proKey;
5138
+ } else if (this.hasAttribute('prokey') && this.getAttribute('prokey') !== '') {
5139
+ this.data = await atcb_get_pro_data(this.getAttribute('prokey'), this);
5140
+ if (this.data.proKey) this.proKey = this.data.proKey;
5141
+ } else {
5131
5142
  this.data = await atcb_process_inline_data(this, this.debug);
5132
- } catch (e) {
5133
- if (this.debug) {
5134
- console.error(e);
5135
- atcb_render_debug_msg(this.shadowRoot, e);
5136
- }
5137
- this.updatePending = false;
5138
- return;
5139
5143
  }
5144
+ } catch (e) {
5145
+ if (this.debug) {
5146
+ console.error(e);
5147
+ atcb_render_debug_msg(this.shadowRoot, e);
5148
+ }
5149
+ this.updatePending = false;
5150
+ return;
5140
5151
  }
5141
5152
  atcb_cleanup(this.shadowRoot, this.identifier);
5142
5153
  await this.initButton();
@@ -5467,19 +5478,28 @@ async function atcb_action(inputData, triggerElement, keyboardTrigger = false) {
5467
5478
  if (!atcbIsBrowser()) {
5468
5479
  return;
5469
5480
  }
5470
- let data = await (async function () {
5471
- const cleanedInput = atcb_secure_content(inputData);
5472
- if (cleanedInput.prokey && cleanedInput.prokey !== '') {
5473
- cleanedInput.proKey = cleanedInput.prokey;
5474
- }
5475
- if (cleanedInput.proKey && cleanedInput.proKey !== '') {
5476
- const proData = await atcb_get_pro_data(cleanedInput.proKey, null, cleanedInput);
5477
- if (proData.name && proData.name != '') {
5478
- return proData;
5481
+ let data;
5482
+ try {
5483
+ data = await (async function () {
5484
+ const cleanedInput = atcb_secure_content(inputData);
5485
+ if (cleanedInput.prokey && cleanedInput.prokey !== '') {
5486
+ cleanedInput.proKey = cleanedInput.prokey;
5479
5487
  }
5480
- }
5481
- return cleanedInput;
5482
- })();
5488
+ if (cleanedInput.proKey && cleanedInput.proKey !== '') {
5489
+ try {
5490
+ const proData = await atcb_get_pro_data(cleanedInput.proKey, null, cleanedInput);
5491
+ return proData;
5492
+ } catch (e) {
5493
+ throw new Error(e.message);
5494
+ }
5495
+ } else {
5496
+ return cleanedInput;
5497
+ }
5498
+ })();
5499
+ } catch (e) {
5500
+ console.error(e);
5501
+ return;
5502
+ }
5483
5503
  data.debug = data.debug === 'true';
5484
5504
  try {
5485
5505
  await atcb_check_required(data);
@@ -5617,9 +5637,6 @@ async function atcb_get_pro_data(licenseKey, el = null, directData = {}) {
5617
5637
  const response = await fetch((dataOverrides.dev ? 'https://event-dev.caldn.net/' : 'https://event.caldn.net/') + licenseKey + '/config.json');
5618
5638
  if (response.ok) {
5619
5639
  const data = await response.json();
5620
- if (!data.name || data.name === '') {
5621
- throw new Error('Not possible to read proKey config from server...');
5622
- }
5623
5640
  if (proOverride) {
5624
5641
  atcbWcParams.forEach((key) => {
5625
5642
  if (Object.prototype.hasOwnProperty.call(dataOverrides, key) && ['hideBranding', 'hidebranding', 'rsvp', 'ty'].indexOf(key) === -1) {
@@ -5633,13 +5650,16 @@ async function atcb_get_pro_data(licenseKey, el = null, directData = {}) {
5633
5650
  }
5634
5651
  });
5635
5652
  }
5653
+ if (!data.name || data.name === '') {
5654
+ throw new Error('Not possible to read proKey config from server...');
5655
+ }
5636
5656
  data.proKey = licenseKey;
5637
5657
  data.identifier = licenseKey;
5638
5658
  return data;
5639
5659
  }
5640
5660
  throw new Error('Not possible to read proKey config from server...');
5641
5661
  } catch {
5642
- console.error('Add to Calendar Button proKey invalid or server not responding! Falling back to local data...');
5662
+ throw new Error('Add to Calendar Button proKey invalid or server not responding!');
5643
5663
  }
5644
5664
  }
5645
5665
  return {};