jquery-migrate.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*!
  2. * jQuery Migrate - v3.0.1 - 2017-09-26
  3. * Copyright jQuery Foundation and other contributors
  4. */
  5. ;( function( factory ) {
  6. if ( typeof define === "function" && define.amd ) {
  7. // AMD. Register as an anonymous module.
  8. define( [ "jquery" ], window, factory );
  9. } else if ( typeof module === "object" && module.exports ) {
  10. // Node/CommonJS
  11. // eslint-disable-next-line no-undef
  12. module.exports = factory( require( "jquery" ), window );
  13. } else {
  14. // Browser globals
  15. factory( jQuery, window );
  16. }
  17. } )( function( jQuery, window ) {
  18. "use strict";
  19. jQuery.migrateVersion = "3.0.1";
  20. /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
  21. ( function() {
  22. var rbadVersions = /^[12]\./;
  23. // Support: IE9 only
  24. // IE9 only creates console object when dev tools are first opened
  25. // IE9 console is a host object, callable but doesn't have .apply()
  26. if ( !window.console || !window.console.log ) {
  27. return;
  28. }
  29. // Need jQuery 3.0.0+ and no older Migrate loaded
  30. if ( !jQuery || rbadVersions.test( jQuery.fn.jquery ) ) {
  31. window.console.log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
  32. }
  33. if ( jQuery.migrateWarnings ) {
  34. window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
  35. }
  36. // Show a message on the console so devs know we're active
  37. window.console.log( "JQMIGRATE: Migrate is installed" +
  38. ( jQuery.migrateMute ? "" : " with logging active" ) +
  39. ", version " + jQuery.migrateVersion );
  40. } )();
  41. var warnedAbout = {};
  42. // List of warnings already given; public read only
  43. jQuery.migrateWarnings = [];
  44. // Set to false to disable traces that appear with warnings
  45. if ( jQuery.migrateTrace === undefined ) {
  46. jQuery.migrateTrace = true;
  47. }
  48. // Forget any warnings we've already given; public
  49. jQuery.migrateReset = function() {
  50. warnedAbout = {};
  51. jQuery.migrateWarnings.length = 0;
  52. };
  53. function migrateWarn( msg ) {
  54. var console = window.console;
  55. if ( !warnedAbout[ msg ] ) {
  56. warnedAbout[ msg ] = true;
  57. jQuery.migrateWarnings.push( msg );
  58. if ( console && console.warn && !jQuery.migrateMute ) {
  59. console.warn( "JQMIGRATE: " + msg );
  60. if ( jQuery.migrateTrace && console.trace ) {
  61. console.trace();
  62. }
  63. }
  64. }
  65. }
  66. function migrateWarnProp( obj, prop, value, msg ) {
  67. Object.defineProperty( obj, prop, {
  68. configurable: true,
  69. enumerable: true,
  70. get: function() {
  71. migrateWarn( msg );
  72. return value;
  73. },
  74. set: function( newValue ) {
  75. migrateWarn( msg );
  76. value = newValue;
  77. }
  78. } );
  79. }
  80. function migrateWarnFunc( obj, prop, newFunc, msg ) {
  81. obj[ prop ] = function() {
  82. migrateWarn( msg );
  83. return newFunc.apply( this, arguments );
  84. };
  85. }
  86. if ( window.document.compatMode === "BackCompat" ) {
  87. // JQuery has never supported or tested Quirks Mode
  88. migrateWarn( "jQuery is not compatible with Quirks Mode" );
  89. }
  90. var oldInit = jQuery.fn.init,
  91. oldIsNumeric = jQuery.isNumeric,
  92. oldFind = jQuery.find,
  93. rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
  94. rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
  95. jQuery.fn.init = function( arg1 ) {
  96. var args = Array.prototype.slice.call( arguments );
  97. if ( typeof arg1 === "string" && arg1 === "#" ) {
  98. // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
  99. migrateWarn( "jQuery( '#' ) is not a valid selector" );
  100. args[ 0 ] = [];
  101. }
  102. return oldInit.apply( this, args );
  103. };
  104. jQuery.fn.init.prototype = jQuery.fn;
  105. jQuery.find = function( selector ) {
  106. var args = Array.prototype.slice.call( arguments );
  107. // Support: PhantomJS 1.x
  108. // String#match fails to match when used with a //g RegExp, only on some strings
  109. if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
  110. // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
  111. // First see if qS thinks it's a valid selector, if so avoid a false positive
  112. try {
  113. window.document.querySelector( selector );
  114. } catch ( err1 ) {
  115. // Didn't *look* valid to qSA, warn and try quoting what we think is the value
  116. selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
  117. return "[" + attr + op + "\"" + value + "\"]";
  118. } );
  119. // If the regexp *may* have created an invalid selector, don't update it
  120. // Note that there may be false alarms if selector uses jQuery extensions
  121. try {
  122. window.document.querySelector( selector );
  123. migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
  124. args[ 0 ] = selector;
  125. } catch ( err2 ) {
  126. migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
  127. }
  128. }
  129. }
  130. return oldFind.apply( this, args );
  131. };
  132. // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
  133. var findProp;
  134. for ( findProp in oldFind ) {
  135. if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
  136. jQuery.find[ findProp ] = oldFind[ findProp ];
  137. }
  138. }
  139. // The number of elements contained in the matched element set
  140. jQuery.fn.size = function() {
  141. migrateWarn( "jQuery.fn.size() is deprecated and removed; use the .length property" );
  142. return this.length;
  143. };
  144. jQuery.parseJSON = function() {
  145. migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
  146. return JSON.parse.apply( null, arguments );
  147. };
  148. jQuery.isNumeric = function( val ) {
  149. // The jQuery 2.2.3 implementation of isNumeric
  150. function isNumeric2( obj ) {
  151. var realStringObj = obj && obj.toString();
  152. return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
  153. }
  154. var newValue = oldIsNumeric( val ),
  155. oldValue = isNumeric2( val );
  156. if ( newValue !== oldValue ) {
  157. migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
  158. }
  159. return oldValue;
  160. };
  161. migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
  162. "jQuery.holdReady is deprecated" );
  163. migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
  164. "jQuery.unique is deprecated; use jQuery.uniqueSort" );
  165. // Now jQuery.expr.pseudos is the standard incantation
  166. migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos,
  167. "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
  168. migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos,
  169. "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
  170. var oldAjax = jQuery.ajax;
  171. jQuery.ajax = function( ) {
  172. var jQXHR = oldAjax.apply( this, arguments );
  173. // Be sure we got a jQXHR (e.g., not sync)
  174. if ( jQXHR.promise ) {
  175. migrateWarnFunc( jQXHR, "success", jQXHR.done,
  176. "jQXHR.success is deprecated and removed" );
  177. migrateWarnFunc( jQXHR, "error", jQXHR.fail,
  178. "jQXHR.error is deprecated and removed" );
  179. migrateWarnFunc( jQXHR, "complete", jQXHR.always,
  180. "jQXHR.complete is deprecated and removed" );
  181. }
  182. return jQXHR;
  183. };
  184. var oldRemoveAttr = jQuery.fn.removeAttr,
  185. oldToggleClass = jQuery.fn.toggleClass,
  186. rmatchNonSpace = /\S+/g;
  187. jQuery.fn.removeAttr = function( name ) {
  188. var self = this;
  189. jQuery.each( name.match( rmatchNonSpace ), function( i, attr ) {
  190. if ( jQuery.expr.match.bool.test( attr ) ) {
  191. migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
  192. self.prop( attr, false );
  193. }
  194. } );
  195. return oldRemoveAttr.apply( this, arguments );
  196. };
  197. jQuery.fn.toggleClass = function( state ) {
  198. // Only deprecating no-args or single boolean arg
  199. if ( state !== undefined && typeof state !== "boolean" ) {
  200. return oldToggleClass.apply( this, arguments );
  201. }
  202. migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
  203. // Toggle entire class name of each element
  204. return this.each( function() {
  205. var className = this.getAttribute && this.getAttribute( "class" ) || "";
  206. if ( className ) {
  207. jQuery.data( this, "__className__", className );
  208. }
  209. // If the element has a class name or if we're passed `false`,
  210. // then remove the whole classname (if there was one, the above saved it).
  211. // Otherwise bring back whatever was previously saved (if anything),
  212. // falling back to the empty string if nothing was stored.
  213. if ( this.setAttribute ) {
  214. this.setAttribute( "class",
  215. className || state === false ?
  216. "" :
  217. jQuery.data( this, "__className__" ) || ""
  218. );
  219. }
  220. } );
  221. };
  222. var internalSwapCall = false;
  223. // If this version of jQuery has .swap(), don't false-alarm on internal uses
  224. if ( jQuery.swap ) {
  225. jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
  226. var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
  227. if ( oldHook ) {
  228. jQuery.cssHooks[ name ].get = function() {
  229. var ret;
  230. internalSwapCall = true;
  231. ret = oldHook.apply( this, arguments );
  232. internalSwapCall = false;
  233. return ret;
  234. };
  235. }
  236. } );
  237. }
  238. jQuery.swap = function( elem, options, callback, args ) {
  239. var ret, name,
  240. old = {};
  241. if ( !internalSwapCall ) {
  242. migrateWarn( "jQuery.swap() is undocumented and deprecated" );
  243. }
  244. // Remember the old values, and insert the new ones
  245. for ( name in options ) {
  246. old[ name ] = elem.style[ name ];
  247. elem.style[ name ] = options[ name ];
  248. }
  249. ret = callback.apply( elem, args || [] );
  250. // Revert the old values
  251. for ( name in options ) {
  252. elem.style[ name ] = old[ name ];
  253. }
  254. return ret;
  255. };
  256. var oldData = jQuery.data;
  257. jQuery.data = function( elem, name, value ) {
  258. var curData;
  259. // Name can be an object, and each entry in the object is meant to be set as data
  260. if ( name && typeof name === "object" && arguments.length === 2 ) {
  261. curData = jQuery.hasData( elem ) && oldData.call( this, elem );
  262. var sameKeys = {};
  263. for ( var key in name ) {
  264. if ( key !== jQuery.camelCase( key ) ) {
  265. migrateWarn( "jQuery.data() always sets/gets camelCased names: " + key );
  266. curData[ key ] = name[ key ];
  267. } else {
  268. sameKeys[ key ] = name[ key ];
  269. }
  270. }
  271. oldData.call( this, elem, sameKeys );
  272. return name;
  273. }
  274. // If the name is transformed, look for the un-transformed name in the data object
  275. if ( name && typeof name === "string" && name !== jQuery.camelCase( name ) ) {
  276. curData = jQuery.hasData( elem ) && oldData.call( this, elem );
  277. if ( curData && name in curData ) {
  278. migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name );
  279. if ( arguments.length > 2 ) {
  280. curData[ name ] = value;
  281. }
  282. return curData[ name ];
  283. }
  284. }
  285. return oldData.apply( this, arguments );
  286. };
  287. var oldTweenRun = jQuery.Tween.prototype.run;
  288. var linearEasing = function( pct ) {
  289. return pct;
  290. };
  291. jQuery.Tween.prototype.run = function( ) {
  292. if ( jQuery.easing[ this.easing ].length > 1 ) {
  293. migrateWarn(
  294. "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
  295. );
  296. jQuery.easing[ this.easing ] = linearEasing;
  297. }
  298. oldTweenRun.apply( this, arguments );
  299. };
  300. jQuery.fx.interval = jQuery.fx.interval || 13;
  301. // Support: IE9, Android <=4.4
  302. // Avoid false positives on browsers that lack rAF
  303. if ( window.requestAnimationFrame ) {
  304. migrateWarnProp( jQuery.fx, "interval", jQuery.fx.interval,
  305. "jQuery.fx.interval is deprecated" );
  306. }
  307. var oldLoad = jQuery.fn.load,
  308. oldEventAdd = jQuery.event.add,
  309. originalFix = jQuery.event.fix;
  310. jQuery.event.props = [];
  311. jQuery.event.fixHooks = {};
  312. migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
  313. "jQuery.event.props.concat() is deprecated and removed" );
  314. jQuery.event.fix = function( originalEvent ) {
  315. var event,
  316. type = originalEvent.type,
  317. fixHook = this.fixHooks[ type ],
  318. props = jQuery.event.props;
  319. if ( props.length ) {
  320. migrateWarn( "jQuery.event.props are deprecated and removed: " + props.join() );
  321. while ( props.length ) {
  322. jQuery.event.addProp( props.pop() );
  323. }
  324. }
  325. if ( fixHook && !fixHook._migrated_ ) {
  326. fixHook._migrated_ = true;
  327. migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type );
  328. if ( ( props = fixHook.props ) && props.length ) {
  329. while ( props.length ) {
  330. jQuery.event.addProp( props.pop() );
  331. }
  332. }
  333. }
  334. event = originalFix.call( this, originalEvent );
  335. return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
  336. };
  337. jQuery.event.add = function( elem, types ) {
  338. // This misses the multiple-types case but that seems awfully rare
  339. if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
  340. migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
  341. }
  342. return oldEventAdd.apply( this, arguments );
  343. };
  344. jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
  345. jQuery.fn[ name ] = function() {
  346. var args = Array.prototype.slice.call( arguments, 0 );
  347. // If this is an ajax load() the first arg should be the string URL;
  348. // technically this could also be the "Anything" arg of the event .load()
  349. // which just goes to show why this dumb signature has been deprecated!
  350. // jQuery custom builds that exclude the Ajax module justifiably die here.
  351. if ( name === "load" && typeof args[ 0 ] === "string" ) {
  352. return oldLoad.apply( this, args );
  353. }
  354. migrateWarn( "jQuery.fn." + name + "() is deprecated" );
  355. args.splice( 0, 0, name );
  356. if ( arguments.length ) {
  357. return this.on.apply( this, args );
  358. }
  359. // Use .triggerHandler here because:
  360. // - load and unload events don't need to bubble, only applied to window or image
  361. // - error event should not bubble to window, although it does pre-1.7
  362. // See http://bugs.jquery.com/ticket/11820
  363. this.triggerHandler.apply( this, args );
  364. return this;
  365. };
  366. } );
  367. jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
  368. "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
  369. "change select submit keydown keypress keyup contextmenu" ).split( " " ),
  370. function( i, name ) {
  371. // Handle event binding
  372. jQuery.fn[ name ] = function( data, fn ) {
  373. migrateWarn( "jQuery.fn." + name + "() event shorthand is deprecated" );
  374. return arguments.length > 0 ?
  375. this.on( name, null, data, fn ) :
  376. this.trigger( name );
  377. };
  378. } );
  379. // Trigger "ready" event only once, on document ready
  380. jQuery( function() {
  381. jQuery( window.document ).triggerHandler( "ready" );
  382. } );
  383. jQuery.event.special.ready = {
  384. setup: function() {
  385. if ( this === window.document ) {
  386. migrateWarn( "'ready' event is deprecated" );
  387. }
  388. }
  389. };
  390. jQuery.fn.extend( {
  391. bind: function( types, data, fn ) {
  392. migrateWarn( "jQuery.fn.bind() is deprecated" );
  393. return this.on( types, null, data, fn );
  394. },
  395. unbind: function( types, fn ) {
  396. migrateWarn( "jQuery.fn.unbind() is deprecated" );
  397. return this.off( types, null, fn );
  398. },
  399. delegate: function( selector, types, data, fn ) {
  400. migrateWarn( "jQuery.fn.delegate() is deprecated" );
  401. return this.on( types, selector, data, fn );
  402. },
  403. undelegate: function( selector, types, fn ) {
  404. migrateWarn( "jQuery.fn.undelegate() is deprecated" );
  405. return arguments.length === 1 ?
  406. this.off( selector, "**" ) :
  407. this.off( types, selector || "**", fn );
  408. },
  409. hover: function( fnOver, fnOut ) {
  410. migrateWarn( "jQuery.fn.hover() is deprecated" );
  411. return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
  412. }
  413. } );
  414. var oldOffset = jQuery.fn.offset;
  415. jQuery.fn.offset = function() {
  416. var docElem,
  417. elem = this[ 0 ],
  418. origin = { top: 0, left: 0 };
  419. if ( !elem || !elem.nodeType ) {
  420. migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
  421. return origin;
  422. }
  423. docElem = ( elem.ownerDocument || window.document ).documentElement;
  424. if ( !jQuery.contains( docElem, elem ) ) {
  425. migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
  426. return origin;
  427. }
  428. return oldOffset.apply( this, arguments );
  429. };
  430. var oldParam = jQuery.param;
  431. jQuery.param = function( data, traditional ) {
  432. var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
  433. if ( traditional === undefined && ajaxTraditional ) {
  434. migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
  435. traditional = ajaxTraditional;
  436. }
  437. return oldParam.call( this, data, traditional );
  438. };
  439. var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
  440. jQuery.fn.andSelf = function() {
  441. migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
  442. return oldSelf.apply( this, arguments );
  443. };
  444. var oldDeferred = jQuery.Deferred,
  445. tuples = [
  446. // Action, add listener, callbacks, .then handlers, final state
  447. [ "resolve", "done", jQuery.Callbacks( "once memory" ),
  448. jQuery.Callbacks( "once memory" ), "resolved" ],
  449. [ "reject", "fail", jQuery.Callbacks( "once memory" ),
  450. jQuery.Callbacks( "once memory" ), "rejected" ],
  451. [ "notify", "progress", jQuery.Callbacks( "memory" ),
  452. jQuery.Callbacks( "memory" ) ]
  453. ];
  454. jQuery.Deferred = function( func ) {
  455. var deferred = oldDeferred(),
  456. promise = deferred.promise();
  457. deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
  458. var fns = arguments;
  459. migrateWarn( "deferred.pipe() is deprecated" );
  460. return jQuery.Deferred( function( newDefer ) {
  461. jQuery.each( tuples, function( i, tuple ) {
  462. var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
  463. // Deferred.done(function() { bind to newDefer or newDefer.resolve })
  464. // deferred.fail(function() { bind to newDefer or newDefer.reject })
  465. // deferred.progress(function() { bind to newDefer or newDefer.notify })
  466. deferred[ tuple[ 1 ] ]( function() {
  467. var returned = fn && fn.apply( this, arguments );
  468. if ( returned && jQuery.isFunction( returned.promise ) ) {
  469. returned.promise()
  470. .done( newDefer.resolve )
  471. .fail( newDefer.reject )
  472. .progress( newDefer.notify );
  473. } else {
  474. newDefer[ tuple[ 0 ] + "With" ](
  475. this === promise ? newDefer.promise() : this,
  476. fn ? [ returned ] : arguments
  477. );
  478. }
  479. } );
  480. } );
  481. fns = null;
  482. } ).promise();
  483. };
  484. if ( func ) {
  485. func.call( deferred, deferred );
  486. }
  487. return deferred;
  488. };
  489. // Preserve handler of uncaught exceptions in promise chains
  490. jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
  491. return jQuery;
  492. } );