/*! * jquery migrate - v1.0.0 - 2013-01-14 * https://github.com/jquery/jquery-migrate * copyright 2005, 2013 jquery foundation, inc. and other contributors; licensed mit */ (function( jquery, window, undefined ) { "use strict"; 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; // forget any warnings we've already given; public jquery.migratereset = function() { warnedabout = {}; jquery.migratewarnings.length = 0; }; function migratewarn( msg) { if ( !warnedabout[ msg ] ) { warnedabout[ msg ] = true; jquery.migratewarnings.push( msg ); if ( window.console && console.warn && !jquery.migratemute ) { } } } 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 = {}, attr = 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 ) { migratewarn("jquery.fn.attr( props, pass ) is deprecated"); if ( elem && !rnoattrnodetype.test( ntype ) && 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 if ( name === "type" && value !== undefined && rnotype.test( elem.nodename ) ) { 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 + ") may use property instead of attribute" ); } } return attr.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("property-based jquery.fn.attr('value') is deprecated"); } 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("property-based jquery.fn.attr('value', val) is deprecated"); } // does not return so that setattribute is also used elem.value = value; } }; var matched, browser, oldinit = jquery.fn.init, // note this does not include the # xss fix from 1.7! rquickexpr = /^(?:.*(<[\w\w]+>)[^>]*|#([\w\-]*))$/; // $(html) "looks like html" rule change jquery.fn.init = function( selector, context, rootjquery ) { var match; if ( selector && typeof selector === "string" && !jquery.isplainobject( context ) && (match = rquickexpr.exec( selector )) && match[1] ) { // this is an html string according to the "old" rules; is it still? if ( selector.charat( 0 ) !== "<" ) { migratewarn("$(html) html strings must start with '<' character"); } // 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( jquery.trim(selector), context, true ), context, rootjquery ); } } return oldinit.apply( this, arguments ); }; jquery.fn.init.prototype = jquery.fn; 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" }; }; 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", browser, "jquery.browser 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 ) { if ( context && context instanceof jquery && !(context instanceof jquerysub) ) { context = jquerysub( context ); } return jquery.fn.init.call( this, selector, context, rootjquerysub ); }; jquerysub.fn.init.prototype = jquerysub.fn; var rootjquerysub = jquerysub(document); migratewarn( "jquery.sub() is deprecated" ); return jquerysub; }; 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, oldself = jquery.fn.andself || jquery.fn.addback, oldfragment = jquery.buildfragment; jquery.fn.andself = function() { migratewarn("jquery.fn.andself() replaced by jquery.fn.addback()"); return oldself.apply( this, arguments ); }; // 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; }; } jquery.buildfragment = function( elems, context, scripts, selection ) { var ret, warning = "jquery.buildfragment() is deprecated"; // set context per 1.8 logic context = context || document; context = !context.nodetype && context[0] || context; context = context.ownerdocument || context; try { ret = oldfragment.call( jquery, elems, context, scripts, selection ); // jquery < 1.8 required arrayish context; jquery 1.9 fails on it } catch( x ) { ret = oldfragment.call( jquery, elems, context.nodetype ? [ context ] : context[ 0 ], scripts, selection ); // success from tweaking context means buildfragment was called by the user migratewarn( warning ); } // jquery < 1.9 returned an object instead of the fragment itself if ( !ret.fragment ) { migratewarnprop( ret, "fragment", ret, warning ); migratewarnprop( ret, "cacheable", false, warning ); } 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, 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 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.fn.error = function() { var args = array.prototype.slice.call( arguments, 0); migratewarn("jquery.fn.error() is deprecated"); args.splice( 0, 0, "error" ); if ( arguments.length ) { return this.bind.apply( this, args ); } // error event should not bubble to window, although it does pre-1.7 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, null, 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, window );