2 * jQuery Migrate - v3.1.0 - 2019-06-08
3 * Copyright OpenJS Foundation and other contributors
5 ;( function( factory ) {
6 if ( typeof define === "function" && define.amd ) {
8 // AMD. Register as an anonymous module.
9 define( [ "jquery" ], function ( jQuery ) {
10 return factory( jQuery, window );
12 } else if ( typeof module === "object" && module.exports ) {
15 // eslint-disable-next-line no-undef
16 module.exports = factory( require( "jquery" ), window );
20 factory( jQuery, window );
22 } )( function( jQuery, window ) {
26 jQuery.migrateVersion = "3.1.0";
28 /* exported jQueryVersionSince, compareVersions */
30 // Returns 0 if v1 == v2, -1 if v1 < v2, 1 if v1 > v2
31 function compareVersions( v1, v2 ) {
32 var rVersionParts = /^(\d+)\.(\d+)\.(\d+)/,
33 v1p = rVersionParts.exec( v1 ) || [ ],
34 v2p = rVersionParts.exec( v2 ) || [ ];
36 for ( var i = 1; i <= 3; i++ ) {
37 if ( +v1p[ i ] > +v2p[ i ] ) {
40 if ( +v1p[ i ] < +v2p[ i ] ) {
47 function jQueryVersionSince( version ) {
48 return compareVersions( jQuery.fn.jquery, version ) >= 0;
51 /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
56 // IE9 only creates console object when dev tools are first opened
57 // IE9 console is a host object, callable but doesn't have .apply()
58 if ( !window.console || !window.console.log ) {
62 // Need jQuery 3.0.0+ and no older Migrate loaded
63 if ( !jQuery || !jQueryVersionSince( "3.0.0" ) ) {
64 window.console.log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
66 if ( jQuery.migrateWarnings ) {
67 window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
70 // Show a message on the console so devs know we're active
71 window.console.log( "JQMIGRATE: Migrate is installed" +
72 ( jQuery.migrateMute ? "" : " with logging active" ) +
73 ", version " + jQuery.migrateVersion );
79 // List of warnings already given; public read only
80 jQuery.migrateWarnings = [];
82 // Set to false to disable traces that appear with warnings
83 if ( jQuery.migrateTrace === undefined ) {
84 jQuery.migrateTrace = true;
87 // Forget any warnings we've already given; public
88 jQuery.migrateReset = function() {
90 jQuery.migrateWarnings.length = 0;
93 function migrateWarn( msg ) {
94 var console = window.console;
95 if ( !warnedAbout[ msg ] ) {
96 warnedAbout[ msg ] = true;
97 jQuery.migrateWarnings.push( msg );
98 if ( console && console.warn && !jQuery.migrateMute ) {
99 console.warn( "JQMIGRATE: " + msg );
100 if ( jQuery.migrateTrace && console.trace ) {
107 function migrateWarnProp( obj, prop, value, msg ) {
108 Object.defineProperty( obj, prop, {
115 set: function( newValue ) {
122 function migrateWarnFunc( obj, prop, newFunc, msg ) {
123 obj[ prop ] = function() {
125 return newFunc.apply( this, arguments );
129 if ( window.document.compatMode === "BackCompat" ) {
131 // JQuery has never supported or tested Quirks Mode
132 migrateWarn( "jQuery is not compatible with Quirks Mode" );
136 var oldInit = jQuery.fn.init,
137 oldIsNumeric = jQuery.isNumeric,
138 oldFind = jQuery.find,
139 rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
140 rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
142 jQuery.fn.init = function( arg1 ) {
143 var args = Array.prototype.slice.call( arguments );
145 if ( typeof arg1 === "string" && arg1 === "#" ) {
147 // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
148 migrateWarn( "jQuery( '#' ) is not a valid selector" );
152 return oldInit.apply( this, args );
154 jQuery.fn.init.prototype = jQuery.fn;
156 jQuery.find = function( selector ) {
157 var args = Array.prototype.slice.call( arguments );
159 // Support: PhantomJS 1.x
160 // String#match fails to match when used with a //g RegExp, only on some strings
161 if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
163 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
164 // First see if qS thinks it's a valid selector, if so avoid a false positive
166 window.document.querySelector( selector );
169 // Didn't *look* valid to qSA, warn and try quoting what we think is the value
170 selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
171 return "[" + attr + op + "\"" + value + "\"]";
174 // If the regexp *may* have created an invalid selector, don't update it
175 // Note that there may be false alarms if selector uses jQuery extensions
177 window.document.querySelector( selector );
178 migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
179 args[ 0 ] = selector;
181 migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
186 return oldFind.apply( this, args );
189 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
191 for ( findProp in oldFind ) {
192 if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
193 jQuery.find[ findProp ] = oldFind[ findProp ];
197 // The number of elements contained in the matched element set
198 jQuery.fn.size = function() {
199 migrateWarn( "jQuery.fn.size() is deprecated and removed; use the .length property" );
203 jQuery.parseJSON = function() {
204 migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
205 return JSON.parse.apply( null, arguments );
208 jQuery.isNumeric = function( val ) {
210 // The jQuery 2.2.3 implementation of isNumeric
211 function isNumeric2( obj ) {
212 var realStringObj = obj && obj.toString();
213 return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
216 var newValue = oldIsNumeric( val ),
217 oldValue = isNumeric2( val );
219 if ( newValue !== oldValue ) {
220 migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
226 if ( jQueryVersionSince( "3.3.0" ) ) {
227 migrateWarnFunc( jQuery, "isWindow",
229 return obj != null && obj === obj.window;
231 "jQuery.isWindow() is deprecated"
235 migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
236 "jQuery.holdReady is deprecated" );
238 migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
239 "jQuery.unique is deprecated; use jQuery.uniqueSort" );
241 // Now jQuery.expr.pseudos is the standard incantation
242 migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos,
243 "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
244 migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos,
245 "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
247 // Prior to jQuery 3.2 there were internal refs so we don't warn there
248 if ( jQueryVersionSince( "3.2.0" ) ) {
249 migrateWarnFunc( jQuery, "nodeName", jQuery.nodeName,
250 "jQuery.nodeName is deprecated" );
254 var oldAjax = jQuery.ajax;
256 jQuery.ajax = function( ) {
257 var jQXHR = oldAjax.apply( this, arguments );
259 // Be sure we got a jQXHR (e.g., not sync)
260 if ( jQXHR.promise ) {
261 migrateWarnFunc( jQXHR, "success", jQXHR.done,
262 "jQXHR.success is deprecated and removed" );
263 migrateWarnFunc( jQXHR, "error", jQXHR.fail,
264 "jQXHR.error is deprecated and removed" );
265 migrateWarnFunc( jQXHR, "complete", jQXHR.always,
266 "jQXHR.complete is deprecated and removed" );
273 var oldRemoveAttr = jQuery.fn.removeAttr,
274 oldToggleClass = jQuery.fn.toggleClass,
275 rmatchNonSpace = /\S+/g;
277 jQuery.fn.removeAttr = function( name ) {
280 jQuery.each( name.match( rmatchNonSpace ), function( _i, attr ) {
281 if ( jQuery.expr.match.bool.test( attr ) ) {
282 migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
283 self.prop( attr, false );
287 return oldRemoveAttr.apply( this, arguments );
290 jQuery.fn.toggleClass = function( state ) {
292 // Only deprecating no-args or single boolean arg
293 if ( state !== undefined && typeof state !== "boolean" ) {
294 return oldToggleClass.apply( this, arguments );
297 migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
299 // Toggle entire class name of each element
300 return this.each( function() {
301 var className = this.getAttribute && this.getAttribute( "class" ) || "";
304 jQuery.data( this, "__className__", className );
307 // If the element has a class name or if we're passed `false`,
308 // then remove the whole classname (if there was one, the above saved it).
309 // Otherwise bring back whatever was previously saved (if anything),
310 // falling back to the empty string if nothing was stored.
311 if ( this.setAttribute ) {
312 this.setAttribute( "class",
313 className || state === false ?
315 jQuery.data( this, "__className__" ) || ""
322 var internalSwapCall = false;
324 // If this version of jQuery has .swap(), don't false-alarm on internal uses
326 jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
327 var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
330 jQuery.cssHooks[ name ].get = function() {
333 internalSwapCall = true;
334 ret = oldHook.apply( this, arguments );
335 internalSwapCall = false;
342 jQuery.swap = function( elem, options, callback, args ) {
346 if ( !internalSwapCall ) {
347 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
350 // Remember the old values, and insert the new ones
351 for ( name in options ) {
352 old[ name ] = elem.style[ name ];
353 elem.style[ name ] = options[ name ];
356 ret = callback.apply( elem, args || [] );
358 // Revert the old values
359 for ( name in options ) {
360 elem.style[ name ] = old[ name ];
366 var oldData = jQuery.data;
368 jQuery.data = function( elem, name, value ) {
371 // Name can be an object, and each entry in the object is meant to be set as data
372 if ( name && typeof name === "object" && arguments.length === 2 ) {
373 curData = jQuery.hasData( elem ) && oldData.call( this, elem );
375 for ( var key in name ) {
376 if ( key !== jQuery.camelCase( key ) ) {
377 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + key );
378 curData[ key ] = name[ key ];
380 sameKeys[ key ] = name[ key ];
384 oldData.call( this, elem, sameKeys );
389 // If the name is transformed, look for the un-transformed name in the data object
390 if ( name && typeof name === "string" && name !== jQuery.camelCase( name ) ) {
391 curData = jQuery.hasData( elem ) && oldData.call( this, elem );
392 if ( curData && name in curData ) {
393 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name );
394 if ( arguments.length > 2 ) {
395 curData[ name ] = value;
397 return curData[ name ];
401 return oldData.apply( this, arguments );
404 var oldTweenRun = jQuery.Tween.prototype.run;
405 var linearEasing = function( pct ) {
409 jQuery.Tween.prototype.run = function( ) {
410 if ( jQuery.easing[ this.easing ].length > 1 ) {
412 "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
415 jQuery.easing[ this.easing ] = linearEasing;
418 oldTweenRun.apply( this, arguments );
421 var intervalValue = jQuery.fx.interval || 13,
422 intervalMsg = "jQuery.fx.interval is deprecated";
424 // Support: IE9, Android <=4.4
425 // Avoid false positives on browsers that lack rAF
426 // Don't warn if document is hidden, jQuery uses setTimeout (#292)
427 if ( window.requestAnimationFrame ) {
428 Object.defineProperty( jQuery.fx, "interval", {
432 if ( !window.document.hidden ) {
433 migrateWarn( intervalMsg );
435 return intervalValue;
437 set: function( newValue ) {
438 migrateWarn( intervalMsg );
439 intervalValue = newValue;
444 var oldLoad = jQuery.fn.load,
445 oldEventAdd = jQuery.event.add,
446 originalFix = jQuery.event.fix;
448 jQuery.event.props = [];
449 jQuery.event.fixHooks = {};
451 migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
452 "jQuery.event.props.concat() is deprecated and removed" );
454 jQuery.event.fix = function( originalEvent ) {
456 type = originalEvent.type,
457 fixHook = this.fixHooks[ type ],
458 props = jQuery.event.props;
460 if ( props.length ) {
461 migrateWarn( "jQuery.event.props are deprecated and removed: " + props.join() );
462 while ( props.length ) {
463 jQuery.event.addProp( props.pop() );
467 if ( fixHook && !fixHook._migrated_ ) {
468 fixHook._migrated_ = true;
469 migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type );
470 if ( ( props = fixHook.props ) && props.length ) {
471 while ( props.length ) {
472 jQuery.event.addProp( props.pop() );
477 event = originalFix.call( this, originalEvent );
479 return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
482 jQuery.event.add = function( elem, types ) {
484 // This misses the multiple-types case but that seems awfully rare
485 if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
486 migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
488 return oldEventAdd.apply( this, arguments );
491 jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
493 jQuery.fn[ name ] = function() {
494 var args = Array.prototype.slice.call( arguments, 0 );
496 // If this is an ajax load() the first arg should be the string URL;
497 // technically this could also be the "Anything" arg of the event .load()
498 // which just goes to show why this dumb signature has been deprecated!
499 // jQuery custom builds that exclude the Ajax module justifiably die here.
500 if ( name === "load" && typeof args[ 0 ] === "string" ) {
501 return oldLoad.apply( this, args );
504 migrateWarn( "jQuery.fn." + name + "() is deprecated" );
506 args.splice( 0, 0, name );
507 if ( arguments.length ) {
508 return this.on.apply( this, args );
511 // Use .triggerHandler here because:
512 // - load and unload events don't need to bubble, only applied to window or image
513 // - error event should not bubble to window, although it does pre-1.7
514 // See http://bugs.jquery.com/ticket/11820
515 this.triggerHandler.apply( this, args );
521 jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
522 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
523 "change select submit keydown keypress keyup contextmenu" ).split( " " ),
524 function( _i, name ) {
526 // Handle event binding
527 jQuery.fn[ name ] = function( data, fn ) {
528 migrateWarn( "jQuery.fn." + name + "() event shorthand is deprecated" );
529 return arguments.length > 0 ?
530 this.on( name, null, data, fn ) :
531 this.trigger( name );
535 // Trigger "ready" event only once, on document ready
537 jQuery( window.document ).triggerHandler( "ready" );
540 jQuery.event.special.ready = {
542 if ( this === window.document ) {
543 migrateWarn( "'ready' event is deprecated" );
550 bind: function( types, data, fn ) {
551 migrateWarn( "jQuery.fn.bind() is deprecated" );
552 return this.on( types, null, data, fn );
554 unbind: function( types, fn ) {
555 migrateWarn( "jQuery.fn.unbind() is deprecated" );
556 return this.off( types, null, fn );
558 delegate: function( selector, types, data, fn ) {
559 migrateWarn( "jQuery.fn.delegate() is deprecated" );
560 return this.on( types, selector, data, fn );
562 undelegate: function( selector, types, fn ) {
563 migrateWarn( "jQuery.fn.undelegate() is deprecated" );
564 return arguments.length === 1 ?
565 this.off( selector, "**" ) :
566 this.off( types, selector || "**", fn );
568 hover: function( fnOver, fnOut ) {
569 migrateWarn( "jQuery.fn.hover() is deprecated" );
570 return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
575 var oldOffset = jQuery.fn.offset;
577 jQuery.fn.offset = function() {
580 origin = { top: 0, left: 0 };
582 if ( !elem || !elem.nodeType ) {
583 migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
587 docElem = ( elem.ownerDocument || window.document ).documentElement;
588 if ( !jQuery.contains( docElem, elem ) ) {
589 migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
593 return oldOffset.apply( this, arguments );
597 var oldParam = jQuery.param;
599 jQuery.param = function( data, traditional ) {
600 var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
602 if ( traditional === undefined && ajaxTraditional ) {
604 migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
605 traditional = ajaxTraditional;
608 return oldParam.call( this, data, traditional );
611 var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
613 jQuery.fn.andSelf = function() {
614 migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
615 return oldSelf.apply( this, arguments );
619 var oldDeferred = jQuery.Deferred,
622 // Action, add listener, callbacks, .then handlers, final state
623 [ "resolve", "done", jQuery.Callbacks( "once memory" ),
624 jQuery.Callbacks( "once memory" ), "resolved" ],
625 [ "reject", "fail", jQuery.Callbacks( "once memory" ),
626 jQuery.Callbacks( "once memory" ), "rejected" ],
627 [ "notify", "progress", jQuery.Callbacks( "memory" ),
628 jQuery.Callbacks( "memory" ) ]
631 jQuery.Deferred = function( func ) {
632 var deferred = oldDeferred(),
633 promise = deferred.promise();
635 deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
638 migrateWarn( "deferred.pipe() is deprecated" );
640 return jQuery.Deferred( function( newDefer ) {
641 jQuery.each( tuples, function( i, tuple ) {
642 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
644 // Deferred.done(function() { bind to newDefer or newDefer.resolve })
645 // deferred.fail(function() { bind to newDefer or newDefer.reject })
646 // deferred.progress(function() { bind to newDefer or newDefer.notify })
647 deferred[ tuple[ 1 ] ]( function() {
648 var returned = fn && fn.apply( this, arguments );
649 if ( returned && jQuery.isFunction( returned.promise ) ) {
651 .done( newDefer.resolve )
652 .fail( newDefer.reject )
653 .progress( newDefer.notify );
655 newDefer[ tuple[ 0 ] + "With" ](
656 this === promise ? newDefer.promise() : this,
657 fn ? [ returned ] : arguments
668 func.call( deferred, deferred );
674 // Preserve handler of uncaught exceptions in promise chains
675 jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;