1 2jQuery(function ($) { 3 'use strict'; 4 try { 5 6 // Shared lightcase options for every gift popup. onFinish operates on the open 7 // case so it works for any modal (eligible gifts, gift products, force gifts). 8 var fgfPopupOptions = { 9 onFinish: { 10 fgf: function () { 11 var lc = $('#lightcase-case'); 12 lc.find('.owl-nav').remove(); 13 lc.find('.owl-dots').remove(); 14 lightcase.resize(); 15 $(document.body).trigger('fgf-enhanced-carousel'); 16 $(document.body).trigger('fgf_lightcase_finished'); 17 } 18 }, 19 onClose: { 20 lc: function () { 21 $(document.body).trigger('fgf_lightcase_closed'); 22 } 23 } 24 }; 25 26 /** 27 * Bind every gift popup trigger carrying the fgf-gifts-popup-trigger class 28 * directly through lightcase: eligible gifts, gift products and the force 29 * checkout gifts popup. Re-run on every cart/checkout refresh so freshly 30 * rendered triggers get bound; lightcase's init() unbinds before binding, so 31 * repeat calls never stack handlers. Each bound trigger is flagged so the 32 * delegated fallback below leaves it alone (avoids opening the modal twice). 33 * 34 * Each trigger opens its own modal via its href; a trigger without one (e.g. 35 * a custom button or href="#") falls back to the main gift products popup. 36 * 37 * @since 12.5.0 38 */ 39 $(document.body).on('fgf-enhanced-lightcase', function ( ) { 40 var $triggers = $('.fgf-gifts-popup-trigger'); 41 if (!$triggers.length) { 42 return; 43 } 44 45 $triggers.each(function () { 46 var href = $(this).attr('href'); 47 if (!href || '#' === href) { 48 $(this).attr('href', '#fgf_gift_products_modal'); 49 } 50 }).lightcase(fgfPopupOptions).attr('data-fgf-lc-bound', '1'); 51 }); 52 53 /** 54 * Delegated fallback for triggers the class based binding above cannot reach: 55 * - block cart/checkout notice triggers whose fgf-gifts-popup-trigger class 56 * the notice sanitizer strips (so only the href survives); 57 * - triggers React re-renders after a block cart update, which replaces the 58 * bound node with a fresh, unbound one (no data-fgf-lc-bound flag). 59 * 60 * Delegation on document.body survives every re-render. Triggers already bound 61 * directly are flagged and skipped here, so lightcase's own click handler opens 62 * them and the modal never opens twice. 63 * 64 * @since 12.5.0 65 */ 66 $(document.body).on('click', '.fgf-gifts-popup-trigger, a[href^="#fgf-eligible-gifts-modal-"], a[href="#fgf_gift_products_modal"]', function (event) { 67 var trigger = $(this); 68 69 // Already bound directly by lightcase init; let that handler open it. 70 if (trigger.attr('data-fgf-lc-bound')) { 71 return; 72 } 73 74 var target = trigger.attr('href'); 75 76 // Triggers with no usable href fall back to the gift products modal. 77 if (!target || '#' === target) { 78 target = '#fgf_gift_products_modal'; 79 } 80 81 if (!$(target).length) { 82 return; 83 } 84 85 event.preventDefault(); 86 87 trigger.lightcase('start', $.extend({ href: target }, fgfPopupOptions)); 88 }); 89 90 /** 91 * Call to close light case popup. 92 * 93 * @since 12.4.0 94 */ 95 $(document.body).on('fgf_close_lightcase', function ( ) { 96 $('.lightcase-icon-close').trigger('click'); 97 }); 98 99 // Initialize carousel when cart updated. 100 $(document.body).on('updated_wc_div', function ( ) { 101 $(document.body).trigger('fgf-enhanced-lightcase'); 102 }); 103 104 // Initialize carousel when checkout updated. 105 $(document.body).on('updated_checkout', function ( ) { 106 $(document.body).trigger('fgf-enhanced-lightcase'); 107 }); 108 109 $(document.body).trigger('fgf-enhanced-lightcase'); 110 } catch (err) { 111 window.console.log(err); 112 } 113 114});
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.