fslightbox 3.3.2 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +24 -72
  2. package/index.js +1 -1
  3. package/package.json +1 -1
  4. package/FsLightbox.js +0 -110
  5. package/components/helpers/renderSvg.js +0 -17
  6. package/components/nav/renderAndGetToolbarButton.js +0 -11
  7. package/components/nav/renderCloseButton.js +0 -10
  8. package/components/nav/renderFullscreenButton.js +0 -42
  9. package/components/nav/renderNav.js +0 -17
  10. package/components/nav/renderSlideNumber.js +0 -33
  11. package/components/nav/renderToolbar.js +0 -13
  12. package/components/renderSlideButton.js +0 -11
  13. package/components/renderSlideButtonContainer.js +0 -15
  14. package/components/renderSlideButtons.js +0 -7
  15. package/components/renderSlideSwipingHoverer.js +0 -6
  16. package/components/sources/proper-sources/renderCustom.js +0 -15
  17. package/components/sources/proper-sources/renderImage.js +0 -18
  18. package/components/sources/proper-sources/renderInvalid.js +0 -19
  19. package/components/sources/proper-sources/renderVideo.js +0 -31
  20. package/components/sources/proper-sources/renderYoutube.js +0 -26
  21. package/components/sources/renderSourceAnimationWrapper.js +0 -4
  22. package/components/sources/renderSourceMainWrapper.js +0 -32
  23. package/components/sources/renderSourceWrappersContainer.js +0 -22
  24. package/constants/classes-names.js +0 -27
  25. package/constants/core-constants.js +0 -6
  26. package/constants/css-constants.js +0 -1
  27. package/constants/dom-constants.js +0 -1
  28. package/constants/elements.js +0 -3
  29. package/constants/local-storage-constants.js +0 -2
  30. package/core/collections/fillSourcesOutersTransformersCollection.js +0 -13
  31. package/core/elements/setUpClassFacade.js +0 -9
  32. package/core/events/setUpEventsDispatcher.js +0 -7
  33. package/core/events/setUpGlobalEventsController.js +0 -34
  34. package/core/fullscreen/setUpFullscreenToggler.js +0 -30
  35. package/core/keyboard/KeyboardController.js +0 -20
  36. package/core/main-component/closing/LightboxCloseActioner.js +0 -46
  37. package/core/main-component/closing/setUpLightboxCloser.js +0 -11
  38. package/core/main-component/initializing/initializeLightbox.js +0 -38
  39. package/core/main-component/opening/setUpLightboxOpener.js +0 -47
  40. package/core/scrollbar/getInnerElementOfWidthGetter.js +0 -5
  41. package/core/scrollbar/getOuterElementOfWidthGetter.js +0 -9
  42. package/core/scrollbar/getScrollbarWidth.js +0 -31
  43. package/core/scrollbar/setUpScrollbarRecompensor.js +0 -20
  44. package/core/setUpCore.js +0 -30
  45. package/core/sizes/setUpWindowResizeActioner.js +0 -35
  46. package/core/slide/setUpSlideChangeFacade.js +0 -23
  47. package/core/slide/setUpSlideIndexChanger.js +0 -60
  48. package/core/sources/SourceLoadActioner.js +0 -29
  49. package/core/sources/SourceLoadHandler.js +0 -41
  50. package/core/sources/SourceSizer.js +0 -36
  51. package/core/sources/creating/CreatingSourcesBucket.js +0 -29
  52. package/core/sources/creating/CreatingSourcesLocalStorageManager.js +0 -55
  53. package/core/sources/creating/createSources.js +0 -28
  54. package/core/sources/pointering/down/setUpSourcesPointerDown.js +0 -36
  55. package/core/sources/pointering/move/SourcesPointerMove.js +0 -16
  56. package/core/sources/pointering/move/SourcesPointerMoveActioner.js +0 -37
  57. package/core/sources/pointering/up/SourcesPointerUp.js +0 -13
  58. package/core/sources/pointering/up/SourcesPointerUpActioner.js +0 -38
  59. package/core/sources/pointering/up/SourcesPointerUpActionerBucket.js +0 -35
  60. package/core/sources/setUpSourceDisplayFacade.js +0 -26
  61. package/core/sources/types/AutomaticTypeDetector.js +0 -70
  62. package/core/sources/types/DetectedTypeActioner.js +0 -44
  63. package/core/sources/types/getAutomaticTypeDetectorBucket.js +0 -14
  64. package/core/stage/setUpStageManager.js +0 -60
  65. package/core/styles/createAndAppendStyles.js +0 -9
  66. package/core/styles/injectStylesIfNotInDom.js +0 -8
  67. package/core/styles/styles-injection/styles-injection.js +0 -5
  68. package/core/timeouts/getQueuedAction.js +0 -15
  69. package/core/transforms/SourceMainWrapperTransformer.js +0 -27
  70. package/fslightbox.js +0 -1
  71. package/helpers/elements/addToElementClassIfNotContains.js +0 -6
  72. package/helpers/elements/removeFromElementChildIfContains.js +0 -5
  73. package/helpers/elements/removeFromElementClassIfContains.js +0 -6
  74. package/helpers/objects/assignToObject.js +0 -10
  75. package/helpers/source/setUpSourceClassName.js +0 -13
  76. package/helpers/source/setUpSourceCustomAttributes.js +0 -5
  77. package/helpers/state/ifOnUpdateExistsHandleItForState.js +0 -6
  78. package/i.js +0 -86
  79. package/styles.js +0 -1
