Path: blob/master/core/main/client/lib/jquery-migrate-1.4.1.js
1154 views
/*!1* jQuery Migrate - v1.4.1 - 2016-05-192* Copyright jQuery Foundation and other contributors3*/4(function( jQuery, window, undefined ) {5// See http://bugs.jquery.com/ticket/133356// "use strict";789jQuery.migrateVersion = "1.4.1";101112var warnedAbout = {};1314// List of warnings already given; public read only15jQuery.migrateWarnings = [];1617// Set to true to prevent console output; migrateWarnings still maintained18jQuery.migrateMute = true;1920// Show a message on the console so devs know we're active21if (window.console && window.console.log && !jQuery.migrateMute) {22window.console.log( "JQMIGRATE: Migrate is installed" +23( jQuery.migrateMute ? "" : " with logging active" ) +24", version " + jQuery.migrateVersion );25}2627// Set to false to disable traces that appear with warnings28if ( jQuery.migrateTrace === undefined ) {29jQuery.migrateTrace = false;30}3132// Forget any warnings we've already given; public33jQuery.migrateReset = function() {34warnedAbout = {};35jQuery.migrateWarnings.length = 0;36};3738function migrateWarn( msg) {39var console = window.console;40if ( !warnedAbout[ msg ] ) {41warnedAbout[ msg ] = true;42jQuery.migrateWarnings.push( msg );43if ( console && console.warn && !jQuery.migrateMute ) {44console.warn( "JQMIGRATE: " + msg );45if ( jQuery.migrateTrace && console.trace ) {46console.trace();47}48}49}50}5152function migrateWarnProp( obj, prop, value, msg ) {53if ( Object.defineProperty ) {54// On ES5 browsers (non-oldIE), warn if the code tries to get prop;55// allow property to be overwritten in case some other plugin wants it56try {57Object.defineProperty( obj, prop, {58configurable: true,59enumerable: true,60get: function() {61migrateWarn( msg );62return value;63},64set: function( newValue ) {65migrateWarn( msg );66value = newValue;67}68});69return;70} catch( err ) {71// IE8 is a dope about Object.defineProperty, can't warn there72}73}7475// Non-ES5 (or broken) browser; just set the property76jQuery._definePropertyBroken = true;77obj[ prop ] = value;78}7980if ( document.compatMode === "BackCompat" ) {81// jQuery has never supported or tested Quirks Mode82migrateWarn( "jQuery is not compatible with Quirks Mode" );83}848586var attrFn = jQuery( "<input/>", { size: 1 } ).attr("size") && jQuery.attrFn,87oldAttr = jQuery.attr,88valueAttrGet = jQuery.attrHooks.value && jQuery.attrHooks.value.get ||89function() { return null; },90valueAttrSet = jQuery.attrHooks.value && jQuery.attrHooks.value.set ||91function() { return undefined; },92rnoType = /^(?:input|button)$/i,93rnoAttrNodeType = /^[238]$/,94rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,95ruseDefault = /^(?:checked|selected)$/i;9697// jQuery.attrFn98migrateWarnProp( jQuery, "attrFn", attrFn || {}, "jQuery.attrFn is deprecated" );99100jQuery.attr = function( elem, name, value, pass ) {101var lowerName = name.toLowerCase(),102nType = elem && elem.nodeType;103104if ( pass ) {105// Since pass is used internally, we only warn for new jQuery106// versions where there isn't a pass arg in the formal params107if ( oldAttr.length < 4 ) {108migrateWarn("jQuery.fn.attr( props, pass ) is deprecated");109}110if ( elem && !rnoAttrNodeType.test( nType ) &&111(attrFn ? name in attrFn : jQuery.isFunction(jQuery.fn[name])) ) {112return jQuery( elem )[ name ]( value );113}114}115116// Warn if user tries to set `type`, since it breaks on IE 6/7/8; by checking117// for disconnected elements we don't warn on $( "<button>", { type: "button" } ).118if ( name === "type" && value !== undefined && rnoType.test( elem.nodeName ) && elem.parentNode ) {119migrateWarn("Can't change the 'type' of an input or button in IE 6/7/8");120}121122// Restore boolHook for boolean property/attribute synchronization123if ( !jQuery.attrHooks[ lowerName ] && rboolean.test( lowerName ) ) {124jQuery.attrHooks[ lowerName ] = {125get: function( elem, name ) {126// Align boolean attributes with corresponding properties127// Fall back to attribute presence where some booleans are not supported128var attrNode,129property = jQuery.prop( elem, name );130return property === true || typeof property !== "boolean" &&131( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ?132133name.toLowerCase() :134undefined;135},136set: function( elem, value, name ) {137var propName;138if ( value === false ) {139// Remove boolean attributes when set to false140jQuery.removeAttr( elem, name );141} else {142// value is true since we know at this point it's type boolean and not false143// Set boolean attributes to the same name and set the DOM property144propName = jQuery.propFix[ name ] || name;145if ( propName in elem ) {146// Only set the IDL specifically if it already exists on the element147elem[ propName ] = true;148}149150elem.setAttribute( name, name.toLowerCase() );151}152return name;153}154};155156// Warn only for attributes that can remain distinct from their properties post-1.9157if ( ruseDefault.test( lowerName ) ) {158migrateWarn( "jQuery.fn.attr('" + lowerName + "') might use property instead of attribute" );159}160}161162return oldAttr.call( jQuery, elem, name, value );163};164165// attrHooks: value166jQuery.attrHooks.value = {167get: function( elem, name ) {168var nodeName = ( elem.nodeName || "" ).toLowerCase();169if ( nodeName === "button" ) {170return valueAttrGet.apply( this, arguments );171}172if ( nodeName !== "input" && nodeName !== "option" ) {173migrateWarn("jQuery.fn.attr('value') no longer gets properties");174}175return name in elem ?176elem.value :177null;178},179set: function( elem, value ) {180var nodeName = ( elem.nodeName || "" ).toLowerCase();181if ( nodeName === "button" ) {182return valueAttrSet.apply( this, arguments );183}184if ( nodeName !== "input" && nodeName !== "option" ) {185migrateWarn("jQuery.fn.attr('value', val) no longer sets properties");186}187// Does not return so that setAttribute is also used188elem.value = value;189}190};191192193var matched, browser,194oldInit = jQuery.fn.init,195oldFind = jQuery.find,196oldParseJSON = jQuery.parseJSON,197rspaceAngle = /^\s*</,198rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,199rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g,200// Note: XSS check is done below after string is trimmed201rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/;202203// $(html) "looks like html" rule change204jQuery.fn.init = function( selector, context, rootjQuery ) {205var match, ret;206207if ( selector && typeof selector === "string" ) {208if ( !jQuery.isPlainObject( context ) &&209(match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) {210211// This is an HTML string according to the "old" rules; is it still?212if ( !rspaceAngle.test( selector ) ) {213migrateWarn("$(html) HTML strings must start with '<' character");214}215if ( match[ 3 ] ) {216migrateWarn("$(html) HTML text after last tag is ignored");217}218219// Consistently reject any HTML-like string starting with a hash (gh-9521)220// Note that this may break jQuery 1.6.x code that otherwise would work.221if ( match[ 0 ].charAt( 0 ) === "#" ) {222migrateWarn("HTML string cannot start with a '#' character");223jQuery.error("JQMIGRATE: Invalid selector string (XSS)");224}225226// Now process using loose rules; let pre-1.8 play too227// Is this a jQuery context? parseHTML expects a DOM element (#178)228if ( context && context.context && context.context.nodeType ) {229context = context.context;230}231232if ( jQuery.parseHTML ) {233return oldInit.call( this,234jQuery.parseHTML( match[ 2 ], context && context.ownerDocument ||235context || document, true ), context, rootjQuery );236}237}238}239240ret = oldInit.apply( this, arguments );241242// Fill in selector and context properties so .live() works243if ( selector && selector.selector !== undefined ) {244// A jQuery object, copy its properties245ret.selector = selector.selector;246ret.context = selector.context;247248} else {249ret.selector = typeof selector === "string" ? selector : "";250if ( selector ) {251ret.context = selector.nodeType? selector : context || document;252}253}254255return ret;256};257jQuery.fn.init.prototype = jQuery.fn;258259jQuery.find = function( selector ) {260var args = Array.prototype.slice.call( arguments );261262// Support: PhantomJS 1.x263// String#match fails to match when used with a //g RegExp, only on some strings264if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {265266// The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0267// First see if qS thinks it's a valid selector, if so avoid a false positive268try {269document.querySelector( selector );270} catch ( err1 ) {271272// Didn't *look* valid to qSA, warn and try quoting what we think is the value273selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {274return "[" + attr + op + "\"" + value + "\"]";275} );276277// If the regexp *may* have created an invalid selector, don't update it278// Note that there may be false alarms if selector uses jQuery extensions279try {280document.querySelector( selector );281migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );282args[ 0 ] = selector;283} catch ( err2 ) {284migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );285}286}287}288289return oldFind.apply( this, args );290};291292// Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)293var findProp;294for ( findProp in oldFind ) {295if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {296jQuery.find[ findProp ] = oldFind[ findProp ];297}298}299300// Let $.parseJSON(falsy_value) return null301jQuery.parseJSON = function( json ) {302if ( !json ) {303migrateWarn("jQuery.parseJSON requires a valid JSON string");304return null;305}306return oldParseJSON.apply( this, arguments );307};308309jQuery.uaMatch = function( ua ) {310ua = ua.toLowerCase();311312var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||313/(webkit)[ \/]([\w.]+)/.exec( ua ) ||314/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||315/(msie) ([\w.]+)/.exec( ua ) ||316ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||317[];318319return {320browser: match[ 1 ] || "",321version: match[ 2 ] || "0"322};323};324325// Don't clobber any existing jQuery.browser in case it's different326if ( !jQuery.browser ) {327matched = jQuery.uaMatch( navigator.userAgent );328browser = {};329330if ( matched.browser ) {331browser[ matched.browser ] = true;332browser.version = matched.version;333}334335// Chrome is Webkit, but Webkit is also Safari.336if ( browser.chrome ) {337browser.webkit = true;338} else if ( browser.webkit ) {339browser.safari = true;340}341342jQuery.browser = browser;343}344345// Warn if the code tries to get jQuery.browser346migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" );347348// jQuery.boxModel deprecated in 1.3, jQuery.support.boxModel deprecated in 1.7349jQuery.boxModel = jQuery.support.boxModel = (document.compatMode === "CSS1Compat");350migrateWarnProp( jQuery, "boxModel", jQuery.boxModel, "jQuery.boxModel is deprecated" );351migrateWarnProp( jQuery.support, "boxModel", jQuery.support.boxModel, "jQuery.support.boxModel is deprecated" );352353jQuery.sub = function() {354function jQuerySub( selector, context ) {355return new jQuerySub.fn.init( selector, context );356}357jQuery.extend( true, jQuerySub, this );358jQuerySub.superclass = this;359jQuerySub.fn = jQuerySub.prototype = this();360jQuerySub.fn.constructor = jQuerySub;361jQuerySub.sub = this.sub;362jQuerySub.fn.init = function init( selector, context ) {363var instance = jQuery.fn.init.call( this, selector, context, rootjQuerySub );364return instance instanceof jQuerySub ?365instance :366jQuerySub( instance );367};368jQuerySub.fn.init.prototype = jQuerySub.fn;369var rootjQuerySub = jQuerySub(document);370migrateWarn( "jQuery.sub() is deprecated" );371return jQuerySub;372};373374// The number of elements contained in the matched element set375jQuery.fn.size = function() {376migrateWarn( "jQuery.fn.size() is deprecated; use the .length property" );377return this.length;378};379380381var internalSwapCall = false;382383// If this version of jQuery has .swap(), don't false-alarm on internal uses384if ( jQuery.swap ) {385jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {386var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;387388if ( oldHook ) {389jQuery.cssHooks[ name ].get = function() {390var ret;391392internalSwapCall = true;393ret = oldHook.apply( this, arguments );394internalSwapCall = false;395return ret;396};397}398});399}400401jQuery.swap = function( elem, options, callback, args ) {402var ret, name,403old = {};404405if ( !internalSwapCall ) {406migrateWarn( "jQuery.swap() is undocumented and deprecated" );407}408409// Remember the old values, and insert the new ones410for ( name in options ) {411old[ name ] = elem.style[ name ];412elem.style[ name ] = options[ name ];413}414415ret = callback.apply( elem, args || [] );416417// Revert the old values418for ( name in options ) {419elem.style[ name ] = old[ name ];420}421422return ret;423};424425426// Ensure that $.ajax gets the new parseJSON defined in core.js427jQuery.ajaxSetup({428converters: {429"text json": jQuery.parseJSON430}431});432433434var oldFnData = jQuery.fn.data;435436jQuery.fn.data = function( name ) {437var ret, evt,438elem = this[0];439440// Handles 1.7 which has this behavior and 1.8 which doesn't441if ( elem && name === "events" && arguments.length === 1 ) {442ret = jQuery.data( elem, name );443evt = jQuery._data( elem, name );444if ( ( ret === undefined || ret === evt ) && evt !== undefined ) {445migrateWarn("Use of jQuery.fn.data('events') is deprecated");446return evt;447}448}449return oldFnData.apply( this, arguments );450};451452453var rscriptType = /\/(java|ecma)script/i;454455// Since jQuery.clean is used internally on older versions, we only shim if it's missing456if ( !jQuery.clean ) {457jQuery.clean = function( elems, context, fragment, scripts ) {458// Set context per 1.8 logic459context = context || document;460context = !context.nodeType && context[0] || context;461context = context.ownerDocument || context;462463migrateWarn("jQuery.clean() is deprecated");464465var i, elem, handleScript, jsTags,466ret = [];467468jQuery.merge( ret, jQuery.buildFragment( elems, context ).childNodes );469470// Complex logic lifted directly from jQuery 1.8471if ( fragment ) {472// Special handling of each script element473handleScript = function( elem ) {474// Check if we consider it executable475if ( !elem.type || rscriptType.test( elem.type ) ) {476// Detach the script and store it in the scripts array (if provided) or the fragment477// Return truthy to indicate that it has been handled478return scripts ?479scripts.push( elem.parentNode ? elem.parentNode.removeChild( elem ) : elem ) :480fragment.appendChild( elem );481}482};483484for ( i = 0; (elem = ret[i]) != null; i++ ) {485// Check if we're done after handling an executable script486if ( !( jQuery.nodeName( elem, "script" ) && handleScript( elem ) ) ) {487// Append to fragment and handle embedded scripts488fragment.appendChild( elem );489if ( typeof elem.getElementsByTagName !== "undefined" ) {490// handleScript alters the DOM, so use jQuery.merge to ensure snapshot iteration491jsTags = jQuery.grep( jQuery.merge( [], elem.getElementsByTagName("script") ), handleScript );492493// Splice the scripts into ret after their former ancestor and advance our index beyond them494ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );495i += jsTags.length;496}497}498}499}500501return ret;502};503}504505var eventAdd = jQuery.event.add,506eventRemove = jQuery.event.remove,507eventTrigger = jQuery.event.trigger,508oldToggle = jQuery.fn.toggle,509oldLive = jQuery.fn.live,510oldDie = jQuery.fn.die,511oldLoad = jQuery.fn.load,512ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess",513rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ),514rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,515hoverHack = function( events ) {516if ( typeof( events ) !== "string" || jQuery.event.special.hover ) {517return events;518}519if ( rhoverHack.test( events ) ) {520migrateWarn("'hover' pseudo-event is deprecated, use 'mouseenter mouseleave'");521}522return events && events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );523};524525// Event props removed in 1.9, put them back if needed; no practical way to warn them526if ( jQuery.event.props && jQuery.event.props[ 0 ] !== "attrChange" ) {527jQuery.event.props.unshift( "attrChange", "attrName", "relatedNode", "srcElement" );528}529530// Undocumented jQuery.event.handle was "deprecated" in jQuery 1.7531if ( jQuery.event.dispatch ) {532migrateWarnProp( jQuery.event, "handle", jQuery.event.dispatch, "jQuery.event.handle is undocumented and deprecated" );533}534535// Support for 'hover' pseudo-event and ajax event warnings536jQuery.event.add = function( elem, types, handler, data, selector ){537if ( elem !== document && rajaxEvent.test( types ) ) {538migrateWarn( "AJAX events should be attached to document: " + types );539}540eventAdd.call( this, elem, hoverHack( types || "" ), handler, data, selector );541};542jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){543eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes );544};545546jQuery.each( [ "load", "unload", "error" ], function( _, name ) {547548jQuery.fn[ name ] = function() {549var args = Array.prototype.slice.call( arguments, 0 );550551// If this is an ajax load() the first arg should be the string URL;552// technically this could also be the "Anything" arg of the event .load()553// which just goes to show why this dumb signature has been deprecated!554// jQuery custom builds that exclude the Ajax module justifiably die here.555if ( name === "load" && typeof args[ 0 ] === "string" ) {556return oldLoad.apply( this, args );557}558559migrateWarn( "jQuery.fn." + name + "() is deprecated" );560561args.splice( 0, 0, name );562if ( arguments.length ) {563return this.bind.apply( this, args );564}565566// Use .triggerHandler here because:567// - load and unload events don't need to bubble, only applied to window or image568// - error event should not bubble to window, although it does pre-1.7569// See http://bugs.jquery.com/ticket/11820570this.triggerHandler.apply( this, args );571return this;572};573574});575576jQuery.fn.toggle = function( fn, fn2 ) {577578// Don't mess with animation or css toggles579if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {580return oldToggle.apply( this, arguments );581}582migrateWarn("jQuery.fn.toggle(handler, handler...) is deprecated");583584// Save reference to arguments for access in closure585var args = arguments,586guid = fn.guid || jQuery.guid++,587i = 0,588toggler = function( event ) {589// Figure out which function to execute590var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;591jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );592593// Make sure that clicks stop594event.preventDefault();595596// and execute the function597return args[ lastToggle ].apply( this, arguments ) || false;598};599600// link all the functions, so any of them can unbind this click handler601toggler.guid = guid;602while ( i < args.length ) {603args[ i++ ].guid = guid;604}605606return this.click( toggler );607};608609jQuery.fn.live = function( types, data, fn ) {610migrateWarn("jQuery.fn.live() is deprecated");611if ( oldLive ) {612return oldLive.apply( this, arguments );613}614jQuery( this.context ).on( types, this.selector, data, fn );615return this;616};617618jQuery.fn.die = function( types, fn ) {619migrateWarn("jQuery.fn.die() is deprecated");620if ( oldDie ) {621return oldDie.apply( this, arguments );622}623jQuery( this.context ).off( types, this.selector || "**", fn );624return this;625};626627// Turn global events into document-triggered events628jQuery.event.trigger = function( event, data, elem, onlyHandlers ){629if ( !elem && !rajaxEvent.test( event ) ) {630migrateWarn( "Global events are undocumented and deprecated" );631}632return eventTrigger.call( this, event, data, elem || document, onlyHandlers );633};634jQuery.each( ajaxEvents.split("|"),635function( _, name ) {636jQuery.event.special[ name ] = {637setup: function() {638var elem = this;639640// The document needs no shimming; must be !== for oldIE641if ( elem !== document ) {642jQuery.event.add( document, name + "." + jQuery.guid, function() {643jQuery.event.trigger( name, Array.prototype.slice.call( arguments, 1 ), elem, true );644});645jQuery._data( this, name, jQuery.guid++ );646}647return false;648},649teardown: function() {650if ( this !== document ) {651jQuery.event.remove( document, name + "." + jQuery._data( this, name ) );652}653return false;654}655};656}657);658659jQuery.event.special.ready = {660setup: function() {661if ( this === document ) {662migrateWarn( "'ready' event is deprecated" );663}664}665};666667var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack,668oldFnFind = jQuery.fn.find;669670jQuery.fn.andSelf = function() {671migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()");672return oldSelf.apply( this, arguments );673};674675jQuery.fn.find = function( selector ) {676var ret = oldFnFind.apply( this, arguments );677ret.context = this.context;678ret.selector = this.selector ? this.selector + " " + selector : selector;679return ret;680};681682683// jQuery 1.6 did not support Callbacks, do not warn there684if ( jQuery.Callbacks ) {685686var oldDeferred = jQuery.Deferred,687tuples = [688// action, add listener, callbacks, .then handlers, final state689[ "resolve", "done", jQuery.Callbacks("once memory"),690jQuery.Callbacks("once memory"), "resolved" ],691[ "reject", "fail", jQuery.Callbacks("once memory"),692jQuery.Callbacks("once memory"), "rejected" ],693[ "notify", "progress", jQuery.Callbacks("memory"),694jQuery.Callbacks("memory") ]695];696697jQuery.Deferred = function( func ) {698var deferred = oldDeferred(),699promise = deferred.promise();700701deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {702var fns = arguments;703704migrateWarn( "deferred.pipe() is deprecated" );705706return jQuery.Deferred(function( newDefer ) {707jQuery.each( tuples, function( i, tuple ) {708var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];709// deferred.done(function() { bind to newDefer or newDefer.resolve })710// deferred.fail(function() { bind to newDefer or newDefer.reject })711// deferred.progress(function() { bind to newDefer or newDefer.notify })712deferred[ tuple[1] ](function() {713var returned = fn && fn.apply( this, arguments );714if ( returned && jQuery.isFunction( returned.promise ) ) {715returned.promise()716.done( newDefer.resolve )717.fail( newDefer.reject )718.progress( newDefer.notify );719} else {720newDefer[ tuple[ 0 ] + "With" ](721this === promise ? newDefer.promise() : this,722fn ? [ returned ] : arguments723);724}725});726});727fns = null;728}).promise();729730};731732deferred.isResolved = function() {733migrateWarn( "deferred.isResolved is deprecated" );734return deferred.state() === "resolved";735};736737deferred.isRejected = function() {738migrateWarn( "deferred.isRejected is deprecated" );739return deferred.state() === "rejected";740};741742if ( func ) {743func.call( deferred, deferred );744}745746return deferred;747};748749}750751})( jQuery, window );752753754