From 7b561f9932a3f5a97d938d60530e03b0471ee7ed Mon Sep 17 00:00:00 2001 From: Daniel Kurowski <daniel.kurowski@grifart.cz> Date: Thu, 10 Sep 2020 13:48:47 +0200 Subject: [PATCH] Main: refactored entry point API, removed redundant functions --- src/esImportTest.ts | 8 +++ src/handlers/linkClickScroll/unitTest.html | 5 +- src/handlers/loadScroll/unitTest.html | 5 +- src/index.ts | 54 ++++++++------------- src/integrationTest.html | 5 +- src/scrollers/scrollToElement.unitTest.html | 6 --- src/scrollers/scrollToOffset.unitTest.html | 6 --- src/scrollers/scrollToTarget.unitTest.html | 6 --- 8 files changed, 31 insertions(+), 64 deletions(-) create mode 100644 src/esImportTest.ts diff --git a/src/esImportTest.ts b/src/esImportTest.ts new file mode 100644 index 0000000..73ca019 --- /dev/null +++ b/src/esImportTest.ts @@ -0,0 +1,8 @@ +// dummy test +// if import statements do not scream this test passes +import {handleGlobalScrollingBehavior} from './index'; +import {handleOnLoadScroll} from './index'; +import {handleOnLinkClickScroll} from './index'; +import {scrollToElement} from './index'; +import {scrollToOffset} from './index'; +import {scrollToTarget} from './index'; diff --git a/src/handlers/linkClickScroll/unitTest.html b/src/handlers/linkClickScroll/unitTest.html index c53bbe8..6f23114 100644 --- a/src/handlers/linkClickScroll/unitTest.html +++ b/src/handlers/linkClickScroll/unitTest.html @@ -7,10 +7,7 @@ <script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5/velocity.min.js"></script> <script src="../../../dist/index.js"></script> <script> - SmoothScroll.enable({ - scrollOnLoad: false, - scrollOnLinkClick: true, - }); + SmoothScroll.handleOnLinkClickScroll(); </script> <style type="text/css"> body { diff --git a/src/handlers/loadScroll/unitTest.html b/src/handlers/loadScroll/unitTest.html index 5877c49..aa3bb3a 100644 --- a/src/handlers/loadScroll/unitTest.html +++ b/src/handlers/loadScroll/unitTest.html @@ -7,10 +7,7 @@ <script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5/velocity.min.js"></script> <script src="../../../dist/index.js"></script> <script> - SmoothScroll.enable({ - scrollOnLoad: true, - scrollOnLinkClick: false, - }); + SmoothScroll.handleOnLoadScroll(); </script> <style type="text/css"> body { diff --git a/src/index.ts b/src/index.ts index 8c433d1..3eb3715 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,47 +7,33 @@ import {scrollToOffset} from './scrollers/scrollToOffset'; import {scrollToTarget} from './scrollers/scrollToTarget'; import {HashTarget} from './HashTarget'; -interface SmoothScrollOptions { - readonly scrollOnLoad?: boolean; - readonly scrollOnLinkClick?: boolean; -} - -/** - * Wrapped into class for intuitive API use – `SmoothScroll.something()` - */ -class SmoothScroll -{ - public static enable(options?: SmoothScrollOptions): void - { - setupVelocity(Velocity); - if ( ! (options && options.scrollOnLoad === false)) { - initializeOnLoadScroll(); - } +// bind automatically on library import +bindEasingToVelocity(Velocity); - if ( ! (options && options.scrollOnLinkClick === false)) { - initializeOnLinkClickScroll(); - } - } - public static scrollToElement(element: HTMLElement, onScrollFinishedCallback?: () => void): void - { - scrollToElement(element, onScrollFinishedCallback); - } +function handleGlobalScrollingBehavior(): void +{ + handleOnLoadScroll(); + handleOnLinkClickScroll(); +} - public static scrollToOffset(topOffset: number, onScrollFinishedCallback?: () => void): void - { - scrollToOffset(topOffset, onScrollFinishedCallback); - } +function handleOnLoadScroll(): void +{ + initializeOnLoadScroll(); +} - public static scrollToTarget(target: HashTarget, onScrollFinishedCallback?: () => void): void - { - scrollToTarget(target, onScrollFinishedCallback); - } +function handleOnLinkClickScroll(): void +{ + initializeOnLinkClickScroll(); } export { - SmoothScrollOptions, HashTarget, + handleGlobalScrollingBehavior, + handleOnLoadScroll, + handleOnLinkClickScroll, + scrollToElement, + scrollToOffset, + scrollToTarget, }; -export default SmoothScroll; diff --git a/src/integrationTest.html b/src/integrationTest.html index 194bf29..d74a879 100644 --- a/src/integrationTest.html +++ b/src/integrationTest.html @@ -7,10 +7,7 @@ <script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5/velocity.min.js"></script> <script src="../dist/index.js" type="text/javascript"></script> <script> - SmoothScroll.enable({ - scrollOnLoad: true, - scrollOnLinkClick: true, - }); + SmoothScroll.handleGlobalScrollingBehavior(); document.addEventListener('DOMContentLoaded', () => { document.getElementById('scrollToElement').addEventListener('click', (event) => { diff --git a/src/scrollers/scrollToElement.unitTest.html b/src/scrollers/scrollToElement.unitTest.html index aafc732..2ca9acd 100644 --- a/src/scrollers/scrollToElement.unitTest.html +++ b/src/scrollers/scrollToElement.unitTest.html @@ -6,12 +6,6 @@ <title>scrollToElement() scroll test</title> <script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5/velocity.min.js"></script> <script src="../../dist/index.js"></script> - <script> - SmoothScroll.enable({ - scrollOnLoad: false, - scrollOnLinkClick: false, - }); - </script> <style type="text/css"> body { margin: 0 auto; diff --git a/src/scrollers/scrollToOffset.unitTest.html b/src/scrollers/scrollToOffset.unitTest.html index a27fc80..7b067ad 100644 --- a/src/scrollers/scrollToOffset.unitTest.html +++ b/src/scrollers/scrollToOffset.unitTest.html @@ -6,12 +6,6 @@ <title>scrollToOffset() scroll test</title> <script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5/velocity.min.js"></script> <script src="../../dist/index.js"></script> - <script> - SmoothScroll.enable({ - scrollOnLoad: false, - scrollOnLinkClick: false, - }); - </script> <style type="text/css"> body { margin: 0 auto; diff --git a/src/scrollers/scrollToTarget.unitTest.html b/src/scrollers/scrollToTarget.unitTest.html index f0d5e54..19ac653 100644 --- a/src/scrollers/scrollToTarget.unitTest.html +++ b/src/scrollers/scrollToTarget.unitTest.html @@ -6,12 +6,6 @@ <title>scrollTarget() scroll test</title> <script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5/velocity.min.js"></script> <script src="../../dist/index.js"></script> - <script> - SmoothScroll.enable({ - scrollOnLoad: false, - scrollOnLinkClick: false, - }); - </script> <style type="text/css"> body { margin: 0 auto; -- GitLab