From e5502d1ffabab7784d85df42cbb3370ce92b0d6d Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 5 May 2014 18:33:23 +0200 Subject: [PATCH] Add jQuery Migrate We're currently on jQuery v1.8.3. jQuery v1.9 introduces breaking changes. The jQuery Migrate plugin adds a compatibility layer that brings back most removed or altered functionality. It can also be loaded on an older version of jQuery to make use of the plugins' accessor tracking that helps finding code that makes use of the deprecated functionality prior to upgrading. Code: http://code.jquery.com/jquery-migrate-1.2.1.js Info: http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/ http://jquery.com/upgrade-guide/1.9/#jquery-migrate-plugin https://github.com/jquery/jquery-migrate/ > The plugin can be included with versions of jQuery as old as > 1.6.4 to identify potential upgrade issues via its JQMIGRATE > console warnings. However, the plugin is only required for > version 1.9.0 or higher to restore deprecated and removed > functionality. Loading it alongside jquery.js should be harmless. However to benefit performance, I'm only loading it in debug mode. Plus, there's a small chance that it does actually change functionality because of the way it is implemented. The plugin always overloads the methods with compatibility versions, which should effectively be a no-op on top of old version of jQuery like ours (one that already has the old functionality), but it feels too risky at this stage when our only intent is instrumentation. Bug: 44740 Change-Id: I468d6b45eae8368fac6af746bbb2ccb702f862ff --- resources/Resources.php | 1 + resources/lib/jquery/jquery.migrate.js | 521 +++++++++++++++++++++++++ 2 files changed, 522 insertions(+) create mode 100644 resources/lib/jquery/jquery.migrate.js diff --git a/resources/Resources.php b/resources/Resources.php index 6057b39417..d4ac249c00 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -191,6 +191,7 @@ return array( 'jquery' => array( 'scripts' => 'resources/lib/jquery/jquery.js', + 'debugScripts' => 'resources/lib/jquery/jquery.migrate.js', 'debugRaw' => false, 'targets' => array( 'desktop', 'mobile' ), ), diff --git a/resources/lib/jquery/jquery.migrate.js b/resources/lib/jquery/jquery.migrate.js new file mode 100644 index 0000000000..25b6c81314 --- /dev/null +++ b/resources/lib/jquery/jquery.migrate.js @@ -0,0 +1,521 @@ +/*! + * jQuery Migrate - v1.2.1 - 2013-05-08 + * https://github.com/jquery/jquery-migrate + * Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors; Licensed MIT + */ +(function( jQuery, window, undefined ) { +// See http://bugs.jquery.com/ticket/13335 +// "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; + +// 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 $( "