Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/css/preloader.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#preloader {
display: flex;
background-color: inherit; /* Fallback for existing overrides in child. Replaced by bg-body class */
}
}
68 changes: 49 additions & 19 deletions assets/js/preloader.js
Original file line number Diff line number Diff line change
@@ -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);
};

});
});
4 changes: 2 additions & 2 deletions inc/enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @author Bootscore
* @package bs Preloader
* @version 5.5.2
* @version 6.0.0
*/


Expand Down Expand Up @@ -34,7 +34,7 @@ function bs_preloader_scripts() {
wp_enqueue_script(
'preloader-js',
$plugin_url . 'assets/js/preloader.js',
['jquery'],
[],
$script_ver,
true
);
Expand Down
10 changes: 5 additions & 5 deletions main.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/*Plugin Name: bs Preloader
Plugin URI: https://bootscore.me/plugins/bs-preloader/
Plugin URI: https://bootscore.me/plugins/documentation/bs-preloader/
Description: Plugin adds a preloader to Bootscore theme.
Version: 5.5.3
Tested up to: 7.0
Requires at least: 5.0
Requires PHP: 7.4
Version: 6.0.0-dev
Tested up to: 7.1
Requires at least: 7.0
Requires PHP: 8.1
Author: Bootscore
Author URI: https://bootscore.me
License: MIT License
Expand Down