Merge "Don't hard-code Preferences page name"
[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 */
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-pre";
30
31 /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
32
33 ( function() {
34
35 // Support: IE9 only
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 &&
39 function() {
40 window.console.log.apply( window.console, arguments );
41 },
42 rbadVersions = /^[12]\./;
43
44 if ( !log ) {
45 return;
46 }
47
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" );
51 }
52 if ( jQuery.migrateWarnings ) {
53 log( "JQMIGRATE: Migrate plugin loaded multiple times" );
54 }
55
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 );
60
61 } )();
62
63 var warnedAbout = {};
64
65 // List of warnings already given; public read only
66 jQuery.migrateWarnings = [];
67
68 // Set to false to disable traces that appear with warnings
69 if ( jQuery.migrateTrace === undefined ) {
70 jQuery.migrateTrace = true;
71 }
72
73 // Forget any warnings we've already given; public
74 jQuery.migrateReset = function() {
75 warnedAbout = {};
76 jQuery.migrateWarnings.length = 0;
77 };
78
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 ) {
87 console.trace();
88 }
89 }
90 }
91 }
92
93 function migrateWarnProp( obj, prop, value, msg ) {
94 Object.defineProperty( obj, prop, {
95 configurable: true,
96 enumerable: true,
97 get: function() {
98 migrateWarn( msg );
99 return value;
100 },
101 set: function( newValue ) {
102 migrateWarn( msg );
103 value = newValue;
104 }
105 } );
106 }
107
108 function migrateWarnFunc( obj, prop, newFunc, msg ) {
109 obj[ prop ] = function() {
110 migrateWarn( msg );
111 return newFunc.apply( this, arguments );
112 };
113 }
114
115 if ( window.document.compatMode === "BackCompat" ) {
116
117 // JQuery has never supported or tested Quirks Mode
118 migrateWarn( "jQuery is not compatible with Quirks Mode" );
119 }
120
121
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;
127
128 jQuery.fn.init = function( arg1 ) {
129 var args = Array.prototype.slice.call( arguments );
130
131 if ( typeof arg1 === "string" && arg1 === "#" ) {
132
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" );
135 args[ 0 ] = [];
136 }
137
138 return oldInit.apply( this, args );
139 };
140 jQuery.fn.init.prototype = jQuery.fn;
141
142 jQuery.find = function( selector ) {
143 var args = Array.prototype.slice.call( arguments );
144
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 ) ) {
148
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
151 try {
152 window.document.querySelector( selector );
153 } catch ( err1 ) {
154
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 + "\"]";
158 } );
159
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
162 try {
163 window.document.querySelector( selector );
164 migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
165 args[ 0 ] = selector;
166 } catch ( err2 ) {
167 migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
168 }
169 }
170 }
171
172 return oldFind.apply( this, args );
173 };
174
175 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
176 var findProp;
177 for ( findProp in oldFind ) {
178 if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
179 jQuery.find[ findProp ] = oldFind[ findProp ];
180 }
181 }
182
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" );
186 return this.length;
187 };
188
189 jQuery.parseJSON = function() {
190 migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
191 return JSON.parse.apply( null, arguments );
192 };
193
194 jQuery.isNumeric = function( val ) {
195
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;
200 }
201
202 var newValue = oldIsNumeric( val ),
203 oldValue = isNumeric2( val );
204
205 if ( newValue !== oldValue ) {
206 migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
207 }
208
209 return oldValue;
210 };
211
212 migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
213 "jQuery.unique is deprecated; use jQuery.uniqueSort" );
214
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" );
220
221
222 var oldAjax = jQuery.ajax;
223
224 jQuery.ajax = function( ) {
225 var jQXHR = oldAjax.apply( this, arguments );
226
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" );
235 }
236
237 return jQXHR;
238 };
239
240
241 var oldRemoveAttr = jQuery.fn.removeAttr,
242 oldToggleClass = jQuery.fn.toggleClass,
243 rmatchNonSpace = /\S+/g;
244
245 jQuery.fn.removeAttr = function( name ) {
246 var self = this;
247
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 );
252 }
253 } );
254
255 return oldRemoveAttr.apply( this, arguments );
256 };
257
258 jQuery.fn.toggleClass = function( state ) {
259
260 // Only deprecating no-args or single boolean arg
261 if ( state !== undefined && typeof state !== "boolean" ) {
262 return oldToggleClass.apply( this, arguments );
263 }
264
265 migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
266
267 // Toggle entire class name of each element
268 return this.each( function() {
269 var className = this.getAttribute && this.getAttribute( "class" ) || "";
270
271 if ( className ) {
272 jQuery.data( this, "__className__", className );
273 }
274
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 ?
282 "" :
283 jQuery.data( this, "__className__" ) || ""
284 );
285 }
286 } );
287 };
288
289
290 var internalSwapCall = false;
291
292 // If this version of jQuery has .swap(), don't false-alarm on internal uses
293 if ( jQuery.swap ) {
294 jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
295 var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
296
297 if ( oldHook ) {
298 jQuery.cssHooks[ name ].get = function() {
299 var ret;
300
301 internalSwapCall = true;
302 ret = oldHook.apply( this, arguments );
303 internalSwapCall = false;
304 return ret;
305 };
306 }
307 } );
308 }
309
310 jQuery.swap = function( elem, options, callback, args ) {
311 var ret, name,
312 old = {};
313
314 if ( !internalSwapCall ) {
315 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
316 }
317
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 ];
322 }
323
324 ret = callback.apply( elem, args || [] );
325
326 // Revert the old values
327 for ( name in options ) {
328 elem.style[ name ] = old[ name ];
329 }
330
331 return ret;
332 };
333
334 var oldData = jQuery.data;
335
336 jQuery.data = function( elem, name, value ) {
337 var curData;
338
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 );
342 var sameKeys = {};
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 ];
347 } else {
348 sameKeys[ key ] = name[ key ];
349 }
350 }
351
352 oldData.call( this, elem, sameKeys );
353
354 return name;
355 }
356
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;
364 }
365 return curData[ name ];
366 }
367 }
368
369 return oldData.apply( this, arguments );
370 };
371
372 var oldTweenRun = jQuery.Tween.prototype.run;
373
374 jQuery.Tween.prototype.run = function( ) {
375 if ( jQuery.easing[ this.easing ].length > 1 ) {
376 migrateWarn(
377 "easing function " +
378 "\"jQuery.easing." + this.easing.toString() +
379 "\" should use only first argument"
380 );
381
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 );
385 }.bind( this );
386 }
387
388 oldTweenRun.apply( this, arguments );
389 };
390
391 jQuery.fx.interval = jQuery.fx.interval || 13;
392
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" );
398 }
399
400 var oldLoad = jQuery.fn.load,
401 oldEventAdd = jQuery.event.add,
402 originalFix = jQuery.event.fix;
403
404 jQuery.event.props = [];
405 jQuery.event.fixHooks = {};
406
407 migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
408 "jQuery.event.props.concat() is deprecated and removed" );
409
410 jQuery.event.fix = function( originalEvent ) {
411 var event,
412 type = originalEvent.type,
413 fixHook = this.fixHooks[ type ],
414 props = jQuery.event.props;
415
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() );
420 }
421 }
422
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() );
429 }
430 }
431 }
432
433 event = originalFix.call( this, originalEvent );
434
435 return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
436 };
437
438 jQuery.event.add = function( elem, types ) {
439
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" );
443 }
444 return oldEventAdd.apply( this, arguments );
445 };
446
447 jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
448
449 jQuery.fn[ name ] = function() {
450 var args = Array.prototype.slice.call( arguments, 0 );
451
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 );
458 }
459
460 migrateWarn( "jQuery.fn." + name + "() is deprecated" );
461
462 args.splice( 0, 0, name );
463 if ( arguments.length ) {
464 return this.on.apply( this, args );
465 }
466
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 );
472 return this;
473 };
474
475 } );
476
477 // Trigger "ready" event only once, on document ready
478 jQuery( function() {
479 jQuery( window.document ).triggerHandler( "ready" );
480 } );
481
482 jQuery.event.special.ready = {
483 setup: function() {
484 if ( this === window.document ) {
485 migrateWarn( "'ready' event is deprecated" );
486 }
487 }
488 };
489
490 jQuery.fn.extend( {
491
492 bind: function( types, data, fn ) {
493 migrateWarn( "jQuery.fn.bind() is deprecated" );
494 return this.on( types, null, data, fn );
495 },
496 unbind: function( types, fn ) {
497 migrateWarn( "jQuery.fn.unbind() is deprecated" );
498 return this.off( types, null, fn );
499 },
500 delegate: function( selector, types, data, fn ) {
501 migrateWarn( "jQuery.fn.delegate() is deprecated" );
502 return this.on( types, selector, data, fn );
503 },
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 );
509 }
510 } );
511
512
513 var oldOffset = jQuery.fn.offset;
514
515 jQuery.fn.offset = function() {
516 var docElem,
517 elem = this[ 0 ],
518 origin = { top: 0, left: 0 };
519
520 if ( !elem || !elem.nodeType ) {
521 migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
522 return origin;
523 }
524
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" );
528 return origin;
529 }
530
531 return oldOffset.apply( this, arguments );
532 };
533
534
535 var oldParam = jQuery.param;
536
537 jQuery.param = function( data, traditional ) {
538 var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
539
540 if ( traditional === undefined && ajaxTraditional ) {
541
542 migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
543 traditional = ajaxTraditional;
544 }
545
546 return oldParam.call( this, data, traditional );
547 };
548
549 var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
550
551 jQuery.fn.andSelf = function() {
552 migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
553 return oldSelf.apply( this, arguments );
554 };
555
556
557 var oldDeferred = jQuery.Deferred,
558 tuples = [
559
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" ) ]
567 ];
568
569 jQuery.Deferred = function( func ) {
570 var deferred = oldDeferred(),
571 promise = deferred.promise();
572
573 deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
574 var fns = arguments;
575
576 migrateWarn( "deferred.pipe() is deprecated" );
577
578 return jQuery.Deferred( function( newDefer ) {
579 jQuery.each( tuples, function( i, tuple ) {
580 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
581
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 ) ) {
588 returned.promise()
589 .done( newDefer.resolve )
590 .fail( newDefer.reject )
591 .progress( newDefer.notify );
592 } else {
593 newDefer[ tuple[ 0 ] + "With" ](
594 this === promise ? newDefer.promise() : this,
595 fn ? [ returned ] : arguments
596 );
597 }
598 } );
599 } );
600 fns = null;
601 } ).promise();
602
603 };
604
605 if ( func ) {
606 func.call( deferred, deferred );
607 }
608
609 return deferred;
610 };
611
612 // Preserve handler of uncaught exceptions in promise chains
613 jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
614
615 return jQuery;
616 } );