Skip to content

Commit 81cd4d5

Browse files
authored
Merge pull request #39 from jekuer/v1.7.0_dev
V1.7.0 dev
2 parents 9e56402 + 7588e9b commit 81cd4d5

File tree

17 files changed

+923
-447
lines changed

17 files changed

+923
-447
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "CodeQL Analysis"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '31 11 * * 0'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'javascript' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v2
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v1
31+
with:
32+
languages: ${{ matrix.language }}
33+
34+
- name: Autobuild
35+
uses: github/codeql-action/autobuild@v1
36+
37+
- name: Perform CodeQL Analysis
38+
uses: github/codeql-action/analyze@v1

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# THE .gitignore
1+
# THE .gitignore
22

33
.vscode/*
44
!.vscode/settings.json
@@ -18,3 +18,4 @@ assets/js/
1818
*.ico
1919
*.gif
2020
index.html
21+
security.md

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const npmDelimiter = /\/\/ START INIT[\s\S]*?\/\/ END INIT/gm
22

33
function process(content, exportPhrase) {
4-
return content.replace(npmDelimiter, `${exportPhrase} { atcb_init };`);
4+
content = content.replace('atcb_addToCalendar', 'addToCalendar');
5+
return content.replace(npmDelimiter, `${exportPhrase} { addToCalendar, atcb_init };`);
56
}
67
module.exports = function(grunt) {
78

README.md

Lines changed: 86 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
1-
# Your next Add-to-Calendar Button
1+
# 📅 Your next Add-to-Calendar Button!
22
![Add-to-Calendar Button](https://github.com/jekuer/add-to-calendar-button/blob/main/repo_image.png?raw=true)
33

4-
_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._
55

6+
![#1 Product of the Day on ProductHunt](https://api.producthunt.com/widgets/embed-image/v1/top-post-badge.svg?post_id=319458&theme=dark&period=daily)
67

7-
## Use case // Who this is for
8+
<br /><br />
9+
10+
## 😎 Use case // Who this is for
811

912
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.
1013
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.
1114
It is for this simple use case. No strings attached.
1215

16+
<br />
1317

14-
## Background // Why this repo exists
18+
## 🔎 Background // Why this repo exists
1519

1620
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.
1721
I did not want to build this from scratch (first) and therefore started the usual web research.
1822
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+
2025
The problems with AddEvent.com:
2126
* it holds tons of features, which I did not need. I do not want to track my button. I just want it to work.
2227
* 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).
2632

33+
<br />
2734

28-
## DEMO
35+
## ▶️ Demo
2936

3037
See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-calendar-button/) for a live demo.
3138

39+
<br />
3240

33-
## Features
41+
## Features
3442

3543
* Simple and convenient integration of multiple buttons - configure them directly within the HTML code.
3644
* 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
4149
* Microsoft 365, Outlook, and Teams.
4250
* Automatically generated iCal/ics files (for all other calendars, like Apple).
4351
* 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.
4654

4755
![Demo Screenshot](https://github.com/jekuer/add-to-calendar-button/blob/main/demo.gif?raw=true)
4856

57+
<br />
4958

50-
## Setup
59+
## 🌱 Setup
5160

5261
### Option 1: simple
5362

@@ -59,18 +68,19 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
5968

6069
### Option 2: npm
6170

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).
6372
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, ...
6675
1. with Angular, you would use `ngAfterViewInit()` with `atcb_init();` (mind that, depending on your app, other hooks might be better);
6776
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());`
6877
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'`;
6978
6. Create your button as can be seen in the "Configuration" section below.
7079
7. That is it. The script takes care of all the rest. :)
7180

81+
<br />
7282

73-
## Configuration
83+
## 🎛️ Configuration
7484

7585
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
7686
(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
163173
</div>
164174
```
165175

166-
### React example
176+
### `addToCalendar` example with React
167177

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.
170181

171182
```js
183+
import React from 'react'
184+
import { addToCalendar } from 'add-to-calendar-button'
185+
172186
const AddToCalendar = () => {
187+
const [name, setName] = React.useState('Some event')
188+
return (
189+
<form onSubmit={e => {
190+
e.preventDefault()
191+
addToCalendar({
192+
name,
193+
startDate: "2022-01-14",
194+
endDate: "2022-01-18",
195+
options: ['Apple', 'Google', 'iCal', 'Microsoft365', 'Outlook.com', 'MicrosoftTeams', 'Yahoo'],
196+
trigger: "click",
197+
iCalFileName: "Reminder-Event",
198+
})
199+
}}>
200+
<input value={name} onChange={setName} />
201+
<input class="atcb_customTrigger" type="submit" value="save">
202+
</form>
203+
);
204+
}
205+
```
173206

174-
useEffect(() => atcb_init());
207+
Alternatively, you could use `atcb_init` with a `useEffect` hook:
175208

176-
const event = { /* Event data */}
209+
```js
210+
import React from 'react'
211+
import { atcb_init } from 'add-to-calendar-button'
177212

178-
return (
179-
<div className='atcb'>
180-
<script type="application/ld+json">
181-
{JSON.stringify(event)}
182-
</script>
183-
</div>
184-
);
213+
const AddToCalendar = () => {
214+
React.useEffect(atcb_init, [])
215+
return (
216+
<div className='atcb' style={{display: 'none'}}>
217+
{JSON.stringify({
218+
name: "Some event",
219+
startDate: "2022-01-14",
220+
endDate: "2022-01-18",
221+
options: ['Apple', 'Google', 'iCal', 'Microsoft365', 'Outlook.com', 'MicrosoftTeams', 'Yahoo'],
222+
trigger: "click",
223+
iCalFileName: "Reminder-Event",
224+
})}
225+
</div>
226+
);
185227
}
186228
```
187229

