1var wfeaModalCallback = function () { 2 console.log('Order complete!'); 3}; 4 5(function ($) { 6 'use strict'; 7 8 var EB_SCRIPT_URL = 'https://www.eventbrite.com/static/widgets/eb_widgets.js'; 9 10 // Populated by wp_localize_script. Absent means no gate, which is the pre-6.7.0 behaviour. 11 var config = (typeof wfea_consent !== 'undefined') ? wfea_consent : {}; 12 var gated = String(config.gate || '0') === '1'; 13 var forceBlock = String(config.forceBlock || '0') === '1'; 14 var categories = config.categories || ['marketing', 'statistics']; 15 16 var scriptPromise = null; 17 // Set by window.wfeaGrantConsent() for banners that do not speak the WP Consent API. 18 var manualConsent = false; 19 20 /** 21 * Fetch eb_widgets.js once, on demand. When the gate is off the script is already on the page 22 * and this resolves immediately. 23 */ 24 function loadEbScript() { 25 if (typeof EBWidgets !== 'undefined') { 26 return $.Deferred().resolve().promise(); 27 } 28 if (!scriptPromise) { 29 scriptPromise = $.ajax({url: EB_SCRIPT_URL, dataType: 'script', cache: true}); 30 } 31 return scriptPromise; 32 } 33 34 /** 35 * Has the visitor agreed to what the embedded checkout will set? 36 * 37 * Only ever called when gated. Without the WP Consent API there is nothing to ask, so the 38 * answer is yes unless the site has explicitly asked us to fail closed. 39 */ 40 function hasConsent() { 41 if (manualConsent) { 42 return true; 43 } 44 if (forceBlock) { 45 return false; 46 } 47 if (typeof window.wp_has_consent !== 'function') { 48 return true; 49 } 50 for (var i = 0; i < categories.length; i++) { 51 if (!window.wp_has_consent(categories[i])) { 52 return false; 53 } 54 } 55 return true; 56 } 57 58 /** 59 * Turn a gated element back into an ordinary link so the click navigates to Eventbrite. 60 */ 61 function releaseToLink($el) { 62 var url = $el.data('ebUrl'); 63 if (!url) { 64 return false; 65 } 66 $el.attr('href', url).removeAttr('onclick'); 67 return url; 68 } 69 70 function createWidget(el) { 71 var $el = $(el); 72 if ($el.data('ebWidgetCreated')) { 73 return; 74 } 75 $el.data('ebWidgetCreated', true); 76 EBWidgets.createWidget({ 77 widgetType: 'checkout', 78 eventId: el.dataset.ebId, 79 modal: true, 80 modalTriggerElementId: el.id, 81 onOrderComplete: wfeaModalCallback 82 }); 83 } 84 85 $.fn.extend({ 86 /** 87 * Bind Eventbrite checkout modals to matched elements. 88 * 89 * Kept as a public jQuery method because calendar.js calls it on every render. 90 */ 91 wfeaBindLinksToEB: function () { 92 return this.each(function () { 93 if (!document.getElementById(this.id) || $(this).data('ebWidgetCreated')) { 94 return; 95 } 96 97 if (!gated) { 98 // Unchanged pre-6.7.0 path: script already loaded, bind immediately. 99 createWidget(this); 100 return; 101 } 102 103 var el = this; 104 var $el = $(el); 105 106 if (!hasConsent()) { 107 // No modal, no request to eventbrite.com. The click leaves the site instead. 108 releaseToLink($el); 109 return; 110 } 111 112 // Consent is in place, so fetching the script is now allowed. 113 loadEbScript().done(function () { 114 createWidget(el); 115 }); 116 }); 117 } 118 }); 119 120 function bindAll() { 121 $('[data-eb-id]').wfeaBindLinksToEB(); 122 } 123 124 /** 125 * Release the checkout for banners that do not implement the WP Consent API. 126 * 127 * Paired with the wfea_consent_force_block filter, which blocks until this is called. 128 */ 129 /** 130 * Put the elements back into modal state after they were released to plain links. 131 */ 132 function restoreModalLinks() { 133 $('[data-eb-id]').each(function () { 134 $(this).attr('href', '#').attr('onclick', 'return false'); 135 }); 136 } 137 138 window.wfeaGrantConsent = function () { 139 manualConsent = true; 140 restoreModalLinks();
141 bindAll(); 142 $(document).trigger('wfea_consent_granted'); 143 }; 144 145 $(function () { 146 bindAll(); 147 148 // A visitor who accepts mid-session should get the modal without reloading. 149 // 150 // The WP Consent API signals this by dispatching a 'wp_listen_for_consent_change' event on 151 // document, with e.detail keyed by category. There is no window.wp_listen_for_consent_change 152 // function, despite the name reading like one. 153 if (gated) { 154 document.addEventListener('wp_listen_for_consent_change', function (e) { 155 var changed = e.detail || {}; 156 var relevant = false; 157 for (var key in changed) { 158 if (categories.indexOf(key) !== -1) { 159 relevant = true; 160 } 161 } 162 if (!relevant) { 163 return; 164 } 165 166 if (hasConsent()) { 167 restoreModalLinks(); 168 bindAll(); 169 } else { 170 // Consent withdrawn. Anything not yet bound goes back to being a plain link.
171 // Widgets already created cannot be undone here; that needs a page load. 172 $('[data-eb-id]').each(function () { 173 if (!$(this).data('ebWidgetCreated')) { 174 releaseToLink($(this)); 175 } 176 }); 177 } 178 }); 179 } 180 }); 181})(jQuery);
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.