Statistiques
| Révision:

fr_b02 / petri / doc / jquery / jquery-migrate-3.0.1.js @ 5

Historique | Voir | Annoter | Télécharger (17,423 ko)

1
/*!
2
 * jQuery Migrate - v3.0.1 - 2017-09-26
3
 * Copyright jQuery Foundation and other contributors
4
 */
5
;( function( factory ) {
6
        if ( typeof define === "function" && define.amd ) {
7

    
8
                // AMD. Register as an anonymous module.
9
                define( [ "jquery" ], window, factory );
10
        } else if ( typeof module === "object" && module.exports ) {
11

    
12
                // Node/CommonJS
13
                // eslint-disable-next-line no-undef
14
                module.exports = factory( require( "jquery" ), window );
15
        } else {
16

    
17
                // Browser globals
18
                factory( jQuery, window );
19
        }
20
} )( function( jQuery, window ) {
21
"use strict";
22

    
23

    
24
jQuery.migrateVersion = "3.0.1";
25

    
26
jQuery.migrateMute = true;
27

    
28
/* exported migrateWarn, migrateWarnFunc, migrateWarnProp */
29

    
30
( function() {
31

    
32
        var rbadVersions = /^[12]\./;
33

    
34
        // Support: IE9 only
35
        // IE9 only creates console object when dev tools are first opened
36
        // IE9 console is a host object, callable but doesn't have .apply()
37
        if ( !window.console || !window.console.log ) {
38
                return;
39
        }
40

    
41
        // Need jQuery 3.0.0+ and no older Migrate loaded
42
        if ( !jQuery || rbadVersions.test( jQuery.fn.jquery ) ) {
43
                window.console.log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
44
        }
45
        if ( jQuery.migrateWarnings ) {
46
                window.console.log( "JQMIGRATE: Migrate plugin loaded multiple times" );
47
        }
48

    
49
        // Show a message on the console so devs know we're active
50
        window.console.log( "JQMIGRATE: Migrate is installed" +
51
                ( jQuery.migrateMute ? "" : " with logging active" ) +
52
                ", version " + jQuery.migrateVersion );
53

    
54
} )();
55

    
56
var warnedAbout = {};
57

    
58
// List of warnings already given; public read only
59
jQuery.migrateWarnings = [];
60

    
61
// Set to false to disable traces that appear with warnings
62
if ( jQuery.migrateTrace === undefined ) {
63
        jQuery.migrateTrace = true;
64
}
65

    
66
// Forget any warnings we've already given; public
67
jQuery.migrateReset = function() {
68
        warnedAbout = {};
69
        jQuery.migrateWarnings.length = 0;
70
};
71

    
72
function migrateWarn( msg ) {
73
        var console = window.console;
74
        if ( !warnedAbout[ msg ] ) {
75
                warnedAbout[ msg ] = true;
76
                jQuery.migrateWarnings.push( msg );
77
                if ( console && console.warn && !jQuery.migrateMute ) {
78
                        console.warn( "JQMIGRATE: " + msg );
79
                        if ( jQuery.migrateTrace && console.trace ) {
80
                                console.trace();
81
                        }
82
                }
83
        }
84
}
85

    
86
function migrateWarnProp( obj, prop, value, msg ) {
87
        Object.defineProperty( obj, prop, {
88
                configurable: true,
89
                enumerable: true,
90
                get: function() {
91
                        migrateWarn( msg );
92
                        return value;
93
                },
94
                set: function( newValue ) {
95
                        migrateWarn( msg );
96
                        value = newValue;
97
                }
98
        } );
99
}
100

    
101
function migrateWarnFunc( obj, prop, newFunc, msg ) {
102
        obj[ prop ] = function() {
103
                migrateWarn( msg );
104
                return newFunc.apply( this, arguments );
105
        };
106
}
107

    
108
if ( window.document.compatMode === "BackCompat" ) {
109

    
110
        // JQuery has never supported or tested Quirks Mode
111
        migrateWarn( "jQuery is not compatible with Quirks Mode" );
112
}
113

    
114

    
115
var oldInit = jQuery.fn.init,
116
        oldIsNumeric = jQuery.isNumeric,
117
        oldFind = jQuery.find,
118
        rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
119
        rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
120

    
121
jQuery.fn.init = function( arg1 ) {
122
        var args = Array.prototype.slice.call( arguments );
123

    
124
        if ( typeof arg1 === "string" && arg1 === "#" ) {
125

    
126
                // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
127
                migrateWarn( "jQuery( '#' ) is not a valid selector" );
128
                args[ 0 ] = [];
129
        }
130

    
131
        return oldInit.apply( this, args );
132
};
133
jQuery.fn.init.prototype = jQuery.fn;
134

    
135
jQuery.find = function( selector ) {
136
        var args = Array.prototype.slice.call( arguments );
137

    
138
        // Support: PhantomJS 1.x
139
        // String#match fails to match when used with a //g RegExp, only on some strings
140
        if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
141

    
142
                // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
143
                // First see if qS thinks it's a valid selector, if so avoid a false positive
144
                try {
145
                        window.document.querySelector( selector );
146
                } catch ( err1 ) {
147

    
148
                        // Didn't *look* valid to qSA, warn and try quoting what we think is the value
149
                        selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
150
                                return "[" + attr + op + "\"" + value + "\"]";
151
                        } );
152

    
153
                        // If the regexp *may* have created an invalid selector, don't update it
154
                        // Note that there may be false alarms if selector uses jQuery extensions
155
                        try {
156
                                window.document.querySelector( selector );
157
                                migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
158
                                args[ 0 ] = selector;
159
                        } catch ( err2 ) {
160
                                migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
161
                        }
162
                }
163
        }
