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