Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-addtocalendar

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-addtocalendar - npm Package Compare versions

Comparing version 1.1.6 to 1.2.0

coverage/Chrome 51.0.2704 (Mac OS X 10.10.5)/lcov-report/addtocalendar/addtocalendar.js.html

2

addtocalendar.min.js

@@ -1,1 +0,1 @@

var forEachAttr=function(attrs,cb){for(key in attrs){if(attrs.hasOwnProperty(key)&&key.indexOf("$")===-1){cb(key,attrs[key])}}};"use strict";var formatIcsText=function(s,maxLength){function _wrap(s){if(s.length<=maxLength){return s}return s.substring(0,maxLength).replace(/\n/g,"\\n")+"\r\n "+_wrap(s.substring(maxLength),75)}return _wrap(s.replace(/\n/g,"\\n"),maxLength)};"use strict";var addtocalendar=angular.module("jshor.angular-addtocalendar",[]);"use strict";addtocalendar.config(["$compileProvider",function($compileProvider){$compileProvider.aHrefSanitizationWhitelist(/^\s*(http(s)?|data):/)}]);"use strict";addtocalendar.controller("AddtocalendarCtrl",["$scope","$attrs",function($scope,$attrs){$scope.description=$scope.description||"";function getIcsCalendar(){return["BEGIN:VCALENDAR","VERSION:2.0","BEGIN:VEVENT","CLASS:PUBLIC","DESCRIPTION:"+formatIcsText($scope.description,62),"DTSTART:"+$scope.startDate,"DTEND:"+$scope.endDate,"LOCATION:"+formatIcsText($scope.location,64),"SUMMARY:"+formatIcsText($scope.title,66),"TRANSP:TRANSPARENT","END:VEVENT","END:VCALENDAR"].join("\n")}function getYahooCalendarUrl(){var yahooCalendarUrl="http://calendar.yahoo.com/?v=60&view=d&type=20";yahooCalendarUrl+="&title="+encodeURIComponent($scope.title);yahooCalendarUrl+="&st="+encodeURIComponent($scope.startDate)+"&et="+encodeURIComponent($scope.endDate);yahooCalendarUrl+="&desc="+encodeURIComponent($scope.description);yahooCalendarUrl+="&in_loc="+encodeURIComponent($scope.location);return yahooCalendarUrl}function getGoogleCalendarUrl(){var googleCalendarUrl="https://www.google.com/calendar/render?action=TEMPLATE";googleCalendarUrl+="&text="+encodeURIComponent($scope.title);googleCalendarUrl+="&dates="+encodeURIComponent($scope.startDate)+"/"+encodeURIComponent($scope.endDate);googleCalendarUrl+="&details="+encodeURIComponent($scope.description);googleCalendarUrl+="&location="+encodeURIComponent($scope.location);return googleCalendarUrl}function getMicrosoftCalendarUrl(){var microsoftCalendarUrl="http://calendar.live.com/calendar/calendar.aspx?rru=addevent";microsoftCalendarUrl+="&summary="+encodeURIComponent($scope.title);microsoftCalendarUrl+="&dtstart="+encodeURIComponent($scope.startDate)+"&dtend="+encodeURIComponent($scope.endDate);microsoftCalendarUrl+="&description="+encodeURIComponent($scope.description);microsoftCalendarUrl+="&location="+encodeURIComponent($scope.location);return microsoftCalendarUrl}function buildUrl(){$scope.calendarUrl={microsoft:getMicrosoftCalendarUrl(),google:getGoogleCalendarUrl(),yahoo:getYahooCalendarUrl(),icalendar:getIcsCalendar(),dlIcal:dlIcal}}function dlIcal(){var fileName=$scope.title.replace(/[^\w ]+/g,"")+".ics";download(getIcsCalendar(),fileName,"application/octet-stream")}forEachAttr($attrs,function(key){$attrs.$observe(key,function(){buildUrl()})});buildUrl()}]);"use strict";addtocalendar.directive("addtocalendar",function(){function getTemplate(prefix){return' <div class="btn-group dropdown" '+prefix+' on-toggle="toggled(open)"> <span ng-class="className || \'btn btn-sm btn-default '+prefix+"-toggle'\" "+prefix+'-toggle> {{btnText || \'Add to calendar\'}} <span class="caret"></span> </span> <ul class="dropdown-menu"> <li><a ng-click="calendarUrl.dlIcal()">iCalendar</a></li> <li><a href="{{calendarUrl.google}}" target="_blank">Google Calendar</a></li> <li><a ng-click="calendarUrl.dlIcal()">Outlook</a></li> <li><a href="{{calendarUrl.yahoo}}" target="_blank">Yahoo! Calendar</a></li> <li><a href="{{calendarUrl.microsoft}}" target="_blank">Microsoft Calendar</a></li> </ul> </div>'}function resolveTemplate(tElement,tAttrs){if(tAttrs.$attr&&tAttrs.$attr["uibDropdown"]){return getTemplate("uib-dropdown")}return getTemplate("dropdown")}return{restrict:"E",scope:{startDate:"@",endDate:"@",title:"@",description:"@",location:"@",className:"@",btnText:"@"},controller:"AddtocalendarCtrl",template:resolveTemplate}});
var forEachAttr=function(attrs,cb){for(key in attrs){if(attrs.hasOwnProperty(key)&&key.indexOf("$")===-1){cb(key,attrs[key])}}};var formatIcsText=function(s,maxLength){function _wrap(s){if(s.length<=maxLength){return s}return s.substring(0,maxLength).replace(/\n/g,"\\n")+"\r\n "+_wrap(s.substring(maxLength),75)}return _wrap(s.replace(/\n/g,"\\n"),maxLength)};function formatTime(timestamp,format){var formats=["YYYYMMDD","HHmmss"];var date=function(){if(format){return new moment(timestamp,format)}return new moment(timestamp)}();return formats.map(function(format){return date.format(format)}).join("T")}function getMilitaryHours(hours){if(hours<10){hours="0"+hours}return hours+"00"}function getHoursDuration(startDate,endDate,timezone){var start=new moment(startDate);var end=new moment(endDate);if(timezone){start.utcOffset(timezone);end.utcOffset(timezone)}var hours=moment.duration(end.diff(start)).asHours();return getMilitaryHours(hours)}function getIcsBlob(icsData){return new Blob([icsData],{type:"application/octet-stream"})}function getIcsFileName(title){return title.replace(/[^\w ]+/g,"")+".ics"}function offsetTimezone(timestamp,timezone){}function getGoogleCalendarUrl(data){var googleCalendarUrl="https://www.google.com/calendar/render?action=TEMPLATE";googleCalendarUrl+="&text="+data.title;googleCalendarUrl+="&dates="+data.startDate+"/"+data.endDate;googleCalendarUrl+="&details="+data.description;googleCalendarUrl+="&location="+data.location;return googleCalendarUrl}function getIcsCalendar(data){return["BEGIN:VCALENDAR","VERSION:2.0","BEGIN:VEVENT","CLASS:PUBLIC","DESCRIPTION:"+formatIcsText(data.description,62),"DTSTART:"+data.startDate,"DTEND:"+data.endDate,"LOCATION:"+formatIcsText(data.location,64),"SUMMARY:"+formatIcsText(data.title,66),"TRANSP:TRANSPARENT","END:VEVENT","END:VCALENDAR"].join("\n")}function getMicrosoftCalendarUrl(data){var microsoftCalendarUrl="http://calendar.live.com/calendar/calendar.aspx?rru=addevent";microsoftCalendarUrl+="&summary="+data.title;microsoftCalendarUrl+="&dtstart="+data.startDate+"&dtend="+data.endDate;microsoftCalendarUrl+="&description="+data.description;microsoftCalendarUrl+="&location="+data.location;return microsoftCalendarUrl}function getYahooCalendarUrl(data){var yahooCalendarUrl="http://calendar.yahoo.com/?v=60&view=d&type=20";var duration=getHoursDuration(data.startDate,data.endDate);yahooCalendarUrl+="&TITLE="+data.title;yahooCalendarUrl+="&ST="+data.startDate+"&DUR="+duration;yahooCalendarUrl+="&DESC="+data.description;yahooCalendarUrl+="&in_loc="+data.location;return yahooCalendarUrl}"use strict";var addtocalendar=angular.module("jshor.angular-addtocalendar",["ngFileSaver"]);"use strict";addtocalendar.config(["$compileProvider",function($compileProvider){$compileProvider.aHrefSanitizationWhitelist(/^\s*(http(s)?|data):/)}]);"use strict";addtocalendar.controller("AddtocalendarCtrl",["$scope","$attrs","FileSaver",function($scope,$attrs,FileSaver){var dates={};$scope.description=$scope.description||"";function setTimesFromFormat(){var format=$scope.format;var timezone=$scope.timezone;["startDate","endDate"].forEach(function(t){dates[t]=formatTime($scope[t],format,timezone)})}function getSanitizedData(){var urlData={};forEachAttr($scope,function(key){urlData[key]=encodeURIComponent($scope[key])});return urlData}function buildUrl(){var urlData=angular.extend(getSanitizedData(),dates);$scope.calendarUrl={microsoft:getMicrosoftCalendarUrl(urlData),google:getGoogleCalendarUrl(urlData),yahoo:getYahooCalendarUrl(urlData),icalendar:getIcsCalendar($scope),dlIcal:dlIcal}}function dlIcal(){var fileName=getIcsFileName($scope.title);var icsData=$scope.calendarUrl.icalendar;var icsBlob=getIcsBlob(icsData);FileSaver.saveAs(icsBlob,fileName)}function init(){buildUrl();setTimesFromFormat()}forEachAttr($attrs,function(key){$attrs.$observe(key,init)});init()}]);"use strict";addtocalendar.directive("addtocalendar",function(){function getTemplate(prefix){return' <div class="btn-group dropdown" '+prefix+' on-toggle="toggled(open)"> <span ng-class="className || \'btn btn-sm btn-default '+prefix+"-toggle'\" "+prefix+'-toggle> {{btnText || \'Add to calendar\'}} <span class="caret"></span> </span> <ul class="dropdown-menu"> <li><a ng-click="calendarUrl.dlIcal()" ng-if="calendarUrl.dlIcal">iCalendar</a></li> <li><a href="{{calendarUrl.google}}" target="_blank">Google Calendar</a></li> <li><a ng-click="calendarUrl.dlIcal()" ng-if="calendarUrl.dlIcal">Outlook</a></li> <li><a href="{{calendarUrl.yahoo}}" target="_blank">Yahoo! Calendar</a></li> <li><a href="{{calendarUrl.microsoft}}" target="_blank">Microsoft Calendar</a></li> </ul> </div>'}function resolveTemplate(tElement,tAttrs){if(tAttrs.$attr&&tAttrs.$attr["uibDropdown"]){return getTemplate("uib-dropdown")}return getTemplate("dropdown")}return{restrict:"E",scope:{startDate:"@",endDate:"@",title:"@",description:"@",location:"@",className:"@",btnText:"@"},controller:"AddtocalendarCtrl",template:resolveTemplate}});

