forked from rubyforgood/casa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_to_calendar_button.js
More file actions
30 lines (24 loc) · 1.07 KB
/
add_to_calendar_button.js
File metadata and controls
30 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'add-to-calendar-button'
function createCalendarEvents () {
const calendarButtons = document.querySelectorAll('div.cal-btn')
for (const calendarButton of calendarButtons) {
// Create the add-to-calendar-button web component
const button = document.createElement('add-to-calendar-button')
// Set attributes from data attributes
button.setAttribute('name', calendarButton.dataset.title)
button.setAttribute('startDate', calendarButton.dataset.start)
button.setAttribute('endDate', calendarButton.dataset.end)
button.setAttribute('description', calendarButton.dataset.title)
button.setAttribute('options', "'Apple','Google','iCal','Microsoft365','Outlook.com','Yahoo'")
button.setAttribute('timeZone', 'currentBrowser')
button.setAttribute('lightMode', 'bodyScheme')
// Set tooltip
button.title = calendarButton.dataset.tooltip
// Replace the div content with the button
calendarButton.innerHTML = ''
calendarButton.appendChild(button)
}
}
$(() => { // JQuery's callback for the DOM loading
createCalendarEvents()
})