@@ -1,60 +0,0 @@
1
- import { ANIMATION_TIME } from "../../constants/css-constants";
2
- import { SOURCE_ANIMATION_WRAPPERS, SOURCE_MAIN_WRAPPERS } from "../../constants/elements";
3
- import {
4
- FADE_IN_CLASS_NAME, FADE_IN_STRONG_CLASS_NAME,
5
- FADE_OUT_CLASS_NAME,
6
- TRANSFORM_TRANSITION_CLASS_NAME,
7
- } from "../../constants/classes-names";
8
- import { removeFromElementClassIfContains } from "../../helpers/elements/removeFromElementClassIfContains";
9
- import { getQueuedAction } from "../timeouts/getQueuedAction";
10
-
11
- export function setUpSlideIndexChanger(
12
- {
13
- collections: { sourceMainWrappersTransformers },
14
- componentsServices,
15
- core: { classFacade, slideIndexChanger: self, sourceDisplayFacade, stageManager },
16
- elements: { sourceAnimationWrappers },
17
- stageIndexes
18
- }
19
- ) {
20
- const runQueuedRemoveFadeOut = getQueuedAction(() => {
21
- classFacade.removeFromEachElementClassIfContains(SOURCE_ANIMATION_WRAPPERS, FADE_OUT_CLASS_NAME);
22
- }, ANIMATION_TIME);
23
-
24
- self.changeTo = (i) => {
25
- stageIndexes.current = i;
26
-
27
- stageManager.updateStageIndexes();
28
-
29
- componentsServices.setSlideNumber(i + 1);
30
-
31
- sourceDisplayFacade.displaySourcesWhichShouldBeDisplayed();
32
- };
33
-
34
- self.jumpTo = (i) => {
35
- let previousI = stageIndexes.current;
36
- self.changeTo(i);
37
-
38
- classFacade.removeFromEachElementClassIfContains(SOURCE_MAIN_WRAPPERS, TRANSFORM_TRANSITION_CLASS_NAME);
39
-
40
- removeFromElementClassIfContains(sourceAnimationWrappers[previousI], FADE_IN_STRONG_CLASS_NAME);
41
- removeFromElementClassIfContains(sourceAnimationWrappers[previousI], FADE_IN_CLASS_NAME);
42
- sourceAnimationWrappers[previousI].classList.add(FADE_OUT_CLASS_NAME);
43
-
44
- removeFromElementClassIfContains(sourceAnimationWrappers[i], FADE_IN_STRONG_CLASS_NAME);
45
- removeFromElementClassIfContains(sourceAnimationWrappers[i], FADE_OUT_CLASS_NAME);
46
- sourceAnimationWrappers[i].classList.add(FADE_IN_CLASS_NAME);
47
-
48
- // we need to remove fade out from all sources because if someone used slide swiping during animation timeout
49
- // we cannot detect what slide will be
50
- runQueuedRemoveFadeOut();
51
-
52
- sourceMainWrappersTransformers[i].zero();
53
-
54
- setTimeout(() => {
55
- if (previousI !== stageIndexes.current) {
56
- sourceMainWrappersTransformers[previousI].negative();
57
- }
58
- }, ANIMATION_TIME - 30);
59
- };
60
- }
@@ -1,29 +0,0 @@
1
- import { SourceSizer } from "./SourceSizer";
2
- import { FADE_IN_STRONG_CLASS_NAME, OPACITY_1_CLASS_NAME } from "../../constants/classes-names";
3
-
4
- export function SourceLoadActioner(
5
- {
6
- collections: { sourceSizers },
7
- elements: { sourceAnimationWrappers, sourceMainWrappers, sources },
8
- resolve
9
- }, i
10
- ) {
11
- this.runActions = (defaultWidth, defaultHeight) => {
12
- sources[i].classList.add(OPACITY_1_CLASS_NAME);
13
- sourceAnimationWrappers[i].classList.add(FADE_IN_STRONG_CLASS_NAME);
14
- sourceMainWrappers[i].removeChild(sourceMainWrappers[i].firstChild);
15
-
16
- runNormalLoadActions(defaultWidth, defaultHeight);
17
- this.runActions = runNormalLoadActions;
18
- };
19
-
20
- /**
21
- * Next loads after initial occur only while using 'srcset' so need to recreate SourceSizer.
22
- *
23
- * Note: Reopening lightbox does not trigger image load.
24
- */
25
- function runNormalLoadActions(defaultWidth, defaultHeight) {
26
- sourceSizers[i] = resolve(SourceSizer, [i, defaultWidth, defaultHeight]);
27
- sourceSizers[i].adjustSize();
28
- }
29
- }
@@ -1,41 +0,0 @@
1
- import { SourceLoadActioner } from "./SourceLoadActioner";
2
-
3
- export function SourceLoadHandler({ elements: { sources }, props, resolve, }, i) {
4
- const sourceLoadActioner = resolve(SourceLoadActioner, [i]);
5
-
6
- let wasVideoLoadCalled;
7
-
8
- this.handleImageLoad = ({ target: { naturalWidth, naturalHeight } }) => {
9
- sourceLoadActioner.runActions(naturalWidth, naturalHeight);
10
- };
11
-
12
- this.handleVideoLoad = ({ target: { videoWidth, videoHeight } }) => {
13
- wasVideoLoadCalled = true;
14
- sourceLoadActioner.runActions(videoWidth, videoHeight);
15
- };
16
-
17
- this.handleNotMetaDatedVideoLoad = () => {
18
- if (!wasVideoLoadCalled) {
19
- this.handleYoutubeLoad();
20
- }
21
- };
22
-
23
- this.handleYoutubeLoad = () => {
24
- let width = 1920;
25
- let height = 1080;
26
-
27
- if (props.maxYoutubeDimensions) {
28
- width = props.maxYoutubeDimensions.width;
29
- height = props.maxYoutubeDimensions.height;
30
- }
31
-
32
- sourceLoadActioner.runActions(width, height);
33
- };
34
-
35
- this.handleCustomLoad = () => {
36
- setTimeout(() => {
37
- const source = sources[i];
38
- sourceLoadActioner.runActions(source.offsetWidth, source.offsetHeight);
39
- });
40
- };
41
- }
@@ -1,36 +0,0 @@
1
- export function SourceSizer({ data, elements: { sources } }, i, defaultWidth, defaultHeight) {
2
- const ratio = defaultWidth / defaultHeight;
3
- let newHeight = 0;
4
-
5
- /**
6
- * This method takes care of setting sources dimensions.
7
- * Unfortunately wa cannot only set max width and max height and allow the sources to scale themselves,
8
- * due tu Youtube source which dimensions needs to be set in advance.
9
- * In this case we are calculating dimensions mathematically.
10
- */
11
- this.adjustSize = () => {
12
- newHeight = data.maxSourceWidth / ratio;
13
-
14
- // wider than higher
15
- if (newHeight < data.maxSourceHeight) {
16
- if (defaultWidth < data.maxSourceWidth) {
17
- newHeight = defaultHeight;
18
- }
19
- return updateDimensions();
20
- }
21
-
22
- // higher than wider
23
- if (defaultHeight > data.maxSourceHeight) {
24
- newHeight = data.maxSourceHeight;
25
- } else {
26
- newHeight = defaultHeight;
27
- }
28
-
29
- updateDimensions();
30
- };
31
-
32
- const updateDimensions = () => {
33
- sources[i].style.width = newHeight * ratio + 'px';
34
- sources[i].style.height = newHeight + 'px';
35
- }
36
- }
@@ -1,29 +0,0 @@
1
- import { AutomaticTypeDetector } from "../types/AutomaticTypeDetector";
2
-
3
- export function CreatingSourcesBucket(
4
- {
5
- props: { types, type, sources }, resolve,
6
- }, localStorageManager, detectedTypeActioner
7
- ) {
8
- this.getTypeSetByClientForIndex = (i) => {
9
- let typeSetManuallyByClient;
10
-
11
- if (types && types[i]) {
12
- typeSetManuallyByClient = types[i];
13
- } else if (type) {
14
- typeSetManuallyByClient = type;
15
- }
16
-
17
- return typeSetManuallyByClient;
18
- };
19
-
20
- this.retrieveTypeWithXhrForIndex = (i) => {
21
- // we need to copy index because xhr will for sure come later than next loop iteration
22
- const automaticTypeDetector = resolve(AutomaticTypeDetector);
23
- automaticTypeDetector.setUrlToCheck(sources[i]);
24
- automaticTypeDetector.getSourceType((sourceType) => {
25
- localStorageManager.handleReceivedSourceTypeForUrl(sourceType, sources[i]);
26
- detectedTypeActioner.runActionsForSourceTypeAndIndex(sourceType, i)
27
- });
28
- };
29
- }
@@ -1,55 +0,0 @@
1
- import { SOURCES_TYPES_KEY } from "../../../constants/local-storage-constants";
2
- import { assignToObject } from "../../../helpers/objects/assignToObject";
3
-
4
- export function CreatingSourcesLocalStorageManager({ props }) {
5
- const NEW_TYPE_SHOULD_BE_ADDED_HERE = false;
6
- let decodedSourceTypes;
7
- let newSourceTypesToDetect = 0;
8
- const newTypes = {};
9
-
10
- this.getSourceTypeFromLocalStorageByUrl = (url) => {
11
- if (!decodedSourceTypes[url]) {
12
- return addNewUrlToDetect(url);
13
- }
14
- return decodedSourceTypes[url];
15
- };
16
-
17
- this.handleReceivedSourceTypeForUrl = (sourceType, url) => {
18
- if (newTypes[url] === NEW_TYPE_SHOULD_BE_ADDED_HERE) {
19
- newSourceTypesToDetect--;
20
-
21
- // not storing invalid types
22
- if (sourceType !== 'invalid') {
23
- newTypes[url] = sourceType;
24
- } else {
25
- delete newTypes[url];
26
- }
27
-
28
- if (newSourceTypesToDetect === 0) {
29
- assignToObject(decodedSourceTypes, newTypes);
30
- localStorage.setItem(SOURCES_TYPES_KEY, JSON.stringify(decodedSourceTypes));
31
- }
32
- }
33
- };
34
-
35
- const addNewUrlToDetect = (url) => {
36
- newSourceTypesToDetect++;
37
- newTypes[url] = NEW_TYPE_SHOULD_BE_ADDED_HERE;
38
- };
39
-
40
- if (!props.disableLocalStorage) {
41
- decodedSourceTypes = JSON.parse(localStorage.getItem(SOURCES_TYPES_KEY));
42
- // we are checking if detected source types contains at certain key source type
43
- // when localStorage will be empty we can overwrite this method because we are sure
44
- // that at every index will be no source type
45
- if (!decodedSourceTypes) {
46
- // in ifAllNewTypesAreDetectedStoreAllTypesToLocalStorage we are assigning to
47
- // decodedSourceTypes new Types so we need to make it an object to avoid errors
48
- decodedSourceTypes = {};
49
- this.getSourceTypeFromLocalStorageByUrl = addNewUrlToDetect;
50
- }
51
- } else {
52
- this.getSourceTypeFromLocalStorageByUrl = function () {};
53
- this.handleReceivedSourceTypeForUrl = function () {};
54
- }
55
- }
@@ -1,28 +0,0 @@
1
- import { CreatingSourcesLocalStorageManager } from "./CreatingSourcesLocalStorageManager";
2
- import { DetectedTypeActioner } from "../types/DetectedTypeActioner";
3
- import { CreatingSourcesBucket } from "./CreatingSourcesBucket";
4
- import { CUSTOM_TYPE } from "../../../constants/core-constants";
5
-
6
- export function createSources({ props: { sources }, resolve }) {
7
- const localStorageManager = resolve(CreatingSourcesLocalStorageManager);
8
- const detectedTypeActioner = resolve(DetectedTypeActioner);
9
- const creatingSourcesBucket = resolve(CreatingSourcesBucket, [localStorageManager, detectedTypeActioner]);
10
-
11
- for (let i = 0; i < sources.length; i++) {
12
- if (typeof sources[i] !== "string") {
13
- detectedTypeActioner.runActionsForSourceTypeAndIndex(CUSTOM_TYPE, i);
14
- continue;
15
- }
16
-
17
- const typeSetManuallyByClient = creatingSourcesBucket.getTypeSetByClientForIndex(i);
18
- if (typeSetManuallyByClient) {
19
- detectedTypeActioner.runActionsForSourceTypeAndIndex(typeSetManuallyByClient, i);
20
- continue;
21
- }
22
-
23
- const sourceTypeRetrievedWithoutXhr = localStorageManager.getSourceTypeFromLocalStorageByUrl(sources[i]);
24
- (sourceTypeRetrievedWithoutXhr) ?
25
- detectedTypeActioner.runActionsForSourceTypeAndIndex(sourceTypeRetrievedWithoutXhr, i) :
26
- creatingSourcesBucket.retrieveTypeWithXhrForIndex(i);
27
- }
28
- }
@@ -1,36 +0,0 @@
1
- import { SOURCE_MAIN_WRAPPERS } from "../../../../constants/elements";
2
- import { TRANSFORM_TRANSITION_CLASS_NAME } from "../../../../constants/classes-names";
3
-
4
- export function setUpSourcesPointerDown(
5
- {
6
- core: { classFacade, sourcesPointerDown: self },
7
- elements: { sources },
8
- sourcePointerProps,
9
- stageIndexes
10
- }
11
- ) {
12
- self.listener = (e) => {
13
- /**
14
- * Preventing default to disable image 'copying' behavior on Firefox desktop browser.
15
- * Cannot prevent default on video click because video would become unclickable in IE11.
16
- */
17
- if (e.target.tagName !== 'VIDEO') {
18
- e.preventDefault();
19
- }
20
-
21
- sourcePointerProps.isPointering = true;
22
-
23
- sourcePointerProps.downScreenX = e.screenX;
24
-
25
- sourcePointerProps.swipedX = 0;
26
-
27
- const currentElement = sources[stageIndexes.current];
28
- (currentElement && currentElement.contains(e.target)) ?
29
- sourcePointerProps.isSourceDownEventTarget = true :
30
- sourcePointerProps.isSourceDownEventTarget = false;
31
-
32
- classFacade.removeFromEachElementClassIfContains(SOURCE_MAIN_WRAPPERS, TRANSFORM_TRANSITION_CLASS_NAME);
33
- };
34
- }
35
-
36
-
@@ -1,16 +0,0 @@
1
- import { SourcesPointerMoveActioner } from "./SourcesPointerMoveActioner";
2
-
3
- export function SourcesPointerMove({ props: { sources }, resolve, sourcePointerProps }) {
4
- const sourcesPointerMoveActioner = resolve(SourcesPointerMoveActioner);
5
-
6
- (sources.length === 1) ?
7
- this.listener = () => {
8
- // if there is only one slide we need to simulate swipe to prevent lightbox from closing
9
- sourcePointerProps.swipedX = 1;
10
- } :
11
- this.listener = (e) => {
12
- if (sourcePointerProps.isPointering) {
13
- sourcesPointerMoveActioner.runActionsForEvent(e);
14
- }
15
- };
16
- }
@@ -1,37 +0,0 @@
1
- import { CURSOR_GRABBING_CLASS_NAME } from "../../../../constants/classes-names";
2
- import { addToElementClassIfNotContains } from "../../../../helpers/elements/addToElementClassIfNotContains";
3
-
4
- export function SourcesPointerMoveActioner(
5
- {
6
- collections: { sourceMainWrappersTransformers },
7
- elements,
8
- sourcePointerProps,
9
- stageIndexes
10
- }
11
- ) {
12
- this.runActionsForEvent = (e) => {
13
- // we are showing InvisibleHover component in move event not in down event
14
- // due to IE problems with videos sources controlling
15
- if (!elements.container.contains(elements.slideSwipingHoverer)) {
16
- elements.container.appendChild(elements.slideSwipingHoverer);
17
- }
18
-
19
- addToElementClassIfNotContains(elements.container, CURSOR_GRABBING_CLASS_NAME);
20
-
21
- sourcePointerProps.swipedX = e.screenX - sourcePointerProps.downScreenX;
22
-
23
- transformSourceHolderAtIndexToPosition(stageIndexes.current, 'zero');
24
- // if there are only two slides we need to check if source we want to transform exists
25
- if (stageIndexes.previous !== undefined && sourcePointerProps.swipedX > 0) {
26
- transformSourceHolderAtIndexToPosition(stageIndexes.previous, 'negative');
27
- } else if (stageIndexes.next !== undefined && sourcePointerProps.swipedX < 0) {
28
- transformSourceHolderAtIndexToPosition(stageIndexes.next, 'positive');
29
- }
30
- };
31
-
32
- function transformSourceHolderAtIndexToPosition(index, position) {
33
- sourceMainWrappersTransformers[index]
34
- .byValue(sourcePointerProps.swipedX)
35
- [position]();
36
- }
37
- }
@@ -1,13 +0,0 @@
1
- import { SourcesPointerUpActioner } from "./SourcesPointerUpActioner";
2
-
3
- export function SourcesPointerUp({ resolve, sourcePointerProps }) {
4
- const sourcesPointerUpActioner = resolve(SourcesPointerUpActioner);
5
-
6
- this.listener = () => {
7
- if (sourcePointerProps.isPointering) {
8
- (sourcePointerProps.swipedX) ?
9
- sourcesPointerUpActioner.runActions() :
10
- sourcesPointerUpActioner.runNoSwipeActions();
11
- }
12
- };
13
- }
@@ -1,38 +0,0 @@
1
- import { SourcesPointerUpActionerBucket } from "./SourcesPointerUpActionerBucket";
2
- import { CURSOR_GRABBING_CLASS_NAME } from "../../../../constants/classes-names";
3
- import { removeFromElementChildIfContains } from '../../../../helpers/elements/removeFromElementChildIfContains';
4
-
5
- export function SourcesPointerUpActioner(
6
- {
7
- core: { lightboxCloser },
8
- elements,
9
- resolve,
10
- sourcePointerProps
11
- }
12
- ) {
13
- const sourcesPointerUpActionsBucket = resolve(SourcesPointerUpActionerBucket);
14
-
15
- this.runNoSwipeActions = () => {
16
- removeFromElementChildIfContains(elements.container, elements.slideSwipingHoverer);
17
-
18
- if (!sourcePointerProps.isSourceDownEventTarget) {
19
- lightboxCloser.closeLightbox();
20
- }
21
-
22
- sourcePointerProps.isPointering = false;
23
- };
24
-
25
- this.runActions = () => {
26
- if (sourcePointerProps.swipedX > 0) {
27
- sourcesPointerUpActionsBucket.runPositiveSwipedXActions();
28
- } else {
29
- sourcesPointerUpActionsBucket.runNegativeSwipedXActions();
30
- }
31
-
32
- removeFromElementChildIfContains(elements.container, elements.slideSwipingHoverer);
33
-
34
- elements.container.classList.remove(CURSOR_GRABBING_CLASS_NAME);
35
-
36
- sourcePointerProps.isPointering = false;
37
- };
38
- }
@@ -1,35 +0,0 @@
1
- import { TRANSFORM_TRANSITION_CLASS_NAME } from "../../../../constants/classes-names";
2
-
3
- export function SourcesPointerUpActionerBucket(
4
- {
5
- collections: { sourceMainWrappersTransformers },
6
- core: { slideIndexChanger },
7
- elements: { sourceMainWrappers },
8
- stageIndexes
9
- }
10
- ) {
11
- this.runPositiveSwipedXActions = () => {
12
- if (stageIndexes.previous === undefined) {
13
- addTransitionToCurrentSourceHolderAndTransformItToPosition('zero');
14
- } else {
15
- addTransitionToCurrentSourceHolderAndTransformItToPosition('positive');
16
- slideIndexChanger.changeTo(stageIndexes.previous);
17
- addTransitionToCurrentSourceHolderAndTransformItToPosition('zero');
18
- }
19
- };
20
-
21
- this.runNegativeSwipedXActions = () => {
22
- if (stageIndexes.next === undefined) {
23
- addTransitionToCurrentSourceHolderAndTransformItToPosition('zero');
24
- } else {
25
- addTransitionToCurrentSourceHolderAndTransformItToPosition('negative');
26
- slideIndexChanger.changeTo(stageIndexes.next);
27
- addTransitionToCurrentSourceHolderAndTransformItToPosition('zero');
28
- }
29
- };
30
-
31
- const addTransitionToCurrentSourceHolderAndTransformItToPosition = (position) => {
32
- sourceMainWrappers[stageIndexes.current].classList.add(TRANSFORM_TRANSITION_CLASS_NAME);
33
- sourceMainWrappersTransformers[stageIndexes.current][position]();
34
- };
35
- }
@@ -1,26 +0,0 @@
1
- export function setUpSourceDisplayFacade(
2
- {
3
- collections: { sourcesRenderFunctions },
4
- core: { sourceDisplayFacade: self },
5
- props,
6
- stageIndexes
7
- }
8
- ) {
9
- self.displaySourcesWhichShouldBeDisplayed = () => {
10
- if (props.loadOnlyCurrentSource) {
11
- runRenderActionsForSourceWithIndex(stageIndexes.current);
12
- return;
13
- }
14
-
15
- for (let i in stageIndexes) {
16
- runRenderActionsForSourceWithIndex(stageIndexes[i]);
17
- }
18
- };
19
-
20
- function runRenderActionsForSourceWithIndex(i) {
21
- if (sourcesRenderFunctions[i]) {
22
- sourcesRenderFunctions[i]();
23
- delete sourcesRenderFunctions[i];
24
- }
25
- }
26
- }
@@ -1,70 +0,0 @@
1
- import {
2
- IMAGE_TYPE,
3
- INVALID_TYPE,
4
- VIDEO_TYPE,
5
- YOUTUBE_TYPE,
6
- } from "../../../constants/core-constants";
7
- import { getAutomaticTypeDetectorBucket } from "./getAutomaticTypeDetectorBucket";
8
-
9
- export function AutomaticTypeDetector() {
10
- const automaticTypeDetectorBucket = getAutomaticTypeDetectorBucket();
11
-
12
- let url;
13
- let resolveSourceType;
14
- let xhr;
15
-
16
- this.setUrlToCheck = (urlToCheck) => {
17
- url = urlToCheck;
18
- };
19
-
20
- /**
21
- * Asynchronous method takes callback which will be called after source type is received with source type as param.
22
- * @param {Function} callback
23
- */
24
- this.getSourceType = (callback) => {
25
- if (automaticTypeDetectorBucket.isUrlYoutubeOne(url)) {
26
- return callback(YOUTUBE_TYPE);
27
- }
28
- resolveSourceType = callback;
29
- xhr = new XMLHttpRequest();
30
- xhr.onreadystatechange = onRequestStateChange;
31
- xhr.open('GET', url, true);
32
- xhr.send();
33
- };
34
-
35
- function onRequestStateChange() {
36
- // If state 4 is executed without state 2 - request has failed (most likely by CORS) so need to resolve invalid type.
37
- // No need to abort request because it is already finished.
38
- if (xhr.readyState === 4) {
39
- resolveSourceType(INVALID_TYPE);
40
- return;
41
- }
42
-
43
- if (xhr.readyState !== 2) {
44
- return;
45
- }
46
-
47
- const headerType = automaticTypeDetectorBucket.getTypeFromResponseContentType(
48
- xhr.getResponseHeader('content-type')
49
- );
50
-
51
- let finalType;
52
- switch (headerType) {
53
- case 'image':
54
- finalType = IMAGE_TYPE;
55
- break;
56
- case 'video':
57
- finalType = VIDEO_TYPE;
58
- break;
59
- default:
60
- finalType = INVALID_TYPE;
61
- }
62
-
63
- // Need to reset onreadystatechange because after xhr.abort() if request is sent (xhr.send())
64
- // xhr will call onreadystatechange with readyState 4: https://xhr.spec.whatwg.org/#the-abort()-method
65
- xhr.onreadystatechange = null;
66
- xhr.abort();
67
-
68
- resolveSourceType(finalType);
69
- }
70
- }
@@ -1,44 +0,0 @@
1
- import { CUSTOM_TYPE, IMAGE_TYPE, INVALID_TYPE, VIDEO_TYPE, YOUTUBE_TYPE } from "../../../constants/core-constants";
2
- import { SourceLoadHandler } from "../SourceLoadHandler";
3
- import { renderImage } from "../../../components/sources/proper-sources/renderImage";
4
- import { renderVideo } from "../../../components/sources/proper-sources/renderVideo";
5
- import { renderYoutube } from "../../../components/sources/proper-sources/renderYoutube";
6
- import { renderCustom } from "../../../components/sources/proper-sources/renderCustom";
7
- import { renderInvalid } from "../../../components/sources/proper-sources/renderInvalid";
8
-
9
- export function DetectedTypeActioner(fsLightbox) {
10
- const {
11
- collections: { sourceLoadHandlers, sourcesRenderFunctions },
12
- core: { sourceDisplayFacade },
13
- resolve
14
- } = fsLightbox;
15
-
16
- this.runActionsForSourceTypeAndIndex = (type, i) => {
17
- if (type !== INVALID_TYPE) {
18
- sourceLoadHandlers[i] = resolve(SourceLoadHandler, [i]);
19
- }
20
-
21
- let renderFunction;
22
-
23
- switch (type) {
24
- case IMAGE_TYPE:
25
- renderFunction = renderImage;
26
- break;
27
- case VIDEO_TYPE:
28
- renderFunction = renderVideo;
29
- break;
30
- case YOUTUBE_TYPE:
31
- renderFunction = renderYoutube;
32
- break;
33
- case CUSTOM_TYPE:
34
- renderFunction = renderCustom;
35
- break;
36
- default:
37
- renderFunction = renderInvalid;
38
- break;
39
- }
40
-
41
- sourcesRenderFunctions[i] = () => renderFunction(fsLightbox, i);
42
- sourceDisplayFacade.displaySourcesWhichShouldBeDisplayed();
43
- };
44
- }
@@ -1,14 +0,0 @@
1
- export function getAutomaticTypeDetectorBucket() {
2
- return {
3
- isUrlYoutubeOne: (url) => {
4
- const parser = document.createElement("a");
5
- parser.href = url;
6
- return parser.hostname === "www.youtube.com"
7
- || parser.hostname === "youtu.be";
8
- },
9
-
10
- getTypeFromResponseContentType: (responseContentType) => {
11
- return responseContentType.slice(0, responseContentType.indexOf("/"));
12
- }
13
- };
14
- }