2 * jQuery Migrate - v3.0.0 - 2016-06-09
3 * Copyright jQuery Foundation and other contributors
5 (function( jQuery
, window
) {
9 jQuery
.migrateVersion
= "3.0.0";
15 // IE9 only creates console object when dev tools are first opened
16 // Also, avoid Function#bind here to simplify PhantomJS usage
17 var log
= window
.console
&& window
.console
.log
&&
18 function() { window
.console
.log
.apply( window
.console
, arguments
); },
19 rbadVersions
= /^[12]\./;
25 // Need jQuery 3.0.0+ and no older Migrate loaded
26 if ( !jQuery
|| rbadVersions
.test( jQuery
.fn
.jquery
) ) {
27 log( "JQMIGRATE: jQuery 3.0.0+ REQUIRED" );
29 if ( jQuery
.migrateWarnings
) {
30 log( "JQMIGRATE: Migrate plugin loaded multiple times" );
33 // Show a message on the console so devs know we're active
34 log( "JQMIGRATE: Migrate is installed" +
35 ( jQuery
.migrateMute
? "" : " with logging active" ) +
36 ", version " + jQuery
.migrateVersion
);
42 // List of warnings already given; public read only
43 jQuery
.migrateWarnings
= [];
45 // Set to false to disable traces that appear with warnings
46 if ( jQuery
.migrateTrace
=== undefined ) {
47 jQuery
.migrateTrace
= true;
50 // Forget any warnings we've already given; public
51 jQuery
.migrateReset = function() {
53 jQuery
.migrateWarnings
.length
= 0;
56 function migrateWarn( msg
) {
57 var console
= window
.console
;
58 if ( !warnedAbout
[ msg
] ) {
59 warnedAbout
[ msg
] = true;
60 jQuery
.migrateWarnings
.push( msg
);
61 if ( console
&& console
.warn
&& !jQuery
.migrateMute
) {
62 console
.warn( "JQMIGRATE: " + msg
);
63 if ( jQuery
.migrateTrace
&& console
.trace
) {
70 function migrateWarnProp( obj
, prop
, value
, msg
) {
71 Object
.defineProperty( obj
, prop
, {
81 if ( document
.compatMode
=== "BackCompat" ) {
83 // JQuery has never supported or tested Quirks Mode
84 migrateWarn( "jQuery is not compatible with Quirks Mode" );
88 var oldInit
= jQuery
.fn
.init
,
89 oldIsNumeric
= jQuery
.isNumeric
,
90 oldFind
= jQuery
.find
,
91 rattrHashTest
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
92 rattrHashGlob
= /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g;
94 jQuery
.fn
.init = function( arg1
) {
95 var args
= Array
.prototype.slice
.call( arguments
);
97 if ( typeof arg1
=== "string" && arg1
=== "#" ) {
99 // JQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
100 migrateWarn( "jQuery( '#' ) is not a valid selector" );
104 return oldInit
.apply( this, args
);
106 jQuery
.fn
.init
.prototype = jQuery
.fn
;
108 jQuery
.find = function( selector
) {
109 var args
= Array
.prototype.slice
.call( arguments
);
111 // Support: PhantomJS 1.x
112 // String#match fails to match when used with a //g RegExp, only on some strings
113 if ( typeof selector
=== "string" && rattrHashTest
.test( selector
) ) {
115 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
116 // First see if qS thinks it's a valid selector, if so avoid a false positive
118 document
.querySelector( selector
);
121 // Didn't *look* valid to qSA, warn and try quoting what we think is the value
122 selector
= selector
.replace( rattrHashGlob
, function( _
, attr
, op
, value
) {
123 return "[" + attr
+ op
+ "\"" + value
+ "\"]";
126 // If the regexp *may* have created an invalid selector, don't update it
127 // Note that there may be false alarms if selector uses jQuery extensions
129 document
.querySelector( selector
);
130 migrateWarn( "Attribute selector with '#' must be quoted: " + args
[ 0 ] );
131 args
[ 0 ] = selector
;
133 migrateWarn( "Attribute selector with '#' was not fixed: " + args
[ 0 ] );
138 return oldFind
.apply( this, args
);
141 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
143 for ( findProp
in oldFind
) {
144 if ( Object
.prototype.hasOwnProperty
.call( oldFind
, findProp
) ) {
145 jQuery
.find
[ findProp
] = oldFind
[ findProp
];
149 // The number of elements contained in the matched element set
150 jQuery
.fn
.size = function() {
151 migrateWarn( "jQuery.fn.size() is deprecated; use the .length property" );
155 jQuery
.parseJSON = function() {
156 migrateWarn( "jQuery.parseJSON is deprecated; use JSON.parse" );
157 return JSON
.parse
.apply( null, arguments
);
160 jQuery
.isNumeric = function( val
) {
162 // The jQuery 2.2.3 implementation of isNumeric
163 function isNumeric2( obj
) {
164 var realStringObj
= obj
&& obj
.toString();
165 return !jQuery
.isArray( obj
) && ( realStringObj
- parseFloat( realStringObj
) + 1 ) >= 0;
168 var newValue
= oldIsNumeric( val
),
169 oldValue
= isNumeric2( val
);
171 if ( newValue
!== oldValue
) {
172 migrateWarn( "jQuery.isNumeric() should not be called on constructed objects" );
178 migrateWarnProp( jQuery
, "unique", jQuery
.uniqueSort
,
179 "jQuery.unique is deprecated, use jQuery.uniqueSort" );
181 // Now jQuery.expr.pseudos is the standard incantation
182 migrateWarnProp( jQuery
.expr
, "filters", jQuery
.expr
.pseudos
,
183 "jQuery.expr.filters is now jQuery.expr.pseudos" );
184 migrateWarnProp( jQuery
.expr
, ":", jQuery
.expr
.pseudos
,
185 "jQuery.expr[\":\"] is now jQuery.expr.pseudos" );
188 var oldAjax
= jQuery
.ajax
;
190 jQuery
.ajax = function( ) {
191 var jQXHR
= oldAjax
.apply( this, arguments
);
193 // Be sure we got a jQXHR (e.g., not sync)
194 if ( jQXHR
.promise
) {
195 migrateWarnProp( jQXHR
, "success", jQXHR
.done
,
196 "jQXHR.success is deprecated and removed" );
197 migrateWarnProp( jQXHR
, "error", jQXHR
.fail
,
198 "jQXHR.error is deprecated and removed" );
199 migrateWarnProp( jQXHR
, "complete", jQXHR
.always
,
200 "jQXHR.complete is deprecated and removed" );
207 var oldRemoveAttr
= jQuery
.fn
.removeAttr
,
208 oldToggleClass
= jQuery
.fn
.toggleClass
,
209 rmatchNonSpace
= /\S+/g;
211 jQuery
.fn
.removeAttr = function( name
) {
214 jQuery
.each( name
.match( rmatchNonSpace
), function( i
, attr
) {
215 if ( jQuery
.expr
.match
.bool
.test( attr
) ) {
216 migrateWarn( "jQuery.fn.removeAttr no longer sets boolean properties: " + attr
);
217 self
.prop( attr
, false );
221 return oldRemoveAttr
.apply( this, arguments
);
224 jQuery
.fn
.toggleClass = function( state
) {
226 // Only deprecating no-args or single boolean arg
227 if ( state
!== undefined && typeof state
!== "boolean" ) {
228 return oldToggleClass
.apply( this, arguments
);
231 migrateWarn( "jQuery.fn.toggleClass( boolean ) is deprecated" );
233 // Toggle entire class name of each element
234 return this.each( function() {
235 var className
= this.getAttribute
&& this.getAttribute( "class" ) || "";
238 jQuery
.data( this, "__className__", className
);
241 // If the element has a class name or if we're passed `false`,
242 // then remove the whole classname (if there was one, the above saved it).
243 // Otherwise bring back whatever was previously saved (if anything),
244 // falling back to the empty string if nothing was stored.
245 if ( this.setAttribute
) {
246 this.setAttribute( "class",
247 className
|| state
=== false ?
249 jQuery
.data( this, "__className__" ) || ""
256 var internalSwapCall
= false;
258 // If this version of jQuery has .swap(), don't false-alarm on internal uses
260 jQuery
.each( [ "height", "width", "reliableMarginRight" ], function( _
, name
) {
261 var oldHook
= jQuery
.cssHooks
[ name
] && jQuery
.cssHooks
[ name
].get;
264 jQuery
.cssHooks
[ name
].get = function() {
267 internalSwapCall
= true;
268 ret
= oldHook
.apply( this, arguments
);
269 internalSwapCall
= false;
276 jQuery
.swap = function( elem
, options
, callback
, args
) {
280 if ( !internalSwapCall
) {
281 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
284 // Remember the old values, and insert the new ones
285 for ( name
in options
) {
286 old
[ name
] = elem
.style
[ name
];
287 elem
.style
[ name
] = options
[ name
];
290 ret
= callback
.apply( elem
, args
|| [] );
292 // Revert the old values
293 for ( name
in options
) {
294 elem
.style
[ name
] = old
[ name
];
300 var oldData
= jQuery
.data
;
302 jQuery
.data = function( elem
, name
, value
) {
305 // If the name is transformed, look for the un-transformed name in the data object
306 if ( name
&& name
!== jQuery
.camelCase( name
) ) {
307 curData
= jQuery
.hasData( elem
) && oldData
.call( this, elem
);
308 if ( curData
&& name
in curData
) {
309 migrateWarn( "jQuery.data() always sets/gets camelCased names: " + name
);
310 if ( arguments
.length
> 2 ) {
311 curData
[ name
] = value
;
313 return curData
[ name
];
317 return oldData
.apply( this, arguments
);
320 var oldTweenRun
= jQuery
.Tween
.prototype.run
;
322 jQuery
.Tween
.prototype.run = function( percent
) {
323 if ( jQuery
.easing
[ this.easing
].length
> 1 ) {
326 "\"jQuery.easing." + this.easing
.toString() +
327 "\" should use only first argument"
330 jQuery
.easing
[ this.easing
] = jQuery
.easing
[ this.easing
].bind(
332 percent
, this.options
.duration
* percent
, 0, 1, this.options
.duration
336 oldTweenRun
.apply( this, arguments
);
339 var oldLoad
= jQuery
.fn
.load
,
340 originalFix
= jQuery
.event
.fix
;
342 jQuery
.event
.props
= [];
343 jQuery
.event
.fixHooks
= {};
345 jQuery
.event
.fix = function( originalEvent
) {
347 type
= originalEvent
.type
,
348 fixHook
= this.fixHooks
[ type
],
349 props
= jQuery
.event
.props
;
351 if ( props
.length
) {
352 migrateWarn( "jQuery.event.props are deprecated and removed: " + props
.join() );
353 while ( props
.length
) {
354 jQuery
.event
.addProp( props
.pop() );
358 if ( fixHook
&& !fixHook
._migrated_
) {
359 fixHook
._migrated_
= true;
360 migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type
);
361 if ( ( props
= fixHook
.props
) && props
.length
) {
362 while ( props
.length
) {
363 jQuery
.event
.addProp( props
.pop() );
368 event
= originalFix
.call( this, originalEvent
);
370 return fixHook
&& fixHook
.filter
? fixHook
.filter( event
, originalEvent
) : event
;
373 jQuery
.each( [ "load", "unload", "error" ], function( _
, name
) {
375 jQuery
.fn
[ name
] = function() {
376 var args
= Array
.prototype.slice
.call( arguments
, 0 );
378 // If this is an ajax load() the first arg should be the string URL;
379 // technically this could also be the "Anything" arg of the event .load()
380 // which just goes to show why this dumb signature has been deprecated!
381 // jQuery custom builds that exclude the Ajax module justifiably die here.
382 if ( name
=== "load" && typeof args
[ 0 ] === "string" ) {
383 return oldLoad
.apply( this, args
);
386 migrateWarn( "jQuery.fn." + name
+ "() is deprecated" );
388 args
.splice( 0, 0, name
);
389 if ( arguments
.length
) {
390 return this.on
.apply( this, args
);
393 // Use .triggerHandler here because:
394 // - load and unload events don't need to bubble, only applied to window or image
395 // - error event should not bubble to window, although it does pre-1.7
396 // See http://bugs.jquery.com/ticket/11820
397 this.triggerHandler
.apply( this, args
);
403 // Trigger "ready" event only once, on document ready
405 jQuery( document
).triggerHandler( "ready" );
408 jQuery
.event
.special
.ready
= {
410 if ( this === document
) {
411 migrateWarn( "'ready' event is deprecated" );
418 bind: function( types
, data
, fn
) {
419 migrateWarn( "jQuery.fn.bind() is deprecated" );
420 return this.on( types
, null, data
, fn
);
422 unbind: function( types
, fn
) {
423 migrateWarn( "jQuery.fn.unbind() is deprecated" );
424 return this.off( types
, null, fn
);
426 delegate: function( selector
, types
, data
, fn
) {
427 migrateWarn( "jQuery.fn.delegate() is deprecated" );
428 return this.on( types
, selector
, data
, fn
);
430 undelegate: function( selector
, types
, fn
) {
431 migrateWarn( "jQuery.fn.undelegate() is deprecated" );
432 return arguments
.length
=== 1 ?
433 this.off( selector
, "**" ) :
434 this.off( types
, selector
|| "**", fn
);
439 var oldOffset
= jQuery
.fn
.offset
;
441 jQuery
.fn
.offset = function() {
444 origin
= { top
: 0, left
: 0 };
446 if ( !elem
|| !elem
.nodeType
) {
447 migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
451 docElem
= ( elem
.ownerDocument
|| document
).documentElement
;
452 if ( !jQuery
.contains( docElem
, elem
) ) {
453 migrateWarn( "jQuery.fn.offset() requires an element connected to a document" );
457 return oldOffset
.apply( this, arguments
);
461 var oldParam
= jQuery
.param
;
463 jQuery
.param = function( data
, traditional
) {
464 var ajaxTraditional
= jQuery
.ajaxSettings
&& jQuery
.ajaxSettings
.traditional
;
466 if ( traditional
=== undefined && ajaxTraditional
) {
468 migrateWarn( "jQuery.param() no longer uses jQuery.ajaxSettings.traditional" );
469 traditional
= ajaxTraditional
;
472 return oldParam
.call( this, data
, traditional
);
475 var oldSelf
= jQuery
.fn
.andSelf
|| jQuery
.fn
.addBack
;
477 jQuery
.fn
.andSelf = function() {
478 migrateWarn( "jQuery.fn.andSelf() replaced by jQuery.fn.addBack()" );
479 return oldSelf
.apply( this, arguments
);
483 var oldDeferred
= jQuery
.Deferred
,
486 // Action, add listener, callbacks, .then handlers, final state
487 [ "resolve", "done", jQuery
.Callbacks( "once memory" ),
488 jQuery
.Callbacks( "once memory" ), "resolved" ],
489 [ "reject", "fail", jQuery
.Callbacks( "once memory" ),
490 jQuery
.Callbacks( "once memory" ), "rejected" ],
491 [ "notify", "progress", jQuery
.Callbacks( "memory" ),
492 jQuery
.Callbacks( "memory" ) ]
495 jQuery
.Deferred = function( func
) {
496 var deferred
= oldDeferred(),
497 promise
= deferred
.promise();
499 deferred
.pipe
= promise
.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
502 migrateWarn( "deferred.pipe() is deprecated" );
504 return jQuery
.Deferred( function( newDefer
) {
505 jQuery
.each( tuples
, function( i
, tuple
) {
506 var fn
= jQuery
.isFunction( fns
[ i
] ) && fns
[ i
];
508 // Deferred.done(function() { bind to newDefer or newDefer.resolve })
509 // deferred.fail(function() { bind to newDefer or newDefer.reject })
510 // deferred.progress(function() { bind to newDefer or newDefer.notify })
511 deferred
[ tuple
[ 1 ] ]( function() {
512 var returned
= fn
&& fn
.apply( this, arguments
);
513 if ( returned
&& jQuery
.isFunction( returned
.promise
) ) {
515 .done( newDefer
.resolve
)
516 .fail( newDefer
.reject
)
517 .progress( newDefer
.notify
);
519 newDefer
[ tuple
[ 0 ] + "With" ](
520 this === promise
? newDefer
.promise() : this,
521 fn
? [ returned
] : arguments
532 func
.call( deferred
, deferred
);
540 })( jQuery
, window
);