Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b479d03dff | ||
|
|
6369bb98f3 | ||
|
|
efb5222403 |
@@ -8,9 +8,10 @@ Now you can make calendar friendly files client-side. It outputs .ics files, so
|
||||
How To Use
|
||||
----------
|
||||
Simply use invoke the object and use the functions...
|
||||
|
||||
|
||||
var cal = ics();
|
||||
cal.addEvent(subject, description, location, begin, end);
|
||||
cal.addEvent(subject, description, location, begin, end); // yes, you can have multiple events :-)
|
||||
cal.download(filename);
|
||||
|
||||
`begin` and `end` need to be formatted in a way that is friendly to `Date()`
|
||||
@@ -52,3 +53,9 @@ Supported Browsers
|
||||
| Opera Next | [FileSaver.js](https://github.com/eligrey/FileSaver.js) |
|
||||
| Opera < 15 | [FileSaver.js](https://github.com/eligrey/FileSaver.js), [Blob.js](https://github.com/eligrey/Blob.js) |
|
||||
| Safari ≤ 6 | [FileSaver.js](https://github.com/eligrey/FileSaver.js), [Blob.js](https://github.com/eligrey/Blob.js) |
|
||||
|
||||
|
||||
Credits
|
||||
------------------
|
||||
* [Travis Krause](https://github.com/nwcell): Me
|
||||
* [Kyle Hornberg](https://github.com/khornberg): Added multi event functionality and made everything a package firendly
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "ics.js",
|
||||
"main": "ics.js",
|
||||
"version": "0.1.1",
|
||||
"homepage": "https://github.com/khornberg/ics.js",
|
||||
"version": "0.1.3",
|
||||
"homepage": "https://github.com/nwcell/ics.js",
|
||||
"contributors": [
|
||||
"Travis Krause <[email protected]>",
|
||||
"Kyle Hornberg <[email protected]>"
|
||||
|
||||
+6
-2
@@ -40,12 +40,16 @@
|
||||
background-color: #428bca;
|
||||
border-color: #357ebd;
|
||||
font-family: sans-serif;
|
||||
width: 120px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<a href="javascript:cal.download('christmas')">Download iCal</a>
|
||||
Look at the console too!
|
||||
<a href="javascript:cal_single.download('Awesome Day')">Single Event</a>
|
||||
<br>
|
||||
<a href="javascript:cal.download('Holidays')">Multiple Events</a>
|
||||
<br>
|
||||
<a href="javascript:makelogs(cal)">Console Output</a>
|
||||
</div>
|
||||
</html>
|
||||
|
||||
+16
-2
@@ -2,5 +2,19 @@
|
||||
var cal = ics();
|
||||
cal.addEvent('Christmas', 'Christian holiday celebrating the birth of Jesus Christ', 'Bethlehem', '12/25/2013', '12/25/2013');
|
||||
cal.addEvent('Christmas', 'Christian holiday celebrating the birth of Jesus Christ', 'Bethlehem', '12/25/2014', '12/25/2014');
|
||||
console.log('Events\n' + cal.events());
|
||||
console.log('Calendar\n' + cal.calendar());
|
||||
cal.addEvent('New Years', 'Watch the ball drop!', 'New York', '01/01/2015', '01/01/2015');
|
||||
cal.addEvent('New Years', 'Watch the ball drop!', 'New York', '01/01/2016', '01/01/2016');
|
||||
|
||||
var cal_single = ics();
|
||||
cal_single.addEvent('Best Day', 'This is the best day to demonstrate a single event.', 'New York', '11/12/1987', '11/12/1987');
|
||||
|
||||
|
||||
// You can use this for easy debugging
|
||||
var makelogs = function(obj) {
|
||||
console.log('Events Array');
|
||||
console.log('=================');
|
||||
console.log(obj.events());
|
||||
console.log('Calendar With Header');
|
||||
console.log('=================');
|
||||
console.log(obj.calendar());
|
||||
}
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
@@ -2,96 +2,126 @@
|
||||
/* exported ics */
|
||||
|
||||
var ics = function() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
if (navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('MSIE 10') == -1) {
|
||||
console.log('Unsupported Browser');
|
||||
return;
|
||||
}
|
||||
if (navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('MSIE 10') == -1) {
|
||||
console.log('Unsupported Browser');
|
||||
return;
|
||||
}
|
||||
|
||||
var SEPARATOR = (navigator.appVersion.indexOf('Win') !== -1) ? '\r\n' : '\n';
|
||||
var calendarEvents = [];
|
||||
var calendarStart = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0'
|
||||
].join(SEPARATOR);
|
||||
var calendarEnd = SEPARATOR + 'END:VCALENDAR';
|
||||
var SEPARATOR = (navigator.appVersion.indexOf('Win') !== -1) ? '\r\n' : '\n';
|
||||
var calendarEvents = [];
|
||||
var calendarStart = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0'
|
||||
].join(SEPARATOR);
|
||||
var calendarEnd = SEPARATOR + 'END:VCALENDAR';
|
||||
|
||||
return {
|
||||
/**
|
||||
* Returns events array
|
||||
* @return {array} Events
|
||||
*/
|
||||
'events' : function () {
|
||||
return calendarEvents;
|
||||
},
|
||||
return {
|
||||
/**
|
||||
* Returns events array
|
||||
* @return {array} Events
|
||||
*/
|
||||
'events': function() {
|
||||
return calendarEvents;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns calendar
|
||||
* @return {string} Calendar in iCalendar format
|
||||
*/
|
||||
'calendar' : function () {
|
||||
return calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
|
||||
},
|
||||
/**
|
||||
* Returns calendar
|
||||
* @return {string} Calendar in iCalendar format
|
||||
*/
|
||||
'calendar': function() {
|
||||
return calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add event to the calendar
|
||||
* @param {string} subject Subject/Title of event
|
||||
* @param {string} description Description of event
|
||||
* @param {string} location Location of event
|
||||
* @param {string} begin Beginning date of event
|
||||
* @param {string} stop Ending date of event
|
||||
*/
|
||||
'addEvent' : function (subject, description, location, begin, stop) {
|
||||
//TODO add time and time zone? use moment to format?
|
||||
var start_date = new Date(begin);
|
||||
var end_date = new Date(stop);
|
||||
/**
|
||||
* Add event to the calendar
|
||||
* @param {string} subject Subject/Title of event
|
||||
* @param {string} description Description of event
|
||||
* @param {string} location Location of event
|
||||
* @param {string} begin Beginning date of event
|
||||
* @param {string} stop Ending date of event
|
||||
*/
|
||||
'addEvent': function(subject, description, location, begin, stop) {
|
||||
// I'm not in the mood to make these optional... So they are all required
|
||||
if (typeof subject === 'undefined' ||
|
||||
typeof description === 'undefined' ||
|
||||
typeof location === 'undefined' ||
|
||||
typeof begin === 'undefined' ||
|
||||
typeof stop === 'undefined'
|
||||
) {
|
||||
return false;
|
||||
};
|
||||
|
||||
var start_year = ('0000' + (start_date.getFullYear().toString())).slice(-4);
|
||||
var start_month = ('00' + ((start_date.getMonth() + 1).toString())).slice(-2);
|
||||
var start_day = ('00' + (start_date.getDate().toString())).slice(-2);
|
||||
var start = start_year + start_month + start_day;
|
||||
//TODO add time and time zone? use moment to format?
|
||||
var start_date = new Date(begin);
|
||||
var end_date = new Date(stop);
|
||||
|
||||
var end_year = ('0000' + (end_date.getFullYear().toString())).slice(-4);
|
||||
var end_month = ('00' + ((end_date.getMonth() + 1).toString())).slice(-2);
|
||||
var end_day = ('00' + (end_date.getDate().toString())).slice(-2);
|
||||
var end = end_year + end_month + end_day;
|
||||
var start_year = ("0000" + (start_date.getFullYear().toString())).slice(-4);
|
||||
var start_month = ("00" + ((start_date.getMonth() + 1).toString())).slice(-2);
|
||||
var start_day = ("00" + ((start_date.getDate()).toString())).slice(-2);
|
||||
var start_hours = ("00" + (start_date.getHours().toString())).slice(-2);
|
||||
var start_minutes = ("00" + (start_date.getMinutes().toString())).slice(-2);
|
||||
var start_seconds = ("00" + (start_date.getMinutes().toString())).slice(-2);
|
||||
|
||||
var calendarEvent = [
|
||||
'BEGIN:VEVENT',
|
||||
'CLASS:PUBLIC',
|
||||
'DESCRIPTION:'+description,
|
||||
'DTSTART;VALUE=DATE:'+start,
|
||||
'DTEND;VALUE=DATE:'+end,
|
||||
'LOCATION:'+location,
|
||||
'SUMMARY;LANGUAGE=en-us:'+subject,
|
||||
'TRANSP:TRANSPARENT',
|
||||
'END:VEVENT'
|
||||
].join(SEPARATOR);
|
||||
var end_year = ("0000" + (end_date.getFullYear().toString())).slice(-4);
|
||||
var end_month = ("00" + ((end_date.getMonth() + 1).toString())).slice(-2);
|
||||
var end_day = ("00" + ((end_date.getDate()).toString())).slice(-2);
|
||||
var end_hours = ("00" + (end_date.getHours().toString())).slice(-2);
|
||||
var end_minutes = ("00" + (end_date.getMinutes().toString())).slice(-2);
|
||||
var end_seconds = ("00" + (end_date.getMinutes().toString())).slice(-2);
|
||||
|
||||
calendarEvents.push(calendarEvent);
|
||||
},
|
||||
// Since some calendars don't add 0 second events, we need to remove time if there is none...
|
||||
var start_time = '';
|
||||
var end_time = '';
|
||||
if (start_minutes + start_seconds + end_minutes + end_seconds != 0) {
|
||||
start_time = 'T' + start_hours + start_minutes + start_seconds;
|
||||
end_time = 'T' + end_hours + end_minutes + end_seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download calendar using the saveAs function from filesave.js
|
||||
* @param {string} filename Filename
|
||||
* @param {string} ext Extention
|
||||
*/
|
||||
'download' : function (filename, ext) {
|
||||
ext = (typeof ext !== 'undefined') ? ext : '.ics';
|
||||
filename = (typeof filename !== 'undefined') ? filename : 'calendar';
|
||||
var calendar = calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
|
||||
var start = start_year + start_month + start_day + start_time;
|
||||
var end = end_year + end_month + end_day + end_time;
|
||||
|
||||
var blob;
|
||||
if (navigator.userAgent.indexOf('MSIE 10') === -1) { // chrome or firefox
|
||||
blob = new Blob([calendar]);
|
||||
}
|
||||
else { // ie
|
||||
var bb = new BlobBuilder();
|
||||
bb.append(calendar);
|
||||
blob = bb.getBlob('text/x-vCalendar;charset=' + document.characterSet);
|
||||
}
|
||||
saveAs(blob, filename+ext);
|
||||
}
|
||||
};
|
||||
var calendarEvent = [
|
||||
'BEGIN:VEVENT',
|
||||
'CLASS:PUBLIC',
|
||||
'DESCRIPTION:' + description,
|
||||
'DTSTART;VALUE=DATE:' + start,
|
||||
'DTEND;VALUE=DATE:' + end,
|
||||
'LOCATION:' + location,
|
||||
'SUMMARY;LANGUAGE=en-us:' + subject,
|
||||
'TRANSP:TRANSPARENT',
|
||||
'END:VEVENT'
|
||||
].join(SEPARATOR);
|
||||
|
||||
calendarEvents.push(calendarEvent);
|
||||
return calendarEvent;
|
||||
},
|
||||
|
||||
/**
|
||||
* Download calendar using the saveAs function from filesave.js
|
||||
* @param {string} filename Filename
|
||||
* @param {string} ext Extention
|
||||
*/
|
||||
'download': function(filename, ext) {
|
||||
if (calendarEvents.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ext = (typeof ext !== 'undefined') ? ext : '.ics';
|
||||
filename = (typeof filename !== 'undefined') ? filename : 'calendar';
|
||||
var calendar = calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
|
||||
|
||||
var blob;
|
||||
if (navigator.userAgent.indexOf('MSIE 10') === -1) { // chrome or firefox
|
||||
blob = new Blob([calendar]);
|
||||
} else { // ie
|
||||
var bb = new BlobBuilder();
|
||||
bb.append(calendar);
|
||||
blob = bb.getBlob('text/x-vCalendar;charset=' + document.characterSet);
|
||||
}
|
||||
saveAs(blob, filename + ext);
|
||||
return calendar;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Vendored
+2
-2
@@ -1,2 +1,2 @@
|
||||
/*! ics.js Thu Dec 19 2013 14:54:06 */
|
||||
var ics=function(){"use strict";if(navigator.userAgent.indexOf("MSIE")>-1&&-1==navigator.userAgent.indexOf("MSIE 10"))return console.log("Unsupported Browser"),void 0;var a=-1!==navigator.appVersion.indexOf("Win")?"\r\n":"\n",b=[],c=["BEGIN:VCALENDAR","VERSION:2.0"].join(a),d=a+"END:VCALENDAR";return{events:function(){return b},calendar:function(){return c+a+b.join(a)+d},addEvent:function(c,d,e,f,g){var h=new Date(f),i=new Date(g),j=("0000"+h.getFullYear().toString()).slice(-4),k=("00"+(h.getMonth()+1).toString()).slice(-2),l=("00"+h.getDate().toString()).slice(-2),m=j+k+l,n=("0000"+i.getFullYear().toString()).slice(-4),o=("00"+(i.getMonth()+1).toString()).slice(-2),p=("00"+i.getDate().toString()).slice(-2),q=n+o+p,r=["BEGIN:VEVENT","CLASS:PUBLIC","DESCRIPTION:"+d,"DTSTART;VALUE=DATE:"+m,"DTEND;VALUE=DATE:"+q,"LOCATION:"+e,"SUMMARY;LANGUAGE=en-us:"+c,"TRANSP:TRANSPARENT","END:VEVENT"].join(a);b.push(r)},download:function(e,f){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)}saveAs(g,e+f)}}};
|
||||
/*! ics.js March 11, 2014 */
|
||||
var ics=function(){"use strict";if(navigator.userAgent.indexOf("MSIE")>-1&&navigator.userAgent.indexOf("MSIE 10")==-1){console.log("Unsupported Browser");return}var e=navigator.appVersion.indexOf("Win")!==-1?"\r\n":"\n";var t=[];var n=["BEGIN:VCALENDAR","VERSION:2.0"].join(e);var r=e+"END:VCALENDAR";return{events:function(){return t},calendar:function(){return n+e+t.join(e)+r},addEvent:function(n,r,i,s,o){if(typeof n==="undefined"||typeof r==="undefined"||typeof i==="undefined"||typeof s==="undefined"||typeof o==="undefined"){return false}var u=new Date(s);var a=new Date(o);var f=("0000"+u.getFullYear().toString()).slice(-4);var l=("00"+(u.getMonth()+1).toString()).slice(-2);var c=("00"+u.getDate().toString()).slice(-2);var h=("00"+u.getHours().toString()).slice(-2);var p=("00"+u.getMinutes().toString()).slice(-2);var d=("00"+u.getMinutes().toString()).slice(-2);var v=("0000"+a.getFullYear().toString()).slice(-4);var m=("00"+(a.getMonth()+1).toString()).slice(-2);var g=("00"+a.getDate().toString()).slice(-2);var y=("00"+a.getHours().toString()).slice(-2);var b=("00"+a.getMinutes().toString()).slice(-2);var w=("00"+a.getMinutes().toString()).slice(-2);var E="";var S="";if(p+d+b+w!=0){E="T"+h+p+d;S="T"+y+b+w}var x=f+l+c+E;var T=v+m+g+S;var N=["BEGIN:VEVENT","CLASS:PUBLIC","DESCRIPTION:"+r,"DTSTART;VALUE=DATE:"+x,"DTEND;VALUE=DATE:"+T,"LOCATION:"+i,"SUMMARY;LANGUAGE=en-us:"+n,"TRANSP:TRANSPARENT","END:VEVENT"].join(e);t.push(N);return N},download:function(i,s){if(t.length<1){return false}s=typeof s!=="undefined"?s:".ics";i=typeof i!=="undefined"?i:"calendar";var o=n+e+t.join(e)+r;var u;if(navigator.userAgent.indexOf("MSIE 10")===-1){u=new Blob([o])}else{var a=new BlobBuilder;a.append(o);u=a.getBlob("text/x-vCalendar;charset="+document.characterSet)}saveAs(u,i+s);return o}}}
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ics.js",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.3",
|
||||
"description": "A browser firendly .ics/.vcs file generator written entirely in javascript",
|
||||
"main": "icsjs",
|
||||
"dependencies": {
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/khornberg/ics.js.git"
|
||||
"url": "https://github.com/nwcell/ics.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ics",
|
||||
@@ -30,6 +30,6 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/khornberg/ics.js/issues"
|
||||
"url": "https://github.com/nwcell/ics.js/issues"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user