@@ -10,64 +10,35 @@ /**

addtocalendar
.controller('AddtocalendarCtrl', ['$scope', '$attrs',
function ($scope, $attrs) {
.controller('AddtocalendarCtrl', ['$scope', '$attrs', 'FileSaver',
function ($scope, $attrs, FileSaver) {
var dates = {};
$scope.description = $scope.description || '';
/**
* Returns file contents for a .ics file.
* @return {String} ics calendar data
*/
function getIcsCalendar() {
return [
'BEGIN:VCALENDAR',
'VERSION:2.0',
'BEGIN:VEVENT',
'CLASS:PUBLIC',
'DESCRIPTION:' + formatIcsText($scope.description, 62),
'DTSTART:' + $scope.startDate,
'DTEND:' + $scope.endDate,
'LOCATION:' + formatIcsText($scope.location, 64),
'SUMMARY:' + formatIcsText($scope.title, 66),
'TRANSP:TRANSPARENT',
'END:VEVENT',
'END:VCALENDAR'
].join('\n');
}
function getYahooCalendarUrl() {
var yahooCalendarUrl = 'http://calendar.yahoo.com/?v=60&view=d&type=20';
yahooCalendarUrl += '&title=' + encodeURIComponent($scope.title);
yahooCalendarUrl += '&st=' + encodeURIComponent($scope.startDate) + '&et=' + encodeURIComponent($scope.endDate);
yahooCalendarUrl += '&desc=' + encodeURIComponent($scope.description);
yahooCalendarUrl += '&in_loc=' + encodeURIComponent($scope.location);
function setTimesFromFormat() {
var format = $scope.format;
var timezone = $scope.timezone;
return yahooCalendarUrl;
['startDate', 'endDate']
.forEach(function(t) {
dates[t] = formatTime($scope[t], format, timezone);
});
}
function getGoogleCalendarUrl() {
var googleCalendarUrl = 'https://www.google.com/calendar/render?action=TEMPLATE';
googleCalendarUrl += '&text=' + encodeURIComponent($scope.title);
googleCalendarUrl += '&dates=' + encodeURIComponent($scope.startDate) + '/' + encodeURIComponent($scope.endDate);
googleCalendarUrl += '&details=' + encodeURIComponent($scope.description);
googleCalendarUrl += '&location=' + encodeURIComponent($scope.location);
return googleCalendarUrl;
function getSanitizedData() {
var urlData = {};
forEachAttr($scope, function(key) {
urlData[key] = encodeURIComponent($scope[key]);
});
return urlData;
}
function getMicrosoftCalendarUrl() {
var microsoftCalendarUrl = 'http://calendar.live.com/calendar/calendar.aspx?rru=addevent';
microsoftCalendarUrl += '&summary=' + encodeURIComponent($scope.title);
microsoftCalendarUrl += '&dtstart=' + encodeURIComponent($scope.startDate) + '&dtend=' + encodeURIComponent($scope.endDate);
microsoftCalendarUrl += '&description=' + encodeURIComponent($scope.description);
microsoftCalendarUrl += '&location=' + encodeURIComponent($scope.location);
function buildUrl() {
var urlData = angular.extend(getSanitizedData(), dates);
return microsoftCalendarUrl;
}
function buildUrl() {
$scope.calendarUrl = {
microsoft: getMicrosoftCalendarUrl(),
google: getGoogleCalendarUrl(),
yahoo: getYahooCalendarUrl(),
icalendar: getIcsCalendar(),
microsoft: getMicrosoftCalendarUrl(urlData),
google: getGoogleCalendarUrl(urlData),
yahoo: getYahooCalendarUrl(urlData),
icalendar: getIcsCalendar($scope),
dlIcal: dlIcal

@@ -77,21 +48,19 @@ };

/**
* Downloads a .ics file for the given parameters.
* The name of the file will be the event title with alphanumeric chars
* having the extension `.ics`.
*/
function dlIcal() {
var fileName = $scope.title.replace(/[^\w ]+/g, '') + '.ics';
download(getIcsCalendar(), fileName, 'application/octet-stream');
var fileName = getIcsFileName($scope.title);
var icsData = $scope.calendarUrl.icalendar;
var icsBlob = getIcsBlob(icsData);
FileSaver.saveAs(icsBlob, fileName);
}
// observe user-specified attributes
function init() {
buildUrl();
setTimesFromFormat();
}
forEachAttr($attrs, function(key) {
$attrs.$observe(key, function() {
buildUrl();
});
$attrs.$observe(key, init);
});
buildUrl();
init();
}
]);

@@ -21,5 +21,5 @@ /**

<ul class="dropdown-menu">\
<li><a ng-click="calendarUrl.dlIcal()">iCalendar</a></li>\
<li><a ng-click="calendarUrl.dlIcal()" ng-if="calendarUrl.dlIcal">iCalendar</a></li>\
<li><a href="{{calendarUrl.google}}" target="_blank">Google Calendar</a></li>\
<li><a ng-click="calendarUrl.dlIcal()">Outlook</a></li>\
<li><a ng-click="calendarUrl.dlIcal()" ng-if="calendarUrl.dlIcal">Outlook</a></li>\
<li><a href="{{calendarUrl.yahoo}}" target="_blank">Yahoo! Calendar</a></li>\

@@ -26,0 +26,0 @@ <li><a href="{{calendarUrl.microsoft}}" target="_blank">Microsoft Calendar</a></li>\

# Changelog
## v1.2.0
- fixes Yahoo! calendar end time issue
- adds support for `timezone` specification
- enables format of timestamp inputs (including source timezone)
- removes download.js and uses FileSaver.js to support iOS/safari
- npm-ignores junk
## v1.1.6

@@ -47,2 +55,6 @@

## v1.0.0
- adds test suite to addtocalendar functions, ensures stability
## v0.0.7

@@ -79,6 +91,2 @@

Initial version
## v1.0.0
- adds test suite to addtocalendar functions, ensures stability
Initial version
{
"name": "angular-addtocalendar",
"version": "1.1.6",
"version": "1.2.0",
"description": "AngularJS directive for adding events to calendar apps",

@@ -8,3 +8,3 @@ "main": "addtocalendar.min.js",

"test": "./node_modules/karma/bin/karma start karma.conf.js --single-run",
"build": "rm -rf ./coverage/ && ./node_modules/uglify-js/bin/uglifyjs lib/*.js addtocalendar/*.js -o addtocalendar.min.js"
"build": "rm -rf ./coverage/ && ./node_modules/uglify-js/bin/uglifyjs lib/*.js lib/**/*.js addtocalendar/*.js -o addtocalendar.min.js"
},

@@ -35,3 +35,3 @@ "repository": {

"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma": "^1.1.0",
"karma-chrome-launcher": "^1.0.1",

@@ -43,7 +43,11 @@ "karma-coverage": "^1.0.0",

"karma-phantomjs-launcher": "^1.0.0",
"karma-sinon": "^1.0.5",
"sinon": "^1.17.4",
"uglify-js": "^2.6.1"
},
"dependencies": {
"angular": "^1.5.3"
"angular": "^1.5.3",
"angular-file-saver": "^1.1.2",
"moment": "^2.14.1"
}
}
# angular-addtocalendar
### v1.1.6
### v1.2.0

@@ -15,25 +15,37 @@ An AngularJS directive for adding an event to calendar apps. It supports .ics files for iCalendar and Outlook and also supports Google Calendar, Yahoo! Calendar and Microsoft Calendar.

bower:
```
bower install angular-addtocalendar
```
npm:
1. Add source
```
npm install angular-addtocalendar
```
bower:
```
bower install angular-addtocalendar --save
```
npm:
You can also [download it directly](https://github.com/jshor/angular-addtocalendar/archive/v1.1.5.tar.gz).
```
npm i angular-addtocalendar --save
```
Inject the dependency `jshor.angular-addtocalendar` into your app:
2. If you're using webpack, you need to require the module.
```
angular
.module('myApp', [
'jshor.angular-addtocalendar',
'ui.bootstrap',
...
]);
```
```javascript
require('angular-addtocalendar');
```
with es6:
```javascript
import 'angular-addtocalendar';
```
3. Inject the dependency `jshor.angular-addtocalendar` into your app:
```javascript
angular
.module('myApp', [
'jshor.angular-addtocalendar',
'ui.bootstrap',
...
]);
```
## Demo

@@ -59,13 +71,19 @@

| **Attribute** | **Description** | **Format** | **Example** | **Required** |
|--------------- |-------------------------------------------------------------------------------------------------------------- |------------------------------------------------------------------------------ |------------------------------------------------------------------------------------------------------------ |-------------- |
| `title` | Name of the event. | Plain text | Fourth of July Fireworks | Yes |
| `description` | Description of the event. | Plain text. Default nil. | Celebrate the independence of the United States with fireworks in one of the greatest cities in the world. | No |
| `location` | Location of the event. | Plain text | Battery Park City, New York, NY | Yes |
| `start-date` | The timestamp of when the event begins. | Date string in format `YYYYMMDDToHHMMSS` | 20150704T190000 | Yes |
| `end-date` | The timestamp of when the event ends. | Date string in format `YYYYMMDDToHHMMSS` | 20150704T210000 | Yes |
| `class-name` | The bootstrap class for the dropdown button ([more info](http://getbootstrap.com/components/#btn-dropdowns)) | Bootstrap class/plain text. Default `btn btn-sm btn-default dropdown-toggle` | btn btn-sm btn-default dropdown-toggle | No |
| `btn-text` | Text for the button to display | Plain text. Default `Add to calendar` | Add to calendar | No |
| `uib-dropdown` | Whether to use ui-bootstrap dropdown | `null` Default `Add to calendar` | `null` | No |
| **Attribute** | **Description** | **Format** | **Example** | **Required** |
|----------------------|-------------------------------------------------------------------------------------------------------------- |------------------------------------------------------------------------------ |------------------------------------------------------------------------------------------------------------ |-------------- |
| `title` | Name of the event. | String | Fourth of July Fireworks | Yes |
| `description` | Description of the event. | String, defaults to empty | Celebrate the independence of the United States with fireworks in one of the greatest cities in the world. | No |
| `location` | Location of the event. | Plain text | Battery Park City, New York, NY | Yes |
| `start-date` | The timestamp of when the event begins. | Date string. Should match format of `end-date` or `format`. | July 4 2017 7:00 PM UTC+500 | Yes |
| `end-date` | The timestamp of when the event ends. | Date string. Should match format of `start-date` or `format`. | July 4 2017 10:00 PM UTC+500 | Yes |
| `format` | The format that the `start-date` and `end-date` are in. May include timezone. | `mm/dd/yyyy hh:mm:ss Z` | `MMMM d YYYY h:m A Z | No |
| `timezone` | Any valid [momentjs UTC offset](http://momentjs.com/docs/#/parsing/utc/) | Moment | America/New_York | No |
| `class-name` | The desired class for the dropdown. See [styling](). | Bootstrap class/plain text. Default `btn btn-sm btn-default dropdown-toggle` | btn btn-sm btn-default dropdown-toggle | No |
| `btn-text` | Text for the button to display | Plain text. Default `Add to calendar` | Add to calendar | No |
| `uib-dropdown` | Whether to use ui-bootstrap dropdown | `null` Default `Add to calendar` | `null` | No |
# Styling
@TODO
## Browser Support

@@ -79,3 +97,3 @@

| Edge | Yes |
| Safari | No |
| Safari | 9+ |
| Firefox | 20.0+ |

@@ -82,0 +100,0 @@ | Opera | 15.0+ |

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc