Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit dc17b75

Browse files
committed
Merge branch 'satya-dash-master'
2 parents 84ba6c0 + 96b1612 commit dc17b75

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ All unprefixed classes (listed below) will be removed in v4.0.0. Use their `ril-
8484
Property | Type | Default | Required | Description
8585
:-------------------|:------:|:--------------:|:--------:|:----------------------------------------
8686
mainSrc | string | | yes | Main display image url
87-
prevSrc | string | | | Previous display image url (displayed to the left). If left undefined, movePrev actions will not be performed, and the button not displayed
88-
nextSrc | string | | | Next display image url (displayed to the right). If left undefined, moveNext actions will not be performed, and the button not displayed
89-
mainSrcThumbnail | string | | | Thumbnail image url corresponding to props.mainSrc
90-
prevSrcThumbnail | string | | | Thumbnail image url corresponding to props.prevSrc
91-
nextSrcThumbnail | string | | | Thumbnail image url corresponding to props.nextSrc
87+
prevSrc | string | | | Previous display image url (displayed to the left). If left undefined, `onMovePrevRequest` will not be called, and the button not displayed
88+
nextSrc | string | | | Next display image url (displayed to the right). If left undefined, `onMoveNextRequest` will not be called, and the button not displayed
89+
mainSrcThumbnail | string | | | Thumbnail image url corresponding to `props.mainSrc`
90+
prevSrcThumbnail | string | | | Thumbnail image url corresponding to `props.prevSrc`
91+
nextSrcThumbnail | string | | | Thumbnail image url corresponding to `props.nextSrc`
9292
onCloseRequest | func | | yes | Close window event. Should change the parent state such that the lightbox is not rendered
93-
onMovePrevRequest | func | empty function | | Move to previous image event. Should change the parent state such that props.prevSrc becomes props.mainSrc, props.mainSrc becomes props.nextSrc, etc.
94-
onMoveNextRequest | func | empty function | | Move to next image event. Should change the parent state such that props.nextSrc becomes props.mainSrc, props.mainSrc becomes props.prevSrc, etc.
93+
onMovePrevRequest | func | empty function | | Move to previous image event. Should change the parent state such that `props.prevSrc` becomes `props.mainSrc`, `props.mainSrc` becomes `props.nextSrc`, etc.
94+
onMoveNextRequest | func | empty function | | Move to next image event. Should change the parent state such that `props.nextSrc` becomes `props.mainSrc`, `props.mainSrc` becomes `props.prevSrc`, etc.
95+
onImageLoadError | func | empty function | | Called when an image fails to load.<div>`(imageSrc: string, srcType: string, errorEvent: object): void`</div>
9596
discourageDownloads | bool | `false` | | Enable download discouragement (prevents [right-click -> Save Image As...])
9697
animationDisabled | bool | `false` | | Disable all animation
9798
animationOnKeyInput | bool | `false` | | Disable animation on actions performed with keyboard shortcuts
@@ -101,20 +102,20 @@ keyRepeatKeyupBonus | number | `40` | | Amount of time (ms) r
101102
imageTitle | node | | | Image title (Descriptive element above image)
102103
imageCaption | node | | | Image caption (Descriptive element below image)
103104
toolbarButtons | node[] | | | Array of custom toolbar buttons
104-
reactModalStyle | Object | `{}` | | Set z-index style, etc., for the parent react-modal (format: https://github.com/reactjs/react-modal#styles )
105+
reactModalStyle | Object | `{}` | | Set `z-index` style, etc., for the parent react-modal ([react-modal style format](https://github.com/reactjs/react-modal#styles))
105106
imagePadding | number | `10` | | Padding (px) between the edge of the window and the lightbox
106107
clickOutsideToClose | bool | `true` | | When true, clicks outside of the image close the lightbox
107108
enableZoom | bool | `true` | | Set to false to disable zoom functionality and hide zoom buttons
108109

109110
## Browser Compatibility
110111

111-
| Browser | Works? |
112-
|:-----|:-----|
113-
| Chrome | Yes |
114-
| Firefox | Yes |
115-
| Safari | Yes |
116-
| IE >= 10 | Yes |
117-
| IE 9 | Everything works, but no animations |
112+
| Browser | Works? |
113+
|:---------|:------------------------------------|
114+
| Chrome | Yes |
115+
| Firefox | Yes |
116+
| Safari | Yes |
117+
| IE >= 10 | Yes |
118+
| IE 9 | Everything works, but no animations |
118119

119120
## Contributing
120121

src/examples/cats/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ const App = React.createClass({
100100
movePrev() {
101101
this.setState({ index: (this.state.index + images.length - 1) % images.length });
102102
},
103+
onImageLoadError(imageSrc, _srcType, errorEvent) {
104+
console.error(`Could not load image at ${imageSrc}`, errorEvent);
105+
},
103106
render() {
104107
let lightbox;
105108
if (this.state.isOpen) {
@@ -116,6 +119,7 @@ const App = React.createClass({
116119
onCloseRequest={this.closeLightbox}
117120
onMovePrevRequest={this.movePrev}
118121
onMoveNextRequest={this.moveNext}
122+
onImageLoadError={this.onImageLoadError}
119123

120124
imageTitle={titles[this.state.index]}
121125
imageCaption={captions[this.state.index]}

src/react-image-lightbox.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -705,20 +705,21 @@ class ReactImageLightbox extends Component {
705705
}
706706

707707
// Load image from src and call callback with image width and height on load
708-
loadImage(imageSrc, callback) {
708+
loadImage(srcType, imageSrc, done) {
709709
// Return the image info if it is already cached
710710
if (this.isImageLoaded(imageSrc)) {
711711
setTimeout(() => {
712-
callback(null, this.imageCache[imageSrc].width, this.imageCache[imageSrc].height);
712+
done();
713713
}, 1);
714714
return;
715715
}
716716

717717
const that = this;
718718
const inMemoryImage = new Image();
719719

720-
inMemoryImage.onerror = function onError() {
721-
callback('image load error');
720+
inMemoryImage.onerror = (errorEvent) => {
721+
this.props.onImageLoadError(imageSrc, srcType, errorEvent);
722+
done(errorEvent);
722723
};
723724

724725
inMemoryImage.onload = function onLoad() {
@@ -728,20 +729,17 @@ class ReactImageLightbox extends Component {
728729
height: this.height,
729730
};
730731

731-
callback(null, this.width, this.height);
732+
done();
732733
};
733734

734735
inMemoryImage.src = imageSrc;
735736
}
736737

737738
// Load all images and their thumbnails
738739
loadAllImages(props = this.props) {
739-
const generateImageLoadedCallback = (srcType, imageSrc) => (err) => {
740+
const generateLoadDoneCallback = (srcType, imageSrc) => (err) => {
740741
// Give up showing image on error
741742
if (err) {
742-
if (window.console) {
743-
window.console.warn(err);
744-
}
745743
return;
746744
}
747745

@@ -761,7 +759,7 @@ class ReactImageLightbox extends Component {
761759

762760
// Load unloaded images
763761
if (props[type] && !this.isImageLoaded(props[type])) {
764-
this.loadImage(props[type], generateImageLoadedCallback(type, props[type]));
762+
this.loadImage(type, props[type], generateLoadDoneCallback(type, props[type]));
765763
}
766764
});
767765
}
@@ -1236,6 +1234,10 @@ ReactImageLightbox.propTypes = {
12361234
// props.mainSrc becomes props.prevSrc, etc.
12371235
onMoveNextRequest: PropTypes.func,
12381236

1237+
// Called when an image fails to load
1238+
// (imageSrc: string, srcType: string, errorEvent: object): void
1239+
onImageLoadError: PropTypes.func,
1240+
12391241
//-----------------------------
12401242
// Download discouragement settings
12411243
//-----------------------------
@@ -1305,6 +1307,7 @@ ReactImageLightbox.propTypes = {
13051307
ReactImageLightbox.defaultProps = {
13061308
onMovePrevRequest: () => {},
13071309
onMoveNextRequest: () => {},
1310+
onImageLoadError: () => {},
13081311

13091312
discourageDownloads: false,
13101313

0 commit comments

Comments
 (0)