2 * jQuery Migrate - v1.4.1 - 2016-05-19
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.1";
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 oldFind = jQuery.find,
197 oldParseJSON = jQuery.parseJSON,
198 rspaceAngle = /^\s*</,
199 rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
200 rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g,
201 // Note: XSS check is done below after string is trimmed
202 rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/;
204 // $(html) "looks like html" rule change
205 jQuery.fn.init = function( selector, context, rootjQuery ) {
208 if ( selector && typeof selector === "string" ) {
209 if ( !jQuery.isPlainObject( context ) &&
210 (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) {
212 // This is an HTML string according to the "old" rules; is it still?
213 if ( !rspaceAngle.test( selector ) ) {
214 migrateWarn("$(html) HTML strings must start with '<' character");
217 migrateWarn("$(html) HTML text after last tag is ignored");
220 // Consistently reject any HTML-like string starting with a hash (gh-9521)
221 // Note that this may break jQuery 1.6.x code that otherwise would work.
222 if ( match[ 0 ].charAt( 0 ) === "#" ) {
223 migrateWarn("HTML string cannot start with a '#' character");
224 jQuery.error("JQMIGRATE: Invalid selector string (XSS)");
227 // Now process using loose rules; let pre-1.8 play too
228 // Is this a jQuery context? parseHTML expects a DOM element (#178)
229 if ( context && context.context && context.context.nodeType ) {
230 context = context.context;
233 if ( jQuery.parseHTML ) {
234 return oldInit.call( this,
235 jQuery.parseHTML( match[ 2 ], context && context.ownerDocument ||
236 context || document, true ), context, rootjQuery );
241 ret = oldInit.apply( this, arguments );
243 // Fill in selector and context properties so .live() works
244 if ( selector && selector.selector !== undefined ) {
245 // A jQuery object, copy its properties
246 ret.selector = selector.selector;
247 ret.context = selector.context;
250 ret.selector = typeof selector === "string" ? selector : "";
252 ret.context = selector.nodeType? selector : context || document;
258 jQuery.fn.init.prototype = jQuery.fn;
260 jQuery.find = function( selector ) {
261 var args = Array.prototype.slice.call( arguments );
263 // Support: PhantomJS 1.x
264 // String#match fails to match when used with a //g RegExp, only on some strings
265 if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
267 // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
268 // First see if qS thinks it's a valid selector, if so avoid a false positive
270 document.querySelector( selector );
273 // Didn't *look* valid to qSA, warn and try quoting what we think is the value
274 selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
275 return "[" + attr + op + "\"" + value + "\"]";
278 // If the regexp *may* have created an invalid selector, don't update it
279 // Note that there may be false alarms if selector uses jQuery extensions
281 document.querySelector( selector );
282 migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
283 args[ 0 ] = selector;
285 migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
290 return oldFind.apply( this, args );
293 // Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
295 for ( findProp in oldFind ) {
296 if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
297 jQuery.find[ findProp ] = oldFind[ findProp ];
301 // Let $.parseJSON(falsy_value) return null
302 jQuery.parseJSON = function( json ) {
304 migrateWarn("jQuery.parseJSON requires a valid JSON string");
307 return oldParseJSON.apply( this, arguments );
310 jQuery.uaMatch = function( ua ) {
311 ua = ua.toLowerCase();
313 var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
314 /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
315 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
316 /(msie) ([\w.]+)/.exec( ua ) ||
317 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
321 browser: match[ 1 ] || "",
322 version: match[ 2 ] || "0"
326 // Don't clobber any existing jQuery.browser in case it's different
327 if ( !jQuery.browser ) {
328 matched = jQuery.uaMatch( navigator.userAgent );
331 if ( matched.browser ) {
332 browser[ matched.browser ] = true;
333 browser.version = matched.version;
336 // Chrome is Webkit, but Webkit is also Safari.
337 if ( browser.chrome ) {
338 browser.webkit = true;
339 } else if ( browser.webkit ) {
340 browser.safari = true;
343 jQuery.browser = browser;
346 // Warn if the code tries to get jQuery.browser
347 migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" );
349 // jQuery.boxModel deprecated in 1.3, jQuery.support.boxModel deprecated in 1.7
350 jQuery.boxModel = jQuery.support.boxModel = (document.compatMode === "CSS1Compat");
351 migrateWarnProp( jQuery, "boxModel", jQuery.boxModel, "jQuery.boxModel is deprecated" );
352 migrateWarnProp( jQuery.support, "boxModel", jQuery.support.boxModel, "jQuery.support.boxModel is deprecated" );
354 jQuery.sub = function() {
355 function jQuerySub( selector, context ) {
356 return new jQuerySub.fn.init( selector, context );
358 jQuery.extend( true, jQuerySub, this );
359 jQuerySub.superclass = this;
360 jQuerySub.fn = jQuerySub.prototype = this();
361 jQuerySub.fn.constructor = jQuerySub;
362 jQuerySub.sub = this.sub;
363 jQuerySub.fn.init = function init( selector, context ) {
364 var instance = jQuery.fn.init.call( this, selector, context, rootjQuerySub );
365 return instance instanceof jQuerySub ?
367 jQuerySub( instance );
369 jQuerySub.fn.init.prototype = jQuerySub.fn;
370 var rootjQuerySub = jQuerySub(document);
371 migrateWarn( "jQuery.sub() is deprecated" );
375 // The number of elements contained in the matched element set
376 jQuery.fn.size = function() {
377 migrateWarn( "jQuery.fn.size() is deprecated; use the .length property" );
382 var internalSwapCall = false;
384 // If this version of jQuery has .swap(), don't false-alarm on internal uses
386 jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
387 var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
390 jQuery.cssHooks[ name ].get = function() {
393 internalSwapCall = true;
394 ret = oldHook.apply( this, arguments );
395 internalSwapCall = false;
402 jQuery.swap = function( elem, options, callback, args ) {
406 if ( !internalSwapCall ) {
407 migrateWarn( "jQuery.swap() is undocumented and deprecated" );
410 // Remember the old values, and insert the new ones
411 for ( name in options ) {
412 old[ name ] = elem.style[ name ];
413 elem.style[ name ] = options[ name ];
416 ret = callback.apply( elem, args || [] );
418 // Revert the old values
419 for ( name in options ) {
420 elem.style[ name ] = old[ name ];
427 // Ensure that $.ajax gets the new parseJSON defined in core.js
430 "text json": jQuery.parseJSON
435 var oldFnData = jQuery.fn.data;
437 jQuery.fn.data = function( name ) {
441 // Handles 1.7 which has this behavior and 1.8 which doesn't
442 if ( elem && name === "events" && arguments.length === 1 ) {
443 ret = jQuery.data( elem, name );
444 evt = jQuery._data( elem, name );
445 if ( ( ret === undefined || ret === evt ) && evt !== undefined ) {
446 migrateWarn("Use of jQuery.fn.data('events') is deprecated");
450 return oldFnData.apply( this, arguments );
454 var rscriptType = /\/(java|ecma)script/i;
456 // Since jQuery.clean is used internally on older versions, we only shim if it's missing
457 if ( !jQuery.clean ) {
458 jQuery.clean = function( elems, context, fragment, scripts ) {
459 // Set context per 1.8 logic
460 context = context || document;
461 context = !context.nodeType && context[0] || context;
462 context = context.ownerDocument || context;
464 migrateWarn("jQuery.clean() is deprecated");
466 var i, elem, handleScript, jsTags,
469 jQuery.merge( ret, jQuery.buildFragment( elems, context ).childNodes );
471 // Complex logic lifted directly from jQuery 1.8
473 // Special handling of each script element
474 handleScript = function( elem ) {
475 // Check if we consider it executable
476 if ( !elem.type || rscriptType.test( elem.type ) ) {
477 // Detach the script and store it in the scripts array (if provided) or the fragment
478 // Return truthy to indicate that it has been handled
480 scripts.push( elem.parentNode ? elem.parentNode.removeChild( elem ) : elem ) :
481 fragment.appendChild( elem );
485 for ( i = 0; (elem = ret[i]) != null; i++ ) {
486 // Check if we're done after handling an executable script
487 if ( !( jQuery.nodeName( elem, "script" ) && handleScript( elem ) ) ) {
488 // Append to fragment and handle embedded scripts
489 fragment.appendChild( elem );
490 if ( typeof elem.getElementsByTagName !== "undefined" ) {
491 // handleScript alters the DOM, so use jQuery.merge to ensure snapshot iteration
492 jsTags = jQuery.grep( jQuery.merge( [], elem.getElementsByTagName("script") ), handleScript );
494 // Splice the scripts into ret after their former ancestor and advance our index beyond them
495 ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
506 var eventAdd = jQuery.event.add,
507 eventRemove = jQuery.event.remove,
508 eventTrigger = jQuery.event.trigger,
509 oldToggle = jQuery.fn.toggle,
510 oldLive = jQuery.fn.live,
511 oldDie = jQuery.fn.die,
512 oldLoad = jQuery.fn.load,
513 ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess",
514 rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ),
515 rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
516 hoverHack = function( events ) {
517 if ( typeof( events ) !== "string" || jQuery.event.special.hover ) {
520 if ( rhoverHack.test( events ) ) {
521 migrateWarn("'hover' pseudo-event is deprecated, use 'mouseenter mouseleave'");
523 return events && events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
526 // Event props removed in 1.9, put them back if needed; no practical way to warn them
527 if ( jQuery.event.props && jQuery.event.props[ 0 ] !== "attrChange" ) {
528 jQuery.event.props.unshift( "attrChange", "attrName", "relatedNode", "srcElement" );
531 // Undocumented jQuery.event.handle was "deprecated" in jQuery 1.7
532 if ( jQuery.event.dispatch ) {
533 migrateWarnProp( jQuery.event, "handle", jQuery.event.dispatch, "jQuery.event.handle is undocumented and deprecated" );
536 // Support for 'hover' pseudo-event and ajax event warnings
537 jQuery.event.add = function( elem, types, handler, data, selector ){
538 if ( elem !== document && rajaxEvent.test( types ) ) {
539 migrateWarn( "AJAX events should be attached to document: " + types );
541 eventAdd.call( this, elem, hoverHack( types || "" ), handler, data, selector );
543 jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){
544 eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes );
547 jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
549 jQuery.fn[ name ] = function() {
550 var args = Array.prototype.slice.call( arguments, 0 );
552 // If this is an ajax load() the first arg should be the string URL;
553 // technically this could also be the "Anything" arg of the event .load()
554 // which just goes to show why this dumb signature has been deprecated!
555 // jQuery custom builds that exclude the Ajax module justifiably die here.
556 if ( name === "load" && typeof args[ 0 ] === "string" ) {
557 return oldLoad.apply( this, args );
560 migrateWarn( "jQuery.fn." + name + "() is deprecated" );
562 args.splice( 0, 0, name );
563 if ( arguments.length ) {
564 return this.bind.apply( this, args );
567 // Use .triggerHandler here because:
568 // - load and unload events don't need to bubble, only applied to window or image
569 // - error event should not bubble to window, although it does pre-1.7
570 // See http://bugs.jquery.com/ticket/11820
571 this.triggerHandler.apply( this, args );
577 jQuery.fn.toggle = function( fn, fn2 ) {
579 // Don't mess with animation or css toggles
580 if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {
581 return oldToggle.apply( this, arguments );
583 migrateWarn("jQuery.fn.toggle(handler, handler...) is deprecated");
585 // Save reference to arguments for access in closure
586 var args = arguments,
587 guid = fn.guid || jQuery.guid++,
589 toggler = function( event ) {
590 // Figure out which function to execute
591 var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
592 jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
594 // Make sure that clicks stop
595 event.preventDefault();
597 // and execute the function
598 return args[ lastToggle ].apply( this, arguments ) || false;
601 // link all the functions, so any of them can unbind this click handler
603 while ( i < args.length ) {
604 args[ i++ ].guid = guid;
607 return this.click( toggler );
610 jQuery.fn.live = function( types, data, fn ) {
611 migrateWarn("jQuery.fn.live() is deprecated");
613 return oldLive.apply( this, arguments );
615 jQuery( this.context ).on( types, this.selector, data, fn );
619 jQuery.fn.die = function( types, fn ) {
620 migrateWarn("jQuery.fn.die() is deprecated");
622 return oldDie.apply( this, arguments );
624 jQuery( this.context ).off( types, this.selector || "**", fn );
628 // Turn global events into document-triggered events
629 jQuery.event.trigger = function( event, data, elem, onlyHandlers ){
630 if ( !elem && !rajaxEvent.test( event ) ) {
631 migrateWarn( "Global events are undocumented and deprecated" );
633 return eventTrigger.call( this, event, data, elem || document, onlyHandlers );
635 jQuery.each( ajaxEvents.split("|"),
636 function( _, name ) {
637 jQuery.event.special[ name ] = {
641 // The document needs no shimming; must be !== for oldIE
642 if ( elem !== document ) {
643 jQuery.event.add( document, name + "." + jQuery.guid, function() {
644 jQuery.event.trigger( name, Array.prototype.slice.call( arguments, 1 ), elem, true );
646 jQuery._data( this, name, jQuery.guid++ );
650 teardown: function() {
651 if ( this !== document ) {
652 jQuery.event.remove( document, name + "." + jQuery._data( this, name ) );
660 jQuery.event.special.ready = {
662 if ( this === document ) {
663 migrateWarn( "'ready' event is deprecated" );
668 var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack,
669 oldFnFind = jQuery.fn.find;
671 jQuery.fn.andSelf = function() {
672 migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()");
673 return oldSelf.apply( this, arguments );
676 jQuery.fn.find = function( selector ) {
677 var ret = oldFnFind.apply( this, arguments );
678 ret.context = this.context;
679 ret.selector = this.selector ? this.selector + " " + selector : selector;
684 // jQuery 1.6 did not support Callbacks, do not warn there
685 if ( jQuery.Callbacks ) {
687 var oldDeferred = jQuery.Deferred,
689 // action, add listener, callbacks, .then handlers, final state
690 [ "resolve", "done", jQuery.Callbacks("once memory"),
691 jQuery.Callbacks("once memory"), "resolved" ],
692 [ "reject", "fail", jQuery.Callbacks("once memory"),
693 jQuery.Callbacks("once memory"), "rejected" ],
694 [ "notify", "progress", jQuery.Callbacks("memory"),
695 jQuery.Callbacks("memory") ]
698 jQuery.Deferred = function( func ) {
699 var deferred = oldDeferred(),
700 promise = deferred.promise();
702 deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
705 migrateWarn( "deferred.pipe() is deprecated" );
707 return jQuery.Deferred(function( newDefer ) {
708 jQuery.each( tuples, function( i, tuple ) {
709 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
710 // deferred.done(function() { bind to newDefer or newDefer.resolve })
711 // deferred.fail(function() { bind to newDefer or newDefer.reject })
712 // deferred.progress(function() { bind to newDefer or newDefer.notify })
713 deferred[ tuple[1] ](function() {
714 var returned = fn && fn.apply( this, arguments );
715 if ( returned && jQuery.isFunction( returned.promise ) ) {
717 .done( newDefer.resolve )
718 .fail( newDefer.reject )
719 .progress( newDefer.notify );
721 newDefer[ tuple[ 0 ] + "With" ](
722 this === promise ? newDefer.promise() : this,
723 fn ? [ returned ] : arguments
733 deferred.isResolved = function() {
734 migrateWarn( "deferred.isResolved is deprecated" );
735 return deferred.state() === "resolved";
738 deferred.isRejected = function() {
739 migrateWarn( "deferred.isRejected is deprecated" );
740 return deferred.state() === "rejected";
744 func.call( deferred, deferred );
752 })( jQuery, window );