1/** 2 * Store discount display 3 * 4 * The struck-through price and the "Save x%" badge are both driven by 5 * FastSpring rather than by postmeta. SBL fills 6 * data-fsc-item-discountPercentValue with a plain number once it has priced 7 * the page, and this reveals the pair when that number is above zero. 8 * 9 * It has to work this way round. discount_amount_usd is what the sync plugin 10 * pushes to FastSpring when a product is saved, but it is not what FastSpring 11 * charges - a store-wide campaign discounts the cart without touching 12 * postmeta. Gating the markup on postmeta, which is what the old cards did, 13 * hides a real saving whenever the two disagree. 14 * 15 * Starts hidden and is only ever revealed, so a page where SBL fails to load 16 * shows no discount rather than an empty one. 17 * 18 * @copyright 2026, ON1 19 */ 20 21(function() { 22 'use strict'; 23 24 var SELECTOR = '[data-fsc-item-discountPercentValue]'; 25 26 function reveal(field) { 27 var value = parseFloat(field.textContent); 28 29 if (isNaN(value) || value <= 0) { 30 return false; 31 } 32 33 var row = field.closest('[data-store-price]'); 34 35 if (!row) { 36 return false; 37 } 38 39 row.querySelectorAll('[data-store-discount]').forEach(function(el) { 40 el.hidden = false; 41 }); 42 43 return true; 44 } 45 46 function sweep() { 47 document.querySelectorAll(SELECTOR).forEach(reveal); 48 } 49 50 function init() { 51 var fields = document.querySelectorAll(SELECTOR); 52 53 if (!fields.length) { 54 return; 55 } 56 57 sweep(); 58 59 /* 60 * SBL paints asynchronously and repaints on a currency or coupon 61 * change, so one pass at load is not enough. Watching the fields 62 * themselves is cheaper than watching the grid. 63 */ 64 var observer = new MutationObserver(sweep); 65 66 fields.forEach(function(field) { 67 observer.observe(field, { characterData: true, childList: true, subtree: true }); 68 }); 69 } 70 71 if (document.readyState === 'loading') { 72 document.addEventListener('DOMContentLoaded', init); 73 } else { 74 init(); 75 } 76})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.