This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathics.min.js
2 lines (2 loc) · 3.09 KB
/
ics.min.js
1
2
/*! ics.js Wed Aug 20 2014 17:23:02 */
var ics=function(){"use strict";if(navigator.userAgent.indexOf("MSIE")>-1&&-1==navigator.userAgent.indexOf("MSIE 10"))return void console.log("Unsupported Browser");var a=-1!==navigator.appVersion.indexOf("Win")?"\r\n":"\n",b=[],c=["BEGIN:VCALENDAR","VERSION:2.0"].join(a),d=a+"END:VCALENDAR",e=["SU","MO","TU","WE","TH","FR","SA"];return{events:function(){return b},calendar:function(){return c+a+b.join(a)+d},addEvent:function(c,d,f,g,h,i){if("undefined"==typeof c||"undefined"==typeof d||"undefined"==typeof f||"undefined"==typeof g||"undefined"==typeof h)return!1;if(i&&!i.rule){if("YEARLY"!==i.freq&&"MONTHLY"!==i.freq&&"WEEKLY"!==i.freq&&"DAILY"!==i.freq)throw"Recurrence rule frequency must be provided and be one of the following: 'YEARLY', 'MONTHLY', 'WEEKLY', or 'DAILY'";if(i.until&&isNaN(Date.parse(i.until)))throw"Recurrence rule 'until' must be a valid date string";if(i.interval&&isNaN(parseInt(i.interval)))throw"Recurrence rule 'interval' must be an integer";if(i.count&&isNaN(parseInt(i.count)))throw"Recurrence rule 'count' must be an integer";if("undefined"!=typeof i.byday){if("[object Array]"!==Object.prototype.toString.call(i.byday))throw"Recurrence rule 'byday' must be an array";if(i.byday.length>7)throw"Recurrence rule 'byday' array must not be longer than the 7 days in a week";i.byday=i.byday.filter(function(a,b){return i.byday.indexOf(a)==b});for(var j in i.byday)if(e.indexOf(i.byday[j])<0)throw"Recurrence rule 'byday' values must include only the following: 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'"}}var k=new Date(g),l=new Date(h),m=("0000"+k.getFullYear().toString()).slice(-4),n=("00"+(k.getMonth()+1).toString()).slice(-2),o=("00"+k.getDate().toString()).slice(-2),p=("00"+k.getHours().toString()).slice(-2),q=("00"+k.getMinutes().toString()).slice(-2),r=("00"+k.getMinutes().toString()).slice(-2),s=("0000"+l.getFullYear().toString()).slice(-4),t=("00"+(l.getMonth()+1).toString()).slice(-2),u=("00"+l.getDate().toString()).slice(-2),v=("00"+l.getHours().toString()).slice(-2),w=("00"+l.getMinutes().toString()).slice(-2),x=("00"+l.getMinutes().toString()).slice(-2),y="",z="";q+r+w+x!==0&&(y="T"+p+q+r,z="T"+v+w+x);var A,B=m+n+o+y,C=s+t+u+z;if(i)if(i.rule)A=i.rule;else{if(A="RRULE:FREQ="+i.freq,i.until){var D=new Date(Date.parse(i.until)).toISOString();A+=";UNTIL="+D.substring(0,D.length-13).replace(/[-]/g,"")+"000000Z"}i.interval&&(A+=";INTERVAL="+i.interval),i.count&&(A+=";COUNT="+i.count),i.byday&&i.byday.length>0&&(A+=";BYDAY="+i.byday.join(","))}var E=(new Date).toISOString(),F=["BEGIN:VEVENT","CLASS:PUBLIC","DESCRIPTION:"+d,"DTSTART:"+B,"DTEND:"+C,"DTSTAMP:"+E.substring(0,E.length-13).replace(/[-]/g,"")+"000000Z","LOCATION:"+f,"SUMMARY;LANGUAGE=en-us:"+c,"TRANSP:TRANSPARENT","END:VEVENT"];return A&&F.splice(4,0,A),F=F.join(a),b.push(F),F},download:function(e,f){if(b.length<1)return!1;f="undefined"!=typeof f?f:".ics",e="undefined"!=typeof e?e:"calendar";var g,h=c+a+b.join(a)+d;if(-1===navigator.userAgent.indexOf("MSIE 10"))g=new Blob([h]);else{var i=new BlobBuilder;i.append(h),g=i.getBlob("text/x-vCalendar;charset="+document.characterSet)}return saveAs(g,e+f),h}}};