1(function() { 2 const is = { 3 arr: function(a) { 4 return Array.isArray(a); 5 }, 6 obj: function(a) { 7 return Object.prototype.toString.call(a).includes("Object"); 8 }, 9 str: function(a) { 10 return typeof a === "string"; 11 }, 12 fnc: function(a) { 13 return typeof a === "function"; 14 }, 15 und: function(a) { 16 return typeof a === "undefined"; 17 }, 18 nil: function(a) { 19 return is.und(a) || a === null; 20 } 21 }; 22 23 /* 24 * Breakpoints 25 */ 26 27 function getMediaQueryString(minWidth, maxWidth) { 28 if (minWidth && maxWidth) { 29 return `(min-width: ${minWidth}px) and (max-width: ${maxWidth}px)`; 30 } 31 32 if (maxWidth) { 33 return `(max-width: ${maxWidth}px)`; 34 } 35 36 if (minWidth) { 37 return `(min-width: ${minWidth}px)`; 38 } 39 40 return null; 41 } 42 43 function matchAnyMedia() { 44 const { BASE_BREAKPOINT_ID, breakpoints } = window.BreakdanceFrontend.data; 45 46 return breakpoints 47 .filter(b => b.id !== BASE_BREAKPOINT_ID) 48 .some(b => matchMedia(b.id)); 49 } 50 51 function matchMedia(id) { 52 const { BASE_BREAKPOINT_ID, breakpoints } = window.BreakdanceFrontend.data; 53 const breakpoint = breakpoints.find(b => b.id === id); 54 55 if (!breakpoint) return false; 56 if (id === BASE_BREAKPOINT_ID) return !matchAnyMedia(); 57 58 const { minWidth, maxWidth } = breakpoint; 59 const mediaQuery = getMediaQueryString(minWidth, maxWidth); 60 return window.matchMedia(mediaQuery).matches; 61 } 62 63 /* 64 * DOM-related utils 65 */ 66 67 function selectString(str) { 68 try { 69 return document.querySelectorAll(str); 70 } catch (e) { 71 return null; 72 } 73 } 74 75 // Turn element, string selector or nodeList into an array 76 function toArray(o) { 77 if (is.arr(o)) { 78 return o; 79 } 80 if (is.str(o)) { 81 o = selectString(o) || o; 82 } 83 if (o instanceof NodeList || o instanceof HTMLCollection) { 84 return [].slice.call(o); 85 } 86 return [o]; 87 } 88 89 /* 90 * Objects 91 */ 92 93 function cloneObject(obj) { 94 return JSON.parse(JSON.stringify(obj)); 95 } 96 97 /** 98 * Performs a deep merge of `source` into `target`. 99 * Undefined values are not copied to the target object. 100 * @author inspired by [jhildenbiddle](https://stackoverflow.com/a/48218209). 101 */ 102 function mergeObjects(obj1, source) { 103 const target = cloneObject(obj1); 104 105 if (!is.obj(source)) { 106 return target; 107 } 108 109 Object.keys(source).forEach(key => { 110 const targetValue = target[key]; 111 const sourceValue = source[key]; 112 113 if (is.obj(targetValue) && is.obj(sourceValue)) { 114 target[key] = mergeObjects(Object.assign({}, targetValue), sourceValue); 115 } else if (!is.nil(sourceValue)) { 116 target[key] = sourceValue; 117 } 118 }); 119 120 return target; 121 } 122 123 /* 124 * Event Listeners 125 */ 126 127 function on(eventName, element, callback) { 128 if (!is.fnc(callback)) { 129 callback = element; 130 element = null; 131 } 132 133 if (element) { 134 toArray(element).forEach(el => { 135 el.addEventListener(eventName, callback); 136 }); 137 } else { 138 window.addEventListener(eventName, callback); 139 } 140 } 141 142 function off(eventName, element, callback) { 143 if (!is.fnc(callback)) { 144 callback = element; 145 element = null; 146 } 147 148 if (element) { 149 toArray(element).forEach(el => { 150 el.removeEventListener(eventName, callback); 151 }); 152 } else { 153 window.removeEventListener(eventName, callback); 154 } 155 } 156 157 function onResize(callback) { 158 const resizeObserver = new ResizeObserver(callback); 159 resizeObserver.observe(document.body); 160 161 return () => { 162 resizeObserver.disconnect(); 163 }; 164 } 165 166 /* 167 * Function 168 */ 169 170 // Returns a function, that, as long as it continues to be invoked, will not 171 // be triggered. The function will be called after it stops being called for 172 // N milliseconds. If `immediate` is passed, trigger the function on the 173 // leading edge, instead of the trailing. 174 function debounce(callback, wait, immediate) { 175 let timeout; 176 return function() { 177 const context = this, 178 args = arguments; 179 const later = function() { 180 timeout = null;
181 if (!immediate) callback.apply(context, args); 182 }; 183 const callNow = immediate && !timeout; 184 clearTimeout(timeout); 185 timeout = setTimeout(later, wait); 186 if (callNow) callback.apply(context, args); 187 }; 188 } 189 190 function throttle(callback, wait) { 191 let waiting = false; 192 return function() { 193 if (!waiting) { 194 callback.apply(this, arguments); 195 waiting = true; 196 setTimeout(() => { 197 waiting = false; 198 }, wait); 199 } 200 }; 201 } 202 203 function prefersReducedMotion() { 204 return window.matchMedia("(prefers-reduced-motion: reduce)").matches; 205 } 206 207 function makeAjaxRequest(url, options) { 208 const urlObject = new URL(url); 209 if (window.BreakdanceFrontend.data.ajaxNonce) { 210 urlObject.searchParams.set( 211 "_ajax_nonce", 212 window.BreakdanceFrontend.data.ajaxNonce 213 ); 214 } 215 return fetch(urlObject.toString(), options).then(response => { 216 const clonedResponse = response.clone(); 217 response.json().then(data => { 218 // if response data contains a _refreshNonce, 219 // update the nonce on the window object 220 if (data?._refreshNonce) { 221 window.BreakdanceFrontend.data.ajaxNonce = data._refreshNonce; 222 } 223 }); 224 return clonedResponse; 225 }); 226 } 227 228 if (!window.BreakdanceFrontend) { 229 window.BreakdanceFrontend = {}; 230 } 231 232 window.BreakdanceFrontend.utils = { 233 is,
234 // Breakpoint 235 getMediaQueryString, 236 matchMedia, 237 matchAnyMedia, 238 239 // DOM 240 toArray, 241 // Objects 242 cloneObject, 243 mergeObjects, 244 // Event Listeners 245 on, 246 off, 247 onResize, 248 // Other 249 debounce, 250 throttle, 251 prefersReducedMotion, 252 makeAjaxRequest 253 }; 254})();
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.