2 * jQuery Migrate - v3.0.1 - 2017-09-26
3 * Copyright jQuery Foundation and other contributors
5 * Patched for MediaWiki:
6 * - Add mw.track instrumentation for statistics.
7 * - Disable jQuery.migrateTrace by default. They are slow and
8 * redundant given console.warn() already provides a trace.
10 ;( function( factory
) {
11 if ( typeof define
=== "function" && define
.amd
) {
13 // AMD. Register as an anonymous module.
14 define( [ "jquery" ], window
, factory
);
15 } else if ( typeof module
=== "object" && module
.exports
) {
18 // eslint-disable-next-line no-undef
19 module
.exports
= factory( require( "jquery" ), window
);
23 factory( jQuery
, window
);
25 } )( function( jQuery
, window
) {
29 jQuery
.migrateVersion
= "3.0.1";
31 /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
35 var rbadVersions
= /^[12]\./;
38 // IE9 only creates console object when dev tools are first opened
39 // IE9 console is a host object, callable but doesn't have .apply()
40 if ( !window
.console
|| !window
.console
.log
) {
44 // Need jQuery 3.0.0+ and no older Migrate loaded
45 if ( !jQuery
|| rbadVersions
.test( jQuery
.fn
.jquery
) ) {
46 window
.console
.log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
48 if ( jQuery
.migrateWarnings
) {
49 window
.console
.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
52 // Show a message on the console so devs know we're active
53 window
.console
.log( "JQMIGRATE: Migrate is installed" +
54 ( jQuery
.migrateMute
? "" : " with logging active" ) +
55 ", version " + jQuery
.migrateVersion
);
61 // List of warnings already given; public read only
62 jQuery
.migrateWarnings
= [];
64 // Set to false to disable traces that appear with warnings
65 if ( jQuery
.migrateTrace
=== undefined ) {
66 // PATCH: Disable extra console.trace() call --Krinkle
67 jQuery
.migrateTrace
= false;
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 // PATCH: Add instrumentation for statistics --Krinkle
82 if ( window
.mw
&& window
.mw
.track
) {
83 window
.mw
.track( "mw.deprecate", "jquery-migrate" );
85 if ( console
&& console
.warn
&& !jQuery
.migrateMute
) {
86 console
.warn( "JQMIGRATE: " + msg
);
87 if ( jQuery
.migrateTrace
&& console
.trace
) {
94 function migrateWarnProp( obj
, prop
, value
, msg
) {
95 Object
.defineProperty( obj
, prop
, {
102 set: function( newValue
) {
109 function migrateWarnFunc( obj
, prop
, newFunc
, msg
) {
110 obj
[ prop
] = function() {
112 return newFunc
.apply( this, arguments
);
116 if ( window
.document
.compatMode
=== "BackCompat" ) {
118 // JQuery has never supported or tested Quirks Mode
119 migrateWarn( "jQuery is not compatible with Quirks Mode" );
123 var oldInit
= jQuery
.fn
.init
,
124 oldIsNumeric
= jQuery
.isNumeric
,
125 oldFind
= jQuery
.find
,
126 rattrHashTest
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
127 rattrHashGlob
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
129 jQuery
.fn
.init = function( arg1
) {
130 var args
= Array
.prototype.slice
.call( arguments
);
132 if ( typeof arg1
=== "string" && arg1
=== "#" ) {
134 // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
135 migrateWarn( "jQuery( '#' ) is not a valid selector" );
139 return oldInit
.apply( this, args
);
141 jQuery
.fn
.init
.prototype = jQuery
.fn
;
143 jQuery
.find = function( selector
) {
144 var args
= Array
.prototype.slice
.call( arguments
);
146 // Support: PhantomJS 1.x
147 // String#match fails to match when used with a //g RegExp, only on some strings
148 if ( typeof selector
=== "string" && rattrHashTest
.test( selector
) ) {
150 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
151 // First see if qS thinks it's a valid selector, if so avoid a false positive
153 window
.document
.querySelector( selector
);
156 // Didn't *look* valid to qSA, warn and try quoting what we think is the value
157 selector
= selector
.replace( rattrHashGlob
, function( _
, attr
, op
, value
) {
158 return "[" + attr
+ op
+ "\"" + value
+ "\"]";
161 // If the regexp *may* have created an invalid selector, don't update it
162 // Note that there may be false alarms if selector uses jQuery extensions
164 window
.document
.querySelector( selector
);
165 migrateWarn( "Attribute selector with '#' must be quoted: " + args
[ 0 ] );
166 args
[ 0 ] = selector
;
168 migrateWarn( "Attribute selector with '#' was not fixed: " + args
[ 0 ] );
173 return oldFind
.apply( this, args
);
176 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
178 for ( findProp
in oldFind
) {
179 if ( Object
.prototype.hasOwnProperty
.call( oldFind
, findProp
) ) {
180 jQuery
.find
[ findProp
] = oldFind
[ findProp
];
184 // The number of elements contained in the matched element set
185 jQuery
.fn
.size = function() {
186 migrateWarn( "jQuery.fn.size() is deprecated and removed; use the .length property" );
190 jQuery
.parseJSON = function() {
191 migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
192 return JSON
.parse
.apply( null, arguments
);
195 jQuery
.isNumeric = function( val
) {
197 // The jQuery 2.2.3 implementation of isNumeric
198 function isNumeric2( obj
) {
199 var realStringObj
= obj
&& obj
.toString();
200 return !jQuery
.isArray( obj
) && ( realStringObj
- parseFloat( realStringObj
) + 1 ) >= 0;
203 var newValue
= oldIsNumeric( val
),
204 oldValue
= isNumeric2( val
);
206 if ( newValue
!== oldValue
) {
207 migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
213 migrateWarnFunc( jQuery
, "holdReady", jQuery
.holdReady
,
214 "jQuery.holdReady is deprecated" );
216 migrateWarnFunc( jQuery
, "unique", jQuery
.uniqueSort
,
217 "jQuery.unique is deprecated; use jQuery.uniqueSort" );
219 // Now jQuery.expr.pseudos is the standard incantation
220 migrateWarnProp( jQuery
.expr
, "filters", jQuery
.expr
.pseudos
,
221 "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
222 migrateWarnProp( jQuery
.expr
, ":", jQuery
.expr
.pseudos
,
223 "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
226 var oldAjax
= jQuery
.ajax
;
228 jQuery
.ajax = function( ) {
229 var jQXHR
= oldAjax
.apply( this, arguments
);
231 // Be sure we got a jQXHR (e.g., not sync)
232 if ( jQXHR
.promise
) {
233 migrateWarnFunc( jQXHR
, "success", jQXHR
.done
,
234 "jQXHR.success is deprecated and removed" );
235 migrateWarnFunc( jQXHR
, "error", jQXHR
.fail
,
236 "jQXHR.error is deprecated and removed" );
237 migrateWarnFunc( jQXHR
, "complete", jQXHR
.always
,
238 "jQXHR.complete is deprecated and removed" );
245 var oldRemoveAttr
= jQuery
.fn
.removeAttr
,
246 oldToggleClass
= jQuery
.fn
.toggleClass
,
247 rmatchNonSpace
= /\S+/g;
249 jQuery
.fn
.removeAttr = function( name
) {
252 jQuery
.each( name
.match( rmatchNonSpace
), function( i
, attr
) {
253 if ( jQuery
.expr
.match
.bool
.test( attr
) ) {
254 migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr
);
255 self
.prop( attr
, false );
259 return oldRemoveAttr
.apply( this, arguments
);
262 jQuery
.fn
.toggleClass = function( state
) {
264 // Only deprecating no-args or single boolean arg
265 if ( state
!== undefined && typeof state
!== "boolean" ) {
266 return oldToggleClass
.apply( this, arguments
);
269 migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
271 // Toggle entire class name of each element
272 return this.each( function() {
273 var className
= this.getAttribute
&& this.getAttribute( "class" ) || "";
276 jQuery
.data( this, "__className__", className
);
279 // If the element has a class name or if we're passed `false`,
280 // then remove the whole classname (if there was one, the above saved it).
281 // Otherwise bring back whatever was previously saved (if anything),
282 // falling back to the empty string if nothing was stored.
283 if ( this.setAttribute
) {
284 this.setAttribute( "class",
285 className
|| state
=== false ?
287 jQuery
.data( this, "__className__" ) || ""
294 var internalSwapCall
= false;
296 // If this version of jQuery has .swap(), don't false-alarm on internal uses
298 jQuery
.each( [ "height", "width", "reliableMarginRight" ], function( _
, name
) {
299 var oldHook
= jQuery
.cssHooks
[ name
] && jQuery
.cssHooks
[ name
].get;
302 jQuery
.cssHooks
[ name
].get = function() {
305 internalSwapCall
= true;
306 ret
= oldHook
.apply( this, arguments
);
307 internalSwapCall
= false;
314 jQuery
.swap = function( elem
, options
, callback
, args
) {
318 if ( !internalSwapCall
) {
319 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
322 // Remember the old values, and insert the new ones
323 for ( name
in options
) {
324 old
[ name
] = elem
.style
[ name
];
325 elem
.style
[ name
] = options
[ name
];
328 ret
= callback
.apply( elem
, args
|| [] );
330 // Revert the old values
331 for ( name
in options
) {
332 elem
.style
[ name
] = old
[ name
];
338 var oldData
= jQuery
.data
;
340 jQuery
.data = function( elem
, name
, value
) {
343 // Name can be an object, and each entry in the object is meant to be set as data
344 if ( name
&& typeof name
=== "object" && arguments
.length
=== 2 ) {
345 curData
= jQuery
.hasData( elem
) && oldData
.call( this, elem
);
347 for ( var key
in name
) {
348 if ( key
!== jQuery
.camelCase( key
) ) {
349 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + key
);
350 curData
[ key
] = name
[ key
];
352 sameKeys
[ key
] = name
[ key
];
356 oldData
.call( this, elem
, sameKeys
);
361 // If the name is transformed, look for the un-transformed name in the data object
362 if ( name
&& typeof name
=== "string" && name
!== jQuery
.camelCase( name
) ) {
363 curData
= jQuery
.hasData( elem
) && oldData
.call( this, elem
);
364 if ( curData
&& name
in curData
) {
365 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name
);
366 if ( arguments
.length
> 2 ) {
367 curData
[ name
] = value
;
369 return curData
[ name
];
373 return oldData
.apply( this, arguments
);
376 var oldTweenRun
= jQuery
.Tween
.prototype.run
;
377 var linearEasing = function( pct
) {
381 jQuery
.Tween
.prototype.run = function( ) {
382 if ( jQuery
.easing
[ this.easing
].length
> 1 ) {
384 "'jQuery.easing." + this.easing
.toString() + "' should use only one argument"
387 jQuery
.easing
[ this.easing
] = linearEasing
;
390 oldTweenRun
.apply( this, arguments
);
393 jQuery
.fx
.interval
= jQuery
.fx
.interval
|| 13;
395 // Support: IE9, Android <=4.4
396 // Avoid false positives on browsers that lack rAF
397 if ( window
.requestAnimationFrame
) {
398 migrateWarnProp( jQuery
.fx
, "interval", jQuery
.fx
.interval
,
399 "jQuery.fx.interval is deprecated" );
402 var oldLoad
= jQuery
.fn
.load
,
403 oldEventAdd
= jQuery
.event
.add
,
404 originalFix
= jQuery
.event
.fix
;
406 jQuery
.event
.props
= [];
407 jQuery
.event
.fixHooks
= {};
409 migrateWarnProp( jQuery
.event
.props
, "concat", jQuery
.event
.props
.concat
,
410 "jQuery.event.props.concat() is deprecated and removed" );
412 jQuery
.event
.fix = function( originalEvent
) {
414 type
= originalEvent
.type
,
415 fixHook
= this.fixHooks
[ type
],
416 props
= jQuery
.event
.props
;
418 if ( props
.length
) {
419 migrateWarn( "jQuery.event.props are deprecated and removed: " + props
.join() );
420 while ( props
.length
) {
421 jQuery
.event
.addProp( props
.pop() );
425 if ( fixHook
&& !fixHook
._migrated_
) {
426 fixHook
._migrated_
= true;
427 migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type
);
428 if ( ( props
= fixHook
.props
) && props
.length
) {
429 while ( props
.length
) {
430 jQuery
.event
.addProp( props
.pop() );
435 event
= originalFix
.call( this, originalEvent
);
437 return fixHook
&& fixHook
.filter
? fixHook
.filter( event
, originalEvent
) : event
;
440 jQuery
.event
.add = function( elem
, types
) {
442 // This misses the multiple-types case but that seems awfully rare
443 if ( elem
=== window
&& types
=== "load" && window
.document
.readyState
=== "complete" ) {
444 migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
446 return oldEventAdd
.apply( this, arguments
);
449 jQuery
.each( [ "load", "unload", "error" ], function( _
, name
) {
451 jQuery
.fn
[ name
] = function() {
452 var args
= Array
.prototype.slice
.call( arguments
, 0 );
454 // If this is an ajax load() the first arg should be the string URL;
455 // technically this could also be the "Anything" arg of the event .load()
456 // which just goes to show why this dumb signature has been deprecated!
457 // jQuery custom builds that exclude the Ajax module justifiably die here.
458 if ( name
=== "load" && typeof args
[ 0 ] === "string" ) {
459 return oldLoad
.apply( this, args
);
462 migrateWarn( "jQuery.fn." + name
+ "() is deprecated" );
464 args
.splice( 0, 0, name
);
465 if ( arguments
.length
) {
466 return this.on
.apply( this, args
);
469 // Use .triggerHandler here because:
470 // - load and unload events don't need to bubble, only applied to window or image
471 // - error event should not bubble to window, although it does pre-1.7
472 // See http://bugs.jquery.com/ticket/11820
473 this.triggerHandler
.apply( this, args
);
479 // Trigger "ready" event only once, on document ready
481 jQuery( window
.document
).triggerHandler( "ready" );
484 jQuery
.event
.special
.ready
= {
486 if ( this === window
.document
) {
487 migrateWarn( "'ready' event is deprecated" );
494 bind: function( types
, data
, fn
) {
495 migrateWarn( "jQuery.fn.bind() is deprecated" );
496 return this.on( types
, null, data
, fn
);
498 unbind: function( types
, fn
) {
499 migrateWarn( "jQuery.fn.unbind() is deprecated" );
500 return this.off( types
, null, fn
);
502 delegate: function( selector
, types
, data
, fn
) {
503 migrateWarn( "jQuery.fn.delegate() is deprecated" );
504 return this.on( types
, selector
, data
, fn
);
506 undelegate: function( selector
, types
, fn
) {
507 migrateWarn( "jQuery.fn.undelegate() is deprecated" );
508 return arguments
.length
=== 1 ?
509 this.off( selector
, "**" ) :
510 this.off( types
, selector
|| "**", fn
);
512 hover: function( fnOver
, fnOut
) {
513 migrateWarn( "jQuery.fn.hover() is deprecated" );
514 return this.on( "mouseenter", fnOver
).on( "mouseleave", fnOut
|| fnOver
);
519 var oldOffset
= jQuery
.fn
.offset
;
521 jQuery
.fn
.offset = function() {
524 origin
= { top
: 0, left
: 0 };
526 if ( !elem
|| !elem
.nodeType
) {
527 migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
531 docElem
= ( elem
.ownerDocument
|| window
.document
).documentElement
;
532 if ( !jQuery
.contains( docElem
, elem
) ) {
533 migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
537 return oldOffset
.apply( this, arguments
);
541 var oldParam
= jQuery
.param
;
543 jQuery
.param = function( data
, traditional
) {
544 var ajaxTraditional
= jQuery
.ajaxSettings
&& jQuery
.ajaxSettings
.traditional
;
546 if ( traditional
=== undefined && ajaxTraditional
) {
548 migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
549 traditional
= ajaxTraditional
;
552 return oldParam
.call( this, data
, traditional
);
555 var oldSelf
= jQuery
.fn
.andSelf
|| jQuery
.fn
.addBack
;
557 jQuery
.fn
.andSelf = function() {
558 migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
559 return oldSelf
.apply( this, arguments
);
563 var oldDeferred
= jQuery
.Deferred
,
566 // Action, add listener, callbacks, .then handlers, final state
567 [ "resolve", "done", jQuery
.Callbacks( "once memory" ),
568 jQuery
.Callbacks( "once memory" ), "resolved" ],
569 [ "reject", "fail", jQuery
.Callbacks( "once memory" ),
570 jQuery
.Callbacks( "once memory" ), "rejected" ],
571 [ "notify", "progress", jQuery
.Callbacks( "memory" ),
572 jQuery
.Callbacks( "memory" ) ]
575 jQuery
.Deferred = function( func
) {
576 var deferred
= oldDeferred(),
577 promise
= deferred
.promise();
579 deferred
.pipe
= promise
.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
582 migrateWarn( "deferred.pipe() is deprecated" );
584 return jQuery
.Deferred( function( newDefer
) {
585 jQuery
.each( tuples
, function( i
, tuple
) {
586 var fn
= jQuery
.isFunction( fns
[ i
] ) && fns
[ i
];
588 // Deferred.done(function() { bind to newDefer or newDefer.resolve })
589 // deferred.fail(function() { bind to newDefer or newDefer.reject })
590 // deferred.progress(function() { bind to newDefer or newDefer.notify })
591 deferred
[ tuple
[ 1 ] ]( function() {
592 var returned
= fn
&& fn
.apply( this, arguments
);
593 if ( returned
&& jQuery
.isFunction( returned
.promise
) ) {
595 .done( newDefer
.resolve
)
596 .fail( newDefer
.reject
)
597 .progress( newDefer
.notify
);
599 newDefer
[ tuple
[ 0 ] + "With" ](
600 this === promise
? newDefer
.promise() : this,
601 fn
? [ returned
] : arguments
612 func
.call( deferred
, deferred
);
618 // Preserve handler of uncaught exceptions in promise chains
619 jQuery
.Deferred
.exceptionHook
= oldDeferred
.exceptionHook
;