188230
### Important information and hidden features
189231

190232
* The "label" is optional, but enables you to customize the button text. Default: "Add to Calendar".
191233
* 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".
194236
* Times need to be formatted as HH:MM.
195237
* Times are optional. If not set, the button generates all-day events.
196238
* 1 option is required. You can add as many as you want. The supported formats are listed above.
@@ -207,25 +249,29 @@ const AddToCalendar = () => {
207249
* Formatting a URL in the description like `[url]https://....[/url]` makes it clickable.
208250
* If you require line breaks within the description, use `\n` or `<br>`.
209251

252+
<br />
210253

211-
## Contributing
254+
## 🙌 Contributing
212255

213256
Anyone is welcome to contribute, but mind the [guidelines](.github/CONTRIBUTING.md):
214257

215258
* [Bug reports](.github/CONTRIBUTING.md#bugs)
216259
* [Feature requests](.github/CONTRIBUTING.md#features)
217260
* [Pull requests](.github/CONTRIBUTING.md#pull-requests)
218261

219-
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!
220263

264+
<br />
221265

222-
## License
266+
## 📃 License
223267

224268
The code is available under the [MIT license (with “Commons Clause” License Condition v1.0)](LICENSE.txt).
225269

270+
<br />
226271

227-
## Changelog (without bug fixes)
272+
## Changelog (without minor changes and fixes)
228273

274+
* v1.7 : new code structure and options + tons of optimizations
229275
* v1.6 : supporting Microsoft Teams
230276
* v1.5 : update to date format and better accesibility
231277
* 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
234280
* v1.1 : npm functionality
235281
* v1.0 : initial release
236282

283+
<br />
237284

238-
## Kudos go to
239-
* [github.com/dudewheresmycode](https://github.com/dudewheresmycodee)
285+
## 💜 Kudos go to
240286
* [uxwing.com](https://uxwing.com)
241-
* all contributors!
287+
* [Brian R (dudewheresmycode)](https://github.com/dudewheresmycode)
288+
* [Chad Ostrowski (chadoh)](https://github.com/chadoh)
289+
* ... and all other contributors!

0 commit comments

Comments
 (0)