164

    
165
        return oldFind.apply( this, args );
166
};
167

    
168
// Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
169
var findProp;
170
for ( findProp in oldFind ) {
171
        if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
172
                jQuery.find[ findProp ] = oldFind[ findProp ];
173
        }
174
}
175

    
176
// The number of elements contained in the matched element set
177
jQuery.fn.size = function() {
178
        migrateWarn( "jQuery.fn.size() is deprecated and removed; use the .length property" );
179
        return this.length;
180
};
181

    
182
jQuery.parseJSON = function() {
183
        migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
184
        return JSON.parse.apply( null, arguments );
185
};
186

    
187
jQuery.isNumeric = function( val ) {
188

    
189
        // The jQuery 2.2.3 implementation of isNumeric
190
        function isNumeric2( obj ) {
191
                var realStringObj = obj && obj.toString();
192
                return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
193
        }
194

    
195
        var newValue = oldIsNumeric( val ),
196
                oldValue = isNumeric2( val );
197

    
198
        if ( newValue !== oldValue ) {
199
                migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
200
        }
201

    
202
        return oldValue;
203
};
204

    
205
migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
206
        "jQuery.holdReady is deprecated" );
207

    
208
migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
209
        "jQuery.unique is deprecated; use jQuery.uniqueSort" );
210

    
211
// Now jQuery.expr.pseudos is the standard incantation
212
migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos,
213
        "jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
214
migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos,
215
        "jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );
216

    
217

    
218
var oldAjax = jQuery.ajax;
219

    
220
jQuery.ajax = function( ) {
221
        var jQXHR = oldAjax.apply( this, arguments );
222

    
223
        // Be sure we got a jQXHR (e.g., not sync)
224
        if ( jQXHR.promise ) {
225
                migrateWarnFunc( jQXHR, "success", jQXHR.done,
226
                        "jQXHR.success is deprecated and removed" );
227
                migrateWarnFunc( jQXHR, "error", jQXHR.fail,
228
                        "jQXHR.error is deprecated and removed" );
229
                migrateWarnFunc( jQXHR, "complete", jQXHR.always,
230
                        "jQXHR.complete is deprecated and removed" );
231
        }
232

    
233
        return jQXHR;
234
};
235

    
236

    
237
var oldRemoveAttr = jQuery.fn.removeAttr,
238
        oldToggleClass = jQuery.fn.toggleClass,
239
        rmatchNonSpace = /\S+/g;
