jquery-migrate-3.0.1.js 17 KB

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