2 * jQuery Migrate - v3.0.1 - 2017-09-26
3 * Copyright jQuery Foundation and other contributors
5 ;( function( factory
) {
6 if ( typeof define
=== "function" && define
.amd
) {
8 // AMD. Register as an anonymous module.
9 define( [ "jquery" ], window
, factory
);
10 } else if ( typeof module
=== "object" && module
.exports
) {
13 // eslint-disable-next-line no-undef
14 module
.exports
= factory( require( "jquery" ), window
);
18 factory( jQuery
, window
);
20 } )( function( jQuery
, window
) {
24 jQuery
.migrateVersion
= "3.0.1";
26 // Included only in the minified build, via Uglify2
27 // Only turn warnings off if not already overridden
28 if ( typeof jQuery
.migrateMute
=== "undefined" ) {
29 jQuery
.migrateMute
= true;
32 /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
36 var rbadVersions
= /^[12]\./;
39 // IE9 only creates console object when dev tools are first opened
40 // IE9 console is a host object, callable but doesn't have .apply()
41 if ( !window
.console
|| !window
.console
.log
) {
45 // Need jQuery 3.0.0+ and no older Migrate loaded
46 if ( !jQuery
|| rbadVersions
.test( jQuery
.fn
.jquery
) ) {
47 window
.console
.log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
49 if ( jQuery
.migrateWarnings
) {
50 window
.console
.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
53 // Show a message on the console so devs know we're active
54 window
.console
.log( "JQMIGRATE: Migrate is installed" +
55 ( jQuery
.migrateMute
? "" : " with logging active" ) +
56 ", version " + jQuery
.migrateVersion
);
62 // List of warnings already given; public read only
63 jQuery
.migrateWarnings
= [];
65 // Set to false to disable traces that appear with warnings
66 if ( jQuery
.migrateTrace
=== undefined ) {
67 jQuery
.migrateTrace
= true;
70 // Forget any warnings we've already given; public
71 jQuery
.migrateReset = function() {
73 jQuery
.migrateWarnings
.length
= 0;
76 function migrateWarn( msg
) {
77 var console
= window
.console
;
78 if ( !warnedAbout
[ msg
] ) {
79 warnedAbout
[ msg
] = true;
80 jQuery
.migrateWarnings
.push( msg
);
81 if ( console
&& console
.warn
&& !jQuery
.migrateMute
) {
82 console
.warn( "JQMIGRATE: " + msg
);
83 if ( jQuery
.migrateTrace
&& console
.trace
) {
90 function migrateWarnProp( obj
, prop
, value
, msg
) {
91 Object
.defineProperty( obj
, prop
, {
98 set: function( newValue
) {
105 function migrateWarnFunc( obj
, prop
, newFunc
, msg
) {
106 obj
[ prop
] = function() {
108 return newFunc
.apply( this, arguments
);
112 if ( window
.document
.compatMode
=== "BackCompat" ) {
114 // JQuery has never supported or tested Quirks Mode
115 migrateWarn( "jQuery is not compatible with Quirks Mode" );
119 var oldInit
= jQuery
.fn
.init
,
120 oldIsNumeric
= jQuery
.isNumeric
,
121 oldFind
= jQuery
.find
,
122 rattrHashTest
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
123 rattrHashGlob
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
125 jQuery
.fn
.init = function( arg1
) {
126 var args
= Array
.prototype.slice
.call( arguments
);
128 if ( typeof arg1
=== "string" && arg1
=== "#" ) {
130 // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
131 migrateWarn( "jQuery( '#' ) is not a valid selector" );
135 return oldInit
.apply( this, args
);
137 jQuery
.fn
.init
.prototype = jQuery
.fn
;
139 jQuery
.find = function( selector
) {
140 var args
= Array
.prototype.slice
.call( arguments
);
142 // Support: PhantomJS 1.x
143 // String#match fails to match when used with a //g RegExp, only on some strings
144 if ( typeof selector
=== "string" && rattrHashTest
.test( selector
) ) {
146 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
147 // First see if qS thinks it's a valid selector, if so avoid a false positive
149 window
.document
.querySelector( selector
);
152 // Didn't *look* valid to qSA, warn and try quoting what we think is the value
153 selector
= selector
.replace( rattrHashGlob
, function( _
, attr
, op
, value
) {
154 return "[" + attr
+ op
+ "\"" + value
+ "\"]";
157 // If the regexp *may* have created an invalid selector, don't update it
158 // Note that there may be false alarms if selector uses jQuery extensions
160 window
.document
.querySelector( selector
);
161 migrateWarn( "Attribute selector with '#' must be quoted: " + args
[ 0 ] );
162 args
[ 0 ] = selector
;
164 migrateWarn( "Attribute selector with '#' was not fixed: " + args
[ 0 ] );
169 return oldFind
.apply( this, args
);
172 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
174 for ( findProp
in oldFind
) {
175 if ( Object
.prototype.hasOwnProperty
.call( oldFind
, findProp
) ) {
176 jQuery
.find
[ findProp
] = oldFind
[ findProp
];
180 // The number of elements contained in the matched element set
181 jQuery
.fn
.size = function() {
182 migrateWarn( "jQuery.fn.size() is deprecated and removed; use the .length property" );
186 jQuery
.parseJSON = function() {
187 migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
188 return JSON
.parse
.apply( null, arguments
);
191 jQuery
.isNumeric = function( val
) {
193 // The jQuery 2.2.3 implementation of isNumeric
194 function isNumeric2( obj
) {
195 var realStringObj
= obj
&& obj
.toString();
196 return !jQuery
.isArray( obj
) && ( realStringObj
- parseFloat( realStringObj
) + 1 ) >= 0;
199 var newValue
= oldIsNumeric( val
),
200 oldValue
= isNumeric2( val
);
202 if ( newValue
!== oldValue
) {
203 migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
209 migrateWarnFunc( jQuery
, "holdReady", jQuery
.holdReady
,
210 "jQuery.holdReady is deprecated" );
212 migrateWarnFunc( jQuery
, "unique", jQuery
.uniqueSort
,
213 "jQuery.unique is deprecated; use jQuery.uniqueSort" );
215 // Now jQuery.expr.pseudos is the standard incantation
216 migrateWarnProp( jQuery
.expr
, "filters", jQuery
.expr
.pseudos
,
217 "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
218 migrateWarnProp( jQuery
.expr
, ":", jQuery
.expr
.pseudos
,
219 "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
222 var oldAjax
= jQuery
.ajax
;
224 jQuery
.ajax = function( ) {
225 var jQXHR
= oldAjax
.apply( this, arguments
);
227 // Be sure we got a jQXHR (e.g., not sync)
228 if ( jQXHR
.promise
) {
229 migrateWarnFunc( jQXHR
, "success", jQXHR
.done
,
230 "jQXHR.success is deprecated and removed" );
231 migrateWarnFunc( jQXHR
, "error", jQXHR
.fail
,
232 "jQXHR.error is deprecated and removed" );
233 migrateWarnFunc( jQXHR
, "complete", jQXHR
.always
,
234 "jQXHR.complete is deprecated and removed" );
241 var oldRemoveAttr
= jQuery
.fn
.removeAttr
,
242 oldToggleClass
= jQuery
.fn
.toggleClass
,
243 rmatchNonSpace
= /\S+/g;
245 jQuery
.fn
.removeAttr = function( name
) {
248 jQuery
.each( name
.match( rmatchNonSpace
), function( i
, attr
) {
249 if ( jQuery
.expr
.match
.bool
.test( attr
) ) {
250 migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr
);
251 self
.prop( attr
, false );
255 return oldRemoveAttr
.apply( this, arguments
);
258 jQuery
.fn
.toggleClass = function( state
) {
260 // Only deprecating no-args or single boolean arg
261 if ( state
!== undefined && typeof state
!== "boolean" ) {
262 return oldToggleClass
.apply( this, arguments
);
265 migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
267 // Toggle entire class name of each element
268 return this.each( function() {
269 var className
= this.getAttribute
&& this.getAttribute( "class" ) || "";
272 jQuery
.data( this, "__className__", className
);
275 // If the element has a class name or if we're passed `false`,
276 // then remove the whole classname (if there was one, the above saved it).
277 // Otherwise bring back whatever was previously saved (if anything),
278 // falling back to the empty string if nothing was stored.
279 if ( this.setAttribute
) {
280 this.setAttribute( "class",
281 className
|| state
=== false ?
283 jQuery
.data( this, "__className__" ) || ""
290 var internalSwapCall
= false;
292 // If this version of jQuery has .swap(), don't false-alarm on internal uses
294 jQuery
.each( [ "height", "width", "reliableMarginRight" ], function( _
, name
) {
295 var oldHook
= jQuery
.cssHooks
[ name
] && jQuery
.cssHooks
[ name
].get;
298 jQuery
.cssHooks
[ name
].get = function() {
301 internalSwapCall
= true;
302 ret
= oldHook
.apply( this, arguments
);
303 internalSwapCall
= false;
310 jQuery
.swap = function( elem
, options
, callback
, args
) {
314 if ( !internalSwapCall
) {
315 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
318 // Remember the old values, and insert the new ones
319 for ( name
in options
) {
320 old
[ name
] = elem
.style
[ name
];
321 elem
.style
[ name
] = options
[ name
];
324 ret
= callback
.apply( elem
, args
|| [] );
326 // Revert the old values
327 for ( name
in options
) {
328 elem
.style
[ name
] = old
[ name
];
334 var oldData
= jQuery
.data
;
336 jQuery
.data = function( elem
, name
, value
) {
339 // Name can be an object, and each entry in the object is meant to be set as data
340 if ( name
&& typeof name
=== "object" && arguments
.length
=== 2 ) {
341 curData
= jQuery
.hasData( elem
) && oldData
.call( this, elem
);
343 for ( var key
in name
) {
344 if ( key
!== jQuery
.camelCase( key
) ) {
345 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + key
);
346 curData
[ key
] = name
[ key
];
348 sameKeys
[ key
] = name
[ key
];
352 oldData
.call( this, elem
, sameKeys
);
357 // If the name is transformed, look for the un-transformed name in the data object
358 if ( name
&& typeof name
=== "string" && name
!== jQuery
.camelCase( name
) ) {
359 curData
= jQuery
.hasData( elem
) && oldData
.call( this, elem
);
360 if ( curData
&& name
in curData
) {
361 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name
);
362 if ( arguments
.length
> 2 ) {
363 curData
[ name
] = value
;
365 return curData
[ name
];
369 return oldData
.apply( this, arguments
);
372 var oldTweenRun
= jQuery
.Tween
.prototype.run
;
373 var linearEasing = function( pct
) {
377 jQuery
.Tween
.prototype.run = function( ) {
378 if ( jQuery
.easing
[ this.easing
].length
> 1 ) {
380 "'jQuery.easing." + this.easing
.toString() + "' should use only one argument"
383 jQuery
.easing
[ this.easing
] = linearEasing
;
386 oldTweenRun
.apply( this, arguments
);
389 jQuery
.fx
.interval
= jQuery
.fx
.interval
|| 13;
391 // Support: IE9, Android <=4.4
392 // Avoid false positives on browsers that lack rAF
393 if ( window
.requestAnimationFrame
) {
394 migrateWarnProp( jQuery
.fx
, "interval", jQuery
.fx
.interval
,
395 "jQuery.fx.interval is deprecated" );
398 var oldLoad
= jQuery
.fn
.load
,
399 oldEventAdd
= jQuery
.event
.add
,
400 originalFix
= jQuery
.event
.fix
;
402 jQuery
.event
.props
= [];
403 jQuery
.event
.fixHooks
= {};
405 migrateWarnProp( jQuery
.event
.props
, "concat", jQuery
.event
.props
.concat
,
406 "jQuery.event.props.concat() is deprecated and removed" );
408 jQuery
.event
.fix = function( originalEvent
) {
410 type
= originalEvent
.type
,
411 fixHook
= this.fixHooks
[ type
],
412 props
= jQuery
.event
.props
;
414 if ( props
.length
) {
415 migrateWarn( "jQuery.event.props are deprecated and removed: " + props
.join() );
416 while ( props
.length
) {
417 jQuery
.event
.addProp( props
.pop() );
421 if ( fixHook
&& !fixHook
._migrated_
) {
422 fixHook
._migrated_
= true;
423 migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type
);
424 if ( ( props
= fixHook
.props
) && props
.length
) {
425 while ( props
.length
) {
426 jQuery
.event
.addProp( props
.pop() );
431 event
= originalFix
.call( this, originalEvent
);
433 return fixHook
&& fixHook
.filter
? fixHook
.filter( event
, originalEvent
) : event
;
436 jQuery
.event
.add = function( elem
, types
) {
438 // This misses the multiple-types case but that seems awfully rare
439 if ( elem
=== window
&& types
=== "load" && window
.document
.readyState
=== "complete" ) {
440 migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
442 return oldEventAdd
.apply( this, arguments
);
445 jQuery
.each( [ "load", "unload", "error" ], function( _
, name
) {
447 jQuery
.fn
[ name
] = function() {
448 var args
= Array
.prototype.slice
.call( arguments
, 0 );
450 // If this is an ajax load() the first arg should be the string URL;
451 // technically this could also be the "Anything" arg of the event .load()
452 // which just goes to show why this dumb signature has been deprecated!
453 // jQuery custom builds that exclude the Ajax module justifiably die here.
454 if ( name
=== "load" && typeof args
[ 0 ] === "string" ) {
455 return oldLoad
.apply( this, args
);
458 migrateWarn( "jQuery.fn." + name
+ "() is deprecated" );
460 args
.splice( 0, 0, name
);
461 if ( arguments
.length
) {
462 return this.on
.apply( this, args
);
465 // Use .triggerHandler here because:
466 // - load and unload events don't need to bubble, only applied to window or image
467 // - error event should not bubble to window, although it does pre-1.7
468 // See http://bugs.jquery.com/ticket/11820
469 this.triggerHandler
.apply( this, args
);
475 jQuery
.each( ( "blur focus focusin focusout resize scroll click dblclick " +
476 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
477 "change select submit keydown keypress keyup contextmenu" ).split( " " ),
478 function( i
, name
) {
480 // Handle event binding
481 jQuery
.fn
[ name
] = function( data
, fn
) {
482 migrateWarn( "jQuery.fn." + name
+ "() event shorthand is deprecated" );
483 return arguments
.length
> 0 ?
484 this.on( name
, null, data
, fn
) :
485 this.trigger( name
);
489 // Trigger "ready" event only once, on document ready
491 jQuery( window
.document
).triggerHandler( "ready" );
494 jQuery
.event
.special
.ready
= {
496 if ( this === window
.document
) {
497 migrateWarn( "'ready' event is deprecated" );
504 bind: function( types
, data
, fn
) {
505 migrateWarn( "jQuery.fn.bind() is deprecated" );
506 return this.on( types
, null, data
, fn
);
508 unbind: function( types
, fn
) {
509 migrateWarn( "jQuery.fn.unbind() is deprecated" );
510 return this.off( types
, null, fn
);
512 delegate: function( selector
, types
, data
, fn
) {
513 migrateWarn( "jQuery.fn.delegate() is deprecated" );
514 return this.on( types
, selector
, data
, fn
);
516 undelegate: function( selector
, types
, fn
) {
517 migrateWarn( "jQuery.fn.undelegate() is deprecated" );
518 return arguments
.length
=== 1 ?
519 this.off( selector
, "**" ) :
520 this.off( types
, selector
|| "**", fn
);
522 hover: function( fnOver
, fnOut
) {
523 migrateWarn( "jQuery.fn.hover() is deprecated" );
524 return this.on( "mouseenter", fnOver
).on( "mouseleave", fnOut
|| fnOver
);
529 var oldOffset
= jQuery
.fn
.offset
;
531 jQuery
.fn
.offset = function() {
534 origin
= { top
: 0, left
: 0 };
536 if ( !elem
|| !elem
.nodeType
) {
537 migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
541 docElem
= ( elem
.ownerDocument
|| window
.document
).documentElement
;
542 if ( !jQuery
.contains( docElem
, elem
) ) {
543 migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
547 return oldOffset
.apply( this, arguments
);
551 var oldParam
= jQuery
.param
;
553 jQuery
.param = function( data
, traditional
) {
554 var ajaxTraditional
= jQuery
.ajaxSettings
&& jQuery
.ajaxSettings
.traditional
;
556 if ( traditional
=== undefined && ajaxTraditional
) {
558 migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
559 traditional
= ajaxTraditional
;
562 return oldParam
.call( this, data
, traditional
);
565 var oldSelf
= jQuery
.fn
.andSelf
|| jQuery
.fn
.addBack
;
567 jQuery
.fn
.andSelf = function() {
568 migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
569 return oldSelf
.apply( this, arguments
);
573 var oldDeferred
= jQuery
.Deferred
,
576 // Action, add listener, callbacks, .then handlers, final state
577 [ "resolve", "done", jQuery
.Callbacks( "once memory" ),
578 jQuery
.Callbacks( "once memory" ), "resolved" ],
579 [ "reject", "fail", jQuery
.Callbacks( "once memory" ),
580 jQuery
.Callbacks( "once memory" ), "rejected" ],
581 [ "notify", "progress", jQuery
.Callbacks( "memory" ),
582 jQuery
.Callbacks( "memory" ) ]
585 jQuery
.Deferred = function( func
) {
586 var deferred
= oldDeferred(),
587 promise
= deferred
.promise();
589 deferred
.pipe
= promise
.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
592 migrateWarn( "deferred.pipe() is deprecated" );
594 return jQuery
.Deferred( function( newDefer
) {
595 jQuery
.each( tuples
, function( i
, tuple
) {
596 var fn
= jQuery
.isFunction( fns
[ i
] ) && fns
[ i
];
598 // Deferred.done(function() { bind to newDefer or newDefer.resolve })
599 // deferred.fail(function() { bind to newDefer or newDefer.reject })
600 // deferred.progress(function() { bind to newDefer or newDefer.notify })
601 deferred
[ tuple
[ 1 ] ]( function() {
602 var returned
= fn
&& fn
.apply( this, arguments
);
603 if ( returned
&& jQuery
.isFunction( returned
.promise
) ) {
605 .done( newDefer
.resolve
)
606 .fail( newDefer
.reject
)
607 .progress( newDefer
.notify
);
609 newDefer
[ tuple
[ 0 ] + "With" ](
610 this === promise
? newDefer
.promise() : this,
611 fn
? [ returned
] : arguments
622 func
.call( deferred
, deferred
);
628 // Preserve handler of uncaught exceptions in promise chains
629 jQuery
.Deferred
.exceptionHook
= oldDeferred
.exceptionHook
;