forked from carlsednaoui/add-to-calendar-buttons
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathadd-to-calendar.min.js
1 lines (1 loc) · 14 KB
/
add-to-calendar.min.js
1
!function(e){var n=6e4,l={selector:".add-to-calendar",duration:60,texts:{label:"Add to Calendar",title:"New event",download:"Calendar-event.ics",google:"Google Calendar",yahoo:"Yahoo! Calendar",off365:"Office 365",ical:"Download iCal",outlook:"Download Outlook",ienoblob:"Sorry, your browser does not support downloading Calendar events."}};"undefined"!=typeof ADDTOCAL_CONFIG&&(l=ADDTOCAL_CONFIG);function t(e,t){if(e){if(t){var a=new Date(e.toLocaleString("en-US",{timeZone:t})),A=e.getTime()-a.getTime();return new Date(e.getTime()+A)}return e}}function a(e){return{google:i.google(e),yahoo:i.yahoo(e),off365:i.off365(e),ical:i.ical(e),outlook:i.outlook(e)}}function A(e){e.options||(e.options={}),e.options.id||(e.options.id=Math.floor(1e6*Math.random())),e.options.class||(e.options.class=""),e.data||(e.data={}),e.data.start||(e.data.start=new Date),e.data.allday&&(delete e.data.end,delete e.data.duration),e.data.end?delete e.data.duration:e.data.duration||(e.data.duration=l.duration),e.data.duration&&(e.data.end=s(e.data.start,e.data.duration)),e.data.timezone?(e.data.tzstart=t(e.data.start,e.data.timezone),e.data.tzend=t(e.data.end,e.data.timezone)):(e.data.tzstart=e.data.start,e.data.tzend=e.data.end),e.data.title||(e.data.title=l.texts.title)}function o(e){return void 0!==e.data&&void 0!==e.data.start&&(void 0!==e.data.end||void 0!==e.data.allday)}var d="msSaveOrOpenBlob"in window.navigator,r=/\b(MSIE |Trident.*?rv:|Edge\/)(\d+)/.exec(navigator.userAgent),i={google:function(e){var t,a,A,o;e.allday?(t=c(e.tzstart),a=c(s(e.tzstart,1440)),t=W(t),a=W(a)):a=e.timezone?(A=new Date(e.start.getTime()-e.start.getTimezoneOffset()*n),e.end&&(o=new Date(e.end.getTime()-e.end.getTimezoneOffset()*n)),t=c(A),a=c(o),t=t.substring(0,t.length-1),a.substring(0,a.length-1)):(t=c(e.start),c(e.end));return'<a class="icon-google" target="_blank" href="'+encodeURI(["https://www.google.com/calendar/render","?action=TEMPLATE","&text="+(e.title||""),"&dates="+(t||""),"/"+(a||""),e.timezone?"&ctz="+e.timezone:"","&details="+(e.description||""),"&location="+(e.address||""),"&sprop=&sprop=name:"].join(""))+'">'+l.texts.google+"</a>"},yahoo:function(e){if(e.allday)var t="allday";else{var a=e.tzend?(e.tzend.getTime()-e.tzstart.getTime())/n:e.duration;t=(a<600?"0"+Math.floor(a/60):Math.floor(a/60)+"")+(a%60<10?"0"+a%60:a%60+"")}var A=c(e.tzstart)||"";return'<a class="icon-yahoo" target="_blank" href="'+encodeURI(["http://calendar.yahoo.com/?v=60&view=d&type=20","&title="+(e.title||""),"&st="+A,"&dur="+(t||""),"&desc="+(e.description||""),"&in_loc="+(e.address||"")].join(""))+'">'+l.texts.yahoo+"</a>"},off365:function(e){var t=c(e.tzstart),a=c(e.tzend);return'<a class="icon-off365" target="_blank" href="'+encodeURI(["https://outlook.office365.com/owa/","?path=/calendar/action/compose","&rru=addevent","&subject="+(e.title||""),"&startdt="+(t||""),"&enddt="+(a||""),"&body="+(e.description||""),"&location="+(e.address||""),(e.allday,"true")].join(""))+'">'+l.texts.off365+"</a>"},ics:function(e,t,a){var A,o;o=e.allday?(A=c(e.tzstart),A=W(A)+"T000000"):(A=c(e.tzstart),c(e.tzend));var n=["BEGIN:VCALENDAR","VERSION:2.0","BEGIN:VEVENT","URL:"+document.URL,"DTSTART:"+(A||""),"DTEND:"+(o||""),"SUMMARY:"+(e.title||""),"DESCRIPTION:"+(e.description||""),"LOCATION:"+(e.address||""),"UID:"+(e.id||"")+"-"+document.URL,"END:VEVENT","END:VCALENDAR"].join("\n");if(r)return'<a class="'+t+'" onclick="ieDownloadCalendar(\''+V(n)+"')\">"+a+"</a>";var d=encodeURI("data:text/calendar;charset=utf8,"+n);return'<a class="'+t+'" download="'+l.texts.download+'" href="'+d+'">'+a+"</a>"},ical:function(e){return this.ics(e,"icon-ical",l.texts.ical)},outlook:function(e){return this.ics(e,"icon-outlook",l.texts.outlook)}},c=function(e){return e?e.toISOString().replace(/-|:|\.\d+/g,""):""},s=function(e,t){return new Date(e.getTime()+t*n)},W=function(e){return e.substr(0,e.indexOf("T"))},V=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/\'/g,"\\'").replace(/(\r?\n|\r)/gm,"\\n")},u=function(){document.getElementById("add-to-calendar-css")||document.getElementsByTagName("head")[0].appendChild(b())},b=function(){var e=document.createElement("style");return e.id="add-to-calendar-css",e.innerHTML=".add-to-calendar{position:relative;text-align:left}.add-to-calendar>*{display:none}.add-to-calendar>.add-to-calendar-widget{display:block}.add-to-calendar-label{cursor:pointer}.add-to-calendar-checkbox+div.add-to-calendar-dropdown{display:none;margin-left:20px}.add-to-calendar-checkbox:checked+div.add-to-calendar-dropdown{display:block}input[type=checkbox].add-to-calendar-checkbox{position:absolute;visibility:hidden}.add-to-calendar-checkbox+div.add-to-calendar-dropdown a{cursor:pointer;display:block}.add-to-calendar-checkbox+div.add-to-calendar-dropdown a:before{width:16px;height:16px;display:inline-block;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAAAQCAYAAACIoli7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyL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68px 0}.icon-yahoo:before{background-position:-36px +4px}.icon-google:before{background-position:-52px 0}.add-to-calendar-widget{font-family:sans-serif;margin:1em 0;position:relative}.add-to-calendar-label{display:inline-block;background-color:#fff;background-image:url(data:image/vndmicrosofticon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/wAAAAAAAAAAVlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/AAAAAFZWVv9WVlb///////////9WVlb///////////9WVlb///////////9WVlb///////////9WVlb/VlZW/wAAAABWVlb/VlZW////////////VlZW////////////VlZW////////////VlZW////////////VlZW/1ZWVv8AAAAAVlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/AAAAAFZWVv9WVlb///////////9WVlb///////////9WVlb///////////9WVlb///////////9WVlb/VlZW/wAAAABWVlb/VlZW////////////VlZW////////////VlZW////////////VlZW////////////VlZW/1ZWVv8AAAAAVlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/AAAAAFZWVv9WVlb///////////9WVlb///////////9WVlb///////////9WVlb///////////9WVlb/VlZW/wAAAABWVlb/VlZW////////////VlZW////////////VlZW////////////VlZW////////////VlZW/1ZWVv8AAAAAVlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/AAAAAFZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/1ZWVv9WVlb/VlZW/wAAAAAAAAAAVlZW/1ZWVv///////////1ZWVv9WVlb/VlZW/1ZWVv9WVlb///////////9WVlb/VlZW/wAAAAAAAAAAAAAAAAAAAABWVlb///////////9WVlb/AAAAAAAAAAAAAAAAVlZW////////////VlZW/wAAAAAAAAAAAAAAAAAAAAAAAAAAVlZW/1ZWVv9WVlb/VlZW/wAAAAAAAAAAAAAAAFZWVv9WVlb/VlZW/1ZWVv8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==);background-position:10px 45%;background-repeat:no-repeat;padding:1em 1em 1em 40px;background-size:20px 20px;border-radius:3px;box-shadow:0 0 0 .5px rgba(50,50,93,.17),0 2px 5px 0 rgba(50,50,93,.1),0 1px 1.5px 0 rgba(0,0,0,.07),0 1px 2px 0 rgba(0,0,0,.08),0 0 0 0 transparent!important}.add-to-calendar-dropdown{position:absolute;z-index:99;background-color:#fff;top:0;left:0;padding:1em;margin:0!important;border-radius:3px;box-shadow:0 0 0 .5px rgba(50,50,93,.17),0 2px 5px 0 rgba(50,50,93,.1),0 1px 1.5px 0 rgba(0,0,0,.07),0 1px 2px 0 rgba(0,0,0,.08),0 0 0 0 transparent!important}.add-to-calendar-dropdown a{display:block;line-height:1.75em;text-decoration:none;color:inherit;opacity:.7}.add-to-calendar-dropdown a:hover{opacity:1}",e};e.ieDownloadCalendar=function(e){if(d){var t=new Blob([e],{type:"text/calendar"});window.navigator.msSaveOrOpenBlob(t,l.texts.download)}else alert(l.texts.ienoblob)},e.closeCalenderOnMouseDown=function(e){var t=function(){setTimeout(function(){e.checked=!1},750),document.removeEventListener("mousedown",t)};document.addEventListener("mousedown",t)},e.addToCalendarData=function(e){if(A(e=e||{}),o(e))return a(e.data);console.error("Event details missing.")},e.createCalendar=function(e){return addToCalendar(e)},e.addToCalendar=function(e){if((e=e||{})instanceof HTMLElement)return function(e){var t,a={};return(t=e.querySelector(".start"))&&(a.start=new Date(t.textContent)),(t=e.querySelector(".end"))&&(a.end=new Date(t.textContent)),(t=e.querySelector(".duration"))&&(a.duration=1*t.textContent),(t=e.querySelector(".allday"))&&(a.allday=!0),(t=e.querySelector(".title"))&&(a.title=t.textContent),(t=e.querySelector(".description"))&&(a.description=t.textContent),(t=e.querySelector(".address"))&&(a.address=t.textContent),a.address||(t=e.querySelector(".location"))&&(a.address=t.textContent),(t=e.querySelector(".timezone"))&&(a.timezone=t.textContent),cal=createCalendar({data:a}),cal&&e.appendChild(cal),cal}(e);if(e instanceof NodeList){var t=0<e.length;return Array.prototype.forEach.call(e,function(e){t=t&&addToCalendar(e)}),t}if(A(e),o(e))return function(t,e,a){var A=document.createElement("div");A.innerHTML='<label for="checkbox-for-'+a+'" class="add-to-calendar-label">'+l.texts.label+"</label>",A.innerHTML+='<input name="add-to-calendar-checkbox" class="add-to-calendar-checkbox" id="checkbox-for-'+a+'" type="checkbox" onclick="closeCalenderOnMouseDown(this)">';var o=document.createElement("div");return o.className="add-to-calendar-dropdown",Object.keys(t).forEach(function(e){o.innerHTML+=t[e]}),A.appendChild(o),A.className="add-to-calendar-widget",void 0!==e&&(A.className+=" "+e),u(),A.id=a,A}(a(e.data),e.options.class,e.options.id);console.error("Event details missing.")},document.addEventListener("DOMContentLoaded",function(e){addToCalendar(document.querySelectorAll(l.selector))})}(this);