240

    
241
jQuery.fn.removeAttr = function( name ) {
242
        var self = this;
243

    
244
        jQuery.each( name.match( rmatchNonSpace ), function( i, attr ) {
245
                if ( jQuery.expr.match.bool.test( attr ) ) {
246
                        migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
247
                        self.prop( attr, false );
248
                }
249
        } );
250

    
251
        return oldRemoveAttr.apply( this, arguments );
252
};
253

    
254
jQuery.fn.toggleClass = function( state ) {
255

    
256
        // Only deprecating no-args or single boolean arg
257
        if ( state !== undefined && typeof state !== "boolean" ) {
258
                return oldToggleClass.apply( this, arguments );
259
        }
260

    
261
        migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
262

    
263
        // Toggle entire class name of each element
264
        return this.each( function() {
265
                var className = this.getAttribute && this.getAttribute( "class" ) || "";
266

    
267
                if ( className ) {
268
                        jQuery.data( this, "__className__", className );
269
                }
270

    
271
                // If the element has a class name or if we're passed `false`,
272
                // then remove the whole classname (if there was one, the above saved it).
273
                // Otherwise bring back whatever was previously saved (if anything),
274
                // falling back to the empty string if nothing was stored.
275
                if ( this.setAttribute ) {
276
                        this.setAttribute( "class",
277
                                className || state === false ?
278
                                "" :
279
                                jQuery.data( this, "__className__" ) || ""
280
                        );
281
                }
282
        } );
283
};
284

    
285

    
286
var internalSwapCall = false;
287

    
288
// If this version of jQuery has .swap(), don't false-alarm on internal uses
289
if ( jQuery.swap ) {
290
        jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
291
                var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
292

    
293
                if ( oldHook ) {
294
                        jQuery.cssHooks[ name ].get = function() {
295
                                var ret;
296

    
297
                                internalSwapCall = true;
298
                                ret = oldHook.apply( this, arguments );
299
                                internalSwapCall = false;
300
                                return ret;
301
                        };
302
                }
303
        } );
304
}
305

    
306
jQuery.swap = function( elem, options, callback, args ) {
307
        var ret, name,
308
                old = {};
309

    
310
        if ( !internalSwapCall ) {
311
                migrateWarn( "jQuery.swap() is undocumented and deprecated" );
312
        }
313

    
314
        // Remember the old values, and insert the new ones
315
        for ( name in options ) {
316
                old[ name ] = elem.style[ name ];
317
                elem.style[ name ] = options[ name ];
318
        }
319

    
320
        ret = callback.apply( elem, args || [] );
321

    
322
        // Revert the old values
323
        for ( name in options ) {
324
                elem.style[ name ] = old[ name ];
325
        }
326

    
327
        return ret;
328
};
329

    
330
var oldData = jQuery.data;
331

    
332
jQuery.data = function( elem, name, value ) {
333
        var curData;
334

    
335
        // Name can be an object, and each entry in the object is meant to be set as data
336
        if ( name && typeof name === "object" && arguments.length === 2 ) {
337
                curData = jQuery.hasData( elem ) && oldData.call( this, elem );
338
                var sameKeys = {};
339
                for ( var key in name ) {
340
                        if ( key !== jQuery.camelCase( key ) ) {
341
                                migrateWarn( "jQuery.data() always sets/gets camelCased names: " + key );
342
                                curData[ key ] = name[ key ];
343
                        } else {
344
                                sameKeys[ key ] = name[ key ];
345
                        }
346
                }
347

    
348
                oldData.call( this, elem, sameKeys );
349

    
350
                return name;
351
        }
352

    
353
        // If the name is transformed, look for the un-transformed name in the data object
354
        if ( name && typeof name === "string" && name !== jQuery.camelCase( name ) ) {
355
                curData = jQuery.hasData( elem ) && oldData.call( this, elem );
356
                if ( curData && name in curData ) {
357
                        migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name );
358
                        if ( arguments.length > 2 ) {
359
                                curData[ name ] = value;
360
                        }
361
                        return curData[ name ];
362
                }
363
        }
364

    
365
        return oldData.apply( this, arguments );
366
};
367

    
368
var oldTweenRun = jQuery.Tween.prototype.run;
369
var linearEasing = function( pct ) {
370
                return pct;
371
        };
372

    
373
jQuery.Tween.prototype.run = function( ) {
374
        if ( jQuery.easing[ this.easing ].length > 1 ) {
375
                migrateWarn(
376
                        "'jQuery.easing." + this.easing.toString() + "' should use only one argument"
377
                );
378

    
379
                jQuery.easing[ this.easing ] = linearEasing;
380
        }
381

    
382
        oldTweenRun.apply( this, arguments );
383
};
384

    
385
jQuery.fx.interval = jQuery.fx.interval || 13;
386

    
387
// Support: IE9, Android <=4.4
388
// Avoid false positives on browsers that lack rAF
389
if ( window.requestAnimationFrame ) {
390
        migrateWarnProp( jQuery.fx, "interval", jQuery.fx.interval,
391
                "jQuery.fx.interval is deprecated" );
392
}
393

    
394
var oldLoad = jQuery.fn.load,
395
        oldEventAdd = jQuery.event.add,
