From 7c455054c20bcd80d0dcb824dad3811b0c141cd1 Mon Sep 17 00:00:00 2001 From: Sonny Le Date: Tue, 12 Nov 2024 11:38:00 +0700 Subject: [PATCH] Add Smooth Scroll Prevent option --- framework/library/astroid/Component/Utility.php | 16 +++++++++++++++- framework/library/astroid/Document.php | 3 +-- framework/options/basic.xml | 1 + language/en-GB/en-GB.astroid.ini | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/framework/library/astroid/Component/Utility.php b/framework/library/astroid/Component/Utility.php index dc35dab8..40f566b7 100644 --- a/framework/library/astroid/Component/Utility.php +++ b/framework/library/astroid/Component/Utility.php @@ -226,6 +226,20 @@ public static function smoothScroll(): void if (!empty($easing)) { $options[] = 'easing: '. Helper\Constants::$easing[$easing]; } + $prevent = $params->get('smooth_scroll_prevent', ''); + $prevent_script = ''; + if (!empty($prevent)) { + $prevent_arr = explode(',', $prevent); + if (count($prevent_arr)) { + $prevent_script .= 'jQuery(document).ready(function($){'; + foreach ($prevent_arr as $key => $value) { + if (!empty(trim($value))) { + $prevent_script .= '$("'.trim($value).'").attr("data-lenis-prevent", "");'; + } + } + $prevent_script .= '});'; + } + } $configs = implode(',', $options); $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); $document = Framework::getDocument(); @@ -248,7 +262,7 @@ public static function smoothScroll(): void .'};' .'if (typeof ScrollTrigger !== \'undefined\') {initSmoothScrollingGSAP()} else {initSmoothScrolling()}'; $wa->registerAndUseStyle('astroid.lenis', 'astroid/lenis.min.css'); - $wa->addInlineScript($script); + $wa->addInlineScript($script.$prevent_script); } } diff --git a/framework/library/astroid/Document.php b/framework/library/astroid/Document.php index a7035b72..8ab2188f 100644 --- a/framework/library/astroid/Document.php +++ b/framework/library/astroid/Document.php @@ -992,8 +992,7 @@ public function loadAnimation(): void $wa->registerAndUseStyle('astroid.animate', 'astroid/animate.min.css'); if (Helper::isPro()) { $this->loadImagesLoaded(); - $this->loadGSAP('ScrollTrigger'); - $wa->registerAndUseScript('astroid.animation.pro', 'media/astroidpro/assets/animations/js/index.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']); + $wa->registerAndUseScript('astroid.animation.pro', 'media/astroidpro/assets/animations/js/index.min.js', ['relative' => true, 'version' => 'auto']); } else { $wa->registerAndUseScript('astroid.animation', 'astroid/animate.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']); } diff --git a/framework/options/basic.xml b/framework/options/basic.xml index c25bb3ef..93a94279 100644 --- a/framework/options/basic.xml +++ b/framework/options/basic.xml @@ -247,6 +247,7 @@ + diff --git a/language/en-GB/en-GB.astroid.ini b/language/en-GB/en-GB.astroid.ini index 6ff1d704..507b92e5 100644 --- a/language/en-GB/en-GB.astroid.ini +++ b/language/en-GB/en-GB.astroid.ini @@ -1146,6 +1146,8 @@ TPL_SMOOTH_SCROLL_SPEED_LBL="Scroll Speed" TPL_SMOOTH_SCROLL_SPEED_DESC="This a number representing the amount of time in milliseconds that it should take to scroll 1000px. Scroll distances shorter than that will take less time, and scroll distances longer than that will take more time. The default is 1200ms." ASTROID_SMOOTH_SCROLL_EASING="Scroll Easing" ASTROID_SMOOTH_SCROLL_EASING_DESC="The easing function to use for the scroll animation, our default is custom but you can pick one from Easings.net." +TPL_SMOOTH_SCROLL_PREVENT_LBL="Prevent Smooth Scroll" +TPL_SMOOTH_SCROLL_PREVENT_DESC="Prevent smooth scroll on specific elements by adding the class or id element. Seperated by comma. Ex: #yourid, .yourclass" ASTROID_JD_BUILDER="Builder" ; Shortcuts