Bug 14862: Upgrade jQuery from 1.7 to 3.4.1 in OPAC
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / lib / jquery / jquery-migrate-3.1.0.js
blobb45d58985390fd0b6eeec17d6a504d463514a4a3
1 /*!
2  * jQuery Migrate - v3.1.0 - 2019-06-08
3  * Copyright OpenJS Foundation and other contributors
4  */
5 ;( function( factory ) {
6     if ( typeof define === "function" && define.amd ) {
8         // AMD. Register as an anonymous module.
9         define( [ "jquery" ], function ( jQuery ) {
10             return factory( jQuery, window );
11         } );
12     } else if ( typeof module === "object" && module.exports ) {
14         // Node/CommonJS
15         // eslint-disable-next-line no-undef
16         module.exports = factory( require( "jquery" ), window );
17     } else {
19         // Browser globals
20         factory( jQuery, window );
21     }
22 } )( function( jQuery, window ) {
23 "use strict";
26 jQuery.migrateVersion = "3.1.0";
28 /* exported jQueryVersionSince, compareVersions */
30 // Returns 0 if v1 == v2, -1 if v1 < v2, 1 if v1 > v2
31 function compareVersions( v1, v2 ) {
32     var rVersionParts = /^(\d+)\.(\d+)\.(\d+)/,
33         v1p = rVersionParts.exec( v1 ) || [ ],
34         v2p = rVersionParts.exec( v2 ) || [ ];
36     for ( var i = 1; i <= 3; i++ ) {
37         if ( +v1p[ i ] > +v2p[ i ] ) {
38             return 1;
39         }
40         if ( +v1p[ i ] < +v2p[ i ] ) {
41             return -1;
42         }
43     }
44     return 0;
47 function jQueryVersionSince( version ) {
48     return compareVersions( jQuery.fn.jquery, version ) >= 0;
51 /* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
53 ( function() {
55     // Support: IE9 only
56     // IE9 only creates console object when dev tools are first opened
57     // IE9 console is a host object, callable but doesn't have .apply()
58     if ( !window.console || !window.console.log ) {
59         return;
60     }
62     // Need jQuery 3.0.0+ and no older Migrate loaded
63     if ( !jQuery || !jQueryVersionSince( "3.0.0" ) ) {
64         window.console.log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
65     }
66     if ( jQuery.migrateWarnings ) {
67         window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
68     }
70     // Show a message on the console so devs know we're active
71     window.console.log( "JQMIGRATE: Migrate is installed" +
72         ( jQuery.migrateMute ? "" : " with logging active" ) +
73         ", version " + jQuery.migrateVersion );
75 } )();
77 var warnedAbout = {};
79 // List of warnings already given; public read only
80 jQuery.migrateWarnings = [];
82 // Set to false to disable traces that appear with warnings
83 if ( jQuery.migrateTrace === undefined ) {
84     jQuery.migrateTrace = true;
87 // Forget any warnings we've already given; public
88 jQuery.migrateReset = function() {
89     warnedAbout = {};
90     jQuery.migrateWarnings.length = 0;
93 function migrateWarn( msg ) {
94     var console = window.console;
95     if ( !warnedAbout[ msg ] ) {
96         warnedAbout[ msg ] = true;
97         jQuery.migrateWarnings.push( msg );
98         if ( console && console.warn && !jQuery.migrateMute ) {
99             console.warn( "JQMIGRATE: " + msg );
100             if ( jQuery.migrateTrace && console.trace ) {
101                 console.trace();
102             }
103         }
104     }
107 function migrateWarnProp( obj, prop, value, msg ) {
108     Object.defineProperty( obj, prop, {
109         configurable: true,
110         enumerable: true,
111         get: function() {
112             migrateWarn( msg );
113             return value;
114         },
115         set: function( newValue ) {
116             migrateWarn( msg );
117             value = newValue;
118         }
119     } );
122 function migrateWarnFunc( obj, prop, newFunc, msg ) {
123     obj[ prop ] = function() {
124         migrateWarn( msg );
125         return newFunc.apply( this, arguments );
126     };
129 if ( window.document.compatMode === "BackCompat" ) {
131     // JQuery has never supported or tested Quirks Mode
132     migrateWarn( "jQuery is not compatible with Quirks Mode" );
136 var oldInit = jQuery.fn.init,
137     oldIsNumeric = jQuery.isNumeric,
138     oldFind = jQuery.find,
139     rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
140     rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
142 jQuery.fn.init = function( arg1 ) {
143     var args = Array.prototype.slice.call( arguments );
145     if ( typeof arg1 === "string" && arg1 === "#" ) {
147         // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
148         migrateWarn( "jQuery( '#' ) is not a valid selector" );
149         args[ 0 ] = [];
150     }
152     return oldInit.apply( this, args );
154 jQuery.fn.init.prototype = jQuery.fn;
156 jQuery.find = function( selector ) {
157     var args = Array.prototype.slice.call( arguments );
159     // Support: PhantomJS 1.x
160     // String#match fails to match when used with a //g RegExp, only on some strings
161     if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
163         // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
164         // First see if qS thinks it's a valid selector, if so avoid a false positive
165         try {
166             window.document.querySelector( selector );
167         } catch ( err1 ) {
169             // Didn't *look* valid to qSA, warn and try quoting what we think is the value
170             selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
171                 return "[" + attr + op + "\"" + value + "\"]";
172             } );
174             // If the regexp *may* have created an invalid selector, don't update it
175             // Note that there may be false alarms if selector uses jQuery extensions
176             try {
177                 window.document.querySelector( selector );
178                 migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
179                 args[ 0 ] = selector;
180             } catch ( err2 ) {
181                 migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
182             }
183         }
184     }
186     return oldFind.apply( this, args );
189 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
190 var findProp;
191 for ( findProp in oldFind ) {
192     if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
193         jQuery.find[ findProp ] = oldFind[ findProp ];
194     }
197 // The number of elements contained in the matched element set
198 jQuery.fn.size = function() {
199     migrateWarn( "jQuery.fn.size() is deprecated and removed; use the .length property" );
200     return this.length;
203 jQuery.parseJSON = function() {
204     migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
205     return JSON.parse.apply( null, arguments );
208 jQuery.isNumeric = function( val ) {
210     // The jQuery 2.2.3 implementation of isNumeric
211     function isNumeric2( obj ) {
212         var realStringObj = obj && obj.toString();
213         return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
214     }
216     var newValue = oldIsNumeric( val ),
217         oldValue = isNumeric2( val );
219     if ( newValue !== oldValue ) {
220         migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
221     }
223     return oldValue;
226 if ( jQueryVersionSince( "3.3.0" ) ) {
227     migrateWarnFunc( jQuery, "isWindow",
228         function( obj ) {
229             return obj != null && obj === obj.window;
230         },
231         "jQuery.isWindow() is deprecated"
232     );
235 migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
236     "jQuery.holdReady is deprecated" );
238 migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
239     "jQuery.unique is deprecated; use jQuery.uniqueSort" );
241 // Now jQuery.expr.pseudos is the standard incantation
242 migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos,
243     "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
244 migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos,
245     "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
247 // Prior to jQuery 3.2 there were internal refs so we don't warn there
248 if ( jQueryVersionSince( "3.2.0" ) ) {
249     migrateWarnFunc( jQuery, "nodeName", jQuery.nodeName,
250     "jQuery.nodeName is deprecated" );
254 var oldAjax = jQuery.ajax;
256 jQuery.ajax = function( ) {
257     var jQXHR = oldAjax.apply( this, arguments );
259     // Be sure we got a jQXHR (e.g., not sync)
260     if ( jQXHR.promise ) {
261         migrateWarnFunc( jQXHR, "success", jQXHR.done,
262             "jQXHR.success is deprecated and removed" );
263         migrateWarnFunc( jQXHR, "error", jQXHR.fail,
264             "jQXHR.error is deprecated and removed" );
265         migrateWarnFunc( jQXHR, "complete", jQXHR.always,
266             "jQXHR.complete is deprecated and removed" );
267     }
269     return jQXHR;
273 var oldRemoveAttr = jQuery.fn.removeAttr,
274     oldToggleClass = jQuery.fn.toggleClass,
275     rmatchNonSpace = /\S+/g;
277 jQuery.fn.removeAttr = function( name ) {
278     var self = this;
280     jQuery.each( name.match( rmatchNonSpace ), function( _i, attr ) {
281         if ( jQuery.expr.match.bool.test( attr ) ) {
282             migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
283             self.prop( attr, false );
284         }
285     } );
287     return oldRemoveAttr.apply( this, arguments );
290 jQuery.fn.toggleClass = function( state ) {
292     // Only deprecating no-args or single boolean arg
293     if ( state !== undefined && typeof state !== "boolean" ) {
294         return oldToggleClass.apply( this, arguments );
295     }
297     migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
299     // Toggle entire class name of each element
300     return this.each( function() {
301         var className = this.getAttribute && this.getAttribute( "class" ) || "";
303         if ( className ) {
304             jQuery.data( this, "__className__", className );
305         }
307         // If the element has a class name or if we're passed `false`,
308         // then remove the whole classname (if there was one, the above saved it).
309         // Otherwise bring back whatever was previously saved (if anything),
310         // falling back to the empty string if nothing was stored.
311         if ( this.setAttribute ) {
312             this.setAttribute( "class",
313                 className || state === false ?
314                 "" :
315                 jQuery.data( this, "__className__" ) || ""
316             );
317         }
318     } );
322 var internalSwapCall = false;
324 // If this version of jQuery has .swap(), don't false-alarm on internal uses
325 if ( jQuery.swap ) {
326     jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
327         var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
329         if ( oldHook ) {
330             jQuery.cssHooks[ name ].get = function() {
331                 var ret;
333                 internalSwapCall = true;
334                 ret = oldHook.apply( this, arguments );
335                 internalSwapCall = false;
336                 return ret;
337             };
338         }
339     } );
342 jQuery.swap = function( elem, options, callback, args ) {
343     var ret, name,
344         old = {};
346     if ( !internalSwapCall ) {
347         migrateWarn( "jQuery.swap() is undocumented and deprecated" );
348     }
350     // Remember the old values, and insert the new ones
351     for ( name in options ) {
352         old[ name ] = elem.style[ name ];
353         elem.style[ name ] = options[ name ];
354     }
356     ret = callback.apply( elem, args || [] );
358     // Revert the old values
359     for ( name in options ) {
360         elem.style[ name ] = old[ name ];
361     }
363     return ret;
366 var oldData = jQuery.data;
368 jQuery.data = function( elem, name, value ) {
369     var curData;
371     // Name can be an object, and each entry in the object is meant to be set as data
372     if ( name && typeof name === "object" && arguments.length === 2 ) {
373         curData = jQuery.hasData( elem ) && oldData.call( this, elem );
374         var sameKeys = {};
375         for ( var key in name ) {
376             if ( key !== jQuery.camelCase( key ) ) {
377                 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + key );
378                 curData[ key ] = name[ key ];
379             } else {
380                 sameKeys[ key ] = name[ key ];
381             }
382         }
384         oldData.call( this, elem, sameKeys );
386         return name;
387     }
389     // If the name is transformed, look for the un-transformed name in the data object
390     if ( name && typeof name === "string" && name !== jQuery.camelCase( name ) ) {
391         curData = jQuery.hasData( elem ) && oldData.call( this, elem );
392         if ( curData && name in curData ) {
393             migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name );
394             if ( arguments.length > 2 ) {
395                 curData[ name ] = value;
396             }
397             return curData[ name ];
398         }
399     }
401     return oldData.apply( this, arguments );
404 var oldTweenRun = jQuery.Tween.prototype.run;
405 var linearEasing = function( pct ) {
406         return pct;
407     };
409 jQuery.Tween.prototype.run = function( ) {
410     if ( jQuery.easing[ this.easing ].length > 1 ) {
411         migrateWarn(
412             "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
413         );
415         jQuery.easing[ this.easing ] = linearEasing;
416     }
418     oldTweenRun.apply( this, arguments );
421 var intervalValue = jQuery.fx.interval || 13,
422     intervalMsg = "jQuery.fx.interval is deprecated";
424 // Support: IE9, Android <=4.4
425 // Avoid false positives on browsers that lack rAF
426 // Don't warn if document is hidden, jQuery uses setTimeout (#292)
427 if ( window.requestAnimationFrame ) {
428     Object.defineProperty( jQuery.fx, "interval", {
429         configurable: true,
430         enumerable: true,
431         get: function() {
432             if ( !window.document.hidden ) {
433                 migrateWarn( intervalMsg );
434             }
435             return intervalValue;
436         },
437         set: function( newValue ) {
438             migrateWarn( intervalMsg );
439             intervalValue = newValue;
440         }
441     } );
444 var oldLoad = jQuery.fn.load,
445     oldEventAdd = jQuery.event.add,
446     originalFix = jQuery.event.fix;
448 jQuery.event.props = [];
449 jQuery.event.fixHooks = {};
451 migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
452     "jQuery.event.props.concat() is deprecated and removed" );
454 jQuery.event.fix = function( originalEvent ) {
455     var event,
456         type = originalEvent.type,
457         fixHook = this.fixHooks[ type ],
458         props = jQuery.event.props;
460     if ( props.length ) {
461         migrateWarn( "jQuery.event.props are deprecated and removed: " + props.join() );
462         while ( props.length ) {
463             jQuery.event.addProp( props.pop() );
464         }
465     }
467     if ( fixHook && !fixHook._migrated_ ) {
468         fixHook._migrated_ = true;
469         migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type );
470         if ( ( props = fixHook.props ) && props.length ) {
471             while ( props.length ) {
472                 jQuery.event.addProp( props.pop() );
473             }
474         }
475     }
477     event = originalFix.call( this, originalEvent );
479     return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
482 jQuery.event.add = function( elem, types ) {
484     // This misses the multiple-types case but that seems awfully rare
485     if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
486         migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
487     }
488     return oldEventAdd.apply( this, arguments );
491 jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
493     jQuery.fn[ name ] = function() {
494         var args = Array.prototype.slice.call( arguments, 0 );
496         // If this is an ajax load() the first arg should be the string URL;
497         // technically this could also be the "Anything" arg of the event .load()
498         // which just goes to show why this dumb signature has been deprecated!
499         // jQuery custom builds that exclude the Ajax module justifiably die here.
500         if ( name === "load" && typeof args[ 0 ] === "string" ) {
501             return oldLoad.apply( this, args );
502         }
504         migrateWarn( "jQuery.fn." + name + "() is deprecated" );
506         args.splice( 0, 0, name );
507         if ( arguments.length ) {
508             return this.on.apply( this, args );
509         }
511         // Use .triggerHandler here because:
512         // - load and unload events don't need to bubble, only applied to window or image
513         // - error event should not bubble to window, although it does pre-1.7
514         // See http://bugs.jquery.com/ticket/11820
515         this.triggerHandler.apply( this, args );
516         return this;
517     };
519 } );
521 jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
522     "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
523     "change select submit keydown keypress keyup contextmenu" ).split( " " ),
524     function( _i, name ) {
526     // Handle event binding
527     jQuery.fn[ name ] = function( data, fn ) {
528         migrateWarn( "jQuery.fn." + name + "() event shorthand is deprecated" );
529         return arguments.length > 0 ?
530             this.on( name, null, data, fn ) :
531             this.trigger( name );
532     };
533 } );
535 // Trigger "ready" event only once, on document ready
536 jQuery( function() {
537     jQuery( window.document ).triggerHandler( "ready" );
538 } );
540 jQuery.event.special.ready = {
541     setup: function() {
542         if ( this === window.document ) {
543             migrateWarn( "'ready' event is deprecated" );
544         }
545     }
548 jQuery.fn.extend( {
550     bind: function( types, data, fn ) {
551         migrateWarn( "jQuery.fn.bind() is deprecated" );
552         return this.on( types, null, data, fn );
553     },
554     unbind: function( types, fn ) {
555         migrateWarn( "jQuery.fn.unbind() is deprecated" );
556         return this.off( types, null, fn );
557     },
558     delegate: function( selector, types, data, fn ) {
559         migrateWarn( "jQuery.fn.delegate() is deprecated" );
560         return this.on( types, selector, data, fn );
561     },
562     undelegate: function( selector, types, fn ) {
563         migrateWarn( "jQuery.fn.undelegate() is deprecated" );
564         return arguments.length === 1 ?
565             this.off( selector, "**" ) :
566             this.off( types, selector || "**", fn );
567     },
568     hover: function( fnOver, fnOut ) {
569         migrateWarn( "jQuery.fn.hover() is deprecated" );
570         return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
571     }
572 } );
575 var oldOffset = jQuery.fn.offset;
577 jQuery.fn.offset = function() {
578     var docElem,
579         elem = this[ 0 ],
580         origin = { top: 0, left: 0 };
582     if ( !elem || !elem.nodeType ) {
583         migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
584         return origin;
585     }
587     docElem = ( elem.ownerDocument || window.document ).documentElement;
588     if ( !jQuery.contains( docElem, elem ) ) {
589         migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
590         return origin;
591     }
593     return oldOffset.apply( this, arguments );
597 var oldParam = jQuery.param;
599 jQuery.param = function( data, traditional ) {
600     var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
602     if ( traditional === undefined && ajaxTraditional ) {
604         migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
605         traditional = ajaxTraditional;
606     }
608     return oldParam.call( this, data, traditional );
611 var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
613 jQuery.fn.andSelf = function() {
614     migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
615     return oldSelf.apply( this, arguments );
619 var oldDeferred = jQuery.Deferred,
620     tuples = [
622         // Action, add listener, callbacks, .then handlers, final state
623         [ "resolve", "done", jQuery.Callbacks( "once memory" ),
624             jQuery.Callbacks( "once memory" ), "resolved" ],
625         [ "reject", "fail", jQuery.Callbacks( "once memory" ),
626             jQuery.Callbacks( "once memory" ), "rejected" ],
627         [ "notify", "progress", jQuery.Callbacks( "memory" ),
628             jQuery.Callbacks( "memory" ) ]
629     ];
631 jQuery.Deferred = function( func ) {
632     var deferred = oldDeferred(),
633         promise = deferred.promise();
635     deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
636         var fns = arguments;
638         migrateWarn( "deferred.pipe() is deprecated" );
640         return jQuery.Deferred( function( newDefer ) {
641             jQuery.each( tuples, function( i, tuple ) {
642                 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
644                 // Deferred.done(function() { bind to newDefer or newDefer.resolve })
645                 // deferred.fail(function() { bind to newDefer or newDefer.reject })
646                 // deferred.progress(function() { bind to newDefer or newDefer.notify })
647                 deferred[ tuple[ 1 ] ]( function() {
648                     var returned = fn && fn.apply( this, arguments );
649                     if ( returned && jQuery.isFunction( returned.promise ) ) {
650                         returned.promise()
651                             .done( newDefer.resolve )
652                             .fail( newDefer.reject )
653                             .progress( newDefer.notify );
654                     } else {
655                         newDefer[ tuple[ 0 ] + "With" ](
656                             this === promise ? newDefer.promise() : this,
657                             fn ? [ returned ] : arguments
658                         );
659                     }
660                 } );
661             } );
662             fns = null;
663         } ).promise();
665     };
667     if ( func ) {
668         func.call( deferred, deferred );
669     }
671     return deferred;
674 // Preserve handler of uncaught exceptions in promise chains
675 jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
677 return jQuery;
678 } );