fixing issue with IE11

This commit is contained in:
Jason Salzman
2017-01-23 19:28:39 -08:00
parent a718d883a7
commit b4a1337142
5 changed files with 14982 additions and 14929 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Jason Salzman Copyright (c) 2016-2017 Jason Salzman
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -88,4 +88,4 @@ The examples are hosted within the docs folder and are ran in the simple add tha
## License ## License
Copyright (c) 2016 Jason Salzman. Licensed under MIT license, see [LICENSE](LICENSE) for the full license. Copyright (c) 2016-2017 Jason Salzman. Licensed under MIT license, see [LICENSE](LICENSE) for the full license.
+14899 -14847
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -2,7 +2,7 @@
"author": "Jason Salzman", "author": "Jason Salzman",
"name": "react-add-to-calendar", "name": "react-add-to-calendar",
"description": "A simple and reusable add to calendar button component for React", "description": "A simple and reusable add to calendar button component for React",
"version": "0.0.6", "version": "0.0.7",
"license": "MIT", "license": "MIT",
"homepage": "https://github.com/jasonsalzman/react-add-to-calendar", "homepage": "https://github.com/jasonsalzman/react-add-to-calendar",
"repository": { "repository": {
+68 -67
View File
@@ -1,24 +1,22 @@
import React, { import React, {Component} from 'react';
Component,
} from 'react';
import helpersClass from './helpers'; import helpersClass from './helpers';
const helpers = new helpersClass(); const helpers = new helpersClass();
export default class ReactAddToCalendar extends React.Component { export default class ReactAddToCalendar extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
optionsOpen: false, optionsOpen: false,
isCrappyIE: false isCrappyIE: false
}; };
this.toggleCalendarDropdown = this.toggleCalendarDropdown.bind(this); this.toggleCalendarDropdown = this.toggleCalendarDropdown.bind(this);
this.handleDropdownLinkClick = this.handleDropdownLinkClick.bind(this); this.handleDropdownLinkClick = this.handleDropdownLinkClick.bind(this);
} }
componentWillMount() { componentWillMount() {
let isCrappyIE = false; let isCrappyIE = false;
if (typeof window !== 'undefined' && window.navigator.msSaveOrOpenBlob && window.Blob) { if (typeof window !== 'undefined' && window.navigator.msSaveOrOpenBlob && window.Blob) {
isCrappyIE = true; isCrappyIE = true;
@@ -28,13 +26,13 @@ export default class ReactAddToCalendar extends React.Component {
} }
toggleCalendarDropdown() { toggleCalendarDropdown() {
let showOptions = !this.state.optionsOpen; let showOptions = !this.state.optionsOpen;
if (showOptions) { if (showOptions) {
document.addEventListener('click', this.toggleCalendarDropdown, false); document.addEventListener('click', this.toggleCalendarDropdown, false);
} else { } else {
document.removeEventListener('click', this.toggleCalendarDropdown); document.removeEventListener('click', this.toggleCalendarDropdown);
} }
this.setState({optionsOpen: showOptions}); this.setState({optionsOpen: showOptions});
} }
@@ -43,8 +41,7 @@ export default class ReactAddToCalendar extends React.Component {
e.preventDefault(); e.preventDefault();
let url = e.currentTarget.getAttribute('href'); let url = e.currentTarget.getAttribute('href');
if (this.state.isCrappyIE && (e.currentTarget.getAttribute('class') === 'ical-link' || if (this.state.isCrappyIE) {
e.currentTarget.getAttribute('class') === 'outlook-calendar-link')) {
let blob = new Blob([url], {type: 'text/calendar'}); let blob = new Blob([url], {type: 'text/calendar'});
window.navigator.msSaveOrOpenBlob(blob, 'download.ics'); window.navigator.msSaveOrOpenBlob(blob, 'download.ics');
} else { } else {
@@ -63,15 +60,15 @@ export default class ReactAddToCalendar extends React.Component {
let icon = null; let icon = null;
if (self.props.displayItemIcons) { if (self.props.displayItemIcons) {
let currentIcon = (currentItem === 'outlook') ? 'windows' : currentItem; let currentIcon = (currentItem === 'outlook')
? 'windows'
: currentItem;
icon = <i className={'fa fa-' + currentIcon}/>; icon = <i className={'fa fa-' + currentIcon}/>;
} }
return ( return (
<li key={helpers.getRandomKey()}> <li key={helpers.getRandomKey()}>
<a className={currentItem + '-link'} onClick={self.handleDropdownLinkClick} <a className={currentItem + '-link'} onClick={self.handleDropdownLinkClick} href={helpers.buildUrl(self.props.event, currentItem, self.state.isCrappyIE)} target="_blank">
href={helpers.buildUrl(self.props.event, currentItem, self.state.isCrappyIE)}
target="_blank">
{icon} {icon}
{currentLabel}</a> {currentLabel}</a>
</li> </li>
@@ -97,20 +94,22 @@ export default class ReactAddToCalendar extends React.Component {
let buttonIconClass = 'react-add-to-calendar__icon--' + iconPlacement + ' fa fa-'; let buttonIconClass = 'react-add-to-calendar__icon--' + iconPlacement + ' fa fa-';
if (template[0] === 'caret') { if (template[0] === 'caret') {
buttonIconClass += (this.state.optionsOpen) ? 'caret-up' : 'caret-down'; buttonIconClass += (this.state.optionsOpen)
? 'caret-up'
: 'caret-down';
} else { } else {
buttonIconClass += template[0]; buttonIconClass += template[0];
} }
buttonIcon = <i className={buttonIconClass}/>; buttonIcon = <i className={buttonIconClass}/>;
buttonLabel = (iconPlacement === 'right') ? buttonLabel = (iconPlacement === 'right')
( ? (
<span> <span>
{buttonLabel + ' '} {buttonLabel + ' '}
{buttonIcon} {buttonIcon}
</span> </span>
) : )
( : (
<span> <span>
{buttonIcon} {buttonIcon}
{' ' + buttonLabel} {' ' + buttonLabel}
@@ -118,18 +117,19 @@ export default class ReactAddToCalendar extends React.Component {
); );
} }
let buttonClass = (this.state.optionsOpen) ? this.props.buttonClassClosed + ' ' + this.props.buttonClassOpen : this.props.buttonClassClosed; let buttonClass = (this.state.optionsOpen)
? this.props.buttonClassClosed + ' ' + this.props.buttonClassOpen
: this.props.buttonClassClosed;
return ( return (
<div className={this.props.buttonWrapperClass}> <div className={this.props.buttonWrapperClass}>
<a className={buttonClass} <a className={buttonClass} onClick={this.toggleCalendarDropdown}>{buttonLabel}</a>
onClick={this.toggleCalendarDropdown}>{buttonLabel}</a>
</div> </div>
); );
} }
render() { render() {
let options = null; let options = null;
if (this.state.optionsOpen) { if (this.state.optionsOpen) {
options = this.renderDropdown(); options = this.renderDropdown();
} }
@@ -145,50 +145,51 @@ export default class ReactAddToCalendar extends React.Component {
{options} {options}
</div> </div>
); );
} }
} }
ReactAddToCalendar.displayName = 'Add To Calendar'; ReactAddToCalendar.displayName = 'Add To Calendar';
ReactAddToCalendar.propTypes = { ReactAddToCalendar.propTypes = {
buttonClassClosed: React.PropTypes.string, buttonClassClosed: React.PropTypes.string,
buttonClassOpen: React.PropTypes.string, buttonClassOpen: React.PropTypes.string,
buttonLabel: React.PropTypes.string, buttonLabel: React.PropTypes.string,
buttonTemplate: React.PropTypes.object, buttonTemplate: React.PropTypes.object,
buttonWrapperClass: React.PropTypes.string, buttonWrapperClass: React.PropTypes.string,
displayItemIcons: React.PropTypes.bool, displayItemIcons: React.PropTypes.bool,
dropdownClass: React.PropTypes.string, dropdownClass: React.PropTypes.string,
event: React.PropTypes.shape({ event: React.PropTypes.shape({title: React.PropTypes.string, description: React.PropTypes.string, location: React.PropTypes.string, startTime: React.PropTypes.string, endTime: React.PropTypes.string}).isRequired,
title: React.PropTypes.string,
description: React.PropTypes.string,
location: React.PropTypes.string,
startTime: React.PropTypes.string,
endTime: React.PropTypes.string
}).isRequired,
listItems: React.PropTypes.arrayOf(React.PropTypes.object), listItems: React.PropTypes.arrayOf(React.PropTypes.object),
rootClass: React.PropTypes.string rootClass: React.PropTypes.string
}; };
ReactAddToCalendar.defaultProps = { ReactAddToCalendar.defaultProps = {
buttonClassClosed: 'react-add-to-calendar__button', buttonClassClosed: 'react-add-to-calendar__button',
buttonClassOpen: 'react-add-to-calendar__button--light', buttonClassOpen: 'react-add-to-calendar__button--light',
buttonLabel: 'Add to My Calendar', buttonLabel: 'Add to My Calendar',
buttonTemplate: { caret: 'right' }, buttonTemplate: {
buttonWrapperClass: 'react-add-to-calendar__wrapper', caret: 'right'
displayItemIcons: true, },
dropdownClass: 'react-add-to-calendar__dropdown', buttonWrapperClass: 'react-add-to-calendar__wrapper',
event: { displayItemIcons: true,
title: 'Sample Event', dropdownClass: 'react-add-to-calendar__dropdown',
description: 'This is the sample event provided as an example only', event: {
location: 'Portland, OR', title: 'Sample Event',
startTime: '2016-09-16T20:15:00-04:00', description: 'This is the sample event provided as an example only',
endTime: '2016-09-16T21:45:00-04:00' location: 'Portland, OR',
}, startTime: '2016-09-16T20:15:00-04:00',
endTime: '2016-09-16T21:45:00-04:00'
},
listItems: [ listItems: [
{ apple: 'Apple Calendar' }, {
{ google: 'Google' }, apple: 'Apple Calendar'
{ outlook: 'Outlook' }, }, {
{ yahoo: 'Yahoo' } google: 'Google'
}, {
outlook: 'Outlook'
}, {
yahoo: 'Yahoo'
}
], ],
rootClass: 'react-add-to-calendar' rootClass: 'react-add-to-calendar'
}; };