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