396
        originalFix = jQuery.event.fix;
397

    
398
jQuery.event.props = [];
399
jQuery.event.fixHooks = {};
400

    
401
migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
402
        "jQuery.event.props.concat() is deprecated and removed" );
403

    
404
jQuery.event.fix = function( originalEvent ) {
405
        var event,
406
                type = originalEvent.type,
407
                fixHook = this.fixHooks[ type ],
408
                props = jQuery.event.props;
409

    
410
        if ( props.length ) {
411
                migrateWarn( "jQuery.event.props are deprecated and removed: " + props.join() );
412
                while ( props.length ) {
413
                        jQuery.event.addProp( props.pop() );
414
                }
415
        }
416

    
417
        if ( fixHook && !fixHook._migrated_ ) {
418
                fixHook._migrated_ = true;
419
                migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type );
420
                if ( ( props = fixHook.props ) && props.length ) {
421
                        while ( props.length ) {
422
                                jQuery.event.addProp( props.pop() );
423
                        }
424
                }
425
        }
426

    
427
        event = originalFix.call( this, originalEvent );
428

    
429
        return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
430
};
431

    
432
jQuery.event.add = function( elem, types ) {
433

    
434
        // This misses the multiple-types case but that seems awfully rare
435
        if ( elem === window && types === "load" && window.document.readyState === "complete" ) {
436
                migrateWarn( "jQuery(window).on('load'...) called after load event occurred" );
437
        }
438
        return oldEventAdd.apply( this, arguments );
439
};
440

    
441
jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
442

    
443
        jQuery.fn[ name ] = function() {
444
                var args = Array.prototype.slice.call( arguments, 0 );
445

    
446
                // If this is an ajax load() the first arg should be the string URL;
447
                // technically this could also be the "Anything" arg of the event .load()
448
                // which just goes to show why this dumb signature has been deprecated!
449
                // jQuery custom builds that exclude the Ajax module justifiably die here.
450
                if ( name === "load" && typeof args[ 0 ] === "string" ) {
451
                        return oldLoad.apply( this, args );
452
                }
453

    
454
                migrateWarn( "jQuery.fn." + name + "() is deprecated" );
455

    
456
                args.splice( 0, 0, name );
457
                if ( arguments.length ) {
458
                        return this.on.apply( this, args );
459
                }
460

    
461
                // Use .triggerHandler here because:
462
                // - load and unload events don't need to bubble, only applied to window or image
463
                // - error event should not bubble to window, although it does pre-1.7
464
                // See http://bugs.jquery.com/ticket/11820
465
                this.triggerHandler.apply( this, args );
466
                return this;
467
        };
468

    
469
} );
470

    
471
jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
472
        "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
473
        "change select submit keydown keypress keyup contextmenu" ).split( " " ),
