data:text/calendar calendar links are not supported in IE/Edge, I think this should go in the README.
Here's a JS snippet that makes it work. Insert the JS code below into your twig template, {% set addToCalendarLink = ... %} somewhere above it, and add a link somewhere with id="download-event".
{% js at endBody %}
(function () {
this.EventHandler = function (linkData, fileData) {
this.fileData = fileData;
this.linkData = linkData;
document.querySelector("a#download-event").addEventListener("click", getIcs.bind(this, event));
}
function isIEdge () {
return ( window.Blob && window.navigator.msSaveOrOpenBlob );
}
function getIcs () {
if (isIEdge()) {
var fileData = [this.fileData];
blobObject = new Blob(fileData);
window.navigator.msSaveOrOpenBlob(blobObject, 'event.ics');
} else {
window.location.href=this.linkData;
}
event.preventDefault();
}
}());
eventHandler = new EventHandler("{{ addToCalendarLink.ics() }}","{{ addToCalendarLink.ics() | replace({'%0A':'\\n'}) | trim('data:text/calendar;charset=utf8,\\n', 'left') }}");
{% endjs %}
Thanks for the plugin!
data:text/calendar calendar links are not supported in IE/Edge, I think this should go in the README.
Here's a JS snippet that makes it work. Insert the JS code below into your twig template, {% set addToCalendarLink = ... %} somewhere above it, and add a link somewhere with id="download-event".