You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars._
4
+
_A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars._
5
5
6
+

6
7
7
-
## Use case // Who this is for
8
+
<br /><br />
9
+
10
+
## 😎 Use case // Who this is for
8
11
9
12
This is for everybody, who wants to include a button at his/her website or app, which enables users to easily add a specific event to their calendars.
10
13
It's main goal is to keep this process as easy as possible. Simply define your button configuration via JSON and everything else is automatically generated by the script.
11
14
It is for this simple use case. No strings attached.
12
15
16
+
<br />
13
17
14
-
## Background // Why this repo exists
18
+
## 🔎 Background // Why this repo exists
15
19
16
20
While building a personal wedding page, I was confronted with the task to include a button, where invited people could save the event to their calendars.
17
21
I did not want to build this from scratch (first) and therefore started the usual web research.
18
22
Unfortunately, all I found where some extremely outdated code snippets, which did not really fit all the modern systems and calendar tools.
19
-
Beside that, there was only the solution by AddEvent.com - all over the place. I was looking at CodePen and all I found where thousands of pens, which basically only included the AddEvent tool.
23
+
Beside that, there was only the solution by AddEvent.com - all over the place. I was looking at CodePen and all I found where thousands of pens, which basically only included the AddEvent tool.
24
+
20
25
The problems with AddEvent.com:
21
26
* it holds tons of features, which I did not need. I do not want to track my button. I just want it to work.
22
27
* it limits the free tier to 50 event adds per month (consider the wedding case - this is way too less).
23
-
* it brings some data privacy issues, since you basically send your users to their service.
24
-
* the UX/UI is not ideal (imho).
25
-
*Bottom line:* Pay for features, which I do not need - at additional privacy "cost" - that made me create this solution (for you).
28
+
* it brings some data privacy issues, since you basically send your users to their service. GDPR alert!
29
+
* the UX/UI is not ideal (imho).
30
+
31
+
**Bottom line:** Paying for features, which I did not need - at additional privacy concerns - that made me create this solution (for you).
26
32
33
+
<br />
27
34
28
-
## DEMO
35
+
## ▶️ Demo
29
36
30
37
See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-calendar-button/) for a live demo.
31
38
39
+
<br />
32
40
33
-
## Features
41
+
## ✨ Features
34
42
35
43
* Simple and convenient integration of multiple buttons - configure them directly within the HTML code.
36
44
* Optimized UX (for desktop and mobile) - adjustable.
@@ -41,13 +49,14 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
41
49
* Microsoft 365, Outlook, and Teams.
42
50
* Automatically generated iCal/ics files (for all other calendars, like Apple).
43
51
* Timed and all-day events.
44
-
* Translatable labels and dynamic.
45
-
* Well documented code, to easily understand the processes.
52
+
* Translatable labels and dynamic dates.
53
+
* Well documented code, to easily understand the processes and build on top of it.
@@ -59,18 +68,19 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
59
68
60
69
### Option 2: npm
61
70
62
-
1. Requires Node.js, npm, and a project, which builds on it (e.g. React or Angular).
71
+
1. Requires Node, npm, and a project, which builds on it (e.g. React or Angular).
63
72
2. Run **`npm install add-to-calendar-button`**.
64
-
3. Import the module into your project/component. For example with Angular/React: `import { atcb_init } from 'add-to-calendar-button';`.
65
-
4.Init the js after the DOM has been loaded. To determine the right moment and execute, ...
73
+
3. Import the module into your project/component. For example with Angular/React: `import { addToCalendar, atcb_init } from 'add-to-calendar-button';`.
74
+
4.Either use `addToCalendar` with your own buttons/forms/etc, or run `atcb_init` after the DOM has been loaded. To determine the right moment and execute, ...
66
75
1. with Angular, you would use `ngAfterViewInit()` with `atcb_init();` (mind that, depending on your app, other hooks might be better);
67
76
2. with React, you might want to include an event listener like `document.addEventListener('DOMContentLoaded', atcb_init, false);` or using hooks in a functional component like `useEffect(() => atcb_init());`
68
77
5. Include the css. For example with Angular or React, add the following to the global style.css: `@import 'add-to-calendar-button/assets/css/atcb.min'`;
69
78
6. Create your button as can be seen in the "Configuration" section below.
70
79
7. That is it. The script takes care of all the rest. :)
71
80
81
+
<br />
72
82
73
-
## Configuration
83
+
## 🎛️ Configuration
74
84
75
85
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
76
86
(The `style="display:none;"` theoretically is not necessary, but should be used for better compatibility.)
@@ -163,34 +173,66 @@ You can use startTime and endTime in the event block, but it is recommended to r
163
173
</div>
164
174
```
165
175
166
-
### React example
176
+
### `addToCalendar` example with React
167
177
168
-
A simpler method uses `JSON.stringify()` where you define your config in an external file or variable and then
169
-
convert it to a string to be passed into the div.
178
+
If you can't or don't want to use `atcb_init`, you can use the `addToCalendar` import with your own buttons or other elements/components. If you omit the second argument, the dropdown list will display as a modal in the middle of the viewport - in this case, add the "atcb_customTrigger" class to the submitting element for better keyboard support.
179
+
180
+
This may work better with React and other frontend frameworks.
* The "label" is optional, but enables you to customize the button text. Default: "Add to Calendar".
191
233
* Dates need to be formatted as YYYY-MM-DD ([ISO-8601](https://en.wikipedia.org/wiki/ISO_8601)).
192
-
* You can also use the word "today" as date. It will then dynamically use the current day at click.
193
-
* Add "+5" at the end of the date to dynamically add 5 days (or any other number). "2022-01-30+12" would generate the 11th of February 2022. This can be interesting, when combined with "today".
234
+
* You can also use the word "today" as date. It will then dynamically use the current day at click (not supported with schema.org style).
235
+
* Add "+5" at the end of the date to dynamically add 5 days (or any other number). "2022-01-30+12" would generate the 11th of February 2022. This can be interesting, when combined with "today".
194
236
* Times need to be formatted as HH:MM.
195
237
* Times are optional. If not set, the button generates all-day events.
196
238
* 1 option is required. You can add as many as you want. The supported formats are listed above.
IMPORTANT NOTE: Run `npm install` and `npm run build` to create the minified js and css file, its sourcemap files as well as the npm_dist/ folder and content!
262
+
**IMPORTANT NOTE:** Run `npm install` and `npm run build` to create the minified js and css file, its sourcemap files as well as the npm_dist/ folder and content!
220
263
264
+
<br />
221
265
222
-
## License
266
+
## 📃 License
223
267
224
268
The code is available under the [MIT license (with “Commons Clause” License Condition v1.0)](LICENSE.txt).
225
269
270
+
<br />
226
271
227
-
## Changelog (without bug fixes)
272
+
## ⚡ Changelog (without minor changes and fixes)
228
273
274
+
* v1.7 : new code structure and options + tons of optimizations
229
275
* v1.6 : supporting Microsoft Teams
230
276
* v1.5 : update to date format and better accesibility
231
277
* v1.4 : schema.org support (also changed some keys in the JSON!)
@@ -234,8 +280,10 @@ The code is available under the [MIT license (with “Commons Clause” License
0 commit comments