From bf82a1dbea7c38cec2076a3c0cdb225a5ca41230 Mon Sep 17 00:00:00 2001 From: Basti <51531217+crftwrk@users.noreply.github.com> Date: Wed, 2 Sep 2026 14:41:37 +0200 Subject: [PATCH] Removed jQuery dependency --- assets/css/preloader.css | 4 +-- assets/js/preloader.js | 68 +++++++++++++++++++++++++++++----------- inc/enqueue.php | 4 +-- main.php | 10 +++--- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/assets/css/preloader.css b/assets/css/preloader.css index 314448b..b73360a 100644 --- a/assets/css/preloader.css +++ b/assets/css/preloader.css @@ -1,4 +1,4 @@ + #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..f35f4d3 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 */ @@ -34,7 +34,7 @@ function bs_preloader_scripts() { wp_enqueue_script( 'preloader-js', $plugin_url . 'assets/js/preloader.js', - ['jquery'], + [], $script_ver, true ); diff --git a/main.php b/main.php index df15405..f7cf9db 100644 --- a/main.php +++ b/main.php @@ -1,11 +1,11 @@