474
        function( i, name ) {
475

    
476
        // Handle event binding
477
        jQuery.fn[ name ] = function( data, fn ) {
478
                migrateWarn( "jQuery.fn." + name + "() event shorthand is deprecated" );
479
                return arguments.length > 0 ?
480
                        this.on( name, null, data, fn ) :
481
                        this.trigger( name );
482
        };
483
} );
484

    
485
// Trigger "ready" event only once, on document ready
486
jQuery( function() {
487
        jQuery( window.document ).triggerHandler( "ready" );
488
} );
489

    
490
jQuery.event.special.ready = {
491
        setup: function() {
492
                if ( this === window.document ) {
493
                        migrateWarn( "'ready' event is deprecated" );
494
                }
495
        }
496
};
497

    
498
jQuery.fn.extend( {
499

    
500
        bind: function( types, data, fn ) {
501
                migrateWarn( "jQuery.fn.bind() is deprecated" );
502
                return this.on( types, null, data, fn );
503
        },
504
        unbind: function( types, fn ) {
505
                migrateWarn( "jQuery.fn.unbind() is deprecated" );
506
                return this.off( types, null, fn );
507
        },
508
        delegate: function( selector, types, data, fn ) {
509
                migrateWarn( "jQuery.fn.delegate() is deprecated" );
510
                return this.on( types, selector, data, fn );
511
        },
512
        undelegate: function( selector, types, fn ) {
513
                migrateWarn( "jQuery.fn.undelegate() is deprecated" );
514
                return arguments.length === 1 ?
515
                        this.off( selector, "**" ) :
516
                        this.off( types, selector || "**", fn );
517
        },
518
        hover: function( fnOver, fnOut ) {
519
                migrateWarn( "jQuery.fn.hover() is deprecated" );
520
                return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver );
521
        }
522
} );
523

    
524

    
525
var oldOffset = jQuery.fn.offset;
526

    
527
jQuery.fn.offset = function() {
528
        var docElem,
529
                elem = this[ 0 ],
530
                origin = { top: 0, left: 0 };
531

    
532
        if ( !elem || !elem.nodeType ) {
533
                migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
534
                return origin;
535
        }
536

    
537
        docElem = ( elem.ownerDocument || window.document ).documentElement;
538
        if ( !jQuery.contains( docElem, elem ) ) {
539
                migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
540
                return origin;
541
        }
542

    
543
        return oldOffset.apply( this, arguments );
544
};
545

    
546

    
547
var oldParam = jQuery.param;
548

    
549
jQuery.param = function( data, traditional ) {
550
        var ajaxTraditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
551

    
552
        if ( traditional === undefined && ajaxTraditional ) {
553

    
554
                migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
555
                traditional = ajaxTraditional;
556
        }
557

    
558
        return oldParam.call( this, data, traditional );
559
};
560

    
561
var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
562

    
563
jQuery.fn.andSelf = function() {
564
        migrateWarn( "jQuery.fn.andSelf() is deprecated and removed, use jQuery.fn.addBack()" );
565
        return oldSelf.apply( this, arguments );
566
};
567

    
568

    
569
var oldDeferred = jQuery.Deferred,
570
        tuples = [
571

    
572
                // Action, add listener, callbacks, .then handlers, final state
573
                [ "resolve", "done", jQuery.Callbacks( "once memory" ),
574
                        jQuery.Callbacks( "once memory" ), "resolved" ],
575
                [ "reject", "fail", jQuery.Callbacks( "once memory" ),
576
                        jQuery.Callbacks( "once memory" ), "rejected" ],
577
                [ "notify", "progress", jQuery.Callbacks( "memory" ),
578
                        jQuery.Callbacks( "memory" ) ]
579
        ];
580

    
581
jQuery.Deferred = function( func ) {
582
        var deferred = oldDeferred(),
583
                promise = deferred.promise();
584

    
585
        deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
586
                var fns = arguments;
587

    
588
                migrateWarn( "deferred.pipe() is deprecated" );
589

    
590
                return jQuery.Deferred( function( newDefer ) {
591
                        jQuery.each( tuples, function( i, tuple ) {
592
                                var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
593

    
594
                                // Deferred.done(function() { bind to newDefer or newDefer.resolve })
595
                                // deferred.fail(function() { bind to newDefer or newDefer.reject })
596
                                // deferred.progress(function() { bind to newDefer or newDefer.notify })
597
                                deferred[ tuple[ 1 ] ]( function() {
598
                                        var returned = fn && fn.apply( this, arguments );
599
                                        if ( returned && jQuery.isFunction( returned.promise ) ) {
600
                                                returned.promise()
601
                                                        .done( newDefer.resolve )
602
                                                        .fail( newDefer.reject )
603
                                                        .progress( newDefer.notify );
604
                                        } else {
605
                                                newDefer[ tuple[ 0 ] + "With" ](
606
                                                        this === promise ? newDefer.promise() : this,
607
                                                        fn ? [ returned ] : arguments
608
                                                );
609
                                        }
610
                                } );
611
                        } );
612
                        fns = null;
613
                } ).promise();
614

    
615
        };
616

    
617
        if ( func ) {
618
                func.call( deferred, deferred );
619
        }
620

    
621
        return deferred;
622
};
623

    
624
// Preserve handler of uncaught exceptions in promise chains
625
jQuery.Deferred.exceptionHook = oldDeferred.exceptionHook;
626

    
627
return jQuery;
628
} );