1/* 2 * jquery4-compat.js 3 * 4 * Compatibility shim for the jQuery 3 -> jQuery 4 jump that came with the 5 * PrimeFaces 15 upgrade. 6 * 7 * PrimeFaces 15 bundles jQuery 4.x, which removed a set of long-deprecated 8 * APIs. Third party code this application depends on still calls them: 9 * 10 * jssocials.min.js (social share buttons) -> $.trim 11 * jquery.bracket.min.js (bracket rendering) -> .size(), .unbind() 12 * jquery.group.min.js (bracket groups) -> .bind(), .size() 13 * jquery.floatingscroll.min.js (bracket scrolling) -> .bind(), .unbind() 14 * 15 * The two jquery.bracket/group .min.js files are GENERATED by 16 * `npm run build:bracket` (esbuild) from the sibling jquery.bracket.js / 17 * jquery.group.js sources; the pages keep loading the .min.js names. 18 * Edit the .js/.css sources and re-run that script - never edit the .min files. 19 * 20 * Without the shim those calls throw, e.g. 21 * TypeError: b.trim is not a function 22 * and the affected widgets silently stop working. 23 * 24 * This file only defines what is actually missing, so it is a no-op on a page 25 * that still uses jQuery 3. It must be loaded from the page <head> (both 26 * templates do) so that it runs after jQuery is present but before any 27 * $(document).ready() callback, which is where the legacy plugins initialise. 28 */ 29(function (global) { 30 "use strict"; 31 32 var patchedCount = 0; 33 34 function patch(jq) { 35 if (!jq || typeof jq !== "function" || jq.__ebJquery4Compat) { 36 return false; 37 } 38 39 /* ---- jQuery statics ---------------------------------------------- */ 40 41 if (typeof jq.trim !== "function") { 42 jq.trim = function (value) { 43 return value == null 44 ? "" 45 : (value + "").replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); 46 }; 47 } 48 49 if (typeof jq.isArray !== "function") { 50 jq.isArray = Array.isArray; 51 } 52 53 if (typeof jq.isFunction !== "function") { 54 jq.isFunction = function (value) { 55 return ( 56 typeof value === "function" && 57 Object.prototype.toString.call(value) !== "[object RegExp]" 58 ); 59 }; 60 } 61 62 if (typeof jq.type !== "function") { 63 jq.type = function (value) { 64 if (value == null) { 65 return String(value); // "null" / "undefined" 66 } 67 if ( 68 typeof value === "number" || 69 typeof value === "boolean" || 70 typeof value === "string" 71 ) { 72 return typeof value; 73 } 74 return Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); 75 }; 76 } 77 78 if (typeof jq.isNumeric !== "function") { 79 jq.isNumeric = function (value) { 80 var kind = jq.type(value); 81 return ( 82 (kind === "number" || kind === "string") && 83 !isNaN(value - parseFloat(value)) 84 ); 85 }; 86 } 87 88 if (typeof jq.isWindow !== "function") { 89 jq.isWindow = function (value) { 90 return value != null && value === value.window; 91 }; 92 } 93 94 if (typeof jq.now !== "function") { 95 jq.now = Date.now; 96 } 97 98 if (typeof jq.parseJSON !== "function") { 99 jq.parseJSON = function (data) { 100 return data == null ? null : JSON.parse(data + ""); 101 }; 102 } 103 104 if (typeof jq.nodeName !== "function") { 105 jq.nodeName = function (elem, name) { 106 return ( 107 !!elem && 108 !!elem.nodeName && 109 elem.nodeName.toLowerCase() === (name + "").toLowerCase() 110 ); 111 }; 112 } 113 114 if (typeof jq.camelCase !== "function") { 115 jq.camelCase = function (value) { 116 return (value + "") 117 .replace(/^-ms-/, "ms-") 118 .replace(/-([a-z])/g, function (all, chr) { 119 return chr.toUpperCase(); 120 }); 121 }; 122 } 123 124 /* ---- jQuery.fn --------------------------------------------------- */ 125 126 var fn = jq.fn; 127 if (fn) { 128 if (typeof fn.bind !== "function") { 129 fn.bind = function () { 130 return this.on.apply(this, arguments); 131 }; 132 } 133 if (typeof fn.unbind !== "function") { 134 fn.unbind = function () { 135 return this.off.apply(this, arguments); 136 }; 137 } 138 if (typeof fn.delegate !== "function") { 139 fn.delegate = function (selector, types, data, handler) { 140 return this.on(types, selector, data, handler); 141 }; 142 } 143 if (typeof fn.undelegate !== "function") { 144 fn.undelegate = function (selector, types, handler) { 145 return this.off(types, selector, handler); 146 }; 147 } 148 if (typeof fn.size !== "function") { 149 fn.size = function () { 150 return this.length; 151 }; 152 } 153 if (typeof fn.andSelf !== "function") { 154 fn.andSelf = 155 typeof fn.addBack === "function" 156 ? fn.addBack 157 : function () { 158 return this; 159 }; 160 } 161 } 162 163 jq.__ebJquery4Compat = true; 164 patchedCount++; 165 return true; 166 } 167 168 function patchGlobals() { 169 patch(global.jQuery); 170 if (global.$ !== global.jQuery) { 171 patch(global.$); 172 } 173 } 174 175 patchGlobals(); 176 177 if (patchedCount === 0) { 178 /* jQuery was not installed yet: wait for it, but never linger. */ 179 var attempts = 0; 180 (function retry() { 181 patchGlobals(); 182 if (patchedCount === 0 && ++attempts < 80) { 183 // ~2s at 25ms
184 global.setTimeout(retry, 25); 185 } 186 })(); 187 } 188 189 /* A jQuery installed by a later resource must be patched before any 190 ready() callback runs. */ 191 if (global.document && global.document.readyState === "loading") { 192 global.document.addEventListener("DOMContentLoaded", patchGlobals); 193 } 194})(typeof window !== "undefined" ? window : this);
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.