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._
5
-
5
+
6
6
7
7
## Use case // Who this is for
8
8
9
9
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
10
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
11
It is for this simple use case. No strings attached.
12
-
12
+
13
13
14
14
## Background // Why this repo exists
15
15
@@ -23,12 +23,12 @@ The problems with AddEvent.com:
23
23
* it brings some data privacy issues, since you basically send your users to their service.
24
24
* the UX/UI is not ideal (imho).
25
25
*Bottom line:* Pay for features, which I do not need - at additional privacy "cost" - that made me create this solution (for you).
26
-
26
+
27
27
28
28
## DEMO
29
29
30
30
See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-calendar-button/) for a live demo.
31
-
31
+
32
32
33
33
## Features
34
34
@@ -45,12 +45,12 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
45
45
* Well documented code, to easily understand the processes.
1. Simply **download** the code from GitHub **or clone** the git repository.
55
55
2. Copy the css (atcb.min.css) and js (atcb.min.js) files from the assets (not the "npm_dist"!) folders into your project (the **.min.** files are required, but it is recommended to also copy the raw and map files).
56
56
3. Include those files in your project. As usual, the css goes into the <head> (`<link rel="stylesheet" href="./assets/css/atcb.min.css">`), the js into the <body> footer (`<script src="./assets/js/atcb.min.js" defer></script>`). You can also combine them with other files, if you want to.
@@ -63,23 +63,23 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
63
63
2. Run **`npm install add-to-calendar-button`**.
64
64
3. Import the module into your project/component. For example with Angular/React: `import { atcb_init } from 'add-to-calendar-button';`.
65
65
4. Init the js after the DOM has been loaded. To determine the right moment and execute, ...
66
-
1. with Angular, you would use `ngAfterViewInit()` with `atcb_init();` (mind that, depending on your app, other hooks might be better);
67
-
2. with React, you might want to include an event listener like `document.addEventListener('DOMContentLoaded', atcb_init, false);`.
66
+
1. with Angular, you would use `ngAfterViewInit()` with `atcb_init();` (mind that, depending on your app, other hooks might be better);
67
+
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
68
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
69
6. Create your button as can be seen in the "Configuration" section below.
70
70
7. That is it. The script takes care of all the rest. :)
71
-
71
+
72
72
73
73
## Configuration
74
74
75
-
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
75
+
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
76
76
(The `style="display:none;"` theoretically is not necessary, but should be used for better compatibility.)
77
77
```html
78
78
<divclass="atcb"style="display:none;">
79
79
(...)
80
80
</div>
81
81
```
82
-
Within this placeholder, you can easily configure the button, by placing a respective JSON structure.
82
+
Within this placeholder, you can easily configure the button, by placing a respective JSON structure.
83
83
Mind that with Angular, you might need to escape the { with `{{ '{' }}` and } with `{{ '}' }}`; with React it would be `{ '{' }` and `{ '}' }`.
84
84
85
85
### Minimal structure (required)
@@ -160,7 +160,28 @@ You can use startTime and endTime in the event block, but it is recommended to r
160
160
</script>
161
161
</div>
162
162
```
163
-
163
+
164
+
### React example
165
+
166
+
A simpler method uses `JSON.stringify()` where you define your config in an external file or variable and then
167
+
convert it to a string to be passed into the div.
168
+
169
+
```js
170
+
constAddToCalendar= () => {
171
+
172
+
useEffect(() =>atcb_init());
173
+
174
+
constevent= { /* Event data */}
175
+
176
+
return (
177
+
<div className='atcb'>
178
+
<script type="application/ld+json">
179
+
{JSON.stringify(event)}
180
+
</script>
181
+
</div>
182
+
);
183
+
}
184
+
```
164
185
165
186
### Important information and hidden features
166
187
@@ -181,7 +202,7 @@ You can use startTime and endTime in the event block, but it is recommended to r
181
202
* If you want to define a specific name for any generated ics file (iCal), you can specify it via the "iCalFileName" option. The default would be "event-to-save-in-my-calendar".
182
203
* You can use the option "inline":true in order to make the button appear with inline-block instead of block style.
183
204
* If you require line breaks within the description, use `\n` or `<br>`.
184
-
205
+
185
206
186
207
## Contributing
187
208
@@ -192,12 +213,12 @@ Anyone is welcome to contribute, but mind the [guidelines](.github/CONTRIBUTING.
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!
195
-
216
+
196
217
197
218
## License
198
219
199
220
The code is available under the [MIT license (with “Commons Clause” License Condition v1.0)](LICENSE.txt).
200
-
221
+
201
222
202
223
## Changelog (without bug fixes)
203
224
@@ -206,7 +227,7 @@ The code is available under the [MIT license (with “Commons Clause” License
0 commit comments