قرار دادن لودینگ برای تمام دکمههای سایت
این کد هنگام کلیک روی دکمههای سایت، یک لودینگ چرخشی روی دکمه نمایش میدهد و از کلیک مجدد روی آن جلوگیری میکند.
ویژگیهای این کد:
نمایش لودینگ روی دکمههای Elementor و دکمههای ووکامرس.
مخفی کردن متن دکمه هنگام نمایش لودینگ.
جلوگیری از کلیک مجدد تا پایان عملیات.
نمایش نشانگر wait هنگام پردازش.
پشتیبانی از دکمههای روشن با رنگ لودینگ متفاوت.
نادیده گرفتن دکمههای غیرفعال و دکمههایی که نباید لودینگ داشته باشند.
امکان حذف لودینگ از یک دکمه با اضافه کردن کلاس glds-no-loading.
جلوگیری از نمایش لودینگ برای لینکهای داخلی مانند # و کدهای javascript:.
حذف خودکار لودینگ پس از حداکثر ۱۵ ثانیه در صورتی که صفحه یا عملیات جدیدی اجرا نشود.
<?php
add_action('wp_footer', function () {
?>
<style>
.glds-button-loading {
position: relative !important;
pointer-events: none !important;
cursor: wait !important;
}
.glds-button-loading .elementor-button-content-wrapper {
visibility: hidden !important;
}
.glds-button-loading::after {
content: "";
position: absolute;
width: 18px;
height: 18px;
border: 2px solid rgba(255,255,255,0.4);
border-top-color: #ffffff;
border-radius: 50%;
top: 50%;
left: 50%;
margin-top: -9px;
margin-left: -9px;
animation: glds-button-spin 0.7s linear infinite;
}
@keyframes glds-button-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.glds-button-loading.glds-light-button::after {
border-color: rgba(0,0,0,0.2);
border-top-color: #DDA63A;
}
</style>
<script>
document.addEventListener('click', function(e) {
const button = e.target.closest(
'.elementor-button, ' +
'.woocommerce button[type="submit"], ' +
'.woocommerce input[type="submit"], ' +
'.woocommerce a.button'
);
if (!button) {
return;
}
if (
button.classList.contains('glds-no-loading') ||
button.classList.contains('disabled') ||
button.getAttribute('aria-disabled') === 'true'
) {
return;
}
if (button.classList.contains('glds-button-loading')) {
return;
}
const href = button.getAttribute('href');
if (
href === '#' ||
href === '' ||
(href && href.toLowerCase().startsWith('javascript:')) ||
button.hasAttribute('data-toggle') ||
button.hasAttribute('data-target')
) {
return;
}
button.classList.add('glds-button-loading');
setTimeout(function() {
button.classList.remove('glds-button-loading');
}, 15000);
}, true);
</script>
<?php
});