Add X13 WebP module for image conversion to next-generation formats
- Implemented the main module class with essential properties and methods. - Added translation support for various user interface strings. - Created XML configuration file for module versioning. - Ensured compatibility with different PHP versions and PrestaShop versions.
This commit is contained in:
56
modules/x13webp/views/js/front/x13webp.front.js
Normal file
56
modules/x13webp/views/js/front/x13webp.front.js
Normal file
@@ -0,0 +1,56 @@
|
||||
$(document).ready(() => {
|
||||
let x13images = [];
|
||||
|
||||
$("img").each(function () {
|
||||
const imgSrc = $(this).attr("data-src") ?? $(this).attr("data-original") ?? $(this).attr("src");
|
||||
|
||||
if (!imgSrc) return;
|
||||
if (imgSrc.includes(".webp")) return;
|
||||
|
||||
if ($(this).siblings("source").length && $(this).siblings("source").attr("srcset") !== undefined) {
|
||||
if ($(this).siblings("source").attr("srcset").includes(".webp")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
x13images.push(imgSrc.trim());
|
||||
});
|
||||
|
||||
$("[style]").each(function () {
|
||||
const bgImage = $(this).css("background-image");
|
||||
|
||||
if (bgImage.includes(".webp") || (!bgImage.includes(".jpg") && !bgImage.includes(".png"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
let image = $(this)
|
||||
.css("background-image")
|
||||
.replace(/url\("([^"]+)"\)/, "$1");
|
||||
x13images.push(image.trim());
|
||||
});
|
||||
|
||||
$("#product #thumbs_list a.fancybox").each(function () {
|
||||
const href = $(this).attr("href");
|
||||
if (href.length) {
|
||||
x13images.push(href.trim());
|
||||
}
|
||||
});
|
||||
$("#product .images-container .thumb").each(function () {
|
||||
const medium = $(this).data("image-medium-src");
|
||||
const large = $(this).data("image-large-src");
|
||||
if (typeof medium !== 'undefined') {
|
||||
x13images.push(medium.trim());
|
||||
}
|
||||
if (typeof large !== 'undefined') {
|
||||
x13images.push(large.trim());
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: x13webp_ajax_convert_url,
|
||||
method: "POST",
|
||||
data: {
|
||||
x13images,
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user