Skip to content
Permalink
Browse files

1.1.1

  • Loading branch information...
piotrzdziarski committed Jun 8, 2019
1 parent 473f19c commit c508fe49dbb047c1f29f8da09fe7a18c8ec57107

Large diffs are not rendered by default.

@@ -1,12 +1,12 @@
{
"name": "fslightbox-react",
"version": "1.1.0",
"version": "1.1.1",
"description": "React version of Fullscreen Lightbox.",
"main": "index.js",
"scripts": {
"test": "jest",
"build": "webpack --mode production --config webpack-prod.config.js --display-modules",
"start": "webpack-dev-server --mode development --open --host 192.168.0.12"
"start": "webpack-dev-server --mode development --open"
},
"repository": {
"type": "git",
@@ -98,6 +98,7 @@ class FsLightbox extends Component {

setUpCollections() {
this.collections = {
sourcesLoadHandlers: [],
// after source load its size adjuster will be stored in this array so SourceSizeAdjusterIterator may use it
sourceSizeAdjusters: [],
// if lightbox is unmounted pending xhrs need to be aborted
@@ -182,14 +183,14 @@ class FsLightbox extends Component {
FsLightbox.propTypes = {
toggler: PropTypes.bool.isRequired,
urls: PropTypes.array.isRequired,
slide: PropTypes.number,
disableLocalStorage: PropTypes.bool,
onOpen: PropTypes.func,
onClose: PropTypes.func,
onInit: PropTypes.func,
onShow: PropTypes.func,
disableLocalStorage: PropTypes.bool,
videosPosters: PropTypes.array,
slideDistance: PropTypes.number
slide: PropTypes.number,
slideDistance: PropTypes.number,
videosPosters: PropTypes.array
};
export default FsLightbox;
@@ -1,40 +1,19 @@
import React from 'react';
import PropTypes from "prop-types";

/**
* @param { FsLightbox.data.urls } urls
* @param { FsLightbox.elements.sources } sources
* @param { FsLightbox.sourcesData.isSourceAlreadyInitializedArray } isSourceAlreadyInitializedArray
* @param { FsLightbox.core.sourceController | SetUpSourceController } sourceController
* @param { number } index
*/
const Image = (
{
fsLightbox: {
data: { urls },
sourcesData: { isSourceAlreadyInitializedArray },
elements: { sources },
core: { sourceController }
collections: { sourcesLoadHandlers }
},
index
}
) => {
const onImageLoad = ({ target }) => {
sourceController.setIndex(index);
(isSourceAlreadyInitializedArray[index]) ?
sourceController.normalLoad() :
initialLoad(target);
};

const initialLoad = (target) => {
sourceController.setSourceWidth(target.width);
sourceController.setSourceHeight(target.height);
sourceController.initialLoad();
};

return (
<img
onLoad={ onImageLoad }
onLoad={ sourcesLoadHandlers[index].handleLoad }
className={ "fslightbox-source fslightbox-opacity-0" }
ref={ sources[index] }
src={ urls[index] }
@@ -48,4 +27,4 @@ Image.propTypes = {
index: PropTypes.number.isRequired,
};

export default Image;
export default Image;
@@ -1,41 +1,20 @@
import React from 'react';
import PropTypes from "prop-types";

/**
* @param { FsLightbox.data.urls } urls
* @param { FsLightbox.elements.sources } sources
* @param { FsLightbox.sourcesData.isSourceAlreadyInitializedArray } isSourceAlreadyInitializedArray
* @param { FsLightbox.sourcesData.videosPosters } videosPosters
* @param { FsLightbox.core.sourceController | SetUpSourceController } sourceController
* @param { number }index
*/
const Video = (
{
fsLightbox: {
data: { urls },
elements: { sources },
sourcesData: { videosPosters, isSourceAlreadyInitializedArray },
core: { sourceController }
sourcesData: { videosPosters },
collections: { sourcesLoadHandlers }
},
index
}
) => {
const onLoadedMetaData = ({ target }) => {
sourceController.setIndex(index);
(isSourceAlreadyInitializedArray[index]) ?
sourceController.normalLoad() :
initialLoad(target);
};

const initialLoad = (target) => {
sourceController.setSourceWidth(target.videoWidth);
sourceController.setSourceHeight(target.videoHeight);
sourceController.initialLoad();
};

return (
<video
onLoadedMetadata={ onLoadedMetaData }
onLoadedMetadata={ sourcesLoadHandlers[index].handleLoad }
className="fslightbox-source fslightbox-video fslightbox-opacity-0"
controls
ref={ sources[index] }
@@ -50,4 +29,4 @@ Video.propTypes = {
index: PropTypes.number.isRequired
};

export default Video;
export default Video;
@@ -2,36 +2,19 @@ import React, { useEffect } from 'react';
import PropTypes from "prop-types";
import { getYoutubeVideoIdFromUrl } from "../../../helpers/source/getYoutubeVideoIdFromUrl";

/**
* @param { FsLightbox.data.urls } urls
* @param { FsLightbox.elements.sources } sources
* @param { FsLightbox.sourcesData.isSourceAlreadyInitializedArray } isSourceAlreadyInitializedArray
* @param { FsLightbox.core.sourceController | SetUpSourceController } sourceController
* @param { number } index
*/
const Youtube = (
{
fsLightbox: {
data: { urls },
sourcesData: { isSourceAlreadyInitializedArray },
elements: { sources },
core: { sourceController }
collections: {
sourcesLoadHandlers
}
},
index,
}
) => {
useEffect(() => {
sourceController.setIndex(index);
(isSourceAlreadyInitializedArray[index]) ?
sourceController.normalLoad() :
initialLoad();
});

const initialLoad = () => {
sourceController.setSourceWidth(1920);
sourceController.setSourceHeight(1080);
sourceController.initialLoad();
};
useEffect(sourcesLoadHandlers[index].handleLoad);

return (
<iframe
@@ -52,4 +35,4 @@ Youtube.propTypes = {
index: PropTypes.number.isRequired
};

export default Youtube;
export default Youtube;
@@ -0,0 +1,50 @@
/**
* @constructor
*/
export function SourceLoadHandler(
{
core: {
sourceController
}
}
) {
let sourceIndex;
let sourceWidth;
let sourceHeight;
let setUpSourceDimensions = () => {};

this.setIndex = (index) => {
sourceIndex = index;
};

this.setUpLoadForImage = () => {
setUpSourceDimensions = ({ target: { width, height } }) => {
sourceWidth = width;
sourceHeight = height;
}
};

this.setUpLoadForVideo = () => {
setUpSourceDimensions = ({ target: { videoWidth, videoHeight } }) => {
sourceWidth = videoWidth;
sourceHeight = videoHeight;
}
};

this.setUpLoadForYoutube = () => {
sourceWidth = 1920;
sourceHeight = 1080;
};

this.handleLoad = (e) => {
setUpSourceDimensions(e);
sourceController.setIndex(sourceIndex);
sourceController.setSourceWidth(sourceWidth);
sourceController.setSourceHeight(sourceHeight);
sourceController.runInitialLoadActions();
this.handleLoad = () => {
sourceController.setIndex(sourceIndex);
sourceController.runNormalLoadActions();
};
};
}

This file was deleted.

@@ -34,7 +34,7 @@ export function CreatingSourcesLocalStorageManager(fsLightbox) {
// in ifAllNewTypesAreDetectedStoreAllTypesToLocalStorage we are assigning to
// decodedSourceTypes new Types so we need to make it an object to avoid errors
decodedSourceTypes = {};
this.getSourceTypeFromLocalStorageByUrl = addNewUrlToDetect
this.getSourceTypeFromLocalStorageByUrl = addNewUrlToDetect;
}
} else {
this.getSourceTypeFromLocalStorageByUrl = function () {};

This file was deleted.

@@ -1,14 +1,14 @@
import { CreatingSourcesActions } from "./CreatingSourcesActions";
import { SourceTypeGetter } from "../types/SourceTypeGetter";
import { CreatingSourcesLocalStorageManager } from "./CreatingSourcesLocalStorageManager";
import { DetectedTypeActions } from "../types/DetectedTypeActions";

export function createSources(
{
props: { urls },
injector: { injectDependency }
}
) {
const creatingSourcesActions = injectDependency(CreatingSourcesActions);
const detectedTypeActions = injectDependency(DetectedTypeActions);
const localStorageManager = injectDependency(CreatingSourcesLocalStorageManager);
let sourceTypeFromLocalStorage;
let sourceIndex;
@@ -22,7 +22,7 @@ export function createSources(
}

function callActionsForSourceTypeFromLocalStorage() {
creatingSourcesActions.runActionsForSourceTypeAndIndex(
detectedTypeActions.runActionsForSourceTypeAndIndex(
sourceTypeFromLocalStorage, sourceIndex
);
}
@@ -34,7 +34,7 @@ export function createSources(
sourceTypeGetter.setUrlToCheck(urls[rememberedSourceIndex]);
sourceTypeGetter.getSourceType((sourceType) => {
localStorageManager.handleReceivedSourceTypeForUrl(sourceType, urls[rememberedSourceIndex]);
creatingSourcesActions.runActionsForSourceTypeAndIndex(sourceType, rememberedSourceIndex)
detectedTypeActions.runActionsForSourceTypeAndIndex(sourceType, rememberedSourceIndex)
});
}
}

0 comments on commit c508fe4

Please sign in to comment.
You can’t perform that action at this time.