You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1018 lines
31 KiB

1 year ago
  1. /*!
  2. * jQuery Migrate - v3.4.1 - 2023-02-23T15: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.4.1";
  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", function( obj ) {
  265. // As of jQuery 3.0, isNumeric is limited to
  266. // strings and numbers (primitives or objects)
  267. // that can be coerced to finite numbers (gh-2662)
  268. var type = typeof obj;
  269. return ( type === "number" || type === "string" ) &&
  270. // parseFloat NaNs numeric-cast false positives ("")
  271. // ...but misinterprets leading-number strings, e.g. hex literals ("0x...")
  272. // subtraction forces infinities to NaN
  273. !isNaN( obj - parseFloat( obj ) );
  274. }, "isNumeric",
  275. "jQuery.isNumeric() is deprecated"
  276. );
  277. // Populate the class2type map
  278. jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".
  279. split( " " ),
  280. function( _, name ) {
  281. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  282. } );
  283. migratePatchAndWarnFunc( jQuery, "type", function( obj ) {
  284. if ( obj == null ) {
  285. return obj + "";
  286. }
  287. // Support: Android <=2.3 only (functionish RegExp)
  288. return typeof obj === "object" || typeof obj === "function" ?
  289. class2type[ Object.prototype.toString.call( obj ) ] || "object" :
  290. typeof obj;
  291. }, "type",
  292. "jQuery.type is deprecated" );
  293. migratePatchAndWarnFunc( jQuery, "isFunction",
  294. function( obj ) {
  295. return typeof obj === "function";
  296. }, "isFunction",
  297. "jQuery.isFunction() is deprecated" );
  298. migratePatchAndWarnFunc( jQuery, "isWindow",
  299. function( obj ) {
  300. return obj != null && obj === obj.window;
  301. }, "isWindow",
  302. "jQuery.isWindow() is deprecated"
  303. );
  304. }
  305. // Support jQuery slim which excludes the ajax module
  306. if ( jQuery.ajax ) {
  307. var oldAjax = jQuery.ajax,
  308. rjsonp = /(=)\?(?=&|$)|\?\?/;
  309. migratePatchFunc( jQuery, "ajax", function() {
  310. var jQXHR = oldAjax.apply( this, arguments );
  311. // Be sure we got a jQXHR (e.g., not sync)
  312. if ( jQXHR.promise ) {
  313. migratePatchAndWarnFunc( jQXHR, "success", jQXHR.done, "jqXHR-methods",
  314. "jQXHR.success is deprecated and removed" );
  315. migratePatchAndWarnFunc( jQXHR, "error", jQXHR.fail, "jqXHR-methods",
  316. "jQXHR.error is deprecated and removed" );
  317. migratePatchAndWarnFunc( jQXHR, "complete", jQXHR.always, "jqXHR-methods",
  318. "jQXHR.complete is deprecated and removed" );
  319. }
  320. return jQXHR;
  321. }, "jqXHR-methods" );
  322. // Only trigger the logic in jQuery <4 as the JSON-to-JSONP auto-promotion
  323. // behavior is gone in jQuery 4.0 and as it has security implications, we don't
  324. // want to restore the legacy behavior.
  325. if ( !jQueryVersionSince( "4.0.0" ) ) {
  326. // Register this prefilter before the jQuery one. Otherwise, a promoted
  327. // request is transformed into one with the script dataType and we can't
  328. // catch it anymore.
  329. jQuery.ajaxPrefilter( "+json", function( s ) {
  330. // Warn if JSON-to-JSONP auto-promotion happens.
  331. if ( s.jsonp !== false && ( rjsonp.test( s.url ) ||
  332. typeof s.data === "string" &&
  333. ( s.contentType || "" )
  334. .indexOf( "application/x-www-form-urlencoded" ) === 0 &&
  335. rjsonp.test( s.data )
  336. ) ) {
  337. migrateWarn( "jsonp-promotion", "JSON-to-JSONP auto-promotion is deprecated" );
  338. }
  339. } );
  340. }
  341. }
  342. var oldRemoveAttr = jQuery.fn.removeAttr,
  343. oldToggleClass = jQuery.fn.toggleClass,
  344. rmatchNonSpace = /\S+/g;
  345. migratePatchFunc( jQuery.fn, "removeAttr", function( name ) {
  346. var self = this,
  347. patchNeeded = false;
  348. jQuery.each( name.match( rmatchNonSpace ), function( _i, attr ) {
  349. if ( jQuery.expr.match.bool.test( attr ) ) {
  350. // Only warn if at least a single node had the property set to
  351. // something else than `false`. Otherwise, this Migrate patch
  352. // doesn't influence the behavior and there's no need to set or warn.
  353. self.each( function() {
  354. if ( jQuery( this ).prop( attr ) !== false ) {
  355. patchNeeded = true;
  356. return false;
  357. }
  358. } );
  359. }
  360. if ( patchNeeded ) {
  361. migrateWarn( "removeAttr-bool",
  362. "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
  363. self.prop( attr, false );
  364. }
  365. } );
  366. return oldRemoveAttr.apply( this, arguments );
  367. }, "removeAttr-bool" );
  368. migratePatchFunc( jQuery.fn, "toggleClass", function( state ) {
  369. // Only deprecating no-args or single boolean arg
  370. if ( state !== undefined && typeof state !== "boolean" ) {
  371. return oldToggleClass.apply( this, arguments );
  372. }
  373. migrateWarn( "toggleClass-bool", "jQuery.fn.toggleClass( boolean ) is deprecated" );
  374. // Toggle entire class name of each element
  375. return this.each( function() {
  376. var className = this.getAttribute && this.getAttribute( "class" ) || "";
  377. if ( className ) {
  378. jQuery.data( this, "__className__", className );
  379. }
  380. // If the element has a class name or if we're passed `false`,
  381. // then remove the whole classname (if there was one, the above saved it).
  382. // Otherwise bring back whatever was previously saved (if anything),
  383. // falling back to the empty string if nothing was stored.
  384. if ( this.setAttribute ) {
  385. this.setAttribute( "class",
  386. className || state === false ?
  387. "" :
  388. jQuery.data( this, "__className__" ) || ""
  389. );
  390. }
  391. } );
  392. }, "toggleClass-bool" );
  393. function camelCase( string ) {
  394. return string.replace( /-([a-z])/g, function( _, letter ) {
  395. return letter.toUpperCase();
  396. } );
  397. }
  398. var origFnCss, internalCssNumber,
  399. internalSwapCall = false,
  400. ralphaStart = /^[a-z]/,
  401. // The regex visualized:
  402. //
  403. // /----------\
  404. // | | /-------\
  405. // | / Top \ | | |
  406. // /--- Border ---+-| Right |-+---+- Width -+---\
  407. // | | Bottom | |
  408. // | \ Left / |
  409. // | |
  410. // | /----------\ |
  411. // | /-------------\ | | |- END
  412. // | | | | / Top \ | |
  413. // | | / Margin \ | | | Right | | |
  414. // |---------+-| |-+---+-| Bottom |-+----|
  415. // | \ Padding / \ Left / |
  416. // BEGIN -| |
  417. // | /---------\ |
  418. // | | | |
  419. // | | / Min \ | / Width \ |
  420. // \--------------+-| |-+---| |---/
  421. // \ Max / \ Height /
  422. rautoPx = /^(?:Border(?:Top|Right|Bottom|Left)?(?:Width|)|(?:Margin|Padding)?(?:Top|Right|Bottom|Left)?|(?:Min|Max)?(?:Width|Height))$/;
  423. // If this version of jQuery has .swap(), don't false-alarm on internal uses
  424. if ( jQuery.swap ) {
  425. jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
  426. var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
  427. if ( oldHook ) {
  428. jQuery.cssHooks[ name ].get = function() {
  429. var ret;
  430. internalSwapCall = true;
  431. ret = oldHook.apply( this, arguments );
  432. internalSwapCall = false;
  433. return ret;
  434. };
  435. }
  436. } );
  437. }
  438. migratePatchFunc( jQuery, "swap", function( elem, options, callback, args ) {
  439. var ret, name,
  440. old = {};
  441. if ( !internalSwapCall ) {
  442. migrateWarn( "swap", "jQuery.swap() is undocumented and deprecated" );
  443. }
  444. // Remember the old values, and insert the new ones
  445. for ( name in options ) {
  446. old[ name ] = elem.style[ name ];
  447. elem.style[ name ] = options[ name ];
  448. }
  449. ret = callback.apply( elem, args || [] );
  450. // Revert the old values
  451. for ( name in options ) {
  452. elem.style[ name ] = old[ name ];
  453. }
  454. return ret;
  455. }, "swap" );
  456. if ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) {
  457. jQuery.cssProps = new Proxy( jQuery.cssProps || {}, {
  458. set: function() {
  459. migrateWarn( "cssProps", "jQuery.cssProps is deprecated" );
  460. return Reflect.set.apply( this, arguments );
  461. }
  462. } );
  463. }
  464. // In jQuery >=4 where jQuery.cssNumber is missing fill it with the latest 3.x version:
  465. // https://github.com/jquery/jquery/blob/3.6.0/src/css.js#L212-L233
  466. // This way, number values for the CSS properties below won't start triggering
  467. // Migrate warnings when jQuery gets updated to >=4.0.0 (gh-438).
  468. if ( jQueryVersionSince( "4.0.0" ) ) {
  469. // We need to keep this as a local variable as we need it internally
  470. // in a `jQuery.fn.css` patch and this usage shouldn't warn.
  471. internalCssNumber = {
  472. animationIterationCount: true,
  473. columnCount: true,
  474. fillOpacity: true,
  475. flexGrow: true,
  476. flexShrink: true,
  477. fontWeight: true,
  478. gridArea: true,
  479. gridColumn: true,
  480. gridColumnEnd: true,
  481. gridColumnStart: true,
  482. gridRow: true,
  483. gridRowEnd: true,
  484. gridRowStart: true,
  485. lineHeight: true,
  486. opacity: true,
  487. order: true,
  488. orphans: true,
  489. widows: true,
  490. zIndex: true,
  491. zoom: true
  492. };
  493. if ( typeof Proxy !== "undefined" ) {
  494. jQuery.cssNumber = new Proxy( internalCssNumber, {
  495. get: function() {
  496. migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
  497. return Reflect.get.apply( this, arguments );
  498. },
  499. set: function() {
  500. migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
  501. return Reflect.set.apply( this, arguments );
  502. }
  503. } );
  504. } else {
  505. // Support: IE 9-11+
  506. // IE doesn't support proxies, but we still want to restore the legacy
  507. // jQuery.cssNumber there.
  508. jQuery.cssNumber = internalCssNumber;
  509. }
  510. } else {
  511. // Make `internalCssNumber` defined for jQuery <4 as well as it's needed
  512. // in the `jQuery.fn.css` patch below.
  513. internalCssNumber = jQuery.cssNumber;
  514. }
  515. function isAutoPx( prop ) {
  516. // The first test is used to ensure that:
  517. // 1. The prop starts with a lowercase letter (as we uppercase it for the second regex).
  518. // 2. The prop is not empty.
  519. return ralphaStart.test( prop ) &&
  520. rautoPx.test( prop[ 0 ].toUpperCase() + prop.slice( 1 ) );
  521. }
  522. origFnCss = jQuery.fn.css;
  523. migratePatchFunc( jQuery.fn, "css", function( name, value ) {
  524. var camelName,
  525. origThis = this;
  526. if ( name && typeof name === "object" && !Array.isArray( name ) ) {
  527. jQuery.each( name, function( n, v ) {
  528. jQuery.fn.css.call( origThis, n, v );
  529. } );
  530. return this;
  531. }
  532. if ( typeof value === "number" ) {
  533. camelName = camelCase( name );
  534. // Use `internalCssNumber` to avoid triggering our warnings in this
  535. // internal check.
  536. if ( !isAutoPx( camelName ) && !internalCssNumber[ camelName ] ) {
  537. migrateWarn( "css-number",
  538. "Number-typed values are deprecated for jQuery.fn.css( \"" +
  539. name + "\", value )" );
  540. }
  541. }
  542. return origFnCss.apply( this, arguments );
  543. }, "css-number" );
  544. var origData = jQuery.data;
  545. migratePatchFunc( jQuery, "data", function( elem, name, value ) {
  546. var curData, sameKeys, key;
  547. // Name can be an object, and each entry in the object is meant to be set as data
  548. if ( name && typeof name === "object" && arguments.length === 2 ) {
  549. curData = jQuery.hasData( elem ) && origData.call( this, elem );
  550. sameKeys = {};
  551. for ( key in name ) {
  552. if ( key !== camelCase( key ) ) {
  553. migrateWarn( "data-camelCase",
  554. "jQuery.data() always sets/gets camelCased names: " + key );
  555. curData[ key ] = name[ key ];
  556. } else {
  557. sameKeys[ key ] = name[ key ];
  558. }
  559. }
  560. origData.call( this, elem, sameKeys );
  561. return name;
  562. }
  563. // If the name is transformed, look for the un-transformed name in the data object
  564. if ( name && typeof name === "string" && name !== camelCase( name ) ) {
  565. curData = jQuery.hasData( elem ) && origData.call( this, elem );
  566. if ( curData && name in curData ) {
  567. migrateWarn( "data-camelCase",
  568. "jQuery.data() always sets/gets camelCased names: " + name );
  569. if ( arguments.length > 2 ) {
  570. curData[ name ] = value;
  571. }
  572. return curData[ name ];
  573. }
  574. }
  575. return origData.apply( this, arguments );
  576. }, "data-camelCase" );
  577. // Support jQuery slim which excludes the effects module
  578. if ( jQuery.fx ) {
  579. var intervalValue, intervalMsg,
  580. oldTweenRun = jQuery.Tween.prototype.run,
  581. linearEasing = function( pct ) {
  582. return pct;
  583. };
  584. migratePatchFunc( jQuery.Tween.prototype, "run", function( ) {
  585. if ( jQuery.easing[ this.easing ].length > 1 ) {
  586. migrateWarn(
  587. "easing-one-arg",
  588. "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
  589. );
  590. jQuery.easing[ this.easing ] = linearEasing;
  591. }
  592. oldTweenRun.apply( this, arguments );
  593. }, "easing-one-arg" );
  594. intervalValue = jQuery.fx.interval;
  595. intervalMsg = "jQuery.fx.interval is deprecated";
  596. // Support: IE9, Android <=4.4
  597. // Avoid false positives on browsers that lack rAF
  598. // Don't warn if document is hidden, jQuery uses setTimeout (#292)
  599. if ( window.requestAnimationFrame ) {
  600. Object.defineProperty( jQuery.fx, "interval", {
  601. configurable: true,
  602. enumerable: true,
  603. get: function() {
  604. if ( !window.document.hidden ) {
  605. migrateWarn( "fx-interval", intervalMsg );
  606. }
  607. // Only fallback to the default if patch is enabled
  608. if ( !jQuery.migrateIsPatchEnabled( "fx-interval" ) ) {
  609. return intervalValue;
  610. }
  611. return intervalValue === undefined ? 13 : intervalValue;
  612. },
  613. set: function( newValue ) {
  614. migrateWarn( "fx-interval", intervalMsg );
  615. intervalValue = newValue;
  616. }
  617. } );
  618. }
  619. }
  620. var oldLoad = jQuery.fn.load,
  621. oldEventAdd = jQuery.event.add,
  622. originalFix = jQuery.event.fix;
  623. jQuery.event.props = [];
  624. jQuery.event.fixHooks = {};
  625. migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
  626. "event-old-patch",
  627. "jQuery.event.props.concat() is deprecated and removed" );
  628. migratePatchFunc( jQuery.event, "fix", function( originalEvent ) {
  629. var event,
  630. type = originalEvent.type,
  631. fixHook = this.fixHooks[ type ],
  632. props = jQuery.event.props;
  633. if ( props.length ) {
  634. migrateWarn( "event-old-patch",
  635. "jQuery.event.props are deprecated and removed: " + props.join() );
  636. while ( props.length ) {
  637. jQuery.event.addProp( props.pop() );
  638. }
  639. }
  640. if ( fixHook && !fixHook._migrated_ ) {
  641. fixHook._migrated_ = true;
  642. migrateWarn( "event-old-patch",
  643. "jQuery.event.fixHooks are deprecated and removed: " + type );
  644. if ( ( props = fixHook.props ) && props.length ) {
  645. while ( props.length ) {
  646. jQuery.event.addProp( props.pop() );
  647. }
  648. }
  649. }
  650. event = originalFix.call( this, originalEvent );
  651. return fixHook && fixHook.filter ?
  652. fixHook.filter( event, originalEvent ) :
  653. event;
  654. }, "event-old-patch" );
  655. migratePatchFunc( jQuery.event, "add", function( elem, types ) {
  656. // This misses the multiple-types case but that seems awfully rare
  657. if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
  658. migrateWarn( "load-after-event",
  659. "jQuery(window).on('load'...) called after load event occurred" );
  660. }
  661. return oldEventAdd.apply( this, arguments );
  662. }, "load-after-event" );
  663. jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
  664. migratePatchFunc( jQuery.fn, name, function() {
  665. var args = Array.prototype.slice.call( arguments, 0 );
  666. // If this is an ajax load() the first arg should be the string URL;
  667. // technically this could also be the "Anything" arg of the event .load()
  668. // which just goes to show why this dumb signature has been deprecated!
  669. // jQuery custom builds that exclude the Ajax module justifiably die here.
  670. if ( name === "load" && typeof args[ 0 ] === "string" ) {
  671. return oldLoad.apply( this, args );
  672. }
  673. migrateWarn( "shorthand-removed-v3",
  674. "jQuery.fn." + name + "() is deprecated" );
  675. args.splice( 0, 0, name );
  676. if ( arguments.length ) {
  677. return this.on.apply( this, args );
  678. }
  679. // Use .triggerHandler here because:
  680. // - load and unload events don't need to bubble, only applied to window or image
  681. // - error event should not bubble to window, although it does pre-1.7
  682. // See http://bugs.jquery.com/ticket/11820
  683. this.triggerHandler.apply( this, args );
  684. return this;
  685. }, "shorthand-removed-v3" );
  686. } );
  687. jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
  688. "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
  689. "change select submit keydown keypress keyup contextmenu" ).split( " " ),
  690. function( _i, name ) {
  691. // Handle event binding
  692. migratePatchAndWarnFunc( jQuery.fn, name, function( data, fn ) {
  693. return arguments.length > 0 ?
  694. this.on( name, null, data, fn ) :
  695. this.trigger( name );
  696. },
  697. "shorthand-deprecated-v3",
  698. "jQuery.fn." + name + "() event shorthand is deprecated" );
  699. } );
  700. // Trigger "ready" event only once, on document ready
  701. jQuery( function() {
  702. jQuery( window.document ).triggerHandler( "ready" );
  703. } );
  704. jQuery.event.special.ready = {
  705. setup: function() {
  706. if ( this === window.document ) {
  707. migrateWarn( "ready-event", "'ready' event is deprecated" );
  708. }
  709. }
  710. };
  711. migratePatchAndWarnFunc( jQuery.fn, "bind", function( types, data, fn ) {
  712. return this.on( types, null, data, fn );
  713. }, "pre-on-methods", "jQuery.fn.bind() is deprecated" );
  714. migratePatchAndWarnFunc( jQuery.fn, "unbind", function( types, fn ) {
  715. return this.off( types, null, fn );
  716. }, "pre-on-methods", "jQuery.fn.unbind() is deprecated" );
  717. migratePatchAndWarnFunc( jQuery.fn, "delegate", function( selector, types, data, fn ) {
  718. return this.on( types, selector, data, fn );
  719. }, "pre-on-methods", "jQuery.fn.delegate() is deprecated" );
  720. migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn ) {
  721. return arguments.length === 1 ?
  722. this.off( selector, "**" ) :
  723. this.off( types, selector || "**", fn );
  724. }, "pre-on-methods", "jQuery.fn.undelegate() is deprecated" );
  725. migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) {
  726. return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
  727. }, "pre-on-methods", "jQuery.fn.hover() is deprecated" );
  728. var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,
  729. makeMarkup = function( html ) {
  730. var doc = window.document.implementation.createHTMLDocument( "" );
  731. doc.body.innerHTML = html;
  732. return doc.body && doc.body.innerHTML;
  733. },
  734. warnIfChanged = function( html ) {
  735. var changed = html.replace( rxhtmlTag, "<$1></$2>" );
  736. if ( changed !== html && makeMarkup( html ) !== makeMarkup( changed ) ) {
  737. migrateWarn( "self-closed-tags",
  738. "HTML tags must be properly nested and closed: " + html );
  739. }
  740. };
  741. /**
  742. * Deprecated, please use `jQuery.migrateDisablePatches( "self-closed-tags" )` instead.
  743. * @deprecated
  744. */
  745. jQuery.UNSAFE_restoreLegacyHtmlPrefilter = function() {
  746. jQuery.migrateEnablePatches( "self-closed-tags" );
  747. };
  748. migratePatchFunc( jQuery, "htmlPrefilter", function( html ) {
  749. warnIfChanged( html );
  750. return html.replace( rxhtmlTag, "<$1></$2>" );
  751. }, "self-closed-tags" );
  752. // This patch needs to be disabled by default as it re-introduces
  753. // security issues (CVE-2020-11022, CVE-2020-11023).
  754. jQuery.migrateDisablePatches( "self-closed-tags" );
  755. var origOffset = jQuery.fn.offset;
  756. migratePatchFunc( jQuery.fn, "offset", function() {
  757. var elem = this[ 0 ];
  758. if ( elem && ( !elem.nodeType || !elem.getBoundingClientRect ) ) {
  759. migrateWarn( "offset-valid-elem", "jQuery.fn.offset() requires a valid DOM element" );
  760. return arguments.length ? this : undefined;
  761. }
  762. return origOffset.apply( this, arguments );
  763. }, "offset-valid-elem" );
  764. // Support jQuery slim which excludes the ajax module
  765. // The jQuery.param patch is about respecting `jQuery.ajaxSettings.traditional`
  766. // so it doesn't make sense for the slim build.
  767. if ( jQuery.ajax ) {
  768. var origParam = jQuery.param;
  769. migratePatchFunc( jQuery, "param", function( data, traditional ) {
  770. var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
  771. if ( traditional === undefined && ajaxTraditional ) {
  772. migrateWarn( "param-ajax-traditional",
  773. "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
  774. traditional = ajaxTraditional;
  775. }
  776. return origParam.call( this, data, traditional );
  777. }, "param-ajax-traditional" );
  778. }
  779. migratePatchAndWarnFunc( jQuery.fn, "andSelf", jQuery.fn.addBack, "andSelf",
  780. "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
  781. // Support jQuery slim which excludes the deferred module in jQuery 4.0+
  782. if ( jQuery.Deferred ) {
  783. var oldDeferred = jQuery.Deferred,
  784. tuples = [
  785. // Action, add listener, callbacks, .then handlers, final state
  786. [ "resolve", "done", jQuery.Callbacks( "once memory" ),
  787. jQuery.Callbacks( "once memory" ), "resolved" ],
  788. [ "reject", "fail", jQuery.Callbacks( "once memory" ),
  789. jQuery.Callbacks( "once memory" ), "rejected" ],
  790. [ "notify", "progress", jQuery.Callbacks( "memory" ),
  791. jQuery.Callbacks( "memory" ) ]
  792. ];
  793. migratePatchFunc( jQuery, "Deferred", function( func ) {
  794. var deferred = oldDeferred(),
  795. promise = deferred.promise();
  796. function newDeferredPipe( /* fnDone, fnFail, fnProgress */ ) {
  797. var fns = arguments;
  798. return jQuery.Deferred( function( newDefer ) {
  799. jQuery.each( tuples, function( i, tuple ) {
  800. var fn = typeof fns[ i ] === "function" && fns[ i ];
  801. // Deferred.done(function() { bind to newDefer or newDefer.resolve })
  802. // deferred.fail(function() { bind to newDefer or newDefer.reject })
  803. // deferred.progress(function() { bind to newDefer or newDefer.notify })
  804. deferred[ tuple[ 1 ] ]( function() {
  805. var returned = fn && fn.apply( this, arguments );
  806. if ( returned && typeof returned.promise === "function" ) {
  807. returned.promise()
  808. .done( newDefer.resolve )
  809. .fail( newDefer.reject )
  810. .progress( newDefer.notify );
  811. } else {
  812. newDefer[ tuple[ 0 ] + "With" ](
  813. this === promise ? newDefer.promise() : this,
  814. fn ? [ returned ] : arguments
  815. );
  816. }
  817. } );
  818. } );
  819. fns = null;
  820. } ).promise();
  821. }
  822. migratePatchAndWarnFunc( deferred, "pipe", newDeferredPipe, "deferred-pipe",
  823. "deferred.pipe() is deprecated" );
  824. migratePatchAndWarnFunc( promise, "pipe", newDeferredPipe, "deferred-pipe",
  825. "deferred.pipe() is deprecated" );
  826. if ( func ) {
  827. func.call( deferred, deferred );
  828. }
  829. return deferred;
  830. }, "deferred-pipe" );
  831. // Preserve handler of uncaught exceptions in promise chains
  832. jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
  833. }
  834. return jQuery;
  835. } );