jquery-migrate-3.3.0.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. /*!
  2. * jQuery Migrate - v3.3.0 - 2020-05-05T01:57Z
  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.3.0";
  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. ( function() {
  43. // Support: IE9 only
  44. // IE9 only creates console object when dev tools are first opened
  45. // IE9 console is a host object, callable but doesn't have .apply()
  46. if ( !window.console || !window.console.log ) {
  47. return;
  48. }
  49. // Need jQuery 3.0.0+ and no older Migrate loaded
  50. if ( !jQuery || !jQueryVersionSince( "3.0.0" ) ) {
  51. window.console.log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
  52. }
  53. if ( jQuery.migrateWarnings ) {
  54. window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
  55. }
  56. // Show a message on the console so devs know we're active
  57. window.console.log( "JQMIGRATE: Migrate is installed" +
  58. ( jQuery.migrateMute ? "" : " with logging active" ) +
  59. ", version " + jQuery.migrateVersion );
  60. } )();
  61. var warnedAbout = {};
  62. // By default each warning is only reported once.
  63. jQuery.migrateDeduplicateWarnings = true;
  64. // List of warnings already given; public read only
  65. jQuery.migrateWarnings = [];
  66. // Set to false to disable traces that appear with warnings
  67. if ( jQuery.migrateTrace === undefined ) {
  68. jQuery.migrateTrace = true;
  69. }
  70. // Forget any warnings we've already given; public
  71. jQuery.migrateReset = function() {
  72. warnedAbout = {};
  73. jQuery.migrateWarnings.length = 0;
  74. };
  75. function migrateWarn( msg ) {
  76. var console = window.console;
  77. if ( !jQuery.migrateDeduplicateWarnings || !warnedAbout[ msg ] ) {
  78. warnedAbout[ msg ] = true;
  79. jQuery.migrateWarnings.push( msg );
  80. if ( console && console.warn && !jQuery.migrateMute ) {
  81. console.warn( "JQMIGRATE: " + msg );
  82. if ( jQuery.migrateTrace && console.trace ) {
  83. console.trace();
  84. }
  85. }
  86. }
  87. }
  88. function migrateWarnProp( obj, prop, value, msg ) {
  89. Object.defineProperty( obj, prop, {
  90. configurable: true,
  91. enumerable: true,
  92. get: function() {
  93. migrateWarn( msg );
  94. return value;
  95. },
  96. set: function( newValue ) {
  97. migrateWarn( msg );
  98. value = newValue;
  99. }
  100. } );
  101. }
  102. function migrateWarnFunc( obj, prop, newFunc, msg ) {
  103. obj[ prop ] = function() {
  104. migrateWarn( msg );
  105. return newFunc.apply( this, arguments );
  106. };
  107. }
  108. if ( window.document.compatMode === "BackCompat" ) {
  109. // JQuery has never supported or tested Quirks Mode
  110. migrateWarn( "jQuery is not compatible with Quirks Mode" );
  111. }
  112. var findProp,
  113. class2type = {},
  114. oldInit = jQuery.fn.init,
  115. oldFind = jQuery.find,
  116. rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
  117. rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g,
  118. // Support: Android <=4.0 only
  119. // Make sure we trim BOM and NBSP
  120. rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
  121. jQuery.fn.init = function( arg1 ) {
  122. var args = Array.prototype.slice.call( arguments );
  123. if ( typeof arg1 === "string" && arg1 === "#" ) {
  124. // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
  125. migrateWarn( "jQuery( '#' ) is not a valid selector" );
  126. args[ 0 ] = [];
  127. }
  128. return oldInit.apply( this, args );
  129. };
  130. jQuery.fn.init.prototype = jQuery.fn;
  131. jQuery.find = function( selector ) {
  132. var args = Array.prototype.slice.call( arguments );
  133. // Support: PhantomJS 1.x
  134. // String#match fails to match when used with a //g RegExp, only on some strings
  135. if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
  136. // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
  137. // First see if qS thinks it's a valid selector, if so avoid a false positive
  138. try {
  139. window.document.querySelector( selector );
  140. } catch ( err1 ) {
  141. // Didn't *look* valid to qSA, warn and try quoting what we think is the value
  142. selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
  143. return "[" + attr + op + "\"" + value + "\"]";
  144. } );
  145. // If the regexp *may* have created an invalid selector, don't update it
  146. // Note that there may be false alarms if selector uses jQuery extensions
  147. try {
  148. window.document.querySelector( selector );
  149. migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
  150. args[ 0 ] = selector;
  151. } catch ( err2 ) {
  152. migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
  153. }
  154. }
  155. }
  156. return oldFind.apply( this, args );
  157. };
  158. // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
  159. for ( findProp in oldFind ) {
  160. if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
  161. jQuery.find[ findProp ] = oldFind[ findProp ];
  162. }
  163. }
  164. // The number of elements contained in the matched element set
  165. migrateWarnFunc( jQuery.fn, "size", function() {
  166. return this.length;
  167. },
  168. "jQuery.fn.size() is deprecated and removed; use the .length property" );
  169. migrateWarnFunc( jQuery, "parseJSON", function() {
  170. return JSON.parse.apply( null, arguments );
  171. },
  172. "jQuery.parseJSON is deprecated; use JSON.parse" );
  173. migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
  174. "jQuery.holdReady is deprecated" );
  175. migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
  176. "jQuery.unique is deprecated; use jQuery.uniqueSort" );
  177. // Now jQuery.expr.pseudos is the standard incantation
  178. migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos,
  179. "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
  180. migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos,
  181. "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
  182. // Prior to jQuery 3.1.1 there were internal refs so we don't warn there
  183. if ( jQueryVersionSince( "3.1.1" ) ) {
  184. migrateWarnFunc( jQuery, "trim", function( text ) {
  185. return text == null ?
  186. "" :
  187. ( text + "" ).replace( rtrim, "" );
  188. },
  189. "jQuery.trim is deprecated; use String.prototype.trim" );
  190. }
  191. // Prior to jQuery 3.2 there were internal refs so we don't warn there
  192. if ( jQueryVersionSince( "3.2.0" ) ) {
  193. migrateWarnFunc( jQuery, "nodeName", function( elem, name ) {
  194. return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
  195. },
  196. "jQuery.nodeName is deprecated" );
  197. }
  198. if ( jQueryVersionSince( "3.3.0" ) ) {
  199. migrateWarnFunc( jQuery, "isNumeric", function( obj ) {
  200. // As of jQuery 3.0, isNumeric is limited to
  201. // strings and numbers (primitives or objects)
  202. // that can be coerced to finite numbers (gh-2662)
  203. var type = typeof obj;
  204. return ( type === "number" || type === "string" ) &&
  205. // parseFloat NaNs numeric-cast false positives ("")
  206. // ...but misinterprets leading-number strings, e.g. hex literals ("0x...")
  207. // subtraction forces infinities to NaN
  208. !isNaN( obj - parseFloat( obj ) );
  209. },
  210. "jQuery.isNumeric() is deprecated"
  211. );
  212. // Populate the class2type map
  213. jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".
  214. split( " " ),
  215. function( _, name ) {
  216. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  217. } );
  218. migrateWarnFunc( jQuery, "type", function( obj ) {
  219. if ( obj == null ) {
  220. return obj + "";
  221. }
  222. // Support: Android <=2.3 only (functionish RegExp)
  223. return typeof obj === "object" || typeof obj === "function" ?
  224. class2type[ Object.prototype.toString.call( obj ) ] || "object" :
  225. typeof obj;
  226. },
  227. "jQuery.type is deprecated" );
  228. migrateWarnFunc( jQuery, "isFunction",
  229. function( obj ) {
  230. return typeof obj === "function";
  231. },
  232. "jQuery.isFunction() is deprecated" );
  233. migrateWarnFunc( jQuery, "isWindow",
  234. function( obj ) {
  235. return obj != null && obj === obj.window;
  236. },
  237. "jQuery.isWindow() is deprecated"
  238. );
  239. migrateWarnFunc( jQuery, "isArray", Array.isArray,
  240. "jQuery.isArray is deprecated; use Array.isArray"
  241. );
  242. }
  243. // Support jQuery slim which excludes the ajax module
  244. if ( jQuery.ajax ) {
  245. var oldAjax = jQuery.ajax;
  246. jQuery.ajax = function( ) {
  247. var jQXHR = oldAjax.apply( this, arguments );
  248. // Be sure we got a jQXHR (e.g., not sync)
  249. if ( jQXHR.promise ) {
  250. migrateWarnFunc( jQXHR, "success", jQXHR.done,
  251. "jQXHR.success is deprecated and removed" );
  252. migrateWarnFunc( jQXHR, "error", jQXHR.fail,
  253. "jQXHR.error is deprecated and removed" );
  254. migrateWarnFunc( jQXHR, "complete", jQXHR.always,
  255. "jQXHR.complete is deprecated and removed" );
  256. }
  257. return jQXHR;
  258. };
  259. }
  260. var oldRemoveAttr = jQuery.fn.removeAttr,
  261. oldToggleClass = jQuery.fn.toggleClass,
  262. rmatchNonSpace = /\S+/g;
  263. jQuery.fn.removeAttr = function( name ) {
  264. var self = this;
  265. jQuery.each( name.match( rmatchNonSpace ), function( _i, attr ) {
  266. if ( jQuery.expr.match.bool.test( attr ) ) {
  267. migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
  268. self.prop( attr, false );
  269. }
  270. } );
  271. return oldRemoveAttr.apply( this, arguments );
  272. };
  273. jQuery.fn.toggleClass = function( state ) {
  274. // Only deprecating no-args or single boolean arg
  275. if ( state !== undefined && typeof state !== "boolean" ) {
  276. return oldToggleClass.apply( this, arguments );
  277. }
  278. migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
  279. // Toggle entire class name of each element
  280. return this.each( function() {
  281. var className = this.getAttribute && this.getAttribute( "class" ) || "";
  282. if ( className ) {
  283. jQuery.data( this, "__className__", className );
  284. }
  285. // If the element has a class name or if we're passed `false`,
  286. // then remove the whole classname (if there was one, the above saved it).
  287. // Otherwise bring back whatever was previously saved (if anything),
  288. // falling back to the empty string if nothing was stored.
  289. if ( this.setAttribute ) {
  290. this.setAttribute( "class",
  291. className || state === false ?
  292. "" :
  293. jQuery.data( this, "__className__" ) || ""
  294. );
  295. }
  296. } );
  297. };
  298. function camelCase( string ) {
  299. return string.replace( /-([a-z])/g, function( _, letter ) {
  300. return letter.toUpperCase();
  301. } );
  302. }
  303. var oldFnCss,
  304. internalSwapCall = false,
  305. ralphaStart = /^[a-z]/,
  306. // The regex visualized:
  307. //
  308. // /----------\
  309. // | | /-------\
  310. // | / Top \ | | |
  311. // /--- Border ---+-| Right |-+---+- Width -+---\
  312. // | | Bottom | |
  313. // | \ Left / |
  314. // | |
  315. // | /----------\ |
  316. // | /-------------\ | | |- END
  317. // | | | | / Top \ | |
  318. // | | / Margin \ | | | Right | | |
  319. // |---------+-| |-+---+-| Bottom |-+----|
  320. // | \ Padding / \ Left / |
  321. // BEGIN -| |
  322. // | /---------\ |
  323. // | | | |
  324. // | | / Min \ | / Width \ |
  325. // \--------------+-| |-+---| |---/
  326. // \ Max / \ Height /
  327. rautoPx = /^(?:Border(?:Top|Right|Bottom|Left)?(?:Width|)|(?:Margin|Padding)?(?:Top|Right|Bottom|Left)?|(?:Min|Max)?(?:Width|Height))$/;
  328. // If this version of jQuery has .swap(), don't false-alarm on internal uses
  329. if ( jQuery.swap ) {
  330. jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
  331. var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
  332. if ( oldHook ) {
  333. jQuery.cssHooks[ name ].get = function() {
  334. var ret;
  335. internalSwapCall = true;
  336. ret = oldHook.apply( this, arguments );
  337. internalSwapCall = false;
  338. return ret;
  339. };
  340. }
  341. } );
  342. }
  343. jQuery.swap = function( elem, options, callback, args ) {
  344. var ret, name,
  345. old = {};
  346. if ( !internalSwapCall ) {
  347. migrateWarn( "jQuery.swap() is undocumented and deprecated" );
  348. }
  349. // Remember the old values, and insert the new ones
  350. for ( name in options ) {
  351. old[ name ] = elem.style[ name ];
  352. elem.style[ name ] = options[ name ];
  353. }
  354. ret = callback.apply( elem, args || [] );
  355. // Revert the old values
  356. for ( name in options ) {
  357. elem.style[ name ] = old[ name ];
  358. }
  359. return ret;
  360. };
  361. if ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) {
  362. jQuery.cssProps = new Proxy( jQuery.cssProps || {}, {
  363. set: function() {
  364. migrateWarn( "JQMIGRATE: jQuery.cssProps is deprecated" );
  365. return Reflect.set.apply( this, arguments );
  366. }
  367. } );
  368. }
  369. // Create a dummy jQuery.cssNumber if missing. It won't be used by jQuery but
  370. // it will prevent code adding new keys to it unconditionally from crashing.
  371. if ( !jQuery.cssNumber ) {
  372. jQuery.cssNumber = {};
  373. }
  374. function isAutoPx( prop ) {
  375. // The first test is used to ensure that:
  376. // 1. The prop starts with a lowercase letter (as we uppercase it for the second regex).
  377. // 2. The prop is not empty.
  378. return ralphaStart.test( prop ) &&
  379. rautoPx.test( prop[ 0 ].toUpperCase() + prop.slice( 1 ) );
  380. }
  381. oldFnCss = jQuery.fn.css;
  382. jQuery.fn.css = function( name, value ) {
  383. var origThis = this;
  384. if ( typeof name !== "string" ) {
  385. jQuery.each( name, function( n, v ) {
  386. jQuery.fn.css.call( origThis, n, v );
  387. } );
  388. }
  389. if ( typeof value === "number" && !isAutoPx( camelCase( name ) ) ) {
  390. migrateWarn( "Use of number-typed values is deprecated in jQuery.fn.css" );
  391. }
  392. return oldFnCss.apply( this, arguments );
  393. };
  394. var oldData = jQuery.data;
  395. jQuery.data = function( elem, name, value ) {
  396. var curData, sameKeys, key;
  397. // Name can be an object, and each entry in the object is meant to be set as data
  398. if ( name && typeof name === "object" && arguments.length === 2 ) {
  399. curData = jQuery.hasData( elem ) && oldData.call( this, elem );
  400. sameKeys = {};
  401. for ( key in name ) {
  402. if ( key !== camelCase( key ) ) {
  403. migrateWarn( "jQuery.data() always sets/gets camelCased names: " + key );
  404. curData[ key ] = name[ key ];
  405. } else {
  406. sameKeys[ key ] = name[ key ];
  407. }
  408. }
  409. oldData.call( this, elem, sameKeys );
  410. return name;
  411. }
  412. // If the name is transformed, look for the un-transformed name in the data object
  413. if ( name && typeof name === "string" && name !== camelCase( name ) ) {
  414. curData = jQuery.hasData( elem ) && oldData.call( this, elem );
  415. if ( curData && name in curData ) {
  416. migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name );
  417. if ( arguments.length > 2 ) {
  418. curData[ name ] = value;
  419. }
  420. return curData[ name ];
  421. }
  422. }
  423. return oldData.apply( this, arguments );
  424. };
  425. // Support jQuery slim which excludes the effects module
  426. if ( jQuery.fx ) {
  427. var intervalValue, intervalMsg,
  428. oldTweenRun = jQuery.Tween.prototype.run,
  429. linearEasing = function( pct ) {
  430. return pct;
  431. };
  432. jQuery.Tween.prototype.run = function( ) {
  433. if ( jQuery.easing[ this.easing ].length > 1 ) {
  434. migrateWarn(
  435. "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
  436. );
  437. jQuery.easing[ this.easing ] = linearEasing;
  438. }
  439. oldTweenRun.apply( this, arguments );
  440. };
  441. intervalValue = jQuery.fx.interval || 13;
  442. intervalMsg = "jQuery.fx.interval is deprecated";
  443. // Support: IE9, Android <=4.4
  444. // Avoid false positives on browsers that lack rAF
  445. // Don't warn if document is hidden, jQuery uses setTimeout (#292)
  446. if ( window.requestAnimationFrame ) {
  447. Object.defineProperty( jQuery.fx, "interval", {
  448. configurable: true,
  449. enumerable: true,
  450. get: function() {
  451. if ( !window.document.hidden ) {
  452. migrateWarn( intervalMsg );
  453. }
  454. return intervalValue;
  455. },
  456. set: function( newValue ) {
  457. migrateWarn( intervalMsg );
  458. intervalValue = newValue;
  459. }
  460. } );
  461. }
  462. }
  463. var oldLoad = jQuery.fn.load,
  464. oldEventAdd = jQuery.event.add,
  465. originalFix = jQuery.event.fix;
  466. jQuery.event.props = [];
  467. jQuery.event.fixHooks = {};
  468. migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
  469. "jQuery.event.props.concat() is deprecated and removed" );
  470. jQuery.event.fix = function( originalEvent ) {
  471. var event,
  472. type = originalEvent.type,
  473. fixHook = this.fixHooks[ type ],
  474. props = jQuery.event.props;
  475. if ( props.length ) {
  476. migrateWarn( "jQuery.event.props are deprecated and removed: " + props.join() );
  477. while ( props.length ) {
  478. jQuery.event.addProp( props.pop() );
  479. }
  480. }
  481. if ( fixHook && !fixHook._migrated_ ) {
  482. fixHook._migrated_ = true;
  483. migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type );
  484. if ( ( props = fixHook.props ) && props.length ) {
  485. while ( props.length ) {
  486. jQuery.event.addProp( props.pop() );
  487. }
  488. }
  489. }
  490. event = originalFix.call( this, originalEvent );
  491. return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
  492. };
  493. jQuery.event.add = function( elem, types ) {
  494. // This misses the multiple-types case but that seems awfully rare
  495. if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
  496. migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
  497. }
  498. return oldEventAdd.apply( this, arguments );
  499. };
  500. jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
  501. jQuery.fn[ name ] = function() {
  502. var args = Array.prototype.slice.call( arguments, 0 );
  503. // If this is an ajax load() the first arg should be the string URL;
  504. // technically this could also be the "Anything" arg of the event .load()
  505. // which just goes to show why this dumb signature has been deprecated!
  506. // jQuery custom builds that exclude the Ajax module justifiably die here.
  507. if ( name === "load" && typeof args[ 0 ] === "string" ) {
  508. return oldLoad.apply( this, args );
  509. }
  510. migrateWarn( "jQuery.fn." + name + "() is deprecated" );
  511. args.splice( 0, 0, name );
  512. if ( arguments.length ) {
  513. return this.on.apply( this, args );
  514. }
  515. // Use .triggerHandler here because:
  516. // - load and unload events don't need to bubble, only applied to window or image
  517. // - error event should not bubble to window, although it does pre-1.7
  518. // See http://bugs.jquery.com/ticket/11820
  519. this.triggerHandler.apply( this, args );
  520. return this;
  521. };
  522. } );
  523. jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
  524. "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
  525. "change select submit keydown keypress keyup contextmenu" ).split( " " ),
  526. function( _i, name ) {
  527. // Handle event binding
  528. jQuery.fn[ name ] = function( data, fn ) {
  529. migrateWarn( "jQuery.fn." + name + "() event shorthand is deprecated" );
  530. return arguments.length > 0 ?
  531. this.on( name, null, data, fn ) :
  532. this.trigger( name );
  533. };
  534. } );
  535. // Trigger "ready" event only once, on document ready
  536. jQuery( function() {
  537. jQuery( window.document ).triggerHandler( "ready" );
  538. } );
  539. jQuery.event.special.ready = {
  540. setup: function() {
  541. if ( this === window.document ) {
  542. migrateWarn( "'ready' event is deprecated" );
  543. }
  544. }
  545. };
  546. jQuery.fn.extend( {
  547. bind: function( types, data, fn ) {
  548. migrateWarn( "jQuery.fn.bind() is deprecated" );
  549. return this.on( types, null, data, fn );
  550. },
  551. unbind: function( types, fn ) {
  552. migrateWarn( "jQuery.fn.unbind() is deprecated" );
  553. return this.off( types, null, fn );
  554. },
  555. delegate: function( selector, types, data, fn ) {
  556. migrateWarn( "jQuery.fn.delegate() is deprecated" );
  557. return this.on( types, selector, data, fn );
  558. },
  559. undelegate: function( selector, types, fn ) {
  560. migrateWarn( "jQuery.fn.undelegate() is deprecated" );
  561. return arguments.length === 1 ?
  562. this.off( selector, "**" ) :
  563. this.off( types, selector || "**", fn );
  564. },
  565. hover: function( fnOver, fnOut ) {
  566. migrateWarn( "jQuery.fn.hover() is deprecated" );
  567. return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
  568. }
  569. } );
  570. var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,
  571. origHtmlPrefilter = jQuery.htmlPrefilter,
  572. makeMarkup = function( html ) {
  573. var doc = window.document.implementation.createHTMLDocument( "" );
  574. doc.body.innerHTML = html;
  575. return doc.body && doc.body.innerHTML;
  576. },
  577. warnIfChanged = function( html ) {
  578. var changed = html.replace( rxhtmlTag, "<$1></$2>" );
  579. if ( changed !== html && makeMarkup( html ) !== makeMarkup( changed ) ) {
  580. migrateWarn( "HTML tags must be properly nested and closed: " + html );
  581. }
  582. };
  583. jQuery.UNSAFE_restoreLegacyHtmlPrefilter = function() {
  584. jQuery.htmlPrefilter = function( html ) {
  585. warnIfChanged( html );
  586. return html.replace( rxhtmlTag, "<$1></$2>" );
  587. };
  588. };
  589. jQuery.htmlPrefilter = function( html ) {
  590. warnIfChanged( html );
  591. return origHtmlPrefilter( html );
  592. };
  593. var oldOffset = jQuery.fn.offset;
  594. jQuery.fn.offset = function() {
  595. var docElem,
  596. elem = this[ 0 ],
  597. bogus = { top: 0, left: 0 };
  598. if ( !elem || !elem.nodeType ) {
  599. migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
  600. return undefined;
  601. }
  602. docElem = ( elem.ownerDocument || window.document ).documentElement;
  603. if ( !jQuery.contains( docElem, elem ) ) {
  604. migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
  605. return bogus;
  606. }
  607. return oldOffset.apply( this, arguments );
  608. };
  609. // Support jQuery slim which excludes the ajax module
  610. // The jQuery.param patch is about respecting `jQuery.ajaxSettings.traditional`
  611. // so it doesn't make sense for the slim build.
  612. if ( jQuery.ajax ) {
  613. var oldParam = jQuery.param;
  614. jQuery.param = function( data, traditional ) {
  615. var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
  616. if ( traditional === undefined && ajaxTraditional ) {
  617. migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
  618. traditional = ajaxTraditional;
  619. }
  620. return oldParam.call( this, data, traditional );
  621. };
  622. }
  623. var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
  624. jQuery.fn.andSelf = function() {
  625. migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
  626. return oldSelf.apply( this, arguments );
  627. };
  628. // Support jQuery slim which excludes the deferred module in jQuery 4.0+
  629. if ( jQuery.Deferred ) {
  630. var oldDeferred = jQuery.Deferred,
  631. tuples = [
  632. // Action, add listener, callbacks, .then handlers, final state
  633. [ "resolve", "done", jQuery.Callbacks( "once memory" ),
  634. jQuery.Callbacks( "once memory" ), "resolved" ],
  635. [ "reject", "fail", jQuery.Callbacks( "once memory" ),
  636. jQuery.Callbacks( "once memory" ), "rejected" ],
  637. [ "notify", "progress", jQuery.Callbacks( "memory" ),
  638. jQuery.Callbacks( "memory" ) ]
  639. ];
  640. jQuery.Deferred = function( func ) {
  641. var deferred = oldDeferred(),
  642. promise = deferred.promise();
  643. deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
  644. var fns = arguments;
  645. migrateWarn( "deferred.pipe() is deprecated" );
  646. return jQuery.Deferred( function( newDefer ) {
  647. jQuery.each( tuples, function( i, tuple ) {
  648. var fn = typeof fns[ i ] === "function" && fns[ i ];
  649. // Deferred.done(function() { bind to newDefer or newDefer.resolve })
  650. // deferred.fail(function() { bind to newDefer or newDefer.reject })
  651. // deferred.progress(function() { bind to newDefer or newDefer.notify })
  652. deferred[ tuple[ 1 ] ]( function() {
  653. var returned = fn && fn.apply( this, arguments );
  654. if ( returned && typeof returned.promise === "function" ) {
  655. returned.promise()
  656. .done( newDefer.resolve )
  657. .fail( newDefer.reject )
  658. .progress( newDefer.notify );
  659. } else {
  660. newDefer[ tuple[ 0 ] + "With" ](
  661. this === promise ? newDefer.promise() : this,
  662. fn ? [ returned ] : arguments
  663. );
  664. }
  665. } );
  666. } );
  667. fns = null;
  668. } ).promise();
  669. };
  670. if ( func ) {
  671. func.call( deferred, deferred );
  672. }
  673. return deferred;
  674. };
  675. // Preserve handler of uncaught exceptions in promise chains
  676. jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
  677. }
  678. return jQuery;
  679. } );