(function( jquery, window, undefined ) {
// see http://bugs.jquery.com/ticket/13335
// "use strict";
jquery.migrateversion = " ";
var warnedabout = {};
// list of warnings already given; public read only
jquery.migratewarnings = [];
// set to true to prevent console output; migratewarnings still maintained
// jquery.migratemute = false;
// show a message on the console so devs know we're active
if ( !jquery.migratemute && window.console && window.console.log ) {
window.console.log("jqmigrate: logging is active");
}
// set to false to disable traces that appear with warnings
if ( jquery.migratetrace === undefined ) {
jquery.migratetrace = true;
}
// forget any warnings we've already given; public
jquery.migratereset = function() {
warnedabout = {};
jquery.migratewarnings.length = 0;
};
function migratewarn( msg) {
var console = window.console;
if ( !warnedabout[ msg ] ) {
warnedabout[ msg ] = true;
jquery.migratewarnings.push( msg );
if ( console && console.warn && !jquery.migratemute ) {
console.warn( "jqmigrate: " + msg );
if ( jquery.migratetrace && console.trace ) {
console.trace();
}
}
}
}
function migratewarnprop( obj, prop, value, msg ) {
if ( object.defineproperty ) {
// on es5 browsers (non-oldie), warn if the code tries to get prop;
// allow property to be overwritten in case some other plugin wants it
try {
object.defineproperty( obj, prop, {
configurable: true,
enumerable: true,
get: function() {
migratewarn( msg );
return value;
},
set: function( newvalue ) {
migratewarn( msg );
value = newvalue;
}
});
return;
} catch( err ) {
// ie8 is a dope about object.defineproperty, can't warn there
}
}
// non-es5 (or broken) browser; just set the property
jquery._definepropertybroken = true;
obj[ prop ] = value;
}
if ( document.compatmode === "backcompat" ) {
// jquery has never supported or tested quirks mode
migratewarn( "jquery is not compatible with quirks mode" );
}
var attrfn = jquery( " ", { size: 1 } ).attr("size") && jquery.attrfn,
oldattr = jquery.attr,
valueattrget = jquery.attrhooks.value && jquery.attrhooks.value.get ||
function() { return null; },
valueattrset = jquery.attrhooks.value && jquery.attrhooks.value.set ||
function() { return undefined; },
rnotype = /^(?:input|button)$/i,
rnoattrnodetype = /^[238]$/,
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
rusedefault = /^(?:checked|selected)$/i;
// jquery.attrfn
migratewarnprop( jquery, "attrfn", attrfn || {}, "jquery.attrfn is deprecated" );
jquery.attr = function( elem, name, value, pass ) {
var lowername = name.tolowercase(),
ntype = elem && elem.nodetype;
if ( pass ) {
// since pass is used internally, we only warn for new jquery
// versions where there isn't a pass arg in the formal params
if ( oldattr.length < 4 ) {
migratewarn("jquery.fn.attr( props, pass ) is deprecated");
}
if ( elem && !rnoattrnodetype.test( ntype ) &&
(attrfn ? name in attrfn : jquery.isfunction(jquery.fn[name])) ) {
return jquery( elem )[ name ]( value );
}
}
// warn if user tries to set `type`, since it breaks on ie 6/7/8; by checking
// for disconnected elements we don't warn on $( "", { type: "button" } ).
if ( name === "type" && value !== undefined && rnotype.test( elem.nodename ) && elem.parentnode ) {
migratewarn("can't change the 'type' of an input or button in ie 6/7/8");
}
// restore boolhook for boolean property/attribute synchronization
if ( !jquery.attrhooks[ lowername ] && rboolean.test( lowername ) ) {
jquery.attrhooks[ lowername ] = {
get: function( elem, name ) {
// align boolean attributes with corresponding properties
// fall back to attribute presence where some booleans are not supported
var attrnode,
property = jquery.prop( elem, name );
return property === true || typeof property !== "boolean" &&
( attrnode = elem.getattributenode(name) ) && attrnode.nodevalue !== false ?
name.tolowercase() :
undefined;
},
set: function( elem, value, name ) {
var propname;
if ( value === false ) {
// remove boolean attributes when set to false
jquery.removeattr( elem, name );
} else {
// value is true since we know at this point it's type boolean and not false
// set boolean attributes to the same name and set the dom property
propname = jquery.propfix[ name ] || name;
if ( propname in elem ) {
// only set the idl specifically if it already exists on the element
elem[ propname ] = true;
}
elem.setattribute( name, name.tolowercase() );
}
return name;
}
};
// warn only for attributes that can remain distinct from their properties post-1.9
if ( rusedefault.test( lowername ) ) {
migratewarn( "jquery.fn.attr('" + lowername + "') might use property instead of attribute" );
}
}
return oldattr.call( jquery, elem, name, value );
};
// attrhooks: value
jquery.attrhooks.value = {
get: function( elem, name ) {
var nodename = ( elem.nodename || "" ).tolowercase();
if ( nodename === "button" ) {
return valueattrget.apply( this, arguments );
}
if ( nodename !== "input" && nodename !== "option" ) {
migratewarn("jquery.fn.attr('value') no longer gets properties");
}
return name in elem ?
elem.value :
null;
},
set: function( elem, value ) {
var nodename = ( elem.nodename || "" ).tolowercase();
if ( nodename === "button" ) {
return valueattrset.apply( this, arguments );
}
if ( nodename !== "input" && nodename !== "option" ) {
migratewarn("jquery.fn.attr('value', val) no longer sets properties");
}
// does not return so that setattribute is also used
elem.value = value;
}
};
var matched, browser,
oldinit = jquery.fn.init,
oldparsejson = jquery.parsejson,
rspaceangle = /^\s*,
// note: xss check is done below after string is trimmed
rquickexpr = /^([^<]*)(<[\w\w]+>)([^>]*)$/;
// $(html) "looks like html" rule change
jquery.fn.init = function( selector, context, rootjquery ) {
var match, ret;
if ( selector && typeof selector === "string" && !jquery.isplainobject( context ) &&
(match = rquickexpr.exec( jquery.trim( selector ) )) && match[ 0 ] ) {
// this is an html string according to the "old" rules; is it still?
if ( !rspaceangle.test( selector ) ) {
migratewarn("$(html) html strings must start with '<' character");
}
if ( match[ 3 ] ) {
migratewarn("$(html) html text after last tag is ignored");
}
// consistently reject any html-like string starting with a hash (#9521)
// note that this may break jquery 1.6.x code that otherwise would work.
if ( match[ 0 ].charat( 0 ) === "#" ) {
migratewarn("html string cannot start with a '#' character");
jquery.error("jqmigrate: invalid selector string (xss)");
}
// now process using loose rules; let pre-1.8 play too
if ( context && context.context ) {
// jquery object as context; parsehtml expects a dom object
context = context.context;
}
if ( jquery.parsehtml ) {
return oldinit.call( this,
jquery.parsehtml( match[ 2 ], context && context.ownerdocument ||
context || document, true ), context, rootjquery );
}
}
// jquery( "#" ) is a bogus id selector, but it returned an empty set before jquery 3.0
if ( selector === "#" ) {
migratewarn( "jquery( '#' ) is not a valid selector" );
selector = [];
}
ret = oldinit.apply( this, arguments );
// fill in selector and context properties so .live() works
if ( selector && selector.selector !== undefined ) {
// a jquery object, copy its properties
ret.selector = selector.selector;
ret.context = selector.context;
} else {
ret.selector = typeof selector === "string" ? selector : "";
if ( selector ) {
ret.context = selector.nodetype? selector : context || document;
}
}
return ret;
};
jquery.fn.init.prototype = jquery.fn;
// let $.parsejson(falsy_value) return null
jquery.parsejson = function( json ) {
if ( !json ) {
migratewarn("jquery.parsejson requires a valid json string");
return null;
}
return oldparsejson.apply( this, arguments );
};
jquery.uamatch = function( ua ) {
ua = ua.tolowercase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexof("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
// don't clobber any existing jquery.browser in case it's different
if ( !jquery.browser ) {
matched = jquery.uamatch( navigator.useragent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
}
// chrome is webkit, but webkit is also safari.
if ( browser.chrome ) {
browser.webkit = true;
} else if ( browser.webkit ) {
browser.safari = true;
}
jquery.browser = browser;
}
// warn if the code tries to get jquery.browser
migratewarnprop( jquery, "browser", jquery.browser, "jquery.browser is deprecated" );
// jquery.boxmodel deprecated in 1.3, jquery.support.boxmodel deprecated in 1.7
jquery.boxmodel = jquery.support.boxmodel = (document.compatmode === "css1compat");
migratewarnprop( jquery, "boxmodel", jquery.boxmodel, "jquery.boxmodel is deprecated" );
migratewarnprop( jquery.support, "boxmodel", jquery.support.boxmodel, "jquery.support.boxmodel is deprecated" );
jquery.sub = function() {
function jquerysub( selector, context ) {
return new jquerysub.fn.init( selector, context );
}
jquery.extend( true, jquerysub, this );
jquerysub.superclass = this;
jquerysub.fn = jquerysub.prototype = this();
jquerysub.fn.constructor = jquerysub;
jquerysub.sub = this.sub;
jquerysub.fn.init = function init( selector, context ) {
var instance = jquery.fn.init.call( this, selector, context, rootjquerysub );
return instance instanceof jquerysub ?
instance :
jquerysub( instance );
};
jquerysub.fn.init.prototype = jquerysub.fn;
var rootjquerysub = jquerysub(document);
migratewarn( "jquery.sub() is deprecated" );
return jquerysub;
};
// the number of elements contained in the matched element set
jquery.fn.size = function() {
migratewarn( "jquery.fn.size() is deprecated; use the .length property" );
return this.length;
};
var internalswapcall = false;
// if this version of jquery has .swap(), don't false-alarm on internal uses
if ( jquery.swap ) {
jquery.each( [ "height", "width", "reliablemarginright" ], function( _, name ) {
var oldhook = jquery.csshooks[ name ] && jquery.csshooks[ name ].get;
if ( oldhook ) {
jquery.csshooks[ name ].get = function() {
var ret;
internalswapcall = true;
ret = oldhook.apply( this, arguments );
internalswapcall = false;
return ret;
};
}
});
}
jquery.swap = function( elem, options, callback, args ) {
var ret, name,
old = {};
if ( !internalswapcall ) {
migratewarn( "jquery.swap() is undocumented and deprecated" );
}
// remember the old values, and insert the new ones
for ( name in options ) {
old[ name ] = elem.style[ name ];
elem.style[ name ] = options[ name ];
}
ret = callback.apply( elem, args || [] );
// revert the old values
for ( name in options ) {
elem.style[ name ] = old[ name ];
}
return ret;
};
// ensure that $.ajax gets the new parsejson defined in core.js
jquery.ajaxsetup({
converters: {
"text json": jquery.parsejson
}
});
var oldfndata = jquery.fn.data;
jquery.fn.data = function( name ) {
var ret, evt,
elem = this[0];
// handles 1.7 which has this behavior and 1.8 which doesn't
if ( elem && name === "events" && arguments.length === 1 ) {
ret = jquery.data( elem, name );
evt = jquery._data( elem, name );
if ( ( ret === undefined || ret === evt ) && evt !== undefined ) {
migratewarn("use of jquery.fn.data('events') is deprecated");
return evt;
}
}
return oldfndata.apply( this, arguments );
};
var rscripttype = /\/(java|ecma)script/i;
// since jquery.clean is used internally on older versions, we only shim if it's missing
if ( !jquery.clean ) {
jquery.clean = function( elems, context, fragment, scripts ) {
// set context per 1.8 logic
context = context || document;
context = !context.nodetype && context[0] || context;
context = context.ownerdocument || context;
migratewarn("jquery.clean() is deprecated");
var i, elem, handlescript, jstags,
ret = [];
jquery.merge( ret, jquery.buildfragment( elems, context ).childnodes );
// complex logic lifted directly from jquery 1.8
if ( fragment ) {
// special handling of each script element
handlescript = function( elem ) {
// check if we consider it executable
if ( !elem.type || rscripttype.test( elem.type ) ) {
// detach the script and store it in the scripts array (if provided) or the fragment
// return truthy to indicate that it has been handled
return scripts ?
scripts.push( elem.parentnode ? elem.parentnode.removechild( elem ) : elem ) :
fragment.appendchild( elem );
}
};
for ( i = 0; (elem = ret[i]) != null; i++ ) {
// check if we're done after handling an executable script
if ( !( jquery.nodename( elem, "script" ) && handlescript( elem ) ) ) {
// append to fragment and handle embedded scripts
fragment.appendchild( elem );
if ( typeof elem.getelementsbytagname !== "undefined" ) {
// handlescript alters the dom, so use jquery.merge to ensure snapshot iteration
jstags = jquery.grep( jquery.merge( [], elem.getelementsbytagname("script") ), handlescript );
// splice the scripts into ret after their former ancestor and advance our index beyond them
ret.splice.apply( ret, [i + 1, 0].concat( jstags ) );
i += jstags.length;
}
}
}
}
return ret;
};
}
var eventadd = jquery.event.add,
eventremove = jquery.event.remove,
eventtrigger = jquery.event.trigger,
oldtoggle = jquery.fn.toggle,
oldlive = jquery.fn.live,
olddie = jquery.fn.die,
oldload = jquery.fn.load,
ajaxevents = "ajaxstart|ajaxstop|ajaxsend|ajaxcomplete|ajaxerror|ajaxsuccess",
rajaxevent = new regexp( "\\b(?:" + ajaxevents + ")\\b" ),
rhoverhack = /(?:^|\s)hover(\.\s+|)\b/,
hoverhack = function( events ) {
if ( typeof( events ) !== "string" || jquery.event.special.hover ) {
return events;
}
if ( rhoverhack.test( events ) ) {
migratewarn("'hover' pseudo-event is deprecated, use 'mouseenter mouseleave'");
}
return events && events.replace( rhoverhack, "mouseenter$1 mouseleave$1" );
};
// event props removed in 1.9, put them back if needed; no practical way to warn them
if ( jquery.event.props && jquery.event.props[ 0 ] !== "attrchange" ) {
jquery.event.props.unshift( "attrchange", "attrname", "relatednode", "srcelement" );
}
// undocumented jquery.event.handle was "deprecated" in jquery 1.7
if ( jquery.event.dispatch ) {
migratewarnprop( jquery.event, "handle", jquery.event.dispatch, "jquery.event.handle is undocumented and deprecated" );
}
// support for 'hover' pseudo-event and ajax event warnings
jquery.event.add = function( elem, types, handler, data, selector ){
if ( elem !== document && rajaxevent.test( types ) ) {
migratewarn( "ajax events should be attached to document: " + types );
}
eventadd.call( this, elem, hoverhack( types || "" ), handler, data, selector );
};
jquery.event.remove = function( elem, types, handler, selector, mappedtypes ){
eventremove.call( this, elem, hoverhack( types ) || "", handler, selector, mappedtypes );
};
jquery.each( [ "load", "unload", "error" ], function( _, name ) {
jquery.fn[ name ] = function() {
var args = array.prototype.slice.call( arguments, 0 );
migratewarn( "jquery.fn." + name + "() is deprecated" );
// if this is an ajax load() the first arg should be the string url;
// technically this could also be the "anything" arg of the event .load()
// which just goes to show why this dumb signature has been deprecated!
// jquery custom builds that exclude the ajax module justifiably die here.
if ( name === "load" && typeof arguments[ 0 ] === "string" ) {
return oldload.apply( this, arguments );
}
args.splice( 0, 0, name );
if ( arguments.length ) {
return this.bind.apply( this, args );
}
// use .triggerhandler here because:
// - load and unload events don't need to bubble, only applied to window or image
// - error event should not bubble to window, although it does pre-1.7
// see http://bugs.jquery.com/ticket/11820
this.triggerhandler.apply( this, args );
return this;
};
});
jquery.fn.toggle = function( fn, fn2 ) {
// don't mess with animation or css toggles
if ( !jquery.isfunction( fn ) || !jquery.isfunction( fn2 ) ) {
return oldtoggle.apply( this, arguments );
}
migratewarn("jquery.fn.toggle(handler, handler...) is deprecated");
// save reference to arguments for access in closure
var args = arguments,
guid = fn.guid || jquery.guid++,
i = 0,
toggler = function( event ) {
// figure out which function to execute
var lasttoggle = ( jquery._data( this, "lasttoggle" + fn.guid ) || 0 ) % i;
jquery._data( this, "lasttoggle" + fn.guid, lasttoggle + 1 );
// make sure that clicks stop
event.preventdefault();
// and execute the function
return args[ lasttoggle ].apply( this, arguments ) || false;
};
// link all the functions, so any of them can unbind this click handler
toggler.guid = guid;
while ( i < args.length ) {
args[ i++ ].guid = guid;
}
return this.click( toggler );
};
jquery.fn.live = function( types, data, fn ) {
migratewarn("jquery.fn.live() is deprecated");
if ( oldlive ) {
return oldlive.apply( this, arguments );
}
jquery( this.context ).on( types, this.selector, data, fn );
return this;
};
jquery.fn.die = function( types, fn ) {
migratewarn("jquery.fn.die() is deprecated");
if ( olddie ) {
return olddie.apply( this, arguments );
}
jquery( this.context ).off( types, this.selector || "**", fn );
return this;
};
// turn global events into document-triggered events
jquery.event.trigger = function( event, data, elem, onlyhandlers ){
if ( !elem && !rajaxevent.test( event ) ) {
migratewarn( "global events are undocumented and deprecated" );
}
return eventtrigger.call( this, event, data, elem || document, onlyhandlers );
};
jquery.each( ajaxevents.split("|"),
function( _, name ) {
jquery.event.special[ name ] = {
setup: function() {
var elem = this;
// the document needs no shimming; must be !== for oldie
if ( elem !== document ) {
jquery.event.add( document, name + "." + jquery.guid, function() {
jquery.event.trigger( name, array.prototype.slice.call( arguments, 1 ), elem, true );
});
jquery._data( this, name, jquery.guid++ );
}
return false;
},
teardown: function() {
if ( this !== document ) {
jquery.event.remove( document, name + "." + jquery._data( this, name ) );
}
return false;
}
};
}
);
jquery.event.special.ready = {
setup: function() { migratewarn( "'ready' event is deprecated" ); }
};
var oldself = jquery.fn.andself || jquery.fn.addback,
oldfind = jquery.fn.find;
jquery.fn.andself = function() {
migratewarn("jquery.fn.andself() replaced by jquery.fn.addback()");
return oldself.apply( this, arguments );
};
jquery.fn.find = function( selector ) {
var ret = oldfind.apply( this, arguments );
ret.context = this.context;
ret.selector = this.selector ? this.selector + " " + selector : selector;
return ret;
};
// jquery 1.6 did not support callbacks, do not warn there
if ( jquery.callbacks ) {
var olddeferred = jquery.deferred,
tuples = [
// action, add listener, callbacks, .then handlers, final state
[ "resolve", "done", jquery.callbacks("once memory"),
jquery.callbacks("once memory"), "resolved" ],
[ "reject", "fail", jquery.callbacks("once memory"),
jquery.callbacks("once memory"), "rejected" ],
[ "notify", "progress", jquery.callbacks("memory"),
jquery.callbacks("memory") ]
];
jquery.deferred = function( func ) {
var deferred = olddeferred(),
promise = deferred.promise();
deferred.pipe = promise.pipe = function( /* fndone, fnfail, fnprogress */ ) {
var fns = arguments;
migratewarn( "deferred.pipe() is deprecated" );
return jquery.deferred(function( newdefer ) {
jquery.each( tuples, function( i, tuple ) {
var fn = jquery.isfunction( fns[ i ] ) && fns[ i ];
// deferred.done(function() { bind to newdefer or newdefer.resolve })
// deferred.fail(function() { bind to newdefer or newdefer.reject })
// deferred.progress(function() { bind to newdefer or newdefer.notify })
deferred[ tuple[1] ](function() {
var returned = fn && fn.apply( this, arguments );
if ( returned && jquery.isfunction( returned.promise ) ) {
returned.promise()
.done( newdefer.resolve )
.fail( newdefer.reject )
.progress( newdefer.notify );
} else {
newdefer[ tuple[ 0 ] + "with" ](
this === promise ? newdefer.promise() : this,
fn ? [ returned ] : arguments
);
}
});
});
fns = null;
}).promise();
};
deferred.isresolved = function() {
migratewarn( "deferred.isresolved is deprecated" );
return deferred.state() === "resolved";
};
deferred.isrejected = function() {
migratewarn( "deferred.isrejected is deprecated" );
return deferred.state() === "rejected";
};
if ( func ) {
func.call( deferred, deferred );
}
return deferred;
};
}
})( jquery, window );