|
|
| Line 1: |
Line 1: |
| <includeonly><span class="ics-container"><script>/* Hashing as seen on https://stackoverflow.com/a/52171480 */ | | <includeonly><span class="ics-container"><script>var icsName = "<!--{$title|escape:'html'}-->"; |
| var cyrb53 = function(str, seedRaw) {
| |
| var seed = seedRaw || 0;
| |
| var h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
| |
| for (var i = 0, ch; i < str.length; i++) {
| |
| ch = str.charCodeAt(i);
| |
| h1 = Math.imul(h1 ^ ch, 2654435761);
| |
| h2 = Math.imul(h2 ^ ch, 1597334677);
| |
| }
| |
| h1 = Math.imul(h1 ^ (h1>>>16), 2246822507) ^ Math.imul(h2 ^ (h2>>>13), 3266489909);
| |
| h2 = Math.imul(h2 ^ (h2>>>16), 2246822507) ^ Math.imul(h1 ^ (h1>>>13), 3266489909);
| |
| return 4294967296 * (2097151 & h2) + (h1>>>0);
| |
| };
| |
| | |
| function buildIcsLink(name, start, end) {
| |
| var d= new Date();
| |
| var currentDateString = d.getFullYear() + ("0"+(d.getMonth()+1)).slice(-2) + ("0" + d.getDate()).slice(-2) + "T"
| |
| + ("0" + d.getHours()).slice(-2) + ("0" + d.getMinutes()).slice(-2) + ("0" + d.getSeconds()).slice(-2);
| |
| | |
| var hash = cyrb53("" + name + start + end);
| |
| | |
| var icsContent = "BEGIN:VCALENDAR\r\n";
| |
| icsContent += "VERSION:2.0\r\n";
| |
| icsContent += "PRODID:-//iopwiki.com//ICS Widget\r\n";
| |
| icsContent += "CALSCALE:GREGORIAN\r\n";
| |
| icsContent += "BEGIN:VEVENT\r\n";
| |
| icsContent += "DTSTAMP:" + currentDateString + "\r\n";
| |
| icsContent += "UID:" + hash + "\r\n";
| |
| icsContent += "DTSTART;TZID=Etc/UTC:" + start + "\r\n";
| |
| icsContent += "DTEND;TZID=Etc/UTC:" + end + "\r\n";
| |
| icsContent += "SUMMARY:" + name + "\r\n";
| |
| icsContent += "END:VEVENT\r\n";
| |
| icsContent += "END:VCALENDAR\r\n";
| |
|
| |
| var icsLink = document.createElement("a");
| |
| icsLink.classList.add('ics-link');
| |
| icsLink.setAttribute("href", "javascript:void(0);");
| |
| icsLink.setAttribute("target", "_blank");
| |
| icsLink.setAttribute("rel", "noopener");
| |
| icsLink.setAttribute("tooltip", "Download iCal file");
| |
| icsLink.setAttribute("download", "event.ics");
| |
| icsLink.addEventListener('click', function(e) {
| |
| var uriContent = "data:text/calendar," + encodeURIComponent(icsContent);
| |
| e.target.href = uriContent;
| |
| });
| |
|
| |
| var visibleText = document.createTextNode("Download iCal file");
| |
| icsLink.appendChild(visibleText);
| |
|
| |
| var container = document.currentScript.parentNode;
| |
| container.appendChild(icsLink);
| |
| }
| |
| | |
| var icsName = "<!--{$title|escape:'html'}-->"; | |
| var icsStart = "<!--{$start|escape:'html'}-->"; | | var icsStart = "<!--{$start|escape:'html'}-->"; |
| var icsEnd = "<!--{$end|escape:'html'}-->"; | | var icsEnd = "<!--{$end|escape:'html'}-->"; |
| buildIcsLink(icsName, icsStart, icsEnd);</script></includeonly><noinclude>{{Documentation}}</noinclude> | | window.iopwidgets.ICSGenerator.buildIcsLink(icsName, icsStart, icsEnd);</script></includeonly><noinclude>{{Documentation}}</noinclude> |
Template parameters[Edit template data]
This template prefers inline formatting of parameters.
| Parameter | Description | Type | Status |
|---|
| Title of the event | title | The general title of the event. This is the text that will be shown in a calendar. Keep it short. - Example
- Shattered Connexion
| String | required |
|---|
| Event start | start | The start date of the event. - Example
- 2021-08-12T04:00:00+07
| Date | required |
|---|
| Event end | end | The ending of the event. - Example
- 2021-08-26T10:00:00+07
| Date | required |
|---|
Usage
See the widget's testcases:
| Test with given full date definition
|
| Wiki code
|
{{#widget:ICSGenerator
|title=Name of the event
|start=20220218T194956
|end=20220218T195956}}
|
| Main version
|
|
| Sandbox version
|
(no sandbox subpage)
|
| Test with short date definition
|
| Wiki code
|
{{#widget:ICSGenerator
|title=Name of the event
|start=20220218T194956
|end=20220218T195956}}
|
| Main version
|
|
| Sandbox version
|
(no sandbox subpage)
|
See also