2 * jQuery Migrate - v3.0.1-pre - 2017-08-17
3 * Copyright jQuery Foundation and other contributors
5 * Patched for MediaWiki:
6 * - Preserve handler of uncaught exceptions in promise chains
7 * https://gerrit.wikimedia.org/r/#/c/360999/
8 * https://github.com/jquery/jquery-migrate/pull/262
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-pre";
31 /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
36 // IE9 only creates console object when dev tools are first opened
37 // Also, avoid Function#bind here to simplify PhantomJS usage
38 var log
= window
.console
&& window
.console
.log
&&
40 window
.console
.log
.apply( window
.console
, arguments
);
42 rbadVersions
= /^[12]\./;
48 // Need jQuery 3.0.0+ and no older Migrate loaded
49 if ( !jQuery
|| rbadVersions
.test( jQuery
.fn
.jquery
) ) {
50 log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
52 if ( jQuery
.migrateWarnings
) {
53 log( "JQMIGRATE: Migrate plugin loaded multiple times" );
56 // Show a message on the console so devs know we're active
57 log( "JQMIGRATE: Migrate is installed" +
58 ( jQuery
.migrateMute
? "" : " with logging active" ) +
59 ", version " + jQuery
.migrateVersion
);
65 // List of warnings already given; public read only
66 jQuery
.migrateWarnings
= [];
68 // Set to false to disable traces that appear with warnings
69 if ( jQuery
.migrateTrace
=== undefined ) {
70 jQuery
.migrateTrace
= true;
73 // Forget any warnings we've already given; public
74 jQuery
.migrateReset = function() {
76 jQuery
.migrateWarnings
.length
= 0;
79 function migrateWarn( msg
) {
80 var console
= window
.console
;
81 if ( !warnedAbout
[ msg
] ) {
82 warnedAbout
[ msg
] = true;
83 jQuery
.migrateWarnings
.push( msg
);
84 if ( console
&& console
.warn
&& !jQuery
.migrateMute
) {
85 console
.warn( "JQMIGRATE: " + msg
);
86 if ( jQuery
.migrateTrace
&& console
.trace
) {
93 function migrateWarnProp( obj
, prop
, value
, msg
) {
94 Object
.defineProperty( obj
, prop
, {
101 set: function( newValue
) {
108 function migrateWarnFunc( obj
, prop
, newFunc
, msg
) {
109 obj
[ prop
] = function() {
111 return newFunc
.apply( this, arguments
);
115 if ( window
.document
.compatMode
=== "BackCompat" ) {
117 // JQuery has never supported or tested Quirks Mode
118 migrateWarn( "jQuery is not compatible with Quirks Mode" );
122 var oldInit
= jQuery
.fn
.init
,
123 oldIsNumeric
= jQuery
.isNumeric
,
124 oldFind
= jQuery
.find
,
125 rattrHashTest
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
126 rattrHashGlob
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
128 jQuery
.fn
.init = function( arg1
) {
129 var args
= Array
.prototype.slice
.call( arguments
);
131 if ( typeof arg1
=== "string" && arg1
=== "#" ) {
133 // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
134 migrateWarn( "jQuery( '#' ) is not a valid selector" );
138 return oldInit
.apply( this, args
);
140 jQuery
.fn
.init
.prototype = jQuery
.fn
;
142 jQuery
.find = function( selector
) {
143 var args
= Array
.prototype.slice
.call( arguments
);
145 // Support: PhantomJS 1.x
146 // String#match fails to match when used with a //g RegExp, only on some strings
147 if ( typeof selector
=== "string" && rattrHashTest
.test( selector
) ) {
149 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
150 // First see if qS thinks it's a valid selector, if so avoid a false positive
152 window
.document
.querySelector( selector
);
155 // Didn't *look* valid to qSA, warn and try quoting what we think is the value
156 selector
= selector
.replace( rattrHashGlob
, function( _
, attr
, op
, value
) {
157 return "[" + attr
+ op
+ "\"" + value
+ "\"]";
160 // If the regexp *may* have created an invalid selector, don't update it
161 // Note that there may be false alarms if selector uses jQuery extensions
163 window
.document
.querySelector( selector
);
164 migrateWarn( "Attribute selector with '#' must be quoted: " + args
[ 0 ] );
165 args
[ 0 ] = selector
;
167 migrateWarn( "Attribute selector with '#' was not fixed: " + args
[ 0 ] );
172 return oldFind
.apply( this, args
);
175 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
177 for ( findProp
in oldFind
) {
178 if ( Object
.prototype.hasOwnProperty
.call( oldFind
, findProp
) ) {
179 jQuery
.find
[ findProp
] = oldFind
[ findProp
];
183 // The number of elements contained in the matched element set
184 jQuery
.fn
.size = function() {
185 migrateWarn( "jQuery.fn.size() is deprecated and removed; use the .length property" );
189 jQuery
.parseJSON = function() {
190 migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
191 return JSON
.parse
.apply( null, arguments
);
194 jQuery
.isNumeric = function( val
) {
196 // The jQuery 2.2.3 implementation of isNumeric
197 function isNumeric2( obj
) {
198 var realStringObj
= obj
&& obj
.toString();
199 return !jQuery
.isArray( obj
) && ( realStringObj
- parseFloat( realStringObj
) + 1 ) >= 0;
202 var newValue
= oldIsNumeric( val
),
203 oldValue
= isNumeric2( val
);
205 if ( newValue
!== oldValue
) {
206 migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
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
;
374 jQuery
.Tween
.prototype.run = function( ) {
375 if ( jQuery
.easing
[ this.easing
].length
> 1 ) {
378 "\"jQuery.easing." + this.easing
.toString() +
379 "\" should use only first argument"
382 var oldEasing
= jQuery
.easing
[ this.easing
];
383 jQuery
.easing
[ this.easing
] = function( percent
) {
384 return oldEasing
.call( jQuery
.easing
, percent
, percent
, 0, 1, 1 );
388 oldTweenRun
.apply( this, arguments
);
391 jQuery
.fx
.interval
= jQuery
.fx
.interval
|| 13;
393 // Support: IE9, Android <=4.4
394 // Avoid false positives on browsers that lack rAF
395 if ( window
.requestAnimationFrame
) {
396 migrateWarnProp( jQuery
.fx
, "interval", jQuery
.fx
.interval
,
397 "jQuery.fx.interval is deprecated" );
400 var oldLoad
= jQuery
.fn
.load
,
401 oldEventAdd
= jQuery
.event
.add
,
402 originalFix
= jQuery
.event
.fix
;
404 jQuery
.event
.props
= [];
405 jQuery
.event
.fixHooks
= {};
407 migrateWarnProp( jQuery
.event
.props
, "concat", jQuery
.event
.props
.concat
,
408 "jQuery.event.props.concat() is deprecated and removed" );
410 jQuery
.event
.fix = function( originalEvent
) {
412 type
= originalEvent
.type
,
413 fixHook
= this.fixHooks
[ type
],
414 props
= jQuery
.event
.props
;
416 if ( props
.length
) {
417 migrateWarn( "jQuery.event.props are deprecated and removed: " + props
.join() );
418 while ( props
.length
) {
419 jQuery
.event
.addProp( props
.pop() );
423 if ( fixHook
&& !fixHook
._migrated_
) {
424 fixHook
._migrated_
= true;
425 migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type
);
426 if ( ( props
= fixHook
.props
) && props
.length
) {
427 while ( props
.length
) {
428 jQuery
.event
.addProp( props
.pop() );
433 event
= originalFix
.call( this, originalEvent
);
435 return fixHook
&& fixHook
.filter
? fixHook
.filter( event
, originalEvent
) : event
;
438 jQuery
.event
.add = function( elem
, types
) {
440 // This misses the multiple-types case but that seems awfully rare
441 if ( elem
=== window
&& types
=== "load" && window
.document
.readyState
=== "complete" ) {
442 migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
444 return oldEventAdd
.apply( this, arguments
);
447 jQuery
.each( [ "load", "unload", "error" ], function( _
, name
) {
449 jQuery
.fn
[ name
] = function() {
450 var args
= Array
.prototype.slice
.call( arguments
, 0 );
452 // If this is an ajax load() the first arg should be the string URL;
453 // technically this could also be the "Anything" arg of the event .load()
454 // which just goes to show why this dumb signature has been deprecated!
455 // jQuery custom builds that exclude the Ajax module justifiably die here.
456 if ( name
=== "load" && typeof args
[ 0 ] === "string" ) {
457 return oldLoad
.apply( this, args
);
460 migrateWarn( "jQuery.fn." + name
+ "() is deprecated" );
462 args
.splice( 0, 0, name
);
463 if ( arguments
.length
) {
464 return this.on
.apply( this, args
);
467 // Use .triggerHandler here because:
468 // - load and unload events don't need to bubble, only applied to window or image
469 // - error event should not bubble to window, although it does pre-1.7
470 // See http://bugs.jquery.com/ticket/11820
471 this.triggerHandler
.apply( this, args
);
477 // Trigger "ready" event only once, on document ready
479 jQuery( window
.document
).triggerHandler( "ready" );
482 jQuery
.event
.special
.ready
= {
484 if ( this === window
.document
) {
485 migrateWarn( "'ready' event is deprecated" );
492 bind: function( types
, data
, fn
) {
493 migrateWarn( "jQuery.fn.bind() is deprecated" );
494 return this.on( types
, null, data
, fn
);
496 unbind: function( types
, fn
) {
497 migrateWarn( "jQuery.fn.unbind() is deprecated" );
498 return this.off( types
, null, fn
);
500 delegate: function( selector
, types
, data
, fn
) {
501 migrateWarn( "jQuery.fn.delegate() is deprecated" );
502 return this.on( types
, selector
, data
, fn
);
504 undelegate: function( selector
, types
, fn
) {
505 migrateWarn( "jQuery.fn.undelegate() is deprecated" );
506 return arguments
.length
=== 1 ?
507 this.off( selector
, "**" ) :
508 this.off( types
, selector
|| "**", fn
);
513 var oldOffset
= jQuery
.fn
.offset
;
515 jQuery
.fn
.offset = function() {
518 origin
= { top
: 0, left
: 0 };
520 if ( !elem
|| !elem
.nodeType
) {
521 migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
525 docElem
= ( elem
.ownerDocument
|| window
.document
).documentElement
;
526 if ( !jQuery
.contains( docElem
, elem
) ) {
527 migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
531 return oldOffset
.apply( this, arguments
);
535 var oldParam
= jQuery
.param
;
537 jQuery
.param = function( data
, traditional
) {
538 var ajaxTraditional
= jQuery
.ajaxSettings
&& jQuery
.ajaxSettings
.traditional
;
540 if ( traditional
=== undefined && ajaxTraditional
) {
542 migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
543 traditional
= ajaxTraditional
;
546 return oldParam
.call( this, data
, traditional
);
549 var oldSelf
= jQuery
.fn
.andSelf
|| jQuery
.fn
.addBack
;
551 jQuery
.fn
.andSelf = function() {
552 migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
553 return oldSelf
.apply( this, arguments
);
557 var oldDeferred
= jQuery
.Deferred
,
560 // Action, add listener, callbacks, .then handlers, final state
561 [ "resolve", "done", jQuery
.Callbacks( "once memory" ),
562 jQuery
.Callbacks( "once memory" ), "resolved" ],
563 [ "reject", "fail", jQuery
.Callbacks( "once memory" ),
564 jQuery
.Callbacks( "once memory" ), "rejected" ],
565 [ "notify", "progress", jQuery
.Callbacks( "memory" ),
566 jQuery
.Callbacks( "memory" ) ]
569 jQuery
.Deferred = function( func
) {
570 var deferred
= oldDeferred(),
571 promise
= deferred
.promise();
573 deferred
.pipe
= promise
.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
576 migrateWarn( "deferred.pipe() is deprecated" );
578 return jQuery
.Deferred( function( newDefer
) {
579 jQuery
.each( tuples
, function( i
, tuple
) {
580 var fn
= jQuery
.isFunction( fns
[ i
] ) && fns
[ i
];
582 // Deferred.done(function() { bind to newDefer or newDefer.resolve })
583 // deferred.fail(function() { bind to newDefer or newDefer.reject })
584 // deferred.progress(function() { bind to newDefer or newDefer.notify })
585 deferred
[ tuple
[ 1 ] ]( function() {
586 var returned
= fn
&& fn
.apply( this, arguments
);
587 if ( returned
&& jQuery
.isFunction( returned
.promise
) ) {
589 .done( newDefer
.resolve
)
590 .fail( newDefer
.reject
)
591 .progress( newDefer
.notify
);
593 newDefer
[ tuple
[ 0 ] + "With" ](
594 this === promise
? newDefer
.promise() : this,
595 fn
? [ returned
] : arguments
606 func
.call( deferred
, deferred
);
612 // Preserve handler of uncaught exceptions in promise chains
613 jQuery
.Deferred
.exceptionHook
= oldDeferred
.exceptionHook
;