jquery-migrate.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. /*!
  2. * jQuery Migrate - v3.5.2 - 2024-07-17T22:31Z
  3. * Copyright OpenJS Foundation and other contributors
  4. */
  5. ( function( factory ) {
  6. "use strict";
  7. if ( typeof define === "function" && define.amd ) {
  8. // AMD. Register as an anonymous module.
  9. define( [ "jquery" ], function( jQuery ) {
  10. return factory( jQuery, window );
  11. } );
  12. } else if ( typeof module === "object" && module.exports ) {
  13. // Node/CommonJS
  14. // eslint-disable-next-line no-undef
  15. module.exports = factory( require( "jquery" ), window );
  16. } else {
  17. // Browser globals
  18. factory( jQuery, window );
  19. }
  20. } )( function( jQuery, window ) {
  21. "use strict";
  22. jQuery.migrateVersion = "3.5.2";
  23. // Returns 0 if v1 == v2, -1 if v1 < v2, 1 if v1 > v2
  24. function compareVersions( v1, v2 ) {
  25. var i,
  26. rVersionParts = /^(\d+)\.(\d+)\.(\d+)/,
  27. v1p = rVersionParts.exec( v1 ) || [ ],
  28. v2p = rVersionParts.exec( v2 ) || [ ];
  29. for ( i = 1; i <= 3; i++ ) {
  30. if ( +v1p[ i ] > +v2p[ i ] ) {
  31. return 1;
  32. }
  33. if ( +v1p[ i ] < +v2p[ i ] ) {
  34. return -1;
  35. }
  36. }
  37. return 0;
  38. }
  39. function jQueryVersionSince( version ) {
  40. return compareVersions( jQuery.fn.jquery, version ) >= 0;
  41. }
  42. // A map from disabled patch codes to `true`. This should really
  43. // be a `Set` but those are unsupported in IE.
  44. var disabledPatches = Object.create( null );
  45. // Don't apply patches for specified codes. Helpful for code bases
  46. // where some Migrate warnings have been addressed and it's desirable
  47. // to avoid needless patches or false positives.
  48. jQuery.migrateDisablePatches = function() {
  49. var i;
  50. for ( i = 0; i < arguments.length; i++ ) {
  51. disabledPatches[ arguments[ i ] ] = true;
  52. }
  53. };
  54. // Allow enabling patches disabled via `jQuery.migrateDisablePatches`.
  55. // Helpful if you want to disable a patch only for some code that won't
  56. // be updated soon to be able to focus on other warnings - and enable it
  57. // immediately after such a call:
  58. // ```js
  59. // jQuery.migrateDisablePatches( "workaroundA" );
  60. // elem.pluginViolatingWarningA( "pluginMethod" );
  61. // jQuery.migrateEnablePatches( "workaroundA" );
  62. // ```
  63. jQuery.migrateEnablePatches = function() {
  64. var i;
  65. for ( i = 0; i < arguments.length; i++ ) {
  66. delete disabledPatches[ arguments[ i ] ];
  67. }
  68. };
  69. jQuery.migrateIsPatchEnabled = function( patchCode ) {
  70. return !disabledPatches[ patchCode ];
  71. };
  72. ( function() {
  73. // Support: IE9 only
  74. // IE9 only creates console object when dev tools are first opened
  75. // IE9 console is a host object, callable but doesn't have .apply()
  76. if ( !window.console || !window.console.log ) {
  77. return;
  78. }
  79. // Need jQuery 3.x-4.x and no older Migrate loaded
  80. if ( !jQuery || !jQueryVersionSince( "3.0.0" ) ||
  81. jQueryVersionSince( "5.0.0" ) ) {
  82. window.console.log( "JQMIGRATE: jQuery 3.x-4.x REQUIRED" );
  83. }
  84. if ( jQuery.migrateWarnings ) {
  85. window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
  86. }
  87. // Show a message on the console so devs know we're active
  88. window.console.log( "JQMIGRATE: Migrate is installed" +
  89. ( jQuery.migrateMute ? "" : " with logging active" ) +
  90. ", version " + jQuery.migrateVersion );
  91. } )();
  92. var warnedAbout = {};
  93. // By default each warning is only reported once.
  94. jQuery.migrateDeduplicateWarnings = true;
  95. // List of warnings already given; public read only
  96. jQuery.migrateWarnings = [];
  97. // Set to false to disable traces that appear with warnings
  98. if ( jQuery.migrateTrace === undefined ) {
  99. jQuery.migrateTrace = true;
  100. }
  101. // Forget any warnings we've already given; public
  102. jQuery.migrateReset = function() {
  103. warnedAbout = {};
  104. jQuery.migrateWarnings.length = 0;
  105. };
  106. function migrateWarn( code, msg ) {
  107. var console = window.console;
  108. if ( jQuery.migrateIsPatchEnabled( code ) &&
  109. ( !jQuery.migrateDeduplicateWarnings || !warnedAbout[ msg ] ) ) {
  110. warnedAbout[ msg ] = true;
  111. jQuery.migrateWarnings.push( msg + " [" + code + "]" );
  112. if ( console && console.warn && !jQuery.migrateMute ) {
  113. console.warn( "JQMIGRATE: " + msg );
  114. if ( jQuery.migrateTrace && console.trace ) {
  115. console.trace();
  116. }
  117. }
  118. }
  119. }
  120. function migrateWarnProp( obj, prop, value, code, msg ) {
  121. Object.defineProperty( obj, prop, {
  122. configurable: true,
  123. enumerable: true,
  124. get: function() {
  125. migrateWarn( code, msg );
  126. return value;
  127. },
  128. set: function( newValue ) {
  129. migrateWarn( code, msg );
  130. value = newValue;
  131. }
  132. } );
  133. }
  134. function migrateWarnFuncInternal( obj, prop, newFunc, code, msg ) {
  135. var finalFunc,
  136. origFunc = obj[ prop ];
  137. obj[ prop ] = function() {
  138. // If `msg` not provided, do not warn; more sophisticated warnings
  139. // logic is most likely embedded in `newFunc`, in that case here
  140. // we just care about the logic choosing the proper implementation
  141. // based on whether the patch is disabled or not.
  142. if ( msg ) {
  143. migrateWarn( code, msg );
  144. }
  145. // Since patches can be disabled & enabled dynamically, we
  146. // need to decide which implementation to run on each invocation.
  147. finalFunc = jQuery.migrateIsPatchEnabled( code ) ?
  148. newFunc :
  149. // The function may not have existed originally so we need a fallback.
  150. ( origFunc || jQuery.noop );
  151. return finalFunc.apply( this, arguments );
  152. };
  153. }
  154. function migratePatchAndWarnFunc( obj, prop, newFunc, code, msg ) {
  155. if ( !msg ) {
  156. throw new Error( "No warning message provided" );
  157. }
  158. return migrateWarnFuncInternal( obj, prop, newFunc, code, msg );
  159. }
  160. function migratePatchFunc( obj, prop, newFunc, code ) {
  161. return migrateWarnFuncInternal( obj, prop, newFunc, code );
  162. }
  163. if ( window.document.compatMode === "BackCompat" ) {
  164. // jQuery has never supported or tested Quirks Mode
  165. migrateWarn( "quirks", "jQuery is not compatible with Quirks Mode" );
  166. }
  167. var findProp,
  168. class2type = {},
  169. oldInit = jQuery.fn.init,
  170. oldFind = jQuery.find,
  171. rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
  172. rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g,
  173. // Require that the "whitespace run" starts from a non-whitespace
  174. // to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position.
  175. rtrim = /^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g;
  176. migratePatchFunc( jQuery.fn, "init", function( arg1 ) {
  177. var args = Array.prototype.slice.call( arguments );
  178. if ( jQuery.migrateIsPatchEnabled( "selector-empty-id" ) &&
  179. typeof arg1 === "string" && arg1 === "#" ) {
  180. // JQuery( "#" ) is a bogus ID selector, but it returned an empty set
  181. // before jQuery 3.0
  182. migrateWarn( "selector-empty-id", "jQuery( '#' ) is not a valid selector" );
  183. args[ 0 ] = [];
  184. }
  185. return oldInit.apply( this, args );
  186. }, "selector-empty-id" );
  187. // This is already done in Core but the above patch will lose this assignment
  188. // so we need to redo it. It doesn't matter whether the patch is enabled or not
  189. // as the method is always going to be a Migrate-created wrapper.
  190. jQuery.fn.init.prototype = jQuery.fn;
  191. migratePatchFunc( jQuery, "find", function( selector ) {
  192. var args = Array.prototype.slice.call( arguments );
  193. // Support: PhantomJS 1.x
  194. // String#match fails to match when used with a //g RegExp, only on some strings
  195. if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
  196. // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
  197. // First see if qS thinks it's a valid selector, if so avoid a false positive
  198. try {
  199. window.document.querySelector( selector );
  200. } catch ( err1 ) {
  201. // Didn't *look* valid to qSA, warn and try quoting what we think is the value
  202. selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
  203. return "[" + attr + op + "\"" + value + "\"]";
  204. } );
  205. // If the regexp *may* have created an invalid selector, don't update it
  206. // Note that there may be false alarms if selector uses jQuery extensions
  207. try {
  208. window.document.querySelector( selector );
  209. migrateWarn( "selector-hash",
  210. "Attribute selector with '#' must be quoted: " + args[ 0 ] );
  211. args[ 0 ] = selector;
  212. } catch ( err2 ) {
  213. migrateWarn( "selector-hash",
  214. "Attribute selector with '#' was not fixed: " + args[ 0 ] );
  215. }
  216. }
  217. }
  218. return oldFind.apply( this, args );
  219. }, "selector-hash" );
  220. // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
  221. for ( findProp in oldFind ) {
  222. if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
  223. jQuery.find[ findProp ] = oldFind[ findProp ];
  224. }
  225. }
  226. // The number of elements contained in the matched element set
  227. migratePatchAndWarnFunc( jQuery.fn, "size", function() {
  228. return this.length;
  229. }, "size",
  230. "jQuery.fn.size() is deprecated and removed; use the .length property" );
  231. migratePatchAndWarnFunc( jQuery, "parseJSON", function() {
  232. return JSON.parse.apply( null, arguments );
  233. }, "parseJSON",
  234. "jQuery.parseJSON is deprecated; use JSON.parse" );
  235. migratePatchAndWarnFunc( jQuery, "holdReady", jQuery.holdReady,
  236. "holdReady", "jQuery.holdReady is deprecated" );
  237. migratePatchAndWarnFunc( jQuery, "unique", jQuery.uniqueSort,
  238. "unique", "jQuery.unique is deprecated; use jQuery.uniqueSort" );
  239. // Now jQuery.expr.pseudos is the standard incantation
  240. migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos, "expr-pre-pseudos",
  241. "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
  242. migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos, "expr-pre-pseudos",
  243. "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
  244. // Prior to jQuery 3.1.1 there were internal refs so we don't warn there
  245. if ( jQueryVersionSince( "3.1.1" ) ) {
  246. migratePatchAndWarnFunc( jQuery, "trim", function( text ) {
  247. return text == null ?
  248. "" :
  249. ( text + "" ).replace( rtrim, "$1" );
  250. }, "trim",
  251. "jQuery.trim is deprecated; use String.prototype.trim" );
  252. }
  253. // Prior to jQuery 3.2 there were internal refs so we don't warn there
  254. if ( jQueryVersionSince( "3.2.0" ) ) {
  255. migratePatchAndWarnFunc( jQuery, "nodeName", function( elem, name ) {
  256. return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
  257. }, "nodeName",
  258. "jQuery.nodeName is deprecated" );
  259. migratePatchAndWarnFunc( jQuery, "isArray", Array.isArray, "isArray",
  260. "jQuery.isArray is deprecated; use Array.isArray"
  261. );
  262. }
  263. if ( jQueryVersionSince( "3.3.0" ) ) {
  264. migratePatchAndWarnFunc( jQuery, "isNumeric",
  265. function( obj ) {
  266. // As of jQuery 3.0, isNumeric is limited to
  267. // strings and numbers (primitives or objects)
  268. // that can be coerced to finite numbers (gh-2662)
  269. var type = typeof obj;
  270. return ( type === "number" || type === "string" ) &&
  271. // parseFloat NaNs numeric-cast false positives ("")
  272. // ...but misinterprets leading-number strings, e.g. hex literals ("0x...")
  273. // subtraction forces infinities to NaN
  274. !isNaN( obj - parseFloat( obj ) );
  275. }, "isNumeric",
  276. "jQuery.isNumeric() is deprecated"
  277. );
  278. // Populate the class2type map
  279. jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".
  280. split( " " ),
  281. function( _, name ) {
  282. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  283. } );
  284. migratePatchAndWarnFunc( jQuery, "type", function( obj ) {
  285. if ( obj == null ) {
  286. return obj + "";
  287. }
  288. // Support: Android <=2.3 only (functionish RegExp)
  289. return typeof obj === "object" || typeof obj === "function" ?
  290. class2type[ Object.prototype.toString.call( obj ) ] || "object" :
  291. typeof obj;
  292. }, "type",
  293. "jQuery.type is deprecated" );
  294. migratePatchAndWarnFunc( jQuery, "isFunction",
  295. function( obj ) {
  296. return typeof obj === "function";
  297. }, "isFunction",
  298. "jQuery.isFunction() is deprecated" );
  299. migratePatchAndWarnFunc( jQuery, "isWindow",
  300. function( obj ) {
  301. return obj != null && obj === obj.window;
  302. }, "isWindow",
  303. "jQuery.isWindow() is deprecated"
  304. );
  305. }
  306. // Support jQuery slim which excludes the ajax module
  307. if ( jQuery.ajax ) {
  308. var oldAjax = jQuery.ajax,
  309. rjsonp = /(=)\?(?=&|$)|\?\?/;
  310. migratePatchFunc( jQuery, "ajax", function() {
  311. var jQXHR = oldAjax.apply( this, arguments );
  312. // Be sure we got a jQXHR (e.g., not sync)
  313. if ( jQXHR.promise ) {
  314. migratePatchAndWarnFunc( jQXHR, "success", jQXHR.done, "jqXHR-methods",
  315. "jQXHR.success is deprecated and removed" );
  316. migratePatchAndWarnFunc( jQXHR, "error", jQXHR.fail, "jqXHR-methods",
  317. "jQXHR.error is deprecated and removed" );
  318. migratePatchAndWarnFunc( jQXHR, "complete", jQXHR.always, "jqXHR-methods",
  319. "jQXHR.complete is deprecated and removed" );
  320. }
  321. return jQXHR;
  322. }, "jqXHR-methods" );
  323. // Only trigger the logic in jQuery <4 as the JSON-to-JSONP auto-promotion
  324. // behavior is gone in jQuery 4.0 and as it has security implications, we don't
  325. // want to restore the legacy behavior.
  326. if ( !jQueryVersionSince( "4.0.0" ) ) {
  327. // Register this prefilter before the jQuery one. Otherwise, a promoted
  328. // request is transformed into one with the script dataType and we can't
  329. // catch it anymore.
  330. jQuery.ajaxPrefilter( "+json", function( s ) {
  331. // Warn if JSON-to-JSONP auto-promotion happens.
  332. if ( s.jsonp !== false && ( rjsonp.test( s.url ) ||
  333. typeof s.data === "string" &&
  334. ( s.contentType || "" )
  335. .indexOf( "application/x-www-form-urlencoded" ) === 0 &&
  336. rjsonp.test( s.data )
  337. ) ) {
  338. migrateWarn( "jsonp-promotion", "JSON-to-JSONP auto-promotion is deprecated" );
  339. }
  340. } );
  341. }
  342. }
  343. var oldRemoveAttr = jQuery.fn.removeAttr,
  344. oldToggleClass = jQuery.fn.toggleClass,
  345. rbooleans = /^(?:checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$/i,
  346. rmatchNonSpace = /\S+/g;
  347. migratePatchFunc( jQuery.fn, "removeAttr", function( name ) {
  348. var self = this,
  349. patchNeeded = false;
  350. jQuery.each( name.match( rmatchNonSpace ), function( _i, attr ) {
  351. if ( rbooleans.test( attr ) ) {
  352. // Only warn if at least a single node had the property set to
  353. // something else than `false`. Otherwise, this Migrate patch
  354. // doesn't influence the behavior and there's no need to set or warn.
  355. self.each( function() {
  356. if ( jQuery( this ).prop( attr ) !== false ) {
  357. patchNeeded = true;
  358. return false;
  359. }
  360. } );
  361. }
  362. if ( patchNeeded ) {
  363. migrateWarn( "removeAttr-bool",
  364. "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
  365. self.prop( attr, false );
  366. }
  367. } );
  368. return oldRemoveAttr.apply( this, arguments );
  369. }, "removeAttr-bool" );
  370. migratePatchFunc( jQuery.fn, "toggleClass", function( state ) {
  371. // Only deprecating no-args or single boolean arg
  372. if ( state !== undefined && typeof state !== "boolean" ) {
  373. return oldToggleClass.apply( this, arguments );
  374. }
  375. migrateWarn( "toggleClass-bool", "jQuery.fn.toggleClass( boolean ) is deprecated" );
  376. // Toggle entire class name of each element
  377. return this.each( function() {
  378. var className = this.getAttribute && this.getAttribute( "class" ) || "";
  379. if ( className ) {
  380. jQuery.data( this, "__className__", className );
  381. }
  382. // If the element has a class name or if we're passed `false`,
  383. // then remove the whole classname (if there was one, the above saved it).
  384. // Otherwise bring back whatever was previously saved (if anything),
  385. // falling back to the empty string if nothing was stored.
  386. if ( this.setAttribute ) {
  387. this.setAttribute( "class",
  388. className || state === false ?
  389. "" :
  390. jQuery.data( this, "__className__" ) || ""
  391. );
  392. }
  393. } );
  394. }, "toggleClass-bool" );
  395. function camelCase( string ) {
  396. return string.replace( /-([a-z])/g, function( _, letter ) {
  397. return letter.toUpperCase();
  398. } );
  399. }
  400. var origFnCss, internalCssNumber,
  401. internalSwapCall = false,
  402. ralphaStart = /^[a-z]/,
  403. // The regex visualized:
  404. //
  405. // /----------\
  406. // | | /-------\
  407. // | / Top \ | | |
  408. // /--- Border ---+-| Right |-+---+- Width -+---\
  409. // | | Bottom | |
  410. // | \ Left / |
  411. // | |
  412. // | /----------\ |
  413. // | /-------------\ | | |- END
  414. // | | | | / Top \ | |
  415. // | | / Margin \ | | | Right | | |
  416. // |---------+-| |-+---+-| Bottom |-+----|
  417. // | \ Padding / \ Left / |
  418. // BEGIN -| |
  419. // | /---------\ |
  420. // | | | |
  421. // | | / Min \ | / Width \ |
  422. // \--------------+-| |-+---| |---/
  423. // \ Max / \ Height /
  424. rautoPx = /^(?:Border(?:Top|Right|Bottom|Left)?(?:Width|)|(?:Margin|Padding)?(?:Top|Right|Bottom|Left)?|(?:Min|Max)?(?:Width|Height))$/;
  425. // If this version of jQuery has .swap(), don't false-alarm on internal uses
  426. if ( jQuery.swap ) {
  427. jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
  428. var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
  429. if ( oldHook ) {
  430. jQuery.cssHooks[ name ].get = function() {
  431. var ret;
  432. internalSwapCall = true;
  433. ret = oldHook.apply( this, arguments );
  434. internalSwapCall = false;
  435. return ret;
  436. };
  437. }
  438. } );
  439. }
  440. migratePatchFunc( jQuery, "swap", function( elem, options, callback, args ) {
  441. var ret, name,
  442. old = {};
  443. if ( !internalSwapCall ) {
  444. migrateWarn( "swap", "jQuery.swap() is undocumented and deprecated" );
  445. }
  446. // Remember the old values, and insert the new ones
  447. for ( name in options ) {
  448. old[ name ] = elem.style[ name ];
  449. elem.style[ name ] = options[ name ];
  450. }
  451. ret = callback.apply( elem, args || [] );
  452. // Revert the old values
  453. for ( name in options ) {
  454. elem.style[ name ] = old[ name ];
  455. }
  456. return ret;
  457. }, "swap" );
  458. if ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) {
  459. jQuery.cssProps = new Proxy( jQuery.cssProps || {}, {
  460. set: function() {
  461. migrateWarn( "cssProps", "jQuery.cssProps is deprecated" );
  462. return Reflect.set.apply( this, arguments );
  463. }
  464. } );
  465. }
  466. // In jQuery >=4 where jQuery.cssNumber is missing fill it with the latest 3.x version:
  467. // https://github.com/jquery/jquery/blob/3.7.1/src/css.js#L216-L246
  468. // This way, number values for the CSS properties below won't start triggering
  469. // Migrate warnings when jQuery gets updated to >=4.0.0 (gh-438).
  470. if ( jQueryVersionSince( "4.0.0" ) ) {
  471. // We need to keep this as a local variable as we need it internally
  472. // in a `jQuery.fn.css` patch and this usage shouldn't warn.
  473. internalCssNumber = {
  474. animationIterationCount: true,
  475. aspectRatio: true,
  476. borderImageSlice: true,
  477. columnCount: true,
  478. flexGrow: true,
  479. flexShrink: true,
  480. fontWeight: true,
  481. gridArea: true,
  482. gridColumn: true,
  483. gridColumnEnd: true,
  484. gridColumnStart: true,
  485. gridRow: true,
  486. gridRowEnd: true,
  487. gridRowStart: true,
  488. lineHeight: true,
  489. opacity: true,
  490. order: true,
  491. orphans: true,
  492. scale: true,
  493. widows: true,
  494. zIndex: true,
  495. zoom: true,
  496. // SVG-related
  497. fillOpacity: true,
  498. floodOpacity: true,
  499. stopOpacity: true,
  500. strokeMiterlimit: true,
  501. strokeOpacity: true
  502. };
  503. if ( typeof Proxy !== "undefined" ) {
  504. jQuery.cssNumber = new Proxy( internalCssNumber, {
  505. get: function() {
  506. migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
  507. return Reflect.get.apply( this, arguments );
  508. },
  509. set: function() {
  510. migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
  511. return Reflect.set.apply( this, arguments );
  512. }
  513. } );
  514. } else {
  515. // Support: IE 9-11+
  516. // IE doesn't support proxies, but we still want to restore the legacy
  517. // jQuery.cssNumber there.
  518. jQuery.cssNumber = internalCssNumber;
  519. }
  520. } else {
  521. // Make `internalCssNumber` defined for jQuery <4 as well as it's needed
  522. // in the `jQuery.fn.css` patch below.
  523. internalCssNumber = jQuery.cssNumber;
  524. }
  525. function isAutoPx( prop ) {
  526. // The first test is used to ensure that:
  527. // 1. The prop starts with a lowercase letter (as we uppercase it for the second regex).
  528. // 2. The prop is not empty.
  529. return ralphaStart.test( prop ) &&
  530. rautoPx.test( prop[ 0 ].toUpperCase() + prop.slice( 1 ) );
  531. }
  532. origFnCss = jQuery.fn.css;
  533. migratePatchFunc( jQuery.fn, "css", function( name, value ) {
  534. var camelName,
  535. origThis = this;
  536. if ( name && typeof name === "object" && !Array.isArray( name ) ) {
  537. jQuery.each( name, function( n, v ) {
  538. jQuery.fn.css.call( origThis, n, v );
  539. } );
  540. return this;
  541. }
  542. if ( typeof value === "number" ) {
  543. camelName = camelCase( name );
  544. // Use `internalCssNumber` to avoid triggering our warnings in this
  545. // internal check.
  546. if ( !isAutoPx( camelName ) && !internalCssNumber[ camelName ] ) {
  547. migrateWarn( "css-number",
  548. "Number-typed values are deprecated for jQuery.fn.css( \"" +
  549. name + "\", value )" );
  550. }
  551. }
  552. return origFnCss.apply( this, arguments );
  553. }, "css-number" );
  554. var origData = jQuery.data;
  555. migratePatchFunc( jQuery, "data", function( elem, name, value ) {
  556. var curData, sameKeys, key;
  557. // Name can be an object, and each entry in the object is meant to be set as data
  558. if ( name && typeof name === "object" && arguments.length === 2 ) {
  559. curData = jQuery.hasData( elem ) && origData.call( this, elem );
  560. sameKeys = {};
  561. for ( key in name ) {
  562. if ( key !== camelCase( key ) ) {
  563. migrateWarn( "data-camelCase",
  564. "jQuery.data() always sets/gets camelCased names: " + key );
  565. curData[ key ] = name[ key ];
  566. } else {
  567. sameKeys[ key ] = name[ key ];
  568. }
  569. }
  570. origData.call( this, elem, sameKeys );
  571. return name;
  572. }
  573. // If the name is transformed, look for the un-transformed name in the data object
  574. if ( name && typeof name === "string" && name !== camelCase( name ) ) {
  575. curData = jQuery.hasData( elem ) && origData.call( this, elem );
  576. if ( curData && name in curData ) {
  577. migrateWarn( "data-camelCase",
  578. "jQuery.data() always sets/gets camelCased names: " + name );
  579. if ( arguments.length > 2 ) {
  580. curData[ name ] = value;
  581. }
  582. return curData[ name ];
  583. }
  584. }
  585. return origData.apply( this, arguments );
  586. }, "data-camelCase" );
  587. // Support jQuery slim which excludes the effects module
  588. if ( jQuery.fx ) {
  589. var intervalValue, intervalMsg,
  590. oldTweenRun = jQuery.Tween.prototype.run,
  591. linearEasing = function( pct ) {
  592. return pct;
  593. };
  594. migratePatchFunc( jQuery.Tween.prototype, "run", function( ) {
  595. if ( jQuery.easing[ this.easing ].length > 1 ) {
  596. migrateWarn(
  597. "easing-one-arg",
  598. "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
  599. );
  600. jQuery.easing[ this.easing ] = linearEasing;
  601. }
  602. oldTweenRun.apply( this, arguments );
  603. }, "easing-one-arg" );
  604. intervalValue = jQuery.fx.interval;
  605. intervalMsg = "jQuery.fx.interval is deprecated";
  606. // Support: IE9, Android <=4.4
  607. // Avoid false positives on browsers that lack rAF
  608. // Don't warn if document is hidden, jQuery uses setTimeout (#292)
  609. if ( window.requestAnimationFrame ) {
  610. Object.defineProperty( jQuery.fx, "interval", {
  611. configurable: true,
  612. enumerable: true,
  613. get: function() {
  614. if ( !window.document.hidden ) {
  615. migrateWarn( "fx-interval", intervalMsg );
  616. }
  617. // Only fallback to the default if patch is enabled
  618. if ( !jQuery.migrateIsPatchEnabled( "fx-interval" ) ) {
  619. return intervalValue;
  620. }
  621. return intervalValue === undefined ? 13 : intervalValue;
  622. },
  623. set: function( newValue ) {
  624. migrateWarn( "fx-interval", intervalMsg );
  625. intervalValue = newValue;
  626. }
  627. } );
  628. }
  629. }
  630. var oldLoad = jQuery.fn.load,
  631. oldEventAdd = jQuery.event.add,
  632. originalFix = jQuery.event.fix;
  633. jQuery.event.props = [];
  634. jQuery.event.fixHooks = {};
  635. migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
  636. "event-old-patch",
  637. "jQuery.event.props.concat() is deprecated and removed" );
  638. migratePatchFunc( jQuery.event, "fix", function( originalEvent ) {
  639. var event,
  640. type = originalEvent.type,
  641. fixHook = this.fixHooks[ type ],
  642. props = jQuery.event.props;
  643. if ( props.length ) {
  644. migrateWarn( "event-old-patch",
  645. "jQuery.event.props are deprecated and removed: " + props.join() );
  646. while ( props.length ) {
  647. jQuery.event.addProp( props.pop() );
  648. }
  649. }
  650. if ( fixHook && !fixHook._migrated_ ) {
  651. fixHook._migrated_ = true;
  652. migrateWarn( "event-old-patch",
  653. "jQuery.event.fixHooks are deprecated and removed: " + type );
  654. if ( ( props = fixHook.props ) && props.length ) {
  655. while ( props.length ) {
  656. jQuery.event.addProp( props.pop() );
  657. }
  658. }
  659. }
  660. event = originalFix.call( this, originalEvent );
  661. return fixHook && fixHook.filter ?
  662. fixHook.filter( event, originalEvent ) :
  663. event;
  664. }, "event-old-patch" );
  665. migratePatchFunc( jQuery.event, "add", function( elem, types ) {
  666. // This misses the multiple-types case but that seems awfully rare
  667. if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
  668. migrateWarn( "load-after-event",
  669. "jQuery(window).on('load'...) called after load event occurred" );
  670. }
  671. return oldEventAdd.apply( this, arguments );
  672. }, "load-after-event" );
  673. jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
  674. migratePatchFunc( jQuery.fn, name, function() {
  675. var args = Array.prototype.slice.call( arguments, 0 );
  676. // If this is an ajax load() the first arg should be the string URL;
  677. // technically this could also be the "Anything" arg of the event .load()
  678. // which just goes to show why this dumb signature has been deprecated!
  679. // jQuery custom builds that exclude the Ajax module justifiably die here.
  680. if ( name === "load" && typeof args[ 0 ] === "string" ) {
  681. return oldLoad.apply( this, args );
  682. }
  683. migrateWarn( "shorthand-removed-v3",
  684. "jQuery.fn." + name + "() is deprecated" );
  685. args.splice( 0, 0, name );
  686. if ( arguments.length ) {
  687. return this.on.apply( this, args );
  688. }
  689. // Use .triggerHandler here because:
  690. // - load and unload events don't need to bubble, only applied to window or image
  691. // - error event should not bubble to window, although it does pre-1.7
  692. // See http://bugs.jquery.com/ticket/11820
  693. this.triggerHandler.apply( this, args );
  694. return this;
  695. }, "shorthand-removed-v3" );
  696. } );
  697. jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
  698. "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
  699. "change select submit keydown keypress keyup contextmenu" ).split( " " ),
  700. function( _i, name ) {
  701. // Handle event binding
  702. migratePatchAndWarnFunc( jQuery.fn, name, function( data, fn ) {
  703. return arguments.length > 0 ?
  704. this.on( name, null, data, fn ) :
  705. this.trigger( name );
  706. },
  707. "shorthand-deprecated-v3",
  708. "jQuery.fn." + name + "() event shorthand is deprecated" );
  709. } );
  710. // Trigger "ready" event only once, on document ready
  711. jQuery( function() {
  712. jQuery( window.document ).triggerHandler( "ready" );
  713. } );
  714. jQuery.event.special.ready = {
  715. setup: function() {
  716. if ( this === window.document ) {
  717. migrateWarn( "ready-event", "'ready' event is deprecated" );
  718. }
  719. }
  720. };
  721. migratePatchAndWarnFunc( jQuery.fn, "bind", function( types, data, fn ) {
  722. return this.on( types, null, data, fn );
  723. }, "pre-on-methods", "jQuery.fn.bind() is deprecated" );
  724. migratePatchAndWarnFunc( jQuery.fn, "unbind", function( types, fn ) {
  725. return this.off( types, null, fn );
  726. }, "pre-on-methods", "jQuery.fn.unbind() is deprecated" );
  727. migratePatchAndWarnFunc( jQuery.fn, "delegate", function( selector, types, data, fn ) {
  728. return this.on( types, selector, data, fn );
  729. }, "pre-on-methods", "jQuery.fn.delegate() is deprecated" );
  730. migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn ) {
  731. return arguments.length === 1 ?
  732. this.off( selector, "**" ) :
  733. this.off( types, selector || "**", fn );
  734. }, "pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
  735. migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) {
  736. return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
  737. }, "pre-on-methods", "jQuery.fn.hover() is deprecated" );
  738. var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,
  739. makeMarkup = function( html ) {
  740. var doc = window.document.implementation.createHTMLDocument( "" );
  741. doc.body.innerHTML = html;
  742. return doc.body && doc.body.innerHTML;
  743. },
  744. warnIfChanged = function( html ) {
  745. var changed = html.replace( rxhtmlTag, "<$1></$2>" );
  746. if ( changed !== html && makeMarkup( html ) !== makeMarkup( changed ) ) {
  747. migrateWarn( "self-closed-tags",
  748. "HTML tags must be properly nested and closed: " + html );
  749. }
  750. };
  751. /**
  752. * Deprecated, please use `jQuery.migrateDisablePatches( "self-closed-tags" )` instead.
  753. * @deprecated
  754. */
  755. migratePatchAndWarnFunc( jQuery, "UNSAFE_restoreLegacyHtmlPrefilter", function() {
  756. jQuery.migrateEnablePatches( "self-closed-tags" );
  757. }, "legacy-self-closed-tags",
  758. "jQuery.UNSAFE_restoreLegacyHtmlPrefilter deprecated; use " +
  759. "`jQuery.migrateEnablePatches( \"self-closed-tags\" )`" );
  760. migratePatchFunc( jQuery, "htmlPrefilter", function( html ) {
  761. warnIfChanged( html );
  762. return html.replace( rxhtmlTag, "<$1></$2>" );
  763. }, "self-closed-tags" );
  764. // This patch needs to be disabled by default as it re-introduces
  765. // security issues (CVE-2020-11022, CVE-2020-11023).
  766. jQuery.migrateDisablePatches( "self-closed-tags" );
  767. var origOffset = jQuery.fn.offset;
  768. migratePatchFunc( jQuery.fn, "offset", function() {
  769. var elem = this[ 0 ];
  770. if ( elem && ( !elem.nodeType || !elem.getBoundingClientRect ) ) {
  771. migrateWarn( "offset-valid-elem", "jQuery.fn.offset() requires a valid DOM element" );
  772. return arguments.length ? this : undefined;
  773. }
  774. return origOffset.apply( this, arguments );
  775. }, "offset-valid-elem" );
  776. // Support jQuery slim which excludes the ajax module
  777. // The jQuery.param patch is about respecting `jQuery.ajaxSettings.traditional`
  778. // so it doesn't make sense for the slim build.
  779. if ( jQuery.ajax ) {
  780. var origParam = jQuery.param;
  781. migratePatchFunc( jQuery, "param", function( data, traditional ) {
  782. var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
  783. if ( traditional === undefined && ajaxTraditional ) {
  784. migrateWarn( "param-ajax-traditional",
  785. "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
  786. traditional = ajaxTraditional;
  787. }
  788. return origParam.call( this, data, traditional );
  789. }, "param-ajax-traditional" );
  790. }
  791. migratePatchAndWarnFunc( jQuery.fn, "andSelf", jQuery.fn.addBack, "andSelf",
  792. "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
  793. // Support jQuery slim which excludes the deferred module in jQuery 4.0+
  794. if ( jQuery.Deferred ) {
  795. var oldDeferred = jQuery.Deferred,
  796. tuples = [
  797. // Action, add listener, callbacks, .then handlers, final state
  798. [ "resolve", "done", jQuery.Callbacks( "once memory" ),
  799. jQuery.Callbacks( "once memory" ), "resolved" ],
  800. [ "reject", "fail", jQuery.Callbacks( "once memory" ),
  801. jQuery.Callbacks( "once memory" ), "rejected" ],
  802. [ "notify", "progress", jQuery.Callbacks( "memory" ),
  803. jQuery.Callbacks( "memory" ) ]
  804. ];
  805. migratePatchFunc( jQuery, "Deferred", function( func ) {
  806. var deferred = oldDeferred(),
  807. promise = deferred.promise();
  808. function newDeferredPipe( /* fnDone, fnFail, fnProgress */ ) {
  809. var fns = arguments;
  810. return jQuery.Deferred( function( newDefer ) {
  811. jQuery.each( tuples, function( i, tuple ) {
  812. var fn = typeof fns[ i ] === "function" && fns[ i ];
  813. // Deferred.done(function() { bind to newDefer or newDefer.resolve })
  814. // deferred.fail(function() { bind to newDefer or newDefer.reject })
  815. // deferred.progress(function() { bind to newDefer or newDefer.notify })
  816. deferred[ tuple[ 1 ] ]( function() {
  817. var returned = fn && fn.apply( this, arguments );
  818. if ( returned && typeof returned.promise === "function" ) {
  819. returned.promise()
  820. .done( newDefer.resolve )
  821. .fail( newDefer.reject )
  822. .progress( newDefer.notify );
  823. } else {
  824. newDefer[ tuple[ 0 ] + "With" ](
  825. this === promise ? newDefer.promise() : this,
  826. fn ? [ returned ] : arguments
  827. );
  828. }
  829. } );
  830. } );
  831. fns = null;
  832. } ).promise();
  833. }
  834. migratePatchAndWarnFunc( deferred, "pipe", newDeferredPipe, "deferred-pipe",
  835. "deferred.pipe() is deprecated" );
  836. migratePatchAndWarnFunc( promise, "pipe", newDeferredPipe, "deferred-pipe",
  837. "deferred.pipe() is deprecated" );
  838. if ( func ) {
  839. func.call( deferred, deferred );
  840. }
  841. return deferred;
  842. }, "deferred-pipe" );
  843. // Preserve handler of uncaught exceptions in promise chains
  844. jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
  845. }
  846. return jQuery;
  847. } );