diff --git a/src/esImportTest.ts b/src/esImportTest.ts new file mode 100644 index 0000000000000000000000000000000000000000..73ca0196dc5bfb638d4d24b66b14328a2cfa8073 --- /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 c53bbe8ff75c53b4cf07650a53f36efc6cc390b5..6f2311486390e83c9e58b2d6a7c19b554119eaf4 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 5877c499aaa2424f8e19321776817e99dcc870a1..aa3bb3affa5c962e1b3e8ca4aa1d7e50ed478257 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 8c433d1110d1f9e1de17647d309c5e4e2737ac83..3eb37152f16be5323f8b30ec62467c26d5b9d5d3 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 194bf299786340507104ede9c2db72988119d199..d74a879baa7611bc73f6ba3e71c99da1020a549d 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 aafc73246f7445d8716570e585eeda02cb32bb01..2ca9acdcb380d8cc708f22eb2b9b5af7668f763e 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 a27fc80d0eb5672f61647ed6a769e465e1612454..7b067ad77bd3d1ab8a5869155a5d7ef180272fd0 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 f0d5e54d7e7a6570a7f3701d57f3e0a9476a312e..19ac6537cfd26d0bc6393efaee0b24841121b6f4 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;