
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
add-to-calendar-button
Advanced tools
A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.
A convenient JavaScript snippet (VanillaJS, React, Angular, ...), which lets you create beautiful buttons, where people can add events to their calendars.
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. 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. It is for this simple use case. No strings attached.
See jekuer.github.io/add-to-calendar-button for a live demo.
<link rel="stylesheet" href="./assets/css/atcb.min.css">
), the js into the footer (<script src="./assets/js/atcb.min.js" defer></script>
). You can also combine them with other files, if you want to.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/add-to-calendar-button@1.9.0/assets/css/atcb.min.css">
into the and <script src="https://cdn.jsdelivr.net/npm/add-to-calendar-button@1.9.0" defer></script>
into the footer of your website. Leave out the patch number at the version ("1.9" instead of "1.9.2") to automatically pull the latest patched version. See Requires Node, npm, and a project, which builds on it (e.g. React or Angular).
Run npm install add-to-calendar-button
.
Import the module into your project/component. For example with Angular/React: import { atcb_action, atcb_init } from 'add-to-calendar-button';
.
Either use atcb_action
with your own buttons/forms/etc, or run atcb_init
after the DOM has been loaded. To determine the right moment and execute, ...
ngAfterViewInit()
with atcb_init();
(mind that, depending on your app, other hooks might be better);document.addEventListener('DOMContentLoaded', atcb_init, false);
or using hooks in a functional component like useEffect(() => atcb_init());
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'
;
Create your button as can be seen in the "Configuration" section below.
You're all done.
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
(The style="display:none;"
theoretically is not necessary, but should be used for better compatibility.)
<div class="atcb" style="display:none;">(...)</div>
Within this placeholder, you can easily configure the button, by placing a respective JSON structure.
Mind that with Angular, you might need to escape the { with {{ '{' }}
and } with {{ '}' }}
; with React it would be { '{' }
and { '}' }
.
<div class="atcb" style="display:none;">
{
"name":"Add the title of your event",
"startDate":"2022-02-21",
"endDate":"2022-03-24",
"options":[
"Google"
]
}
</div>
<div class="atcb" style="display:none;">
{
"name":"Add the title of your event",
"description":"A nice description does not hurt",
"startDate":"2022-02-21",
"endDate":"2022-03-24",
"startTime":"10:13",
"endTime":"17:57",
"location":"Somewhere over the rainbow",
"label":"Add to Calendar",
"options":[
"Apple",
"Google",
"iCal",
"Microsoft365",
"MicrosoftTeams",
"Outlook.com",
"Yahoo"
],
"timeZone":"Europe/Berlin",
"trigger":"click",
"iCalFileName":"Reminder-Event"
}
</div>
You can save on the style="display:none;"
, but mind that you should not use dynamic dates (e.g. "today" or "+1") here!
You can use startTime and endTime in the event block, but it is recommended to rather add it to startDate and endDate with "T" as delimiter here.
<div class="atcb">
<script type="application/ld+json">
{
"event": {
"@context": "https://schema.org",
"@type": "Event",
"name": "Add the title of your event",
"description": "A nice description does not hurt",
"startDate": "2022-02-21T10:13",
"endDate": "2022-03-24T17:57",
"location": "Somewhere over the rainbow"
},
"label": "Add to Calendar",
"options": ["Apple", "Google", "iCal", "Microsoft365", "MicrosoftTeams", "Outlook.com", "Yahoo"],
"timeZone": "Europe/Berlin",
"trigger": "click",
"iCalFileName": "Reminder-Event"
}
</script>
</div>
If you can't or don't want to use atcb_init
, you can use the atcb_action
import with your own buttons or other elements/components.
This may work better with React and other frontend frameworks, but it misses the Schema.org and button specific functionalities.
import React from 'react';
import { atcb_action } from 'add-to-calendar-button';
const MyComponent = () => {
const [name, setName] = React.useState('Some event');
return (
<form onSubmit={e => {
e.preventDefault();
atcb_action({
name,
startDate: "2022-01-14",
endDate: "2022-01-18",
options: ['Apple', 'Google', 'iCal', 'Microsoft365', 'Outlook.com', 'MicrosoftTeams', 'Yahoo'],
timeZone: "Europe/Berlin",
trigger: "click",
iCalFileName: "Reminder-Event",
}, triggerEl);
}}>
<input value={name} onChange={setName} />
<input type="submit" value="save">
</form>
);
}
Alternatively, you could use atcb_init
with a useEffect
hook:
import React from "react";
import { atcb_init } from "add-to-calendar-button";
const atcb_action = () => {
React.useEffect(atcb_init, []);
return (
<div className="atcb" style={{ display: "none" }}>
{JSON.stringify({
name: "Some event",
startDate: "2022-01-14",
endDate: "2022-01-18",
options: ["Apple", "Google", "iCal", "Microsoft365", "Outlook.com", "MicrosoftTeams", "Yahoo"],
timeZone: "Europe/Berlin",
trigger: "click",
iCalFileName: "Reminder-Event",
})}
</div>
);
};
label
is optional, but enables you to customize the button text. Default: "Add to Calendar".today
as date. It will then dynamically use the current day at click (not supported with schema.org style).+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
.timeZone
(TZ name) or explicit timeZoneOffset
. You can find a list of them at Wikipedia.timeZoneOffset
is set, it will always override the timeZone
. If none is set, the date refers to UTC time.timeZone
option is recommended since it considers things like summer/winter time, but might not work in very old browsers. timeZoneOffset
works with older browsers, but is quite static.timeZone
to dynamically use the time of the user's browser. Use this with caution, since it would mean that the date and time will differ per user, which should not be the usual case! (Requires all times to be set.)trigger
to click
. This makes the button open on click at desktop. Otherwise, the default would be to open on hover. On touch devices, this makes no difference.iCalFileName
option. The default would be "event-to-save-in-my-calendar"."inline":true
in order to make the button appear with inline-block instead of block style.listStyle
to "modal" in order to force the modal version.[url]https://....[/url]
makes it clickable.\n
or <br>
.Anyone is welcome to contribute, but mind the guidelines:
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!
Copyright (c) Jens Kuerschner. Licensed under MIT license (with “Commons Clause” License Condition v1.0).
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. I did not want to build this from scratch (first) and therefore started the usual web research. Unfortunately, all I found where some extremely outdated code snippets, which did not really fit all the modern systems and calendar tools. 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.
The problems with AddEvent.com:
Bottom line: Paying for features, which I did not need - at additional privacy concerns - that made me create this solution (for you).
FAQs
A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.
The npm package add-to-calendar-button receives a total of 35,286 weekly downloads. As such, add-to-calendar-button popularity was classified as popular.
We found that add-to-calendar-button demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.