Skip to content

Commit 6479810

Browse files
Support for multiple events
1 parent ea3f1d9 commit 6479810

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

src/helpers/index.js

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,60 @@ export default class helpers {
7070
break;
7171

7272
default:
73-
calendarUrl = [
74-
"BEGIN:VCALENDAR",
75-
"VERSION:2.0",
76-
"BEGIN:VEVENT",
77-
"URL:" + document.URL,
78-
"DTSTART:" + this.formatTime(event.startTime),
79-
"DTEND:" + this.formatTime(event.endTime),
80-
"SUMMARY:" + event.title,
81-
"DESCRIPTION:" + event.description,
82-
"LOCATION:" + event.location,
83-
"END:VEVENT",
84-
"END:VCALENDAR"
85-
].join("\n");
73+
if (event.constructor === Array) {
74+
event.map(el => {
75+
calendarUrl =
76+
[
77+
...calendarUrl,
78+
"BEGIN:VEVENT",
79+
"URL:" + document.URL,
80+
"DTSTART:" + this.formatTime(el.startTime),
81+
"DTEND:" + this.formatTime(el.endTime),
82+
"SUMMARY:" + el.title,
83+
"DESCRIPTION:" + el.description,
84+
"LOCATION:" + el.location,
85+
"END:VEVENT",
86+
]
87+
})
88+
calendarUrl.unshift( "BEGIN:VCALENDAR","VERSION:2.0")
89+
calendarUrl.push("END:VCALENDAR")
90+
var calAux = calendarUrl
91+
92+
calAux.map(el => {
93+
calendarUrl = [...calAux ,el].join("\n")
94+
})
95+
} else {
96+
calendarUrl = [
97+
"BEGIN:VCALENDAR",
98+
"VERSION:2.0",
99+
"BEGIN:VEVENT",
100+
"URL:" + document.URL,
101+
"DTSTART:" + this.formatTime(event.startTime),
102+
"DTEND:" + this.formatTime(event.endTime),
103+
"SUMMARY:" + event.title,
104+
"DESCRIPTION:" + event.description,
105+
"LOCATION:" + event.location,
106+
"END:VEVENT",
107+
"END:VCALENDAR"
108+
].join("\n");
109+
}
110+
86111

87112
if (!isCrappyIE && this.isMobile()) {
88113
calendarUrl = encodeURI(
89114
"data:text/calendar;charset=utf8," + calendarUrl
90115
);
91116
}
92117
}
93-
118+
console.log(calendarUrl)
94119
return calendarUrl;
95120
}
96121

97122
// determine if a mobile browser is being used
98123
isMobile() {
99124
let mobile = false;
100125

101-
(function(a) {
126+
(function (a) {
102127
if (
103128
/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
104129
a

0 commit comments

Comments
 (0)