add-to-calendar-button 1.5.1 → 1.6.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/README.md CHANGED
@@ -38,7 +38,7 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
38
38
  * Up-to-date integration of all popular calendars:
39
39
  * Google Calendar.
40
40
  * Yahoo Calender.
41
- * Microsoft 365 (and Outlook).
41
+ * Microsoft 365, Outlook, and Teams.
42
42
  * Automatically generated iCal/ics files (for all other calendars, like Apple).
43
43
  * Timed and all-day events.
44
44
  * Translatable labels and dynamic.
@@ -115,6 +115,7 @@ Mind that with Angular, you might need to escape the { with `{{ '{' }}` and } wi
115
115
  "Google",
116
116
  "iCal",
117
117
  "Microsoft365",
118
+ "MicrosoftTeams",
118
119
  "Outlook.com",
119
120
  "Yahoo"
120
121
  ],
@@ -149,6 +150,7 @@ You can use startTime and endTime in the event block, but it is recommended to r
149
150
  "Google",
150
151
  "iCal",
151
152
  "Microsoft365",
153
+ "MicrosoftTeams",
152
154
  "Outlook.com",
153
155
  "Yahoo"
154
156
  ],
@@ -224,6 +226,7 @@ The code is available under the [MIT license (with “Commons Clause” License
224
226
 
225
227
  ## Changelog (without bug fixes)
226
228
 
229
+ * v1.6 : supporting Microsoft Teams
227
230
  * v1.5 : update to date format and better accesibility
228
231
  * v1.4 : schema.org support (also changed some keys in the JSON!)
229
232
  * v1.3 : new license (MIT with “Commons Clause”)
@@ -235,3 +238,4 @@ The code is available under the [MIT license (with “Commons Clause” License
235
238
  ## Kudos go to
236
239
  * [github.com/dudewheresmycode](https://github.com/dudewheresmycodee)
237
240
  * [uxwing.com](https://uxwing.com)
241
+ * all contributors!
@@ -3,7 +3,7 @@
3
3
  * Add-to-Calendar Button
4
4
  * ++++++++++++++++++++++
5
5
  *
6
- * Version: 1.5.1
6
+ * Version: 1.6.2
7
7
  * Creator: Jens Kuerschner (https://jenskuerschner.de)
8
8
  * Project: https://github.com/jekuer/add-to-calendar-button
9
9
  * License: MIT with “Commons Clause” License Condition v1.0
@@ -3,7 +3,7 @@
3
3
  * Add-to-Calendar Button
4
4
  * ++++++++++++++++++++++
5
5
  */
6
- const atcbVersion = '1.5.1';
6
+ const atcbVersion = '1.6.2';
7
7
  /* Creator: Jens Kuerschner (https://jenskuerschner.de)
8
8
  * Project: https://github.com/jekuer/add-to-calendar-button
9
9
  * License: MIT with “Commons Clause” License Condition v1.0
@@ -35,13 +35,13 @@ function atcb_init() {
35
35
  // get their JSON content first
36
36
  if (schema && schema.innerHTML) {
37
37
  // get schema.org event markup and flatten the event block
38
- atcbConfig = JSON.parse(schema.innerHTML);
38
+ atcbConfig = JSON.parse(schema.innerHTML.replace(/(\r\n|\n|\r)/gm, "")); // we also remove any real code line breaks from the JSON before parsing it. Use <br> or \n explicitely in the description to create a line break
39
39
  atcbConfig = atcb_clean_schema_json(atcbConfig);
40
40
  // set flag to not delete HTML content later
41
41
  atcbConfig['deleteJSON'] = false;
42
42
  } else {
43
43
  // get JSON from HTML block
44
- atcbConfig = JSON.parse(atcButtons[i].innerHTML);
44
+ atcbConfig = JSON.parse(atcButtons[i].innerHTML.replace(/(\r\n|\n|\r)/gm, "")); // we also remove any real code line breaks from the JSON before parsing it. Use <br> or \n explicitely in the description to create a line break
45
45
  // set flag to delete HTML content later
46
46
  atcbConfig['deleteJSON'] = true;
47
47
  }
@@ -154,7 +154,7 @@ function atcb_date_calculation(dateString) {
154
154
  // VALIDATE THE JSON DATA
155
155
  function atcb_validate(data) {
156
156
  // validate options
157
- const options = ['Apple', 'Google', 'iCal', 'Microsoft365', 'Outlook.com', 'Yahoo']
157
+ const options = ['Apple', 'Google', 'iCal', 'Microsoft365', 'Outlook.com', 'MicrosoftTeams', 'Yahoo']
158
158
  if (!data['options'].every(function(option) {
159
159
  let cleanOption = option.split('|');
160
160
  if (!options.includes(cleanOption[0])) {
@@ -303,6 +303,16 @@ function atcb_generate(button, buttonId, data) {
303
303
  atcb_close_all();
304
304
  });
305
305
  break;
306
+ case "MicrosoftTeams":
307
+ optionItem.innerHTML = '<span class="atcb_icon"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 2228.833 2073.333"><g fill="#5059c9"><path d="M1554.637 777.5h575.713c54.391 0 98.483 44.092 98.483 98.483v524.398c0 199.901-162.051 361.952-361.952 361.952h0-1.711c-199.901.028-361.975-162-362.004-361.901v-.052-571.409c.001-28.427 23.045-51.471 51.471-51.471h0z"/><circle cx="1943.75" cy="440.583" r="233.25"/></g><g fill="#7b83eb"><circle cx="1218.083" cy="336.917" r="336.917"/><path d="M1667.323 777.5H717.01c-53.743 1.33-96.257 45.931-95.01 99.676v598.105c-7.505 322.519 247.657 590.16 570.167 598.053 322.51-7.893 577.671-275.534 570.167-598.053V877.176c1.245-53.745-41.268-98.346-95.011-99.676z"/></g><path opacity=".1" d="M1244 777.5v838.145c-.258 38.435-23.549 72.964-59.09 87.598-11.316 4.787-23.478 7.254-35.765 7.257H667.613c-6.738-17.105-12.958-34.21-18.142-51.833-18.144-59.477-27.402-121.307-27.472-183.49V877.02c-1.246-53.659 41.198-98.19 94.855-99.52H1244z"/><path opacity=".2" d="M1192.167 777.5v889.978a91.84 91.84 0 0 1-7.257 35.765c-14.634 35.541-49.163 58.833-87.598 59.09H691.975c-8.812-17.105-17.105-34.21-24.362-51.833s-12.958-34.21-18.142-51.833a631.28 631.28 0 0 1-27.472-183.49V877.02c-1.246-53.659 41.198-98.19 94.855-99.52h475.313z"/><path opacity=".2" d="M1192.167 777.5v786.312c-.395 52.223-42.632 94.46-94.855 94.855h-447.84A631.28 631.28 0 0 1 622 1475.177V877.02c-1.246-53.659 41.198-98.19 94.855-99.52h475.312z"/><path opacity=".2" d="M1140.333 777.5v786.312c-.395 52.223-42.632 94.46-94.855 94.855H649.472A631.28 631.28 0 0 1 622 1475.177V877.02c-1.246-53.659 41.198-98.19 94.855-99.52h423.478z"/><path opacity=".1" d="M1244 509.522v163.275c-8.812.518-17.105 1.037-25.917 1.037s-17.105-.518-25.917-1.037c-17.496-1.161-34.848-3.937-51.833-8.293a336.92 336.92 0 0 1-233.25-198.003 288.02 288.02 0 0 1-16.587-51.833h258.648c52.305.198 94.657 42.549 94.856 94.854z"/><use xlink:href="#C" opacity=".2"/><use xlink:href="#C" opacity=".2"/><path opacity=".2" d="M1140.333 561.355v103.148A336.92 336.92 0 0 1 907.083 466.5h138.395c52.305.199 94.656 42.551 94.855 94.855z"/><linearGradient id="A" gradientUnits="userSpaceOnUse" x1="198.099" y1="392.261" x2="942.234" y2="1681.073"><stop offset="0" stop-color="#5a62c3"/><stop offset=".5" stop-color="#4d55bd"/><stop offset="1" stop-color="#3940ab"/></linearGradient><path fill="url(#A)" d="M95.01 466.5h950.312c52.473 0 95.01 42.538 95.01 95.01v950.312c0 52.473-42.538 95.01-95.01 95.01H95.01c-52.473 0-95.01-42.538-95.01-95.01V561.51c0-52.472 42.538-95.01 95.01-95.01z"/><path fill="#fff" d="M820.211,828.193H630.241v517.297H509.211V828.193H320.123V727.844h500.088V828.193z"/><defs ><path id="C" d="M1192.167 561.355v111.442c-17.496-1.161-34.848-3.937-51.833-8.293a336.92 336.92 0 0 1-233.25-198.003h190.228c52.304.198 94.656 42.55 94.855 94.854z"/></defs></svg></span>';
308
+ optionItem.innerHTML += '<span class="atcb_text">';
309
+ optionItem.innerHTML += optionParts[1] || 'Microsoft Teams';
310
+ optionItem.innerHTML += '</span>';
311
+ optionItem.addEventListener('click', function() {
312
+ atcb_generate_teams(data);
313
+ atcb_close_all();
314
+ });
315
+ break;
306
316
  case "Microsoft365":
307
317
  optionItem.innerHTML = '<span class="atcb_icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 278050 333334" shape-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd"><path fill="#ea3e23" d="M278050 305556l-29-16V28627L178807 0 448 66971l-448 87 22 200227 60865-23821V80555l117920-28193-17 239519L122 267285l178668 65976v73l99231-27462v-316z"/></svg></span>';
308
318
  optionItem.innerHTML += '<span class="atcb_text">';
@@ -344,7 +354,7 @@ function atcb_generate(button, buttonId, data) {
344
354
  let bgOverlay = document.createElement('div');
345
355
  bgOverlay.id = 'atcb_bgoverlay_' + buttonId;
346
356
  bgOverlay.classList.add('atcb_bgoverlay');
347
- bgOverlay.style.display = 'none';
357
+ bgOverlay.style.display = 'none';
348
358
  bgOverlay.tabIndex = 0;
349
359
  button.appendChild(bgOverlay);
350
360
  bgOverlay.addEventListener('click', atcb_close_all);
@@ -461,14 +471,14 @@ function atcb_generate_microsoft(data, type = '365') {
461
471
  }
462
472
  url += '/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent';
463
473
  // generate and add date
464
- let formattedDate = atcb_generate_time(data, 'delimiters', 'microsoft');
474
+ let formattedDate = atcb_generate_time(data, 'delimiters', 'microsoft');
465
475
  url += '&startdt=' + formattedDate['start'] + '&enddt=' + formattedDate['end'];
466
476
  if (formattedDate['allday']) {
467
477
  url += '&allday=true';
468
478
  }
469
479
  // add details (if set)
470
480
  if (data['description'] != null && data['description'] != '') {
471
- url += '&body=' + encodeURIComponent(data['description']);
481
+ url += '&body=' + encodeURIComponent(data['description'].replace(/\n/g, '<br>'));
472
482
  }
473
483
  if (data['location'] != null && data['location'] != '') {
474
484
  url += '&location=' + encodeURIComponent(data['location']);
@@ -481,15 +491,42 @@ function atcb_generate_microsoft(data, type = '365') {
481
491
 
482
492
 
483
493
 
494
+ // FUNCTION TO GENERATE THE MICROSOFT TEAMS URL
495
+ // Mind that this is still in development mode by Microsoft! (https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/build-and-test/deep-links#deep-linking-to-the-scheduling-dialog)
496
+ // Location, html tags and linebreaks in the description are not supported yet.
497
+ function atcb_generate_teams(data) {
498
+ // base url
499
+ let url = 'https://teams.microsoft.com/l/meeting/new?';
500
+ // generate and add date
501
+ let formattedDate = atcb_generate_time(data, 'delimiters', 'microsoft');
502
+ url += '&startTime=' + formattedDate['start'] + '&endTime=' + formattedDate['end'];
503
+ // add details (if set)
504
+ let locationString = '';
505
+ if (data['location'] != null && data['location'] != '') {
506
+ locationString = encodeURIComponent(data['location']);
507
+ url += '&location=' + locationString; // workaround putting the location into the description, since the native field is not supported yet
508
+ locationString += ' // ';
509
+ }
510
+ if (data['description_iCal'] != null && data['description_iCal'] != '') { // using description_iCal instead of description, since Teams does not support html tags
511
+ url += '&content=' + locationString + encodeURIComponent(data['description_iCal']);
512
+ }
513
+ if (data['name'] != null && data['name'] != '') {
514
+ url += '&subject=' + encodeURIComponent(data['name']);
515
+ }
516
+ window.open(url, '_blank').focus();
517
+ }
518
+
519
+
520
+
484
521
  // FUNCTION TO GENERATE THE iCAL FILE (also for the Apple option)
485
- function atcb_generate_ical(data) {
522
+ function atcb_generate_ical(data) {
486
523
  let now = new Date();
487
524
  now = now.toISOString().replace(/\-/g, '').replace(/\:/g, '').replace(/\..../g, '');
488
525
  let formattedDate = atcb_generate_time(data, 'clean', 'ical');
489
526
  let timeslot = '';
490
527
  if (formattedDate['allday']) {
491
528
  timeslot = ';VALUE=DATE';
492
- }
529
+ }
493
530
  let ics_lines = [
494
531
  "BEGIN:VCALENDAR",
495
532
  "VERSION:2.0",
@@ -507,7 +544,7 @@ function atcb_generate_ical(data) {
507
544
  "END:VEVENT",
508
545
  "END:VCALENDAR"
509
546
  ];
510
- let dlurl = 'data:text/calendar;base64,'+btoa(ics_lines.join('\r\n').replace(/[\u00A0-\u2666]/g, function(c) { return '&#' + c.charCodeAt(0) + ';'; })); // includes a fix to not throw an error with non-Latin1 characters. However, still needs improvement, since it shows up encoded in the iCal file.
547
+ let dlurl = 'data:text/calendar;charset=utf-8,'+encodeURIComponent(ics_lines.join('\r\n'));
511
548
  try {
512
549
  if (!window.ActiveXObject) {
513
550
  let save = document.createElement('a');
@@ -595,4 +632,4 @@ function atcb_generate_time(data, style = 'delimiters', targetCal = 'general') {
595
632
 
596
633
 
597
634
 
598
- export { atcb_init };
635
+ export { atcb_init };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "add-to-calendar-button",
3
- "version": "1.5.1",
3
+ "version": "1.6.2",
4
4
  "description": "A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.",
5
5
  "main": "npm_dist/atcb_npm.js",
6
6
  "types": "index.d.ts",