diff --git a/assets/css/preloader.css b/assets/css/preloader.css deleted file mode 100644 index 314448b..0000000 --- a/assets/css/preloader.css +++ /dev/null @@ -1,4 +0,0 @@ -#preloader { - display: flex; - background-color: inherit; /* Fallback for existing overrides in child. Replaced by bg-body class */ -} \ No newline at end of file diff --git a/assets/js/preloader.js b/assets/js/preloader.js index 120af42..63f6bfc 100644 --- a/assets/js/preloader.js +++ b/assets/js/preloader.js @@ -1,32 +1,62 @@ -jQuery(document).ready(function ($) { +document.addEventListener('DOMContentLoaded', function () { // Exclude links to fade-in let ignore_onbeforeunload = false; - $('a[href^=mailto], a[href^=tel], a[data-fade="false"], .woocommerce-MyAccount-downloads-file').on('click', function () { - ignore_onbeforeunload = true; - }); + document.querySelectorAll('a[href^="mailto"], a[href^="tel"], a[data-fade="false"], .woocommerce-MyAccount-downloads-file') + .forEach(function (el) { + el.addEventListener('click', function () { + ignore_onbeforeunload = true; + }); + }); + + // Fade helpers (CSS-transition based) + function fadeIn(el, duration = 200) { + if (!el) return; + el.style.transition = `opacity ${duration}ms`; + el.style.opacity = 0; + el.style.display = ''; + requestAnimationFrame(() => { + el.style.opacity = 1; + }); + } + + function fadeOut(el, duration = 400, delay = 0) { + if (!el) return; + setTimeout(() => { + el.style.transition = `opacity ${duration}ms`; + el.style.opacity = 0; + setTimeout(() => { + el.style.display = 'none'; + }, duration); + }, delay); + } + + const preloader = document.getElementById('preloader'); + const status = document.getElementById('status'); // Preloader - $(window).bind('beforeunload', function () { + window.addEventListener('beforeunload', function () { if (!ignore_onbeforeunload) { - $("#preloader").fadeIn('fast'); - $('#status').fadeIn('fast'); + fadeIn(preloader, 200); + fadeIn(status, 200); } ignore_onbeforeunload = false; - }) - $(window).on('load', function () { - $('#status').fadeOut(); - $('#preloader').delay(350).fadeOut('slow'); - }) + }); + + window.addEventListener('load', function () { + fadeOut(status); + fadeOut(preloader, 400, 350); + }); + setTimeout(function () { - $('#status').fadeOut(); - $('#preloader').delay(350).fadeOut('slow'); + fadeOut(status); + fadeOut(preloader, 400, 350); }, 1500); - - // Prevents preloader stucking by press the browser back/forward buttons + + // Prevents preloader stucking by pressing the browser back/forward buttons window.onpagehide = function () { - $('#status').fadeOut('fast'); - $('#preloader').delay(350).fadeOut('slow'); + fadeOut(status, 200); + fadeOut(preloader, 400, 350); }; -}); +}); \ No newline at end of file diff --git a/inc/enqueue.php b/inc/enqueue.php index 65d7269..fed6b07 100644 --- a/inc/enqueue.php +++ b/inc/enqueue.php @@ -5,7 +5,7 @@ * * @author Bootscore * @package bs Preloader - * @version 5.5.2 + * @version 6.0.0 */ @@ -24,28 +24,19 @@ function bs_preloader_scripts() { // File paths $script_file = $plugin_dir . 'assets/js/preloader.js'; - $style_file = $plugin_dir . 'assets/css/preloader.css'; // Timestamps as version numbers $script_ver = file_exists($script_file) ? date('YmdHi', filemtime($script_file)) : false; - $style_ver = file_exists($style_file) ? date('YmdHi', filemtime($style_file)) : false; // Enqueue script wp_enqueue_script( 'preloader-js', $plugin_url . 'assets/js/preloader.js', - ['jquery'], + [], $script_ver, true ); - // Enqueue style - wp_enqueue_style( - 'preloader-css', - $plugin_url . 'assets/css/preloader.css', - [], - $style_ver - ); } add_action('wp_enqueue_scripts', 'bs_preloader_scripts'); diff --git a/main.php b/main.php index df15405..f7cf9db 100644 --- a/main.php +++ b/main.php @@ -1,11 +1,11 @@ -