2 * jQuery Migrate - v1.4.0 - 2016-02-26
3 * Copyright jQuery Foundation and other contributors
5 (function( jQuery, window, undefined ) {
6 // See http://bugs.jquery.com/ticket/13335
10 jQuery.migrateVersion = "1.4.0";
15 // List of warnings already given; public read only
16 jQuery.migrateWarnings = [];
18 // Set to true to prevent console output; migrateWarnings still maintained
19 // jQuery.migrateMute = false;
21 // Show a message on the console so devs know we're active
22 if ( window.console && window.console.log ) {
23 window.console.log( "JQMIGRATE: Migrate is installed" +
24 ( jQuery.migrateMute ? "" : " with logging active" ) +
25 ", version " + jQuery.migrateVersion );
28 // Set to false to disable traces that appear with warnings
29 if ( jQuery.migrateTrace === undefined ) {
30 jQuery.migrateTrace = true;
33 // Forget any warnings we've already given; public
34 jQuery.migrateReset = function() {
36 jQuery.migrateWarnings.length = 0;
39 function migrateWarn( msg) {
40 var console = window.console;
41 if ( !warnedAbout[ msg ] ) {
42 warnedAbout[ msg ] = true;
43 jQuery.migrateWarnings.push( msg );
44 if ( console && console.warn && !jQuery.migrateMute ) {
45 console.warn( "JQMIGRATE: " + msg );
46 if ( jQuery.migrateTrace && console.trace ) {
53 function migrateWarnProp( obj, prop, value, msg ) {
54 if ( Object.defineProperty ) {
55 // On ES5 browsers (non-oldIE), warn if the code tries to get prop;
56 // allow property to be overwritten in case some other plugin wants it
58 Object.defineProperty( obj, prop, {
65 set: function( newValue ) {
72 // IE8 is a dope about Object.defineProperty, can't warn there
76 // Non-ES5 (or broken) browser; just set the property
77 jQuery._definePropertyBroken = true;
81 if ( document.compatMode === "BackCompat" ) {
82 // jQuery has never supported or tested Quirks Mode
83 migrateWarn( "jQuery is not compatible with Quirks Mode" );
87 var attrFn = jQuery( "<input/>", { size: 1 } ).attr("size") && jQuery.attrFn,
88 oldAttr = jQuery.attr,
89 valueAttrGet = jQuery.attrHooks.value && jQuery.attrHooks.value.get ||
90 function() { return null; },
91 valueAttrSet = jQuery.attrHooks.value && jQuery.attrHooks.value.set ||
92 function() { return undefined; },
93 rnoType = /^(?:input|button)$/i,
94 rnoAttrNodeType = /^[238]$/,
95 rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
96 ruseDefault = /^(?:checked|selected)$/i;
99 migrateWarnProp( jQuery, "attrFn", attrFn || {}, "jQuery.attrFn is deprecated" );
101 jQuery.attr = function( elem, name, value, pass ) {
102 var lowerName = name.toLowerCase(),
103 nType = elem && elem.nodeType;
106 // Since pass is used internally, we only warn for new jQuery
107 // versions where there isn't a pass arg in the formal params
108 if ( oldAttr.length < 4 ) {
109 migrateWarn("jQuery.fn.attr( props, pass ) is deprecated");
111 if ( elem && !rnoAttrNodeType.test( nType ) &&
112 (attrFn ? name in attrFn : jQuery.isFunction(jQuery.fn[name])) ) {
113 return jQuery( elem )[ name ]( value );
117 // Warn if user tries to set `type`, since it breaks on IE 6/7/8; by checking
118 // for disconnected elements we don't warn on $( "<button>", { type: "button" } ).
119 if ( name === "type" && value !== undefined && rnoType.test( elem.nodeName ) && elem.parentNode ) {
120 migrateWarn("Can't change the 'type' of an input or button in IE 6/7/8");
123 // Restore boolHook for boolean property/attribute synchronization
124 if ( !jQuery.attrHooks[ lowerName ] && rboolean.test( lowerName ) ) {
125 jQuery.attrHooks[ lowerName ] = {
126 get: function( elem, name ) {
127 // Align boolean attributes with corresponding properties
128 // Fall back to attribute presence where some booleans are not supported
130 property = jQuery.prop( elem, name );
131 return property === true || typeof property !== "boolean" &&
132 ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ?
137 set: function( elem, value, name ) {
139 if ( value === false ) {
140 // Remove boolean attributes when set to false
141 jQuery.removeAttr( elem, name );
143 // value is true since we know at this point it's type boolean and not false
144 // Set boolean attributes to the same name and set the DOM property
145 propName = jQuery.propFix[ name ] || name;
146 if ( propName in elem ) {
147 // Only set the IDL specifically if it already exists on the element
148 elem[ propName ] = true;
151 elem.setAttribute( name, name.toLowerCase() );
157 // Warn only for attributes that can remain distinct from their properties post-1.9
158 if ( ruseDefault.test( lowerName ) ) {
159 migrateWarn( "jQuery.fn.attr('" + lowerName + "') might use property instead of attribute" );
163 return oldAttr.call( jQuery, elem, name, value );
167 jQuery.attrHooks.value = {
168 get: function( elem, name ) {
169 var nodeName = ( elem.nodeName || "" ).toLowerCase();
170 if ( nodeName === "button" ) {
171 return valueAttrGet.apply( this, arguments );
173 if ( nodeName !== "input" && nodeName !== "option" ) {
174 migrateWarn("jQuery.fn.attr('value') no longer gets properties");
176 return name in elem ?
180 set: function( elem, value ) {
181 var nodeName = ( elem.nodeName || "" ).toLowerCase();
182 if ( nodeName === "button" ) {
183 return valueAttrSet.apply( this, arguments );
185 if ( nodeName !== "input" && nodeName !== "option" ) {
186 migrateWarn("jQuery.fn.attr('value', val) no longer sets properties");
188 // Does not return so that setAttribute is also used
194 var matched, browser,
195 oldInit = jQuery.fn.init,
196 oldParseJSON = jQuery.parseJSON,
197 rspaceAngle = /^\s*</,
198 rattrHash = /\[\s*\w+\s*[~|^$*]?=\s*(?![\s'"])[^#\]]*#/,
199 // Note: XSS check is done below after string is trimmed
200 rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/;
202 // $(html) "looks like html" rule change
203 jQuery.fn.init = function( selector, context, rootjQuery ) {
206 if ( selector && typeof selector === "string" && !jQuery.isPlainObject( context ) &&
207 (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) {
208 // This is an HTML string according to the "old" rules; is it still?
209 if ( !rspaceAngle.test( selector ) ) {
210 migrateWarn("$(html) HTML strings must start with '<' character");
213 migrateWarn("$(html) HTML text after last tag is ignored");
216 // Consistently reject any HTML-like string starting with a hash (#9521)
217 // Note that this may break jQuery 1.6.x code that otherwise would work.
218 if ( match[ 0 ].charAt( 0 ) === "#" ) {
219 migrateWarn("HTML string cannot start with a '#' character");
220 jQuery.error("JQMIGRATE: Invalid selector string (XSS)");
222 // Now process using loose rules; let pre-1.8 play too
223 if ( context && context.context ) {
224 // jQuery object as context; parseHTML expects a DOM object
225 context = context.context;
227 if ( jQuery.parseHTML ) {
228 return oldInit.call( this,
229 jQuery.parseHTML( match[ 2 ], context && context.ownerDocument ||
230 context || document, true ), context, rootjQuery );
234 if ( selector === "#" ) {
236 // jQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0
237 migrateWarn( "jQuery( '#' ) is not a valid selector" );
240 } else if ( rattrHash.test( selector ) ) {
242 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
243 // Note that this doesn't actually fix the selector due to potential false positives
244 migrateWarn( "Attribute selectors with '#' must be quoted: '" + selector + "'" );
247 ret = oldInit.apply( this, arguments );
249 // Fill in selector and context properties so .live() works
250 if ( selector && selector.selector !== undefined ) {
251 // A jQuery object, copy its properties
252 ret.selector = selector.selector;
253 ret.context = selector.context;
256 ret.selector = typeof selector === "string" ? selector : "";
258 ret.context = selector.nodeType? selector : context || document;
264 jQuery.fn.init.prototype = jQuery.fn;
266 // Let $.parseJSON(falsy_value) return null
267 jQuery.parseJSON = function( json ) {
269 migrateWarn("jQuery.parseJSON requires a valid JSON string");
272 return oldParseJSON.apply( this, arguments );
275 jQuery.uaMatch = function( ua ) {
276 ua = ua.toLowerCase();
278 var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
279 /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
280 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
281 /(msie) ([\w.]+)/.exec( ua ) ||
282 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
286 browser: match[ 1 ] || "",
287 version: match[ 2 ] || "0"
291 // Don't clobber any existing jQuery.browser in case it's different
292 if ( !jQuery.browser ) {
293 matched = jQuery.uaMatch( navigator.userAgent );
296 if ( matched.browser ) {
297 browser[ matched.browser ] = true;
298 browser.version = matched.version;
301 // Chrome is Webkit, but Webkit is also Safari.
302 if ( browser.chrome ) {
303 browser.webkit = true;
304 } else if ( browser.webkit ) {
305 browser.safari = true;
308 jQuery.browser = browser;
311 // Warn if the code tries to get jQuery.browser
312 migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" );
314 // jQuery.boxModel deprecated in 1.3, jQuery.support.boxModel deprecated in 1.7
315 jQuery.boxModel = jQuery.support.boxModel = (document.compatMode === "CSS1Compat");
316 migrateWarnProp( jQuery, "boxModel", jQuery.boxModel, "jQuery.boxModel is deprecated" );
317 migrateWarnProp( jQuery.support, "boxModel", jQuery.support.boxModel, "jQuery.support.boxModel is deprecated" );
319 jQuery.sub = function() {
320 function jQuerySub( selector, context ) {
321 return new jQuerySub.fn.init( selector, context );
323 jQuery.extend( true, jQuerySub, this );
324 jQuerySub.superclass = this;
325 jQuerySub.fn = jQuerySub.prototype = this();
326 jQuerySub.fn.constructor = jQuerySub;
327 jQuerySub.sub = this.sub;
328 jQuerySub.fn.init = function init( selector, context ) {
329 var instance = jQuery.fn.init.call( this, selector, context, rootjQuerySub );
330 return instance instanceof jQuerySub ?
332 jQuerySub( instance );
334 jQuerySub.fn.init.prototype = jQuerySub.fn;
335 var rootjQuerySub = jQuerySub(document);
336 migrateWarn( "jQuery.sub() is deprecated" );
340 // The number of elements contained in the matched element set
341 jQuery.fn.size = function() {
342 migrateWarn( "jQuery.fn.size() is deprecated; use the .length property" );
347 var internalSwapCall = false;
349 // If this version of jQuery has .swap(), don't false-alarm on internal uses
351 jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
352 var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
355 jQuery.cssHooks[ name ].get = function() {
358 internalSwapCall = true;
359 ret = oldHook.apply( this, arguments );
360 internalSwapCall = false;
367 jQuery.swap = function( elem, options, callback, args ) {
371 if ( !internalSwapCall ) {
372 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
375 // Remember the old values, and insert the new ones
376 for ( name in options ) {
377 old[ name ] = elem.style[ name ];
378 elem.style[ name ] = options[ name ];
381 ret = callback.apply( elem, args || [] );
383 // Revert the old values
384 for ( name in options ) {
385 elem.style[ name ] = old[ name ];
392 // Ensure that $.ajax gets the new parseJSON defined in core.js
395 "text json": jQuery.parseJSON
400 var oldFnData = jQuery.fn.data;
402 jQuery.fn.data = function( name ) {
406 // Handles 1.7 which has this behavior and 1.8 which doesn't
407 if ( elem && name === "events" && arguments.length === 1 ) {
408 ret = jQuery.data( elem, name );
409 evt = jQuery._data( elem, name );
410 if ( ( ret === undefined || ret === evt ) && evt !== undefined ) {
411 migrateWarn("Use of jQuery.fn.data('events') is deprecated");
415 return oldFnData.apply( this, arguments );
419 var rscriptType = /\/(java|ecma)script/i;
421 // Since jQuery.clean is used internally on older versions, we only shim if it's missing
422 if ( !jQuery.clean ) {
423 jQuery.clean = function( elems, context, fragment, scripts ) {
424 // Set context per 1.8 logic
425 context = context || document;
426 context = !context.nodeType && context[0] || context;
427 context = context.ownerDocument || context;
429 migrateWarn("jQuery.clean() is deprecated");
431 var i, elem, handleScript, jsTags,
434 jQuery.merge( ret, jQuery.buildFragment( elems, context ).childNodes );
436 // Complex logic lifted directly from jQuery 1.8
438 // Special handling of each script element
439 handleScript = function( elem ) {
440 // Check if we consider it executable
441 if ( !elem.type || rscriptType.test( elem.type ) ) {
442 // Detach the script and store it in the scripts array (if provided) or the fragment
443 // Return truthy to indicate that it has been handled
445 scripts.push( elem.parentNode ? elem.parentNode.removeChild( elem ) : elem ) :
446 fragment.appendChild( elem );
450 for ( i = 0; (elem = ret[i]) != null; i++ ) {
451 // Check if we're done after handling an executable script
452 if ( !( jQuery.nodeName( elem, "script" ) && handleScript( elem ) ) ) {
453 // Append to fragment and handle embedded scripts
454 fragment.appendChild( elem );
455 if ( typeof elem.getElementsByTagName !== "undefined" ) {
456 // handleScript alters the DOM, so use jQuery.merge to ensure snapshot iteration
457 jsTags = jQuery.grep( jQuery.merge( [], elem.getElementsByTagName("script") ), handleScript );
459 // Splice the scripts into ret after their former ancestor and advance our index beyond them
460 ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
471 var eventAdd = jQuery.event.add,
472 eventRemove = jQuery.event.remove,
473 eventTrigger = jQuery.event.trigger,
474 oldToggle = jQuery.fn.toggle,
475 oldLive = jQuery.fn.live,
476 oldDie = jQuery.fn.die,
477 oldLoad = jQuery.fn.load,
478 ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess",
479 rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ),
480 rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
481 hoverHack = function( events ) {
482 if ( typeof( events ) !== "string" || jQuery.event.special.hover ) {
485 if ( rhoverHack.test( events ) ) {
486 migrateWarn("'hover' pseudo-event is deprecated, use 'mouseenter mouseleave'");
488 return events && events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
491 // Event props removed in 1.9, put them back if needed; no practical way to warn them
492 if ( jQuery.event.props && jQuery.event.props[ 0 ] !== "attrChange" ) {
493 jQuery.event.props.unshift( "attrChange", "attrName", "relatedNode", "srcElement" );
496 // Undocumented jQuery.event.handle was "deprecated" in jQuery 1.7
497 if ( jQuery.event.dispatch ) {
498 migrateWarnProp( jQuery.event, "handle", jQuery.event.dispatch, "jQuery.event.handle is undocumented and deprecated" );
501 // Support for 'hover' pseudo-event and ajax event warnings
502 jQuery.event.add = function( elem, types, handler, data, selector ){
503 if ( elem !== document && rajaxEvent.test( types ) ) {
504 migrateWarn( "AJAX events should be attached to document: " + types );
506 eventAdd.call( this, elem, hoverHack( types || "" ), handler, data, selector );
508 jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){
509 eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes );
512 jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
514 jQuery.fn[ name ] = function() {
515 var args = Array.prototype.slice.call( arguments, 0 );
517 // If this is an ajax load() the first arg should be the string URL;
518 // technically this could also be the "Anything" arg of the event .load()
519 // which just goes to show why this dumb signature has been deprecated!
520 // jQuery custom builds that exclude the Ajax module justifiably die here.
521 if ( name === "load" && typeof args[ 0 ] === "string" ) {
522 return oldLoad.apply( this, args );
525 migrateWarn( "jQuery.fn." + name + "() is deprecated" );
527 args.splice( 0, 0, name );
528 if ( arguments.length ) {
529 return this.bind.apply( this, args );
532 // Use .triggerHandler here because:
533 // - load and unload events don't need to bubble, only applied to window or image
534 // - error event should not bubble to window, although it does pre-1.7
535 // See http://bugs.jquery.com/ticket/11820
536 this.triggerHandler.apply( this, args );
542 jQuery.fn.toggle = function( fn, fn2 ) {
544 // Don't mess with animation or css toggles
545 if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {
546 return oldToggle.apply( this, arguments );
548 migrateWarn("jQuery.fn.toggle(handler, handler...) is deprecated");
550 // Save reference to arguments for access in closure
551 var args = arguments,
552 guid = fn.guid || jQuery.guid++,
554 toggler = function( event ) {
555 // Figure out which function to execute
556 var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
557 jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
559 // Make sure that clicks stop
560 event.preventDefault();
562 // and execute the function
563 return args[ lastToggle ].apply( this, arguments ) || false;
566 // link all the functions, so any of them can unbind this click handler
568 while ( i < args.length ) {
569 args[ i++ ].guid = guid;
572 return this.click( toggler );
575 jQuery.fn.live = function( types, data, fn ) {
576 migrateWarn("jQuery.fn.live() is deprecated");
578 return oldLive.apply( this, arguments );
580 jQuery( this.context ).on( types, this.selector, data, fn );
584 jQuery.fn.die = function( types, fn ) {
585 migrateWarn("jQuery.fn.die() is deprecated");
587 return oldDie.apply( this, arguments );
589 jQuery( this.context ).off( types, this.selector || "**", fn );
593 // Turn global events into document-triggered events
594 jQuery.event.trigger = function( event, data, elem, onlyHandlers ){
595 if ( !elem && !rajaxEvent.test( event ) ) {
596 migrateWarn( "Global events are undocumented and deprecated" );
598 return eventTrigger.call( this, event, data, elem || document, onlyHandlers );
600 jQuery.each( ajaxEvents.split("|"),
601 function( _, name ) {
602 jQuery.event.special[ name ] = {
606 // The document needs no shimming; must be !== for oldIE
607 if ( elem !== document ) {
608 jQuery.event.add( document, name + "." + jQuery.guid, function() {
609 jQuery.event.trigger( name, Array.prototype.slice.call( arguments, 1 ), elem, true );
611 jQuery._data( this, name, jQuery.guid++ );
615 teardown: function() {
616 if ( this !== document ) {
617 jQuery.event.remove( document, name + "." + jQuery._data( this, name ) );
625 jQuery.event.special.ready = {
627 if ( this === document ) {
628 migrateWarn( "'ready' event is deprecated" );
633 var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack,
634 oldFind = jQuery.fn.find;
636 jQuery.fn.andSelf = function() {
637 migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()");
638 return oldSelf.apply( this, arguments );
641 jQuery.fn.find = function( selector ) {
642 var ret = oldFind.apply( this, arguments );
643 ret.context = this.context;
644 ret.selector = this.selector ? this.selector + " " + selector : selector;
649 // jQuery 1.6 did not support Callbacks, do not warn there
650 if ( jQuery.Callbacks ) {
652 var oldDeferred = jQuery.Deferred,
654 // action, add listener, callbacks, .then handlers, final state
655 [ "resolve", "done", jQuery.Callbacks("once memory"),
656 jQuery.Callbacks("once memory"), "resolved" ],
657 [ "reject", "fail", jQuery.Callbacks("once memory"),
658 jQuery.Callbacks("once memory"), "rejected" ],
659 [ "notify", "progress", jQuery.Callbacks("memory"),
660 jQuery.Callbacks("memory") ]
663 jQuery.Deferred = function( func ) {
664 var deferred = oldDeferred(),
665 promise = deferred.promise();
667 deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
670 migrateWarn( "deferred.pipe() is deprecated" );
672 return jQuery.Deferred(function( newDefer ) {
673 jQuery.each( tuples, function( i, tuple ) {
674 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
675 // deferred.done(function() { bind to newDefer or newDefer.resolve })
676 // deferred.fail(function() { bind to newDefer or newDefer.reject })
677 // deferred.progress(function() { bind to newDefer or newDefer.notify })
678 deferred[ tuple[1] ](function() {
679 var returned = fn && fn.apply( this, arguments );
680 if ( returned && jQuery.isFunction( returned.promise ) ) {
682 .done( newDefer.resolve )
683 .fail( newDefer.reject )
684 .progress( newDefer.notify );
686 newDefer[ tuple[ 0 ] + "With" ](
687 this === promise ? newDefer.promise() : this,
688 fn ? [ returned ] : arguments
698 deferred.isResolved = function() {
699 migrateWarn( "deferred.isResolved is deprecated" );
700 return deferred.state() === "resolved";
703 deferred.isRejected = function() {
704 migrateWarn( "deferred.isRejected is deprecated" );
705 return deferred.state() === "rejected";
709 func.call( deferred, deferred );
717 })( jQuery, window );