|
|
@@ -16,19 +16,6 @@
|
|
|
var isUploading = false;
|
|
|
var originalGalleryImages = {};
|
|
|
|
|
|
- // Broad selectors for add-to-cart elements
|
|
|
- var addToCartSelectors = [
|
|
|
- '.single_add_to_cart_button',
|
|
|
- '.add_to_cart_button',
|
|
|
- 'button[name="add-to-cart"]',
|
|
|
- 'input[name="add-to-cart"]',
|
|
|
- 'a[data-product_id]',
|
|
|
- 'button[data-product_id]',
|
|
|
- 'a[href*="add-to-cart"]',
|
|
|
- '.product form.cart button[type="submit"]',
|
|
|
- '.product form.cart input[type="submit"]'
|
|
|
- ].join(', ');
|
|
|
-
|
|
|
// Upload area elements
|
|
|
var $dropzone = $uploadWrap.find('#studiou-fpp-dropzone');
|
|
|
var $fileInput = $uploadWrap.find('#studiou-fpp-file-input');
|
|
|
@@ -41,66 +28,6 @@
|
|
|
var $removeBtn = $uploadWrap.find('.studiou-fpp-remove-file');
|
|
|
var $messages = $uploadWrap.find('.studiou-fpp-messages');
|
|
|
|
|
|
- // ==========================================
|
|
|
- // Disable/enable add-to-cart buttons
|
|
|
- // ==========================================
|
|
|
- function disableAddToCart() {
|
|
|
- $(addToCartSelectors).each(function () {
|
|
|
- var $el = $(this);
|
|
|
- $el.addClass('studiou-fpp-disabled');
|
|
|
- if ($el.is('a')) {
|
|
|
- if (!$el.data('studiou-fpp-href')) {
|
|
|
- $el.data('studiou-fpp-href', $el.attr('href'));
|
|
|
- }
|
|
|
- $el.attr('href', '#');
|
|
|
- } else {
|
|
|
- $el.prop('disabled', true);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- function enableAddToCart() {
|
|
|
- $(addToCartSelectors).each(function () {
|
|
|
- var $el = $(this);
|
|
|
- $el.removeClass('studiou-fpp-disabled');
|
|
|
- if ($el.is('a')) {
|
|
|
- var origHref = $el.data('studiou-fpp-href');
|
|
|
- if (origHref) {
|
|
|
- $el.attr('href', origHref);
|
|
|
- }
|
|
|
- } else {
|
|
|
- $el.prop('disabled', false);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Fallback: intercept clicks on disabled elements (capture phase)
|
|
|
- document.addEventListener('click', function (e) {
|
|
|
- if (!uploadedAttachmentId) {
|
|
|
- var el = e.target.closest(addToCartSelectors.replace(/,\s*/g, ', '));
|
|
|
- if (el) {
|
|
|
- e.preventDefault();
|
|
|
- e.stopImmediatePropagation();
|
|
|
- showMessage(studiouWcfppFront.i18n.uploadFile, 'error');
|
|
|
- $('html, body').animate({ scrollTop: $uploadWrap.offset().top - 100 }, 400);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- }, true); // capture phase - fires before bubble
|
|
|
-
|
|
|
- // Disable buttons on page load
|
|
|
- disableAddToCart();
|
|
|
-
|
|
|
- // Also watch for dynamically added buttons (e.g. AJAX-loaded variations)
|
|
|
- var observer = new MutationObserver(function () {
|
|
|
- if (!uploadedAttachmentId) {
|
|
|
- disableAddToCart();
|
|
|
- }
|
|
|
- });
|
|
|
- observer.observe(document.querySelector('.product') || document.body, {
|
|
|
- childList: true, subtree: true
|
|
|
- });
|
|
|
-
|
|
|
// ==========================================
|
|
|
// Restore session state on page load
|
|
|
// ==========================================
|
|
|
@@ -109,7 +36,6 @@
|
|
|
uploadedFileRecordId = studiouWcfppSession.file_record_id;
|
|
|
showPreview(studiouWcfppSession.thumbnail_url, studiouWcfppSession.file_name);
|
|
|
updateProductGallery(studiouWcfppSession.preview_url || studiouWcfppSession.thumbnail_url);
|
|
|
- enableAddToCart();
|
|
|
}
|
|
|
|
|
|
// ==========================================
|
|
|
@@ -226,7 +152,6 @@
|
|
|
|
|
|
showPreview(response.data.thumbnail_url, response.data.file_name);
|
|
|
updateProductGallery(response.data.preview_url || response.data.thumbnail_url);
|
|
|
- enableAddToCart();
|
|
|
$progress.hide();
|
|
|
isUploading = false;
|
|
|
} else {
|
|
|
@@ -293,27 +218,19 @@
|
|
|
$img = $(selectors[i]).first();
|
|
|
if ($img.length) break;
|
|
|
}
|
|
|
-
|
|
|
if (!$img || !$img.length) return;
|
|
|
|
|
|
if (!originalGalleryImages.src) {
|
|
|
originalGalleryImages.src = $img.attr('src');
|
|
|
originalGalleryImages.srcset = $img.attr('srcset') || '';
|
|
|
originalGalleryImages.sizes = $img.attr('sizes') || '';
|
|
|
- var $parentLink = $img.closest('a');
|
|
|
- if ($parentLink.length) {
|
|
|
- originalGalleryImages.href = $parentLink.attr('href');
|
|
|
- }
|
|
|
+ var $link = $img.closest('a');
|
|
|
+ if ($link.length) originalGalleryImages.href = $link.attr('href');
|
|
|
}
|
|
|
|
|
|
- $img.attr('src', imageUrl);
|
|
|
- $img.removeAttr('srcset');
|
|
|
- $img.removeAttr('sizes');
|
|
|
-
|
|
|
- var $parentLink = $img.closest('a');
|
|
|
- if ($parentLink.length) {
|
|
|
- $parentLink.attr('href', imageUrl);
|
|
|
- }
|
|
|
+ $img.attr('src', imageUrl).removeAttr('srcset').removeAttr('sizes');
|
|
|
+ var $link = $img.closest('a');
|
|
|
+ if ($link.length) $link.attr('href', imageUrl);
|
|
|
}
|
|
|
|
|
|
function restoreProductGallery() {
|
|
|
@@ -333,16 +250,12 @@
|
|
|
$img = $(selectors[i]).first();
|
|
|
if ($img.length) break;
|
|
|
}
|
|
|
-
|
|
|
if (!$img || !$img.length) return;
|
|
|
|
|
|
$img.attr('src', originalGalleryImages.src);
|
|
|
if (originalGalleryImages.srcset) $img.attr('srcset', originalGalleryImages.srcset);
|
|
|
if (originalGalleryImages.sizes) $img.attr('sizes', originalGalleryImages.sizes);
|
|
|
-
|
|
|
- if (originalGalleryImages.href) {
|
|
|
- $img.closest('a').attr('href', originalGalleryImages.href);
|
|
|
- }
|
|
|
+ if (originalGalleryImages.href) $img.closest('a').attr('href', originalGalleryImages.href);
|
|
|
|
|
|
originalGalleryImages = {};
|
|
|
}
|
|
|
@@ -391,7 +304,6 @@
|
|
|
uploadedFileRecordId = null;
|
|
|
clearSession();
|
|
|
restoreProductGallery();
|
|
|
- disableAddToCart();
|
|
|
$preview.hide();
|
|
|
$previewImg.attr('src', '');
|
|
|
$previewName.text('');
|