Merge "Add attributes parameter to ShowSearchHitTitle"
[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 * - Disable jQuery.migrateTrace by default. They are slow and
8 * redundant given console.warn() already provides a trace.
9 */
10 ;( function( factory ) {
11 if ( typeof define === "function" && define.amd ) {
12
13 // AMD. Register as an anonymous module.
14 define( [ "jquery" ], window, factory );
15 } else if ( typeof module === "object" && module.exports ) {
16
17 // Node/CommonJS
18 // eslint-disable-next-line no-undef
19 module.exports = factory( require( "jquery" ), window );
20 } else {
21
22 // Browser globals
23 factory( jQuery, window );
24 }
25 } )( function( jQuery, window ) {
26 "use strict";
27
28
29 jQuery.migrateVersion = "3.0.1";
30
31 /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
32
33 ( function() {
34
35 var rbadVersions = /^[12]\./;
36
37 // Support: IE9 only
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 ) {
41 return;
42 }
43
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" );
47 }
48 if ( jQuery.migrateWarnings ) {
49 window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
50 }
51
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 );
56
57 } )();
58
59 var warnedAbout = {};
60
61 // List of warnings already given; public read only
62 jQuery.migrateWarnings = [];
63
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;
68 }
69
70 // Forget any warnings we've already given; public
71 jQuery.migrateReset = function() {
72 warnedAbout = {};
73 jQuery.migrateWarnings.length = 0;
74 };
75
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" );
84 }
85 if ( console && console.warn && !jQuery.migrateMute ) {
86 console.warn( "JQMIGRATE: " + msg );
87 if ( jQuery.migrateTrace && console.trace ) {
88 console.trace();
89 }
90 }
91 }
92 }
93
94 function migrateWarnProp( obj, prop, value, msg ) {
95 Object.defineProperty( obj, prop, {
96 configurable: true,
97 enumerable: true,
98 get: function() {
99 migrateWarn( msg );
100 return value;
101 },
102 set: function( newValue ) {
103 migrateWarn( msg );
104 value = newValue;
105 }
106 } );
107 }
108
109 function migrateWarnFunc( obj, prop, newFunc, msg ) {
110 obj[ prop ] = function() {
111 migrateWarn( msg );
112 return newFunc.apply( this, arguments );
113 };
114 }
115
116 if ( window.document.compatMode === "BackCompat" ) {
117
118 // JQuery has never supported or tested Quirks Mode
119 migrateWarn( "jQuery is not compatible with Quirks Mode" );
120 }
121
122
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;
128
129 jQuery.fn.init = function( arg1 ) {
130 var args = Array.prototype.slice.call( arguments );
131
132 if ( typeof arg1 === "string" && arg1 === "#" ) {
133
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" );
136 args[ 0 ] = [];
137 }
138
139 return oldInit.apply( this, args );
140 };
141 jQuery.fn.init.prototype = jQuery.fn;
142
143 jQuery.find = function( selector ) {
144 var args = Array.prototype.slice.call( arguments );
145
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 ) ) {
149
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
152 try {
153 window.document.querySelector( selector );
154 } catch ( err1 ) {
155
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 + "\"]";
159 } );
160
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
163 try {
164 window.document.querySelector( selector );
165 migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
166 args[ 0 ] = selector;
167 } catch ( err2 ) {
168 migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
169 }
170 }
171 }
172
173 return oldFind.apply( this, args );
174 };
175
176 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
177 var findProp;
178 for ( findProp in oldFind ) {
179 if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
180 jQuery.find[ findProp ] = oldFind[ findProp ];
181 }
182 }
183
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" );
187 return this.length;
188 };
189
190 jQuery.parseJSON = function() {
191 migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
192 return JSON.parse.apply( null, arguments );
193 };
194
195 jQuery.isNumeric = function( val ) {
196
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;
201 }
202
203 var newValue = oldIsNumeric( val ),
204 oldValue = isNumeric2( val );
205
206 if ( newValue !== oldValue ) {
207 migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
208 }
209
210 return oldValue;
211 };
212
213 migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
214 "jQuery.holdReady is deprecated" );
215
216 migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
217 "jQuery.unique is deprecated; use jQuery.uniqueSort" );
218
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" );
224
225
226 var oldAjax = jQuery.ajax;
227
228 jQuery.ajax = function( ) {
229 var jQXHR = oldAjax.apply( this, arguments );
230
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" );
239 }
240
241 return jQXHR;
242 };
243
244
245 var oldRemoveAttr = jQuery.fn.removeAttr,
246 oldToggleClass = jQuery.fn.toggleClass,
247 rmatchNonSpace = /\S+/g;
248
249 jQuery.fn.removeAttr = function( name ) {
250 var self = this;
251
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 );
256 }
257 } );
258
259 return oldRemoveAttr.apply( this, arguments );
260 };
261
262 jQuery.fn.toggleClass = function( state ) {
263
264 // Only deprecating no-args or single boolean arg
265 if ( state !== undefined && typeof state !== "boolean" ) {
266 return oldToggleClass.apply( this, arguments );
267 }
268
269 migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
270
271 // Toggle entire class name of each element
272 return this.each( function() {
273 var className = this.getAttribute && this.getAttribute( "class" ) || "";
274
275 if ( className ) {
276 jQuery.data( this, "__className__", className );
277 }
278
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 ?
286 "" :
287 jQuery.data( this, "__className__" ) || ""
288 );
289 }
290 } );
291 };
292
293
294 var internalSwapCall = false;
295
296 // If this version of jQuery has .swap(), don't false-alarm on internal uses
297 if ( jQuery.swap ) {
298 jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
299 var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
300
301 if ( oldHook ) {
302 jQuery.cssHooks[ name ].get = function() {
303 var ret;
304
305 internalSwapCall = true;
306 ret = oldHook.apply( this, arguments );
307 internalSwapCall = false;
308 return ret;
309 };
310 }
311 } );
312 }
313
314 jQuery.swap = function( elem, options, callback, args ) {
315 var ret, name,
316 old = {};
317
318 if ( !internalSwapCall ) {
319 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
320 }
321
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 ];
326 }
327
328 ret = callback.apply( elem, args || [] );
329
330 // Revert the old values
331 for ( name in options ) {
332 elem.style[ name ] = old[ name ];
333 }
334
335 return ret;
336 };
337
338 var oldData = jQuery.data;
339
340 jQuery.data = function( elem, name, value ) {
341 var curData;
342
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 );
346 var sameKeys = {};
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 ];
351 } else {
352 sameKeys[ key ] = name[ key ];
353 }
354 }
355
356 oldData.call( this, elem, sameKeys );
357
358 return name;
359 }
360
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;
368 }
369 return curData[ name ];
370 }
371 }
372
373 return oldData.apply( this, arguments );
374 };
375
376 var oldTweenRun = jQuery.Tween.prototype.run;
377 var linearEasing = function( pct ) {
378 return pct;
379 };
380
381 jQuery.Tween.prototype.run = function( ) {
382 if ( jQuery.easing[ this.easing ].length > 1 ) {
383 migrateWarn(
384 "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
385 );
386
387 jQuery.easing[ this.easing ] = linearEasing;
388 }
389
390 oldTweenRun.apply( this, arguments );
391 };
392
393 jQuery.fx.interval = jQuery.fx.interval || 13;
394
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" );
400 }
401
402 var oldLoad = jQuery.fn.load,
403 oldEventAdd = jQuery.event.add,
404 originalFix = jQuery.event.fix;
405
406 jQuery.event.props = [];
407 jQuery.event.fixHooks = {};
408
409 migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
410 "jQuery.event.props.concat() is deprecated and removed" );
411
412 jQuery.event.fix = function( originalEvent ) {
413 var event,
414 type = originalEvent.type,
415 fixHook = this.fixHooks[ type ],
416 props = jQuery.event.props;
417
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() );
422 }
423 }
424
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() );
431 }
432 }
433 }
434
435 event = originalFix.call( this, originalEvent );
436
437 return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
438 };
439
440 jQuery.event.add = function( elem, types ) {
441
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" );
445 }
446 return oldEventAdd.apply( this, arguments );
447 };
448
449 jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
450
451 jQuery.fn[ name ] = function() {
452 var args = Array.prototype.slice.call( arguments, 0 );
453
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 );
460 }
461
462 migrateWarn( "jQuery.fn." + name + "() is deprecated" );
463
464 args.splice( 0, 0, name );
465 if ( arguments.length ) {
466 return this.on.apply( this, args );
467 }
468
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 );
474 return this;
475 };
476
477 } );
478
479 // Trigger "ready" event only once, on document ready
480 jQuery( function() {
481 jQuery( window.document ).triggerHandler( "ready" );
482 } );
483
484 jQuery.event.special.ready = {
485 setup: function() {
486 if ( this === window.document ) {
487 migrateWarn( "'ready' event is deprecated" );
488 }
489 }
490 };
491
492 jQuery.fn.extend( {
493
494 bind: function( types, data, fn ) {
495 migrateWarn( "jQuery.fn.bind() is deprecated" );
496 return this.on( types, null, data, fn );
497 },
498 unbind: function( types, fn ) {
499 migrateWarn( "jQuery.fn.unbind() is deprecated" );
500 return this.off( types, null, fn );
501 },
502 delegate: function( selector, types, data, fn ) {
503 migrateWarn( "jQuery.fn.delegate() is deprecated" );
504 return this.on( types, selector, data, fn );
505 },
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 );
511 },
512 hover: function( fnOver, fnOut ) {
513 migrateWarn( "jQuery.fn.hover() is deprecated" );
514 return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
515 }
516 } );
517
518
519 var oldOffset = jQuery.fn.offset;
520
521 jQuery.fn.offset = function() {
522 var docElem,
523 elem = this[ 0 ],
524 origin = { top: 0, left: 0 };
525
526 if ( !elem || !elem.nodeType ) {
527 migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
528 return origin;
529 }
530
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" );
534 return origin;
535 }
536
537 return oldOffset.apply( this, arguments );
538 };
539
540
541 var oldParam = jQuery.param;
542
543 jQuery.param = function( data, traditional ) {
544 var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
545
546 if ( traditional === undefined && ajaxTraditional ) {
547
548 migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
549 traditional = ajaxTraditional;
550 }
551
552 return oldParam.call( this, data, traditional );
553 };
554
555 var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
556
557 jQuery.fn.andSelf = function() {
558 migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
559 return oldSelf.apply( this, arguments );
560 };
561
562
563 var oldDeferred = jQuery.Deferred,
564 tuples = [
565
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" ) ]
573 ];
574
575 jQuery.Deferred = function( func ) {
576 var deferred = oldDeferred(),
577 promise = deferred.promise();
578
579 deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
580 var fns = arguments;
581
582 migrateWarn( "deferred.pipe() is deprecated" );
583
584 return jQuery.Deferred( function( newDefer ) {
585 jQuery.each( tuples, function( i, tuple ) {
586 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
587
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 ) ) {
594 returned.promise()
595 .done( newDefer.resolve )
596 .fail( newDefer.reject )
597 .progress( newDefer.notify );
598 } else {
599 newDefer[ tuple[ 0 ] + "With" ](
600 this === promise ? newDefer.promise() : this,
601 fn ? [ returned ] : arguments
602 );
603 }
604 } );
605 } );
606 fns = null;
607 } ).promise();
608
609 };
610
611 if ( func ) {
612 func.call( deferred, deferred );
613 }
614
615 return deferred;
616 };
617
618 // Preserve handler of uncaught exceptions in promise chains
619 jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
620
621 return jQuery;
622 } );