UNPKG

vue-add-to-calendar

Version:

A Vue.js component providing 'Add to Calendar' functionality

6 lines 2.09 kB
/*! * vue-add-to-calendar v1.0.7 * (c) 2021 nicolasbeauvais * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueAddToCalendar=e()}(this,function(){"use strict";var t={template:'<a :href="$parent.calendarUrl(calendar)" :class="calendarClass" target="_blank"><slot></slot></a>',computed:{calendarClass:function(){return["vue-add-to-calendar",this.calendar+"-calendar"]}}},e={google:{url:"http://www.google.com/calendar/render?action=TEMPLATE&trp=false",parameters:function(t,e,a,n,r){var o={text:t,location:e,details:a};return n&&r&&(o.dates=n+"/"+r),o}},microsoft:{url:"https://outlook.live.com/owa/?rru=addevent",parameters:function(t,e,a,n,r){return{subject:t,location:e,body:a,startdt:n,enddt:r}}},office365:{url:"https://outlook.office.com/owa/?path=/calendar/action/compose&rru=addevent",parameters:function(t,e,a,n,r){return{subject:t,location:e,body:a,startdt:n,enddt:r}}}},a={props:{title:{type:String,default:""},location:{type:String,default:""},details:{type:String,default:""},start:{type:Date,default:null},end:{type:Date,default:null}},data:function(){return{calendars:e}},methods:{calendarUrl:function(t){var e=this.calendars[t].url,a=this.calendars[t].parameters(this.formatString(this.title),this.formatString(this.location),this.formatString(this.details),this.formatDate(this.start),this.formatDate(this.end));for(var n in a)a.hasOwnProperty(n)&&a[n]&&(e+="&"+n+"="+a[n]);return e},formatString:function(t){return encodeURIComponent(t).replace(/%20/g,"+")},formatDate:function(t){return t?t.toISOString().replace(/-|:|\.\d+/g,""):null}},mounted:function(){},components:{"google-calendar":{mixins:[t],data:function(){return{calendar:"google"}}},"microsoft-calendar":{mixins:[t],data:function(){return{calendar:"microsoft"}}},"office365-calendar":{mixins:[t],data:function(){return{calendar:"office365"}}}}};return a.version="1.0.7",a.install=function(t){t.component("add-to-calendar",a)},"undefined"!=typeof window&&(window.AddToCalendar=a),a});