' + '
' + '
' + MSDEV_PICKUP.titleHtml + '
' + ' ' + escapeHtml(MSDEV_PICKUP.linkText) + '' + '
' + ' ' + '
' + escapeHtml(data.price) + '
' + ' ' + '
' + ''; } function buildPickupModalHtml(data){ return '' + ''; } function upsertPickupModal(data){ var wasOpen = $('#msdev-pickup-modal').hasClass('is-open'); $('#msdev-pickup-modal').remove(); $('body').append(buildPickupModalHtml(data)); if (wasOpen) { $('#msdev-pickup-modal').addClass('is-open').attr('aria-hidden', 'false'); $('body').css('overflow', 'hidden'); } } function upsertPickupCard(data, $row){ var $result = $row.closest('.result'); var $existing = $('#msdev-pickup-card'); $row.addClass('msdev-pickup-source-row'); if ($existing.length) { $existing.replaceWith(buildPickupCardHtml(data)); return; } if ($result.length) { $result.append(buildPickupCardHtml(data)); return; } $row.closest('.product-shipping').append(buildPickupCardHtml(data)); } function removePickupUi(){ $('#msdev-pickup-card').remove(); $('#msdev-pickup-modal').remove(); $('.product-shipping .shipping-rates-table tr.msdev-pickup-source-row').removeClass('msdev-pickup-source-row'); msdevPickupLastSignature = ''; } function ensurePickupUi(){ if (!MSDEV_PICKUP.enabled || !isProductPage()) return; if (msdevPickupApplying) return; if (isStillLoading()) { if (msdevPickupLastState !== 'loading') { log('[MSDEV PICKUP] Aguardando carregamento completo dos fretes...'); msdevPickupLastState = 'loading'; } return; } var $row = getPickupRow(); if (!$row.length) { if (msdevPickupLastState !== 'not-found') { log('[MSDEV PICKUP] Opção de retirada não encontrada na resposta atual.'); msdevPickupLastState = 'not-found'; } removePickupUi(); return; } var data = extractPickupData($row); var signature = getDataSignature(data); if (signature === msdevPickupLastSignature && $('#msdev-pickup-card').length) { return; } msdevPickupLastState = 'found'; log('[MSDEV PICKUP] Opção de retirada encontrada:', data); msdevPickupApplying = true; try { upsertPickupCard(data, $row); upsertPickupModal(data); msdevPickupLastSignature = signature; log('[MSDEV PICKUP] Alteração aplicada no módulo de retirada.'); } finally { setTimeout(function(){ msdevPickupApplying = false; }, 120); } } function scheduleEnsurePickupUi(delay){ clearTimeout(msdevPickupTimer); msdevPickupTimer = setTimeout(function(){ ensurePickupUi(); }, delay || 250); } function observeProductShipping(){ if (!isProductPage()) return; var $shippingBox = getShippingBox(); if (!$shippingBox.length) return; if (msdevPickupObserver) return; if (window.MutationObserver) { msdevPickupObserver = new MutationObserver(function(mutations){ var shouldSchedule = false; for (var i = 0; i < mutations.length; i++) { var target = mutations[i].target; if ($(target).closest('#msdev-pickup-card, #msdev-pickup-modal').length) { continue; } shouldSchedule = true; break; } if (shouldSchedule) { scheduleEnsurePickupUi(350); } }); msdevPickupObserver.observe($shippingBox[0], { childList: true, subtree: true, characterData: false, attributes: false }); } $(document).on('click', '.submit-shipping, .botao-simular-frete, [data-app="product.shipping-calculate"]', function(){ scheduleEnsurePickupUi(900); setTimeout(function(){ scheduleEnsurePickupUi(1600); }, 900); setTimeout(function(){ scheduleEnsurePickupUi(2600); }, 1900); }); $(document).on('submit', '.shipping-form', function(){ scheduleEnsurePickupUi(900); setTimeout(function(){ scheduleEnsurePickupUi(1600); }, 900); setTimeout(function(){ scheduleEnsurePickupUi(2600); }, 1900); }); } function openPickupModal(){ $('#msdev-pickup-modal').addClass('is-open').attr('aria-hidden', 'false'); $('body').css('overflow', 'hidden'); } function closePickupModal(){ $('#msdev-pickup-modal').removeClass('is-open').attr('aria-hidden', 'true'); $('body').css('overflow', ''); } $(document).on('click', '#msdev-pickup-card, #msdev-pickup-card .msdev-pickup-card-link', function(e){ e.preventDefault(); e.stopPropagation(); openPickupModal(); }); $(document).on('click', '#msdev-pickup-modal .msdev-pickup-dialog', function(e){ e.stopPropagation(); }); $(document).on('click', '#msdev-pickup-modal .msdev-pickup-overlay, #msdev-pickup-modal .msdev-pickup-close', function(e){ e.preventDefault(); e.stopPropagation(); closePickupModal(); }); $(document).on('keydown', function(e){ if (e.key === 'Escape') { closePickupModal(); } }); $(window).on('load resize', function(){ scheduleEnsurePickupUi(400); }); $(function(){ observeProductShipping(); scheduleEnsurePickupUi(500); }); })(window.jQuery);

MAIS VENDIDOS

MAIS VENDIDOS

MAIS VENDIDOS

MAIS VENDIDOS