Created
September 21, 2020 19:11
-
-
Save Pross/30e760e592a799b868ce827e47f25e86 to your computer and use it in GitHub Desktop.
Filer to disable smoothscroll >> `add_filter( 'fl_theme_disable_smoothscroll', '__return_true' );`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7485624b4814ccafb6edefc1358be7ca3f531478 Mon Sep 17 00:00:00 2001 | |
From: Simon Prosser <pross@pross.org.uk> | |
Date: Mon, 21 Sep 2020 20:06:41 +0100 | |
Subject: [PATCH] New filter fl_theme_disable_smoothscroll to disable | |
smoothscroll | |
add_filter( 'fl_theme_disable_smoothscroll', '__return_true' ); | |
Fixes #148 | |
--- | |
classes/class-fl-theme.php | 6 +++++- | |
js/theme.js | 9 +++++++-- | |
2 files changed, 12 insertions(+), 3 deletions(-) | |
diff --git a/classes/class-fl-theme.php b/classes/class-fl-theme.php | |
index 26be40f..6e6e635 100644 | |
--- a/classes/class-fl-theme.php | |
+++ b/classes/class-fl-theme.php | |
@@ -244,7 +244,11 @@ static public function enqueue_scripts() { | |
* JS Options for breakpoints | |
* @see fl_theme_breakpoint_opts | |
*/ | |
- wp_localize_script( 'fl-automator', 'themeopts', self::get_theme_breakpoints() ); | |
+ $themeopts = self::get_theme_breakpoints(); | |
+ if ( true === apply_filters( 'fl_theme_disable_smoothscroll', false ) ) { | |
+ $themeopts['smooth'] = 'disabled'; | |
+ } | |
+ wp_localize_script( 'fl-automator', 'themeopts', $themeopts ); | |
// Skin | |
if ( 'file' === FLTheme::get_asset_enqueue_method() ) { | |
diff --git a/js/theme.js b/js/theme.js | |
index 092756f..e60a4ff 100644 | |
--- a/js/theme.js | |
+++ b/js/theme.js | |
@@ -379,6 +379,11 @@ | |
return; | |
} | |
+ // if scroll is disabled globally via filter do not scroll. | |
+ if ('undefined' !== typeof window.themeopts.smooth && 'disabled' === window.themeopts.smooth) { | |
+ return; | |
+ } | |
+ | |
if (location.hash && $( location.hash ).length) { | |
setTimeout(function() { | |
window.scrollTo(0, 0); | |
@@ -984,11 +989,11 @@ | |
$( win ).on( 'scroll.fl-fixed-header', FLTheme._fixThemerLayoutOnScroll ); | |
} | |
- | |
+ | |
if($('body.fl-scroll-header').length === 0 && $('.fl-header-padding-top-custom').length === 0 ) { | |
$('.fl-page').css('padding-top', totalHeaderHeight); | |
} | |
- | |
+ | |
$( win ).trigger( 'scroll' ); | |
} | |
else { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment