From e3c89685095cfabdd1060b5d9cb57a62f60b7f2f Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Tue, 22 Dec 2015 13:03:11 -0500 Subject: [PATCH] Revert "Misc: Drop support for older browsers; update support comments" This reverts commit 90d7cc1d8b2ea7ac75f0eacb42439349c9c73278. --- README.md | 2 +- src/.jshintrc | 1 + src/ajax.js | 17 +- src/ajax/parseJSON.js | 46 ++- src/ajax/script.js | 3 +- src/ajax/xhr.js | 9 +- src/attributes/attr.js | 98 +++++- src/attributes/prop.js | 22 ++ src/attributes/support.js | 19 +- src/attributes/val.js | 35 +- src/core.js | 7 +- src/core/init.js | 16 +- src/core/ready.js | 32 +- src/css.js | 13 +- src/css/curCSS.js | 12 +- src/css/support.js | 11 +- src/data/var/acceptData.js | 4 +- src/dimensions.js | 2 +- src/effects.js | 17 +- src/event.js | 5 +- src/manipulation.js | 43 ++- src/manipulation/buildFragment.js | 45 ++- src/manipulation/support.js | 20 +- src/manipulation/wrapMap.js | 4 +- src/offset.js | 6 +- src/support.js | 46 ++- test/data/css/cssWidthBeforeDocReady.html | 1 + test/data/dimensions/documentSmall.html | 10 + test/data/testsuite.css | 12 +- test/unit/ajax.js | 18 +- test/unit/attributes.js | 17 +- test/unit/core.js | 2 +- test/unit/css.js | 37 +- test/unit/effects.js | 356 ++++++++++--------- test/unit/event.js | 47 ++- test/unit/manipulation.js | 20 +- test/unit/offset.js | 83 +++-- test/unit/selector.js | 6 +- test/unit/support.js | 396 ++++++++++++++++++++-- 39 files changed, 1161 insertions(+), 379 deletions(-) diff --git a/README.md b/README.md index 3c1b2f355..79dfb4942 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ In the spirit of open source software development, jQuery always encourages comm Environments in which to use jQuery -------------------------------------- -- [Browser support](http://jquery.com/browser-support/) differs between the master branch and the compat branch. Specifically, the master branch does not support legacy browsers such as IE8. The jQuery team continues to provide support for legacy browsers on the compat branch. Use the latest compat release if support for those browsers is required. See [browser support](http://jquery.com/browser-support/) for more info. +- [Browser support](http://jquery.com/browser-support/) differs between the master branch and the compat branch. Specifically, the master branch does not support legacy browsers such as IE6-8. The jQuery team continues to provide support for legacy browsers on the compat branch. Use the latest compat release if support for those browsers is required. See [browser support](http://jquery.com/browser-support/) for more info. - To use jQuery in Node, browser extensions, and other non-browser environments, use only master branch releases given the name "jquery" rather than "jquery-compat". The compat branch does not support these environments. diff --git a/src/.jshintrc b/src/.jshintrc index f1a2eb53e..1ba47a261 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -10,6 +10,7 @@ "undef": true, "unused": true, + "evil": true, "sub": true, // Support: IE < 10, Android < 4.1 diff --git a/src/ajax.js b/src/ajax.js index e92c29c75..45e8cfe21 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -5,6 +5,7 @@ define( [ "./ajax/var/location", "./ajax/var/nonce", "./ajax/var/rquery", + "./core/init", "./ajax/parseJSON", "./ajax/parseXML", @@ -68,7 +69,7 @@ function addToPrefiltersOrTransports( structure ) { while ( ( dataType = dataTypes[ i++ ] ) ) { // Prepend if requested - if ( dataType[ 0 ] === "+" ) { + if ( dataType.charAt( 0 ) === "+" ) { dataType = dataType.slice( 1 ) || "*"; ( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func ); @@ -264,7 +265,7 @@ function ajaxConvert( s, response, jqXHR, isSuccess ) { if ( conv !== true ) { // Unless errors are allowed to bubble, catch and return them - if ( conv && s.throws ) { + if ( conv && s[ "throws" ] ) { // jscs:ignore requireDotNotation response = conv( response ); } else { try { @@ -520,7 +521,7 @@ jQuery.extend( { jqXHR.error = jqXHR.fail; // Remove hash character (#7531: and string promotion) - // Add protocol if not provided (prefilters might expect it) + // Add protocol if not provided (#5866: IE7 issue with protocol-less urls) // Handle falsy url in the settings object (#10093: consistency with old signature) // We also use the url parameter if available s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" ) @@ -536,12 +537,12 @@ jQuery.extend( { if ( s.crossDomain == null ) { urlAnchor = document.createElement( "a" ); - // Support: IE8-11+ + // Support: IE6-11+ // IE throws exception if url is malformed, e.g. http://example.com:80x/ try { urlAnchor.href = s.url; - // Support: IE8-11+ + // Support: IE6-11+ // Anchor's host property isn't correctly set when s.url is relative urlAnchor.href = urlAnchor.href; s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !== @@ -650,9 +651,9 @@ jQuery.extend( { strAbort = "abort"; // Install callbacks on deferreds - for ( i in { success: 1, error: 1, complete: 1 } ) { - jqXHR[ i ]( s[ i ] ); - } + completeDeferred.add( s.complete ); + jqXHR.done( s.success ); + jqXHR.fail( s.error ); // Get transport transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR ); diff --git a/src/ajax/parseJSON.js b/src/ajax/parseJSON.js index 11918b06d..34efb79b2 100644 --- a/src/ajax/parseJSON.js +++ b/src/ajax/parseJSON.js @@ -2,10 +2,50 @@ define( [ "../core" ], function( jQuery ) { -// Support: Android 2.3 -// Workaround failure to string-cast null input +var rvalidtokens = /(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g; + jQuery.parseJSON = function( data ) { - return JSON.parse( data + "" ); + + // Attempt to parse using the native JSON parser first + if ( window.JSON && window.JSON.parse ) { + + // Support: Android 2.3 + // Workaround failure to string-cast null input + return window.JSON.parse( data + "" ); + } + + var requireNonComma, + depth = null, + str = jQuery.trim( data + "" ); + + // Guard against invalid (and possibly dangerous) input by ensuring that nothing remains + // after removing valid tokens + return str && !jQuery.trim( str.replace( rvalidtokens, function( token, comma, open, close ) { + + // Force termination if we see a misplaced comma + if ( requireNonComma && comma ) { + depth = 0; + } + + // Perform no more replacements after returning to outermost depth + if ( depth === 0 ) { + return token; + } + + // Commas must not follow "[", "{", or "," + requireNonComma = open || comma; + + // Determine new depth + // array/object open ("[" or "{"): depth += true - false (increment) + // array/object close ("]" or "}"): depth += false - true (decrement) + // other cases ("," or primitive): depth += true - true (numeric cast) + depth += !close - !open; + + // Remove this token + return ""; + } ) ) ? + ( Function( "return " + str ) )() : + jQuery.error( "Invalid JSON: " + data ); }; return jQuery.parseJSON; diff --git a/src/ajax/script.js b/src/ajax/script.js index d6094f520..9167b0462 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -85,8 +85,9 @@ jQuery.ajaxTransport( "script", function( s ) { } }; + // Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending // Use native DOM manipulation to avoid our domManip AJAX trickery - head.appendChild( script ); + head.insertBefore( script, head.firstChild ); }, abort: function() { diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 5e34d3812..6502d24c2 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -9,7 +9,7 @@ define( [ // (This is still attached to ajaxSettings for backward compatibility) jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ? - // Support: IE8 + // Support: IE6-IE8 function() { // XHR cannot access local files, always use ActiveX for that case @@ -17,7 +17,7 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ? return createActiveXHR(); } - // Support: IE 10-11 + // Support: IE 9-11 // IE seems to error on cross-domain PATCH requests when ActiveX XHR // is used. In IE 9+ always use the native XHR. // Note: this condition won't catch Edge as it doesn't define @@ -172,6 +172,11 @@ if ( xhrSupported ) { // If we're in sync mode we fire the callback callback(); + } else if ( xhr.readyState === 4 ) { + + // (IE6 & IE7) if it's in cache and has been + // retrieved directly we need to fire the callback + window.setTimeout( callback ); } else { // Register the callback, but delay it in case `xhr.send` throws diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 125e094d9..127c418f9 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -7,9 +7,10 @@ define( [ "../selector" ], function( jQuery, access, support, rnotwhite ) { -var boolHook, +var nodeHook, boolHook, attrHandle = jQuery.expr.attrHandle, ruseDefault = /^(?:checked|selected)$/i, + getSetAttribute = support.getSetAttribute, getSetInput = support.input; jQuery.fn.extend( { @@ -44,7 +45,7 @@ jQuery.extend( { if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { name = name.toLowerCase(); hooks = jQuery.attrHooks[ name ] || - ( jQuery.expr.match.bool.test( name ) ? boolHook : undefined ); + ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook ); } if ( value !== undefined ) { @@ -104,7 +105,7 @@ jQuery.extend( { if ( jQuery.expr.match.bool.test( name ) ) { // Set corresponding property to false - if ( getSetInput || !ruseDefault.test( name ) ) { + if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { elem[ propName ] = false; // Support: IE<9 @@ -113,9 +114,13 @@ jQuery.extend( { elem[ jQuery.camelCase( "default-" + name ) ] = elem[ propName ] = false; } + + // See #9699 for explanation of this approach (setting first, then removal) + } else { + jQuery.attr( elem, name, "" ); } - elem.removeAttribute( name ); + elem.removeAttribute( getSetAttribute ? name : propName ); } } } @@ -128,8 +133,10 @@ boolHook = { // Remove boolean attributes when set to false jQuery.removeAttr( elem, name ); - } else if ( getSetInput || !ruseDefault.test( name ) ) { - elem.setAttribute( jQuery.propFix[ name ] || name, name ); + } else if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { + + // IE<8 needs the *property* name + elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name ); } else { @@ -144,7 +151,7 @@ boolHook = { jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) { var getter = attrHandle[ name ] || jQuery.find.attr; - if ( getSetInput || !ruseDefault.test( name ) ) { + if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { attrHandle[ name ] = function( elem, name, isXML ) { var ret, handle; if ( !isXML ) { @@ -171,16 +178,89 @@ jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) } ); // fix oldIE attroperties -if ( !getSetInput ) { +if ( !getSetInput || !getSetAttribute ) { jQuery.attrHooks.value = { - set: function( elem, value ) { + set: function( elem, value, name ) { if ( jQuery.nodeName( elem, "input" ) ) { // Does not return so that setAttribute is also used elem.defaultValue = value; + } else { + + // Use nodeHook if defined (#1954); otherwise setAttribute is fine + return nodeHook && nodeHook.set( elem, value, name ); + } + } + }; +} + +// IE6/7 do not support getting/setting some attributes with get/setAttribute +if ( !getSetAttribute ) { + + // Use this for any attribute in IE6/7 + // This fixes almost every IE6/7 issue + nodeHook = { + set: function( elem, value, name ) { + + // Set the existing or create a new attribute node + var ret = elem.getAttributeNode( name ); + if ( !ret ) { + elem.setAttributeNode( + ( ret = elem.ownerDocument.createAttribute( name ) ) + ); + } + + ret.value = value += ""; + + // Break association with cloned elements by also using setAttribute (#9646) + if ( name === "value" || value === elem.getAttribute( name ) ) { + return value; + } + } + }; + + // Some attributes are constructed with empty-string values when not defined + attrHandle.id = attrHandle.name = attrHandle.coords = + function( elem, name, isXML ) { + var ret; + if ( !isXML ) { + return ( ret = elem.getAttributeNode( name ) ) && ret.value !== "" ? + ret.value : + null; } + }; + + // Fixing value retrieval on a button requires this module + jQuery.valHooks.button = { + get: function( elem, name ) { + var ret = elem.getAttributeNode( name ); + if ( ret && ret.specified ) { + return ret.value; + } + }, + set: nodeHook.set + }; + + // Set contenteditable to false on removals(#10429) + // Setting to empty string throws an error as an invalid value + jQuery.attrHooks.contenteditable = { + set: function( elem, value, name ) { + nodeHook.set( elem, value === "" ? false : value, name ); } }; + + // Set width and height to auto instead of 0 on empty string( Bug #8150 ) + // This is for removals + jQuery.each( [ "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = { + set: function( elem, value ) { + if ( value === "" ) { + elem.setAttribute( name, "auto" ); + return value; + } + } + }; + } ); } if ( !support.style ) { diff --git a/src/attributes/prop.js b/src/attributes/prop.js index 3eb5d8261..7672ce4f8 100644 --- a/src/attributes/prop.js +++ b/src/attributes/prop.js @@ -85,6 +85,23 @@ jQuery.extend( { } } ); +// Some attributes require a special call on IE +// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx +if ( !support.hrefNormalized ) { + + // href/src property should get the full normalized URL (#10299/#12915) + jQuery.each( [ "href", "src" ], function( i, name ) { + jQuery.propHooks[ name ] = { + get: function( elem ) { + return elem.getAttribute( name, 4 ); + } + }; + } ); +} + +// Support: Safari, IE9+ +// mis-reports the default selected property of an option +// Accessing the parent's selectedIndex property fixes it if ( !support.optSelected ) { jQuery.propHooks.selected = { get: function( elem ) { @@ -118,4 +135,9 @@ jQuery.each( [ jQuery.propFix[ this.toLowerCase() ] = this; } ); +// IE6/7 call enctype encoding +if ( !support.enctype ) { + jQuery.propFix.enctype = "encoding"; +} + } ); diff --git a/src/attributes/support.js b/src/attributes/support.js index 5e2de2ae2..2292ab77d 100644 --- a/src/attributes/support.js +++ b/src/attributes/support.js @@ -11,7 +11,10 @@ define( [ opt = select.appendChild( document.createElement( "option" ) ); // Setup - div.innerHTML = " a"; + div = document.createElement( "div" ); + div.setAttribute( "className", "t" ); + div.innerHTML = "
a"; + a = div.getElementsByTagName( "a" )[ 0 ]; // Support: Windows Web Apps (WWA) // `type` must use .setAttribute for WWA (#14901) @@ -23,18 +26,28 @@ define( [ // First batch of tests. a.style.cssText = "top:1px"; + // Test setAttribute on camelCase class. + // If it works, we need attrFixes when doing get/setAttribute (ie6/7) + support.getSetAttribute = div.className !== "t"; + // Get the style information from getAttribute // (IE uses .cssText instead) support.style = /top/.test( a.getAttribute( "style" ) ); + // Make sure that URLs aren't manipulated + // (IE normalizes it by default) + support.hrefNormalized = a.getAttribute( "href" ) === "/a"; + // Check the default checkbox/radio value ("" on WebKit; "on" elsewhere) support.checkOn = !!input.value; - // Support: IE8-11+ // Make sure that a selected-by-default option has a working selected property. - // (IE defaults to false instead of true if it's in an optgroup) + // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) support.optSelected = opt.selected; + // Tests for enctype support on a form (#6743) + support.enctype = !!document.createElement( "form" ).enctype; + // Make sure that the options inside disabled selects aren't marked as disabled // (WebKit marks them as disabled) select.disabled = true; diff --git a/src/attributes/val.js b/src/attributes/val.js index 7af79cfef..d4ed96f31 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -78,10 +78,13 @@ jQuery.extend( { valHooks: { option: { get: function( elem ) { + var val = jQuery.find.attr( elem, "value" ); + return val != null ? + val : - // Support: IE<11 - // option.value not trimmed (#14858) - return jQuery.trim( elem.value ); + // Support: IE10-11+ + // option.text throws exceptions (#14686, #14858) + jQuery.trim( jQuery.text( elem ) ); } }, select: { @@ -100,8 +103,7 @@ jQuery.extend( { for ( ; i < max; i++ ) { option = options[ i ]; - // Support: IE<10 - // IE8-9 doesn't update selected after form reset (#2551) + // oldIE doesn't update selected after form reset (#2551) if ( ( option.selected || i === index ) && // Don't return options that are disabled or in a disabled optgroup @@ -135,11 +137,24 @@ jQuery.extend( { while ( i-- ) { option = options[ i ]; - if ( - option.selected = - jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 - ) { - optionSet = true; + + if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0 ) { + + // Support: IE6 + // When new option element is added to select box we need to + // force reflow of newly added node in order to workaround delay + // of initialization properties + try { + option.selected = optionSet = true; + + } catch ( _ ) { + + // Will be executed only in IE6 + option.scrollHeight; + } + + } else { + option.selected = false; } } diff --git a/src/core.js b/src/core.js index b7425d277..c000e5339 100644 --- a/src/core.js +++ b/src/core.js @@ -285,7 +285,6 @@ jQuery.extend( { typeof obj; }, - // Evaluates a script in a global context // Workarounds based on findings by Jim Driscoll // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context globalEval: function( data ) { @@ -295,11 +294,7 @@ jQuery.extend( { // We use an anonymous function so that context is window // rather than jQuery in Firefox ( window.execScript || function( data ) { - - // jscs:disable - window[ "eval" ].call( window, data ); - // jscs:enable - + window[ "eval" ].call( window, data ); // jscs:ignore requireDotNotation } )( data ); } }, diff --git a/src/core/init.js b/src/core/init.js index 6225d15e4..fbd87d4e8 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -28,8 +28,8 @@ var rootjQuery, // Handle HTML strings if ( typeof selector === "string" ) { - if ( selector[ 0 ] === "<" && - selector[ selector.length - 1 ] === ">" && + if ( selector.charAt( 0 ) === "<" && + selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { // Assume that strings that start and end with <> are HTML and skip the regex check @@ -75,9 +75,17 @@ var rootjQuery, } else { elem = document.getElementById( match[ 2 ] ); - if ( elem ) { + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { - // Inject the element directly into the jQuery object + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id !== match[ 2 ] ) { + return rootjQuery.find( selector ); + } + + // Otherwise, we inject the element directly into the jQuery object this.length = 1; this[ 0 ] = elem; } diff --git a/src/core/ready.js b/src/core/ready.js index 2371eba3a..49c1da202 100644 --- a/src/core/ready.js +++ b/src/core/ready.js @@ -69,7 +69,6 @@ function detach() { document.removeEventListener( "DOMContentLoaded", completed ); window.removeEventListener( "load", completed ); - // Support: IE<9 } else { document.detachEvent( "onreadystatechange", completed ); window.detachEvent( "onload", completed ); @@ -116,7 +115,6 @@ jQuery.ready.promise = function( obj ) { // A fallback to window.onload, that will always work window.addEventListener( "load", completed ); - // Support: IE<9 // If IE event model is used } else { @@ -125,6 +123,36 @@ jQuery.ready.promise = function( obj ) { // A fallback to window.onload, that will always work window.attachEvent( "onload", completed ); + + // If IE and not a frame + // continually check to see if the document is ready + var top = false; + + try { + top = window.frameElement == null && document.documentElement; + } catch ( e ) {} + + if ( top && top.doScroll ) { + ( function doScrollCheck() { + if ( !jQuery.isReady ) { + + try { + + // Use the trick by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + top.doScroll( "left" ); + } catch ( e ) { + return window.setTimeout( doScrollCheck, 50 ); + } + + // detach all dom ready events + detach(); + + // and execute any waiting functions + jQuery.ready(); + } + } )(); + } } } return readyList.promise( obj ); diff --git a/src/css.js b/src/css.js index b48fe0a3b..610267d44 100644 --- a/src/css.js +++ b/src/css.js @@ -41,7 +41,7 @@ var fontWeight: "400" }, - cssPrefixes = [ "Webkit", "Moz", "ms" ], + cssPrefixes = [ "Webkit", "O", "Moz", "ms" ], emptyStyle = document.createElement( "div" ).style; // BuildExclude @@ -56,7 +56,7 @@ function vendorPropName( name ) { } // check for vendor prefixed names - var capName = name[ 0 ].toUpperCase() + name.slice( 1 ), + var capName = name.charAt( 0 ).toUpperCase() + name.slice( 1 ), i = cssPrefixes.length; while ( i-- ) { @@ -183,7 +183,8 @@ function getWidthOrHeight( elem, name, extra ) { var valueIsBorderBox = true, val = name === "width" ? elem.offsetWidth : elem.offsetHeight, styles = getStyles( elem ), - isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box"; + isBorderBox = support.boxSizing && + jQuery.css( elem, "boxSizing", false, styles ) === "border-box"; // Support: IE11 only // In IE 11 fullscreen elements inside of an iframe have @@ -329,7 +330,7 @@ jQuery.extend( { if ( !hooks || !( "set" in hooks ) || ( value = hooks.set( elem, value, extra ) ) !== undefined ) { - // Support: IE<9 + // Support: IE // Swallow errors from 'invalid' CSS values (#5509) try { style[ name ] = value; @@ -409,7 +410,8 @@ jQuery.each( [ "height", "width" ], function( i, name ) { elem, name, extra, - jQuery.css( elem, "boxSizing", false, styles ) === "border-box", + support.boxSizing && + jQuery.css( elem, "boxSizing", false, styles ) === "border-box", styles ) : 0 ); @@ -466,7 +468,6 @@ if ( !support.opacity ) { }; } -// Support: Android 2.3 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight, function( elem, computed ) { if ( computed ) { diff --git a/src/css/curCSS.js b/src/css/curCSS.js index 078cff6e1..67fc27525 100644 --- a/src/css/curCSS.js +++ b/src/css/curCSS.js @@ -42,9 +42,11 @@ if ( window.getComputedStyle ) { } // A tribute to the "awesome hack by Dean Edwards" - // Android Browser returns percentage for some values, - // but width seems to be reliably pixels. - // This is against the CSSOM draft spec: + // Chrome < 17 and Safari 5.0 uses "computed value" + // instead of "used value" for margin-right + // Safari 5.1.7 (at least) returns percentage for a larger set of values, + // but width seems to be reliably pixels + // this is against the CSSOM draft spec: // http://dev.w3.org/csswg/cssom/#resolved-values if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) { @@ -64,7 +66,7 @@ if ( window.getComputedStyle ) { } } - // Support: IE9-11+ + // Support: IE // IE returns zIndex value as an integer. return ret === undefined ? ret : @@ -118,7 +120,7 @@ if ( window.getComputedStyle ) { } } - // Support: IE<9 + // Support: IE // IE returns zIndex value as an integer. return ret === undefined ? ret : diff --git a/src/css/support.js b/src/css/support.js index be39dabb9..97d6d4aa1 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -36,6 +36,11 @@ define( [ div.innerHTML = ""; container.appendChild( div ); + // Support: Firefox<29, Android 2.3 + // Vendor-prefix box-sizing + support.boxSizing = div.style.boxSizing === "" || div.style.MozBoxSizing === "" || + div.style.WebkitBoxSizing === ""; + jQuery.extend( support, { reliableHiddenOffsets: function() { if ( pixelPositionVal == null ) { @@ -133,8 +138,8 @@ define( [ // Support: Android 2.3 // Vendor-prefix box-sizing - "-webkit-box-sizing:content-box;box-sizing:content-box;" + - "display:block;margin:0;border:0;padding:0"; + "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" + + "box-sizing:content-box;display:block;margin:0;border:0;padding:0"; contents.style.marginRight = contents.style.width = "0"; div.style.width = "1px"; @@ -144,7 +149,7 @@ define( [ div.removeChild( contents ); } - // Support: IE<9 + // Support: IE8 // Check if table cells still have offsetWidth/Height when they are set // to display:none and there are still other visible table cells in a // table row; if so, offsetWidth/Height are not reliable for use when diff --git a/src/data/var/acceptData.js b/src/data/var/acceptData.js index 76c74337c..99c61d5fe 100644 --- a/src/data/var/acceptData.js +++ b/src/data/var/acceptData.js @@ -1,4 +1,6 @@ -define( function() { +define( [ + "../../core" +], function( jQuery ) { /** * Determines whether an object can have data diff --git a/src/dimensions.js b/src/dimensions.js index 24ab4e921..0095cb9c6 100644 --- a/src/dimensions.js +++ b/src/dimensions.js @@ -31,7 +31,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height], // whichever is greatest - // unfortunately, this causes bug #3838 in IE8 only, + // unfortunately, this causes bug #3838 in IE6/8 only, // but there is currently no good, small way to fix it. return Math.max( elem.body[ "scroll" + name ], doc[ "scroll" + name ], diff --git a/src/effects.js b/src/effects.js index 1241a2f99..d286e5565 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,22 +1,22 @@ define( [ "./core", - "./var/document", + "./support", "./var/rcssNum", "./var/rnotwhite", "./css/var/cssExpand", "./css/var/isHidden", "./css/adjustCSS", "./css/defaultDisplay", - "./var/document", + "./var/document", "./core/init", "./effects/Tween", "./queue", "./css", "./deferred", "./traversing" -], function( jQuery, document, rcssNum, rnotwhite, cssExpand, - isHidden, adjustCSS, defaultDisplay ) { +], function( jQuery, support, rcssNum, rnotwhite, + cssExpand, isHidden, adjustCSS, defaultDisplay ) { var fxNow, timerId, @@ -120,7 +120,14 @@ function defaultPrefilter( elem, props, opts ) { jQuery._data( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display; if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) { - style.display = "inline-block"; + + // inline-level elements accept inline-block; + // block-level elements need to be inline with layout + if ( !support.inlineBlockNeedsLayout || defaultDisplay( elem.nodeName ) === "inline" ) { + style.display = "inline-block"; + } else { + style.zoom = 1; + } } } diff --git a/src/event.js b/src/event.js index f7af22083..8f6fd9f0c 100644 --- a/src/event.js +++ b/src/event.js @@ -411,9 +411,8 @@ jQuery.event = { ) { // Call a native DOM method on the target with the same name name as the event. + // Can't use an .isFunction() check here because IE6/7 fails that test. // Don't do default actions on window, that's where global variables be (#6170) - // Support: IE<9 - // Can't use an .isFunction() check here because IE8 fails that test. if ( ontype && elem[ type ] && !jQuery.isWindow( elem ) ) { // Don't re-trigger an onFOO event when we call its FOO() method @@ -763,7 +762,7 @@ jQuery.removeEvent = document.removeEventListener ? if ( elem.detachEvent ) { - // #8545, #7054, preventing memory leaks for custom events in IE8 + // #8545, #7054, preventing memory leaks for custom events in IE6-8 // detachEvent needed property on element, by name of that event, // to properly expose it to GC if ( typeof elem[ name ] === "undefined" ) { diff --git a/src/manipulation.js b/src/manipulation.js index da2e055f4..f73a9db57 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -44,6 +44,7 @@ var rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, safeFragment = createSafeFragment( document ), fragmentDiv = safeFragment.appendChild( document.createElement( "div" ) ); +// Support: IE<8 // Manipulating tables requires a tbody function manipulationTarget( elem, content ) { return jQuery.nodeName( elem, "table" ) && @@ -106,6 +107,7 @@ function fixCloneNodeIssues( src, dest ) { nodeName = dest.nodeName.toLowerCase(); + // IE6-8 copies events bound via attachEvent when using cloneNode. if ( !support.noCloneEvent && dest[ jQuery.expando ] ) { data = jQuery._data( dest ); @@ -117,26 +119,46 @@ function fixCloneNodeIssues( src, dest ) { dest.removeAttribute( jQuery.expando ); } - // Support: IE<9 // IE blanks contents when cloning scripts, and tries to evaluate newly-set text if ( nodeName === "script" && dest.text !== src.text ) { disableScript( dest ).text = src.text; restoreScript( dest ); - // Support: IE<9 - // IE8 fails to persist the checked state of a cloned checkbox - // or radio button. + // IE6-10 improperly clones children of object elements using classid. + // IE10 throws NoModificationAllowedError if parent is null, #12132. + } else if ( nodeName === "object" ) { + if ( dest.parentNode ) { + dest.outerHTML = src.outerHTML; + } + + // This path appears unavoidable for IE9. When cloning an object + // element in IE9, the outerHTML strategy above is not sufficient. + // If the src has innerHTML and the destination does not, + // copy the src.innerHTML into the dest.innerHTML. #10324 + if ( support.html5Clone && ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) ) { + dest.innerHTML = src.innerHTML; + } + } else if ( nodeName === "input" && rcheckableType.test( src.type ) ) { - dest.checked = src.checked; - // Support: IE<9 - // IE8 fails to return the selected option to the default selected + // IE6-8 fails to persist the checked state of a cloned checkbox + // or radio button. Worse, IE6-7 fail to give the cloned element + // a checked appearance if the defaultChecked value isn't also set + + dest.defaultChecked = dest.checked = src.checked; + + // IE6-7 get confused and end up setting the value of a cloned + // checkbox/radio button to an empty string instead of "on" + if ( dest.value !== src.value ) { + dest.value = src.value; + } + + // IE6-8 fails to return the selected option to the default selected // state when cloning options } else if ( nodeName === "option" ) { dest.defaultSelected = dest.selected = src.defaultSelected; - // Support: IE<9 - // IE8 fails to set the defaultValue to the correct value when + // IE6-8 fails to set the defaultValue to the correct value when // cloning other types of input fields } else if ( nodeName === "input" || nodeName === "textarea" ) { dest.defaultValue = src.defaultValue; @@ -547,8 +569,7 @@ jQuery.each( { elems = i === last ? this : this.clone( true ); jQuery( insert[ i ] )[ original ]( elems ); - // Support: IE<9, Android<4.1, PhantomJS<2 - // .get() because push.apply(_, arraylike) throws on ancient WebKit + // Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get() push.apply( ret, elems.get() ); } diff --git a/src/manipulation/buildFragment.js b/src/manipulation/buildFragment.js index 0e7958f23..df58bc898 100644 --- a/src/manipulation/buildFragment.js +++ b/src/manipulation/buildFragment.js @@ -1,5 +1,6 @@ define( [ "../core", + "./var/rcheckableType", "./var/rtagName", "./var/rscriptType", "./var/rleadingWhitespace", @@ -8,18 +9,26 @@ define( [ "./getAll", "./setGlobalEval", "./support" -], function( jQuery, rtagName, rscriptType, rleadingWhitespace, +], function( jQuery, rcheckableType, rtagName, rscriptType, rleadingWhitespace, createSafeFragment, wrapMap, getAll, setGlobalEval, support ) { -var rhtml = /<|&#?\w+;/; +var rhtml = /<|&#?\w+;/, + rtbody = / from table fragments + if ( !support.tbody ) { + + // String was a , *may* have spurious + elem = tag === "table" && !rtbody.test( elem ) ? + tmp.firstChild : + + // String was a bare or + wrap[ 1 ] === "
" && !rtbody.test( elem ) ? + tmp : + 0; + + j = elem && elem.childNodes.length; + while ( j-- ) { + if ( jQuery.nodeName( ( tbody = elem.childNodes[ j ] ), "tbody" ) && + !tbody.childNodes.length ) { + + elem.removeChild( tbody ); + } + } + } + jQuery.merge( nodes, tmp.childNodes ); // Fix #12392 for WebKit and IE > 9 @@ -77,6 +109,12 @@ function buildFragment( elems, context, scripts, selection, ignored ) { safe.removeChild( tmp ); } + // Reset defaultChecked for any radios and checkboxes + // about to be appended to the DOM in IE 6/7 (#8060) + if ( !support.appendChecked ) { + jQuery.grep( getAll( nodes, "input" ), fixDefaultChecked ); + } + i = 0; while ( ( elem = nodes[ i++ ] ) ) { @@ -85,6 +123,7 @@ function buildFragment( elems, context, scripts, selection, ignored ) { if ( ignored ) { ignored.push( elem ); } + continue; } diff --git a/src/manipulation/support.js b/src/manipulation/support.js index 8feb7aca3..4147a33aa 100644 --- a/src/manipulation/support.js +++ b/src/manipulation/support.js @@ -10,11 +10,15 @@ define( [ input = document.createElement( "input" ); // Setup - div.innerHTML = " "; + div.innerHTML = "
a"; // IE strips leading whitespace when .innerHTML is used support.leadingWhitespace = div.firstChild.nodeType === 3; + // Make sure that tbody elements aren't automatically inserted + // IE will insert them into empty tables + support.tbody = !div.getElementsByTagName( "tbody" ).length; + // Make sure that link elements get serialized correctly by innerHTML // This requires a wrapper element in IE support.htmlSerialize = !!div.getElementsByTagName( "link" ).length; @@ -24,8 +28,15 @@ define( [ support.html5Clone = document.createElement( "nav" ).cloneNode( true ).outerHTML !== "<:nav>"; + // Check if a disconnected checkbox will retain its checked + // value of true after appended to the DOM (IE6/7) + input.type = "checkbox"; + input.checked = true; + fragment.appendChild( input ); + support.appendChecked = input.checked; + // Make sure textarea (and checkbox) defaultValue is properly cloned - // Support: IE8-IE11+ + // Support: IE6-IE11+ div.innerHTML = ""; support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue; @@ -34,14 +45,15 @@ define( [ // Support: Windows Web Apps (WWA) // `name` and `type` must use .setAttribute for WWA (#14901) + input = document.createElement( "input" ); input.setAttribute( "type", "radio" ); input.setAttribute( "checked", "checked" ); input.setAttribute( "name", "t" ); div.appendChild( input ); - // Support: Android<4.2 - // Older WebKit doesn't clone checked state correctly in fragments + // Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3 + // old WebKit doesn't clone checked state correctly in fragments support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked; // Support: IE<9 diff --git a/src/manipulation/wrapMap.js b/src/manipulation/wrapMap.js index 4bde1df4f..d40685aad 100644 --- a/src/manipulation/wrapMap.js +++ b/src/manipulation/wrapMap.js @@ -7,13 +7,15 @@ var wrapMap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], area: [ 1, "", "" ], + + // Support: IE8 param: [ 1, "", "" ], thead: [ 1, "", "
" ], tr: [ 2, "", "
" ], col: [ 2, "", "
" ], td: [ 3, "", "
" ], - // IE8 can't serialize link, script, style, or any html5 (NoScope) tags, + // IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags, // unless wrapped in a div with non-breaking characters in front of it. _default: support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X
", "
" ] }; diff --git a/src/offset.js b/src/offset.js index b7dbdf561..9160f7e88 100644 --- a/src/offset.js +++ b/src/offset.js @@ -105,7 +105,11 @@ jQuery.fn.extend( { return box; } - box = elem.getBoundingClientRect(); + // If we don't have gBCR, just use 0,0 rather than error + // BlackBerry 5, iOS 3 (original iPhone) + if ( typeof elem.getBoundingClientRect !== "undefined" ) { + box = elem.getBoundingClientRect(); + } win = getWindow( doc ); return { top: box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ), diff --git a/src/support.js b/src/support.js index 97b3587da..71ac60f19 100644 --- a/src/support.js +++ b/src/support.js @@ -1,10 +1,11 @@ define( [ "./core", "./var/support", + "./var/document", "./core/init", // Needed for hasOwn support test // This is listed as a dependency for build order, but it's still optional in builds "./core/ready" -], function( jQuery, support ) { +], function( jQuery, support, document ) { // Support: IE<9 // Iteration over object's inherited properties before its own @@ -15,5 +16,48 @@ for ( i in jQuery( support ) ) { support.ownFirst = i === "0"; // Note: most support tests are defined in their respective modules. +// false until the test is run +support.inlineBlockNeedsLayout = false; +// Execute ASAP in case we need to set body.style.zoom +jQuery( function() { + + // Minified: var a,b,c,d + var val, div, body, container; + + body = document.getElementsByTagName( "body" )[ 0 ]; + if ( !body || !body.style ) { + + // Return for frameset docs that don't have a body + return; + } + + // Setup + div = document.createElement( "div" ); + container = document.createElement( "div" ); + container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px"; + body.appendChild( container ).appendChild( div ); + + if ( typeof div.style.zoom !== "undefined" ) { + + // Support: IE<8 + // Check if natively block-level elements act like inline-block + // elements when setting their display to 'inline' and giving + // them layout + div.style.cssText = "display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1"; + + support.inlineBlockNeedsLayout = val = div.offsetWidth === 3; + if ( val ) { + + // Prevent IE 6 from affecting layout for positioned elements #11048 + // Prevent IE from shrinking the body in IE 7 mode #12869 + // Support: IE<8 + body.style.zoom = 1; + } + } + + body.removeChild( container ); +} ); + +return support; } ); diff --git a/test/data/css/cssWidthBeforeDocReady.html b/test/data/css/cssWidthBeforeDocReady.html index c45b6811a..3bdd1b5ab 100644 --- a/test/data/css/cssWidthBeforeDocReady.html +++ b/test/data/css/cssWidthBeforeDocReady.html @@ -5,6 +5,7 @@
diff --git a/test/data/testsuite.css b/test/data/testsuite.css index de5f3fb00..d9909ddcc 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -1,7 +1,7 @@ /* for testing opacity set in styles in IE */ ol#empty { opacity: 0; - -ms-filter: "Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff')"; + filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); } div#fx-tests h4 { @@ -47,7 +47,7 @@ div.largeheight { } div.largeopacity { - -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=100)"; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); } div.medwidth { @@ -60,7 +60,7 @@ div.medheight { div.medopacity { opacity: 0.5; - -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=50)"; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); } div.nowidth { @@ -73,7 +73,7 @@ div.noheight { div.noopacity { opacity: 0; - -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=0)"; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); } div.hidden { @@ -143,8 +143,8 @@ dfn { display: none; } /* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; } -/* #6652 Remove -ms-filter: "alpha(opacity=100)" after animation */ -#t6652 div { -ms-filter: "alpha(opacity=50)"; } +/* #6652 REMOVE FILTER:ALPHA(OPACITY=100) AFTER ANIMATION */ +#t6652 div { filter: alpha(opacity=50); } /* #10501 */ section { background:#f0f; display:block; } diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 11cb902d2..9abc5e613 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1,8 +1,8 @@ -var isIE8 = /msie 8\.0/i.test( window.navigator.userAgent ); +var isoldIE = /msie [876]\.0/i.test( window.navigator.userAgent ); QUnit.module( "ajax", { setup: function() { - if ( !isIE8 ) { + if ( !isoldIE ) { return; } @@ -52,7 +52,7 @@ QUnit.module( "ajax", { ); ajaxTest( "jQuery.ajax() - success callbacks", 8, function( assert ) { - return { + return { setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), url: url( "data/name.html" ), beforeSend: function() { @@ -820,7 +820,7 @@ QUnit.module( "ajax", { "jsonpCallback option is set back to default in callbacks" ); - if ( isIE8 ) { + if ( isoldIE ) { assert.ok( true, "IE8 can't remove property from the window" ); } else { @@ -1417,8 +1417,8 @@ QUnit.module( "ajax", { }; } ); - test( "#11743 - jQuery.ajax() - script, throws exception", 1, function() { - throws( function() { + QUnit.test( "#11743 - jQuery.ajax() - script, throws exception", 1, function(assert) { + assert.throws( function() { jQuery.ajax( { url: "data/badjson.js", dataType: "script", @@ -1430,10 +1430,10 @@ QUnit.module( "ajax", { // Global events get confused by the exception global: false, success: function() { - ok( false, "Success." ); + assert.ok( false, "Success." ); }, error: function() { - ok( false, "Error." ); + assert.ok( false, "Error." ); } } ); }, "exception bubbled" ); @@ -1656,7 +1656,7 @@ QUnit.module( "ajax", { url: url( "data/ajax/content-type.php" ), data: { "content-type": "test/jsontest", - "response": JSON.stringify( { test: "test" } ) + "response": "{ \"test\": \"test\" }" }, success: function( result ) { assert.strictEqual( diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 9f8502d5d..be905cfd6 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -46,7 +46,11 @@ QUnit.test( "jQuery.propFix integrity test", function( assert ) { "contenteditable": "contentEditable" }; - assert.deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" ); + if ( !jQuery.support.enctype ) { + props.enctype = "encoding"; + } + + deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" ); } ); QUnit.test( "attr(String)", function( assert ) { @@ -588,11 +592,12 @@ QUnit.test( "removeAttr(String)", function( assert ) { assert.ok( false, "Removing contenteditable threw an error (#10429)" ); } - $first = jQuery( "
" ); - assert.equal( $first.attr( "Case" ), "mixed", "case of attribute doesn't matter" ); - $first.removeAttr( "Case" ); - assert.equal( $first.attr( "Case" ), undefined, "mixed-case attribute was removed" ); -} ); + $first = jQuery("
"); + equal( $first.attr("Case"), "mixed", "case of attribute doesn't matter" ); + $first.removeAttr("Case"); + // IE 6/7 return empty string here, not undefined + ok( !$first.attr("Case"), "mixed-case attribute was removed" ); +}); QUnit.test( "removeAttr(String) in XML", function( assert ) { assert.expect( 7 ); diff --git a/test/unit/core.js b/test/unit/core.js index 9714b8685..81fbd4e54 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1541,7 +1541,7 @@ QUnit.test("jQuery.parseHTML", function( assert ) { assert.equal( jQuery.parseHTML( "" )[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" ); } ); -if ( jQuery.support.createHTMLDocument ) { +if ( jQuery.support.createHTMLDocument && !/opera.*version\/12\.1/i.test( navigator.userAgent ) ) { QUnit.asyncTest( "jQuery.parseHTML", function( assert ) { assert.expect( 1 ); diff --git a/test/unit/css.js b/test/unit/css.js index df4b800f0..adfc46cb8 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -209,7 +209,7 @@ QUnit.test( "css() explicit and relative values", function( assert ) { } ); QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) { - assert.expect( 17 ); + assert.expect( 16 ); var cssCurrent, units = {}, @@ -271,7 +271,10 @@ QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) { add( "lineHeight", 30, "pc" ); add( "lineHeight", 1, "cm" ); add( "lineHeight", -20, "mm" ); - add( "lineHeight", 50, "%" ); + + // Opera 12 does something funky for this one + // Just disabling for 1.12 + // add( "lineHeight", 50, "%" ); } ); QUnit.test( "css(String, Object)", function( assert ) { @@ -530,7 +533,7 @@ QUnit.test( "show();", function( assert ) { assert.expect( 18 ); - var hiddendiv, div, pass, test; + var hiddendiv, div, pass, old, test; hiddendiv = jQuery( "div.hidden" ); assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" ); @@ -553,7 +556,9 @@ QUnit.test( "show();", function( assert ) { assert.ok( pass, "Show" ); // #show-tests * is set display: none in CSS - jQuery( "#qunit-fixture" ).append( "

" ); + jQuery( "#qunit-fixture" ).append( "

" ); + old = jQuery( "#test-table" ).show().css( "display" ) !== "table"; + jQuery( "#test-table" ).remove(); test = { "div": "block", @@ -562,14 +567,14 @@ QUnit.test( "show();", function( assert ) { "code": "inline", "pre": "block", "span": "inline", - "table": "table", - "thead": "table-header-group", - "tbody": "table-row-group", - "tr": "table-row", - "th": "table-cell", - "td": "table-cell", + "table": old ? "block" : "table", + "thead": old ? "block" : "table-header-group", + "tbody": old ? "block" : "table-row-group", + "tr": old ? "block" : "table-row", + "th": old ? "block" : "table-cell", + "td": old ? "block" : "table-cell", "ul": "block", - "li": "list-item" + "li": old ? "block" : "list-item" }; jQuery.each( test, function( selector, expected ) { @@ -1021,13 +1026,13 @@ QUnit.test( "css opacity consistency across browsers (#12685)", function( assert fixture = jQuery( "#qunit-fixture" ); // Append style element - jQuery( "" ).appendTo( fixture ); + jQuery( "" ).appendTo( fixture ); el = jQuery( "
" ).appendTo( fixture ); - assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "opacity from style sheet (-ms-filter:alpha with spaces)" ); + assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" ); el.removeClass( "opacityWithSpaces_t12685" ).addClass( "opacityNoSpaces_t12685" ); - assert.equal( Math.round( el.css( "opacity" ) * 100 ), 20, "opacity from style sheet (-ms-filter:alpha without spaces)" ); + assert.equal( Math.round( el.css( "opacity" ) * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" ); el.css( "opacity", 0.3 ); assert.equal( Math.round( el.css( "opacity" ) * 100 ), 30, "override opacity" ); el.css( "opacity", "" ); @@ -1275,7 +1280,7 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function( } } ); -QUnit.test( "get upper case alpha opacity in IE8", function( assert ) { +QUnit[/msie 8\.0/.test(navigator.userAgent) ? "test" : "skip"]( "get upper case alpha opacity in IE8", function( assert ) { assert.expect( 1 ); var div = document.createElement( "div" ), @@ -1295,7 +1300,7 @@ QUnit.test( "get upper case alpha opacity in IE8", function( assert ) { function resetCssPropsFor( name ) { delete jQuery.cssProps[ name ]; jQuery.each( vendorPrefixes, function( index, prefix ) { - delete jQuery.cssProps[ prefix + name[ 0 ].toUpperCase() + name.slice( 1 ) ]; + delete jQuery.cssProps[ prefix + name.charAt( 0 ).toUpperCase() + name.slice( 1 ) ]; } ); } diff --git a/test/unit/effects.js b/test/unit/effects.js index 78dbe9dca..c1d67b651 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -24,7 +24,7 @@ QUnit.test( "sanity check", function( assert ) { assert.equal( jQuery( "#dl:visible, #qunit-fixture:visible, #foo:visible" ).length, 3, "QUnit state is correct for testing effects" ); } ); -test( "show() basic", 2, function() { +QUnit.test( "show() basic", 2, function() { var div, hiddendiv = jQuery( "div.hidden" ); @@ -42,8 +42,8 @@ test( "show() basic", 2, function() { QUnit.expectJqData( this, hiddendiv, "olddisplay" ); } ); -test( "show()", 27, function() { - var div, speeds, test, +QUnit.test( "show()", 27, function() { + var div, speeds, test, old, displaysActual, displaysExpected, hiddendiv = jQuery( "div.hidden" ); @@ -93,7 +93,11 @@ test( "show()", 27, function() { QUnit.expectJqData( this, div, "olddisplay" ); // #show-tests * is set display: none in CSS - jQuery( "#qunit-fixture" ).append( "

" ); + jQuery( "#qunit-fixture" ) + .append( "

" ); + + old = jQuery( "#test-table" ).show().css( "display" ) !== "table"; + jQuery( "#test-table" ).remove(); test = { "div": "block", @@ -102,14 +106,14 @@ test( "show()", 27, function() { "code": "inline", "pre": "block", "span": "inline", - "table": "table", - "thead": "table-header-group", - "tbody": "table-row-group", - "tr": "table-row", - "th": "table-cell", - "td": "table-cell", + "table": old ? "block" : "table", + "thead": old ? "block" : "table-header-group", + "tbody": old ? "block" : "table-row-group", + "tr": old ? "block" : "table-row", + "th": old ? "block" : "table-cell", + "td": old ? "block" : "table-cell", "ul": "block", - "li": "list-item" + "li": old ? "block" : "list-item" }; jQuery.each( test, function( selector, expected ) { @@ -124,31 +128,35 @@ test( "show()", 27, function() { jQuery( "
test
text test" ).hide().remove(); } ); -test( "show(Number) - other displays", function() { +QUnit.test( "show(Number) - other displays", function() { expect( 15 ); // #show-tests * is set display: none in CSS - jQuery( "#qunit-fixture" ).append( "

" ); + jQuery( "#qunit-fixture" ).append( "

" ); + + var test, + old = jQuery("#test-table").show().css("display") !== "table"; + jQuery("#test-table").remove(); // Note: inline elements are expected to be inline-block // because we're showing width/height // Can't animate width/height inline // See #14344 - var test = { + test = { "div": "block", "p": "block", "a": "inline-block", "code": "inline-block", "pre": "block", "span": "inline-block", - "table": "table", - "thead": "table-header-group", - "tbody": "table-row-group", - "tr": "table-row", - "th": "table-cell", - "td": "table-cell", + "table": old ? "block" : "table", + "thead": old ? "block" : "table-header-group", + "tbody": old ? "block" : "table-row-group", + "tr": old ? "block" : "table-row", + "th": old ? "block" : "table-cell", + "td": old ? "block" : "table-cell", "ul": "block", - "li": "list-item" + "li": old ? "block" : "list-item" }; jQuery.each( test, function( selector, expected ) { @@ -162,7 +170,7 @@ test( "show(Number) - other displays", function() { } ); // Supports #7397 -test( "Persist correct display value", function() { +QUnit.test( "Persist correct display value", function() { expect( 3 ); // #show-tests * is set display: none in CSS @@ -194,7 +202,7 @@ test( "Persist correct display value", function() { QUnit.expectJqData( this, $span, "olddisplay" ); } ); -test( "animate(Hash, Object, Function)", function() { +QUnit.test( "animate(Hash, Object, Function)", function() { expect( 1 ); var hash = { opacity: "show" }, hashCopy = jQuery.extend( {}, hash ); @@ -203,7 +211,7 @@ test( "animate(Hash, Object, Function)", function() { } ); } ); -test( "animate relative values", function() { +QUnit.test( "animate relative values", function() { var value = 40, clock = this.clock, @@ -242,7 +250,7 @@ test( "animate relative values", function() { } ); } ); -test( "animate negative height", function() { +QUnit.test( "animate negative height", function() { expect( 1 ); jQuery( "#foo" ).animate( { height: -100 }, 100, function() { equal( this.offsetHeight, 0, "Verify height." ); @@ -250,7 +258,7 @@ test( "animate negative height", function() { this.clock.tick( 100 ); } ); -test( "animate negative margin", function() { +QUnit.test( "animate negative margin", function() { expect( 1 ); jQuery( "#foo" ).animate( { "marginTop": -100 }, 100, function() { equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." ); @@ -258,7 +266,7 @@ test( "animate negative margin", function() { this.clock.tick( 100 ); } ); -test( "animate negative margin with px", function() { +QUnit.test( "animate negative margin with px", function() { expect( 1 ); jQuery( "#foo" ).animate( { marginTop: "-100px" }, 100, function() { equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." ); @@ -266,7 +274,7 @@ test( "animate negative margin with px", function() { this.clock.tick( 100 ); } ); -test( "animate negative padding", function() { +QUnit.test( "animate negative padding", function() { expect( 1 ); jQuery( "#foo" ).animate( { "paddingBottom": -100 }, 100, function() { equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." ); @@ -274,42 +282,59 @@ test( "animate negative padding", function() { this.clock.tick( 100 ); } ); -test( "animate block as inline width/height", function() { +QUnit.test( "animate block as inline width/height", function() { expect( 3 ); - var span = jQuery( "" ).css( "display", "inline-block" ).appendTo( "body" ); + var span = jQuery("").css("display", "inline-block").appendTo("body"), + expected = span.css("display"); span.remove(); - jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, 100, function() { - equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); - equal( this.offsetWidth, 42, "width was animated" ); - equal( this.offsetHeight, 42, "height was animated" ); - } ); + if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) { + + jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() { + equal( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); + equal( this.offsetWidth, 42, "width was animated" ); + equal( this.offsetHeight, 42, "height was animated" ); + }); + // Browser doesn't support inline-block + } else { + ok( true, "Browser doesn't support inline-block" ); + ok( true, "Browser doesn't support inline-block" ); + ok( true, "Browser doesn't support inline-block" ); + } this.clock.tick( 100 ); } ); -test( "animate native inline width/height", function() { +QUnit.test( "animate native inline width/height", function() { expect( 3 ); - var span = jQuery( "" ).css( "display", "inline-block" ).appendTo( "body" ); + var span = jQuery("").css("display", "inline-block").appendTo("body"), + expected = span.css("display"); span.remove(); - jQuery( "#foo" ).css( { display: "", width: "", height: "" } ) - .append( "text" ) - .children( "span" ) - .animate( { width: 42, height: 42 }, 100, function() { - equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); - equal( this.offsetWidth, 42, "width was animated" ); - equal( this.offsetHeight, 42, "height was animated" ); - } ); - + if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) { + jQuery("#foo").css({ display: "", width: "", height: "" }) + .append("text") + .children("span") + .animate({ width: 42, height: 42 }, 100, function() { + equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); + equal( this.offsetWidth, 42, "width was animated" ); + equal( this.offsetHeight, 42, "height was animated" ); + }); + + // Browser doesn't support inline-block + } else { + ok( true, "Browser doesn't support inline-block" ); + ok( true, "Browser doesn't support inline-block" ); + ok( true, "Browser doesn't support inline-block" ); + } this.clock.tick( 100 ); } ); -test( "animate block width/height", function() { +QUnit.test( "animate block width/height", function() { expect( 3 ); jQuery( "
" ).appendTo( "#qunit-fixture" ).css( { @@ -336,47 +361,56 @@ test( "animate block width/height", function() { this.clock.tick( 100 ); } ); -test( "animate table width/height", function() { +QUnit.test("animate table width/height", function() { expect( 1 ); + var displayMode = jQuery( "#table" ).css( "display" ) !== "table" ? "block" : "table"; + jQuery( "#table" ).animate( { width: 42, height: 42 }, 100, function() { - equal( jQuery( this ).css( "display" ), "table", "display mode is correct" ); + equal( jQuery( this ).css( "display" ), displayMode, "display mode is correct" ); } ); this.clock.tick( 100 ); } ); -test( "animate table-row width/height", function() { +QUnit.test("animate table-row width/height", function() { expect( 3 ); - var tr = jQuery( "#table" ) + var displayMode, + tr = jQuery( "#table" ) .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } ) .html( "
" ) .find( "tr" ); + // IE<8 uses "block" instead of the correct display type + displayMode = tr.css( "display" ) !== "table-row" ? "block" : "table-row"; + tr.animate( { width: 10, height: 10 }, 100, function() { - equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" ); + equal( jQuery( this ).css( "display" ), displayMode, "display mode is correct" ); equal( this.offsetWidth, 20, "width animated to shrink wrap point" ); equal( this.offsetHeight, 20, "height animated to shrink wrap point" ); } ); this.clock.tick( 100 ); } ); -test( "animate table-cell width/height", function() { +QUnit.test( "animate table-cell width/height", function() { expect( 3 ); - - var td = jQuery( "#table" ) - .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } ) + var displayMode, + td = jQuery( "#table" ) + .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 }) .html( "
" ) .find( "td" ); + // IE<8 uses "block" instead of the correct display type + displayMode = td.css( "display" ) !== "table-cell" ? "block" : "table-cell"; + td.animate( { width: 10, height: 10 }, 100, function() { - equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" ); + equal( jQuery( this ).css( "display" ), displayMode, "display mode is correct" ); equal( this.offsetWidth, 20, "width animated to shrink wrap point" ); equal( this.offsetHeight, 20, "height animated to shrink wrap point" ); } ); this.clock.tick( 100 ); } ); -test( "animate percentage(%) on width/height", function() { +QUnit.test( "animate percentage(%) on width/height", function() { expect( 2 ); var $div = jQuery( "
" ) @@ -390,7 +424,7 @@ test( "animate percentage(%) on width/height", function() { this.clock.tick( 20 ); } ); -test( "animate resets overflow-x and overflow-y when finished", function() { +QUnit.test( "animate resets overflow-x and overflow-y when finished", function() { expect( 2 ); jQuery( "#foo" ) .css( { display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" } ) @@ -402,7 +436,7 @@ test( "animate resets overflow-x and overflow-y when finished", function() { } ); /* // This test ends up being flaky depending upon the CPU load -test("animate option (queue === false)", function () { +QUnit.test("animate option (queue === false)", function () { expect(1); stop(); @@ -422,7 +456,7 @@ test("animate option (queue === false)", function () { }); */ -test( "animate option { queue: false }", function() { +QUnit.test( "animate option { queue: false }", function() { expect( 2 ); var foo = jQuery( "#foo" ); @@ -440,7 +474,7 @@ test( "animate option { queue: false }", function() { equal( foo.queue().length, 0, "Queue is empty" ); } ); -test( "animate option { queue: true }", function() { +QUnit.test( "animate option { queue: true }", function() { expect( 2 ); var foo = jQuery( "#foo" ); @@ -460,7 +494,7 @@ test( "animate option { queue: true }", function() { this.clock.tick( 10 ); } ); -test( "animate option { queue: 'name' }", function() { +QUnit.test( "animate option { queue: 'name' }", function() { expect( 5 ); var foo = jQuery( "#foo" ), origWidth = parseFloat( foo.css( "width" ) ), @@ -492,7 +526,7 @@ test( "animate option { queue: 'name' }", function() { } ); -test( "animate with no properties", function() { +QUnit.test( "animate with no properties", function() { expect( 2 ); var foo, @@ -514,7 +548,7 @@ test( "animate with no properties", function() { this.clock.tick( 100 ); } ); -test( "animate duration 0", function() { +QUnit.test( "animate duration 0", function() { expect( 11 ); var $elem, @@ -564,7 +598,7 @@ test( "animate duration 0", function() { $elem.remove(); } ); -test( "animate hyphenated properties", function() { +QUnit.test( "animate hyphenated properties", function() { expect( 1 ); jQuery( "#foo" ) @@ -578,7 +612,7 @@ test( "animate hyphenated properties", function() { } ); -test( "animate non-element", function() { +QUnit.test( "animate non-element", function() { expect( 1 ); var obj = { test: 0 }; @@ -589,7 +623,7 @@ test( "animate non-element", function() { this.clock.tick( 200 ); } ); -test( "stop()", function() { +QUnit.test( "stop()", function() { expect( 4 ); var $one, $two, @@ -629,7 +663,7 @@ test( "stop()", function() { this.clock.tick( 100 ); } ); -test( "stop() - several in queue", function() { +QUnit.test( "stop() - several in queue", function() { expect( 5 ); var nw, $foo = jQuery( "#foo" ); @@ -659,7 +693,7 @@ test( "stop() - several in queue", function() { equal( $foo.queue().length, 0, "0 in the queue" ); } ); -test( "stop(clearQueue)", function() { +QUnit.test( "stop(clearQueue)", function() { expect( 4 ); var $foo = jQuery( "#foo" ), @@ -683,7 +717,7 @@ test( "stop(clearQueue)", function() { equal( nw, $foo.css( "width" ), "The animation didn't continue" ); } ); -test( "stop(clearQueue, gotoEnd)", function() { +QUnit.test( "stop(clearQueue, gotoEnd)", function() { expect( 1 ); var $foo = jQuery( "#foo" ), @@ -712,7 +746,7 @@ test( "stop(clearQueue, gotoEnd)", function() { $foo.stop( true ); } ); -test( "stop( queue, ..., ... ) - Stop single queues", function() { +QUnit.test( "stop( queue, ..., ... ) - Stop single queues", function() { expect( 3 ); var saved, foo = jQuery( "#foo" ).css( { width: 200, height: 200 } ); @@ -743,10 +777,10 @@ test( "stop( queue, ..., ... ) - Stop single queues", function() { queue: "height" } ).dequeue( "height" ).stop( "height", false, false ); saved = parseFloat( foo.css( "height" ) ); - this.clock.tick( 500 ); + this.clock.tick( 500 ); } ); -test( "toggle()", function() { +QUnit.test( "toggle()", function() { expect( 6 ); var x = jQuery( "#foo" ); ok( x.is( ":visible" ), "is visible" ); @@ -763,7 +797,7 @@ test( "toggle()", function() { ok( x.is( ":visible" ), "is visible again" ); } ); -test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() { +QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() { var div = jQuery( "
" ).appendTo( "#qunit-fixture" ).css( { color: "#ABC", border: "5px solid black", @@ -817,7 +851,7 @@ test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() { jQuery( div ).remove(); } ); -test( "Overflow and Display", function() { +QUnit.test( "Overflow and Display", function() { expect( 4 ); var @@ -896,7 +930,7 @@ jQuery.each( { return 0; } }, function( tn, t ) { - test( fn + " to " + tn, function() { + QUnit.test( fn + " to " + tn, function() { var num, anim, elem = jQuery.makeTest( fn + " to " + tn ), t_w = t( elem, "width" ), @@ -1013,12 +1047,12 @@ jQuery.each( { } ); } ); -test( "Effects chaining", function() { +QUnit.test( "Effects chaining", function() { var remaining = 16, props = [ "opacity", "height", "width", "display", "overflow" ], setup = function( name, selector ) { var $el = jQuery( selector ); - return $el.data( getProps( $el[ 0 ] ) ).data( "name", name ); + return $el.data( getProps( $el[0] ) ).data( "name", name ); }, assert = function() { var data = jQuery.data( this ), @@ -1041,39 +1075,39 @@ test( "Effects chaining", function() { setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", assert ); setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", assert ); - setup( ".hide().show()", "#show div" ).hide( "fast" ).show( "fast", assert ); - setup( ".show().hide()", "#hide div" ).show( "fast" ).hide( "fast", assert ); - setup( ".show().hide(easing)", "#easehide div" ).show( "fast" ).hide( "fast", "linear", assert ); - setup( ".toggle().toggle() - in", "#togglein div" ).toggle( "fast" ).toggle( "fast", assert ); - setup( ".toggle().toggle() - out", "#toggleout div" ).toggle( "fast" ).toggle( "fast", assert ); - setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle( "fast" ).toggle( "fast", "linear", assert ); - setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown( "fast" ).slideUp( "fast", assert ); - setup( ".slideUp().slideDown()", "#slideup div" ).slideUp( "fast" ).slideDown( "fast", assert ); - setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp( "fast" ).slideDown( "fast", "linear", assert ); - setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle( "fast" ).slideToggle( "fast", assert ); - setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle( "fast" ).slideToggle( "fast", assert ); + setup( ".hide().show()", "#show div" ).hide("fast").show( "fast", assert ); + setup( ".show().hide()", "#hide div" ).show("fast").hide( "fast", assert ); + setup( ".show().hide(easing)", "#easehide div" ).show("fast").hide( "fast", "linear", assert ); + setup( ".toggle().toggle() - in", "#togglein div" ).toggle("fast").toggle( "fast", assert ); + setup( ".toggle().toggle() - out", "#toggleout div" ).toggle("fast").toggle( "fast", assert ); + setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle("fast").toggle( "fast", "linear", assert ); + setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown("fast").slideUp( "fast", assert ); + setup( ".slideUp().slideDown()", "#slideup div" ).slideUp("fast").slideDown( "fast", assert ); + setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp("fast").slideDown( "fast", "linear", assert ); + setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle("fast").slideToggle( "fast", assert ); + setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle("fast").slideToggle( "fast", assert ); setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert ); setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert ); setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert ); - this.clock.tick( 400 ); + this.clock.tick( 400 ); } ); jQuery.makeTest = function( text ) { - var elem = jQuery( "
" ) - .attr( "id", "test" + jQuery.makeTest.id++ ) - .addClass( "box" ); + var elem = jQuery( "
" ) + .attr( "id", "test" + jQuery.makeTest.id++ ) + .addClass( "box" ); - jQuery( "

" ) - .text( text ) - .appendTo( "#fx-tests" ) - .after( elem ); + jQuery( "

" ) + .text( text ) + .appendTo( "#fx-tests" ) + .after( elem ); - return elem; + return elem; }; jQuery.makeTest.id = 1; -test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function() { +QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function() { expect( 4 ); var $checkedtest = jQuery( "#checkedtest" ); @@ -1086,7 +1120,7 @@ test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function() this.clock.tick( 200 ); } ); -test( "interrupt toggle", function() { +QUnit.test( "interrupt toggle", function() { expect( 24 ); var env = this, @@ -1148,7 +1182,7 @@ test( "interrupt toggle", function() { // FIXME untangle the set timeouts } ); -test( "animate with per-property easing", function() { +QUnit.test( "animate with per-property easing", function() { expect( 5 ); @@ -1188,7 +1222,7 @@ test( "animate with per-property easing", function() { this.clock.tick( 400 ); } ); -test( "animate with CSS shorthand properties", function() { +QUnit.test( "animate with CSS shorthand properties", function() { expect( 11 ); var easeAnimation_count = 0, @@ -1234,7 +1268,7 @@ test( "animate with CSS shorthand properties", function() { this.clock.tick( 400 ); } ); -test( "hide hidden elements, with animation (bug #7141)", function() { +QUnit.test( "hide hidden elements, with animation (bug #7141)", function() { expect( 3 ); var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); @@ -1248,7 +1282,7 @@ test( "hide hidden elements, with animation (bug #7141)", function() { this.clock.tick( 10 ); } ); -test( "animate unit-less properties (#4966)", 2, function() { +QUnit.test( "animate unit-less properties (#4966)", 2, function() { var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); equal( div.css( "z-index" ), "0", "z-index is 0" ); div.animate( { zIndex: 2 }, function() { @@ -1257,7 +1291,7 @@ test( "animate unit-less properties (#4966)", 2, function() { this.clock.tick( 400 ); } ); -test( "animate properties missing px w/ opacity as last (#9074)", 2, function() { +QUnit.test( "animate properties missing px w/ opacity as last (#9074)", 2, function() { expect( 6 ); var ml, l, div = jQuery( "
" ) @@ -1284,7 +1318,7 @@ test( "animate properties missing px w/ opacity as last (#9074)", 2, function() div.stop().remove(); } ); -test( "callbacks should fire in correct order (#9100)", function() { +QUnit.test( "callbacks should fire in correct order (#9100)", function() { expect( 1 ); var a = 1, @@ -1304,7 +1338,7 @@ test( "callbacks should fire in correct order (#9100)", function() { this.clock.tick( 20 ); } ); -test( "callbacks that throw exceptions will be removed (#5684)", function() { +QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function() { expect( 2 ); var foo = jQuery( "#foo" ); @@ -1332,7 +1366,7 @@ test( "callbacks that throw exceptions will be removed (#5684)", function() { } ); -test( "animate will scale margin properties individually", function() { +QUnit.test( "animate will scale margin properties individually", function() { expect( 2 ); var foo = jQuery( "#foo" ).css( { @@ -1357,7 +1391,7 @@ test( "animate will scale margin properties individually", function() { } ); } ); -test( "Do not append px to 'fill-opacity' #9548", 1, function() { +QUnit.test( "Do not append px to 'fill-opacity' #9548", 1, function() { var $div = jQuery( "
" ).appendTo( "#qunit-fixture" ); $div.css( "fill-opacity", 0 ).animate( { "fill-opacity": 1.0 }, 0, function() { @@ -1372,7 +1406,7 @@ test( "Do not append px to 'fill-opacity' #9548", 1, function() { } ); } ); -test( "line-height animates correctly (#13855)", 12, function() { +QUnit.test( "line-height animates correctly (#13855)", 12, function() { var t0, clock = this.clock, longDuration = 2000, @@ -1434,7 +1468,7 @@ clock.tick( 50 ); } ); // Start 1.8 Animation tests -test( "jQuery.Animation( object, props, opts )", 4, function() { +QUnit.test( "jQuery.Animation( object, props, opts )", 4, function() { var animation, testObject = { "foo": 0, @@ -1459,7 +1493,7 @@ test( "jQuery.Animation( object, props, opts )", 4, function() { this.clock.tick( 10 ); } ); -test( "Animate Option: step: function( percent, tween )", 1, function() { +QUnit.test( "Animate Option: step: function( percent, tween )", 1, function() { var counter = {}; jQuery( "#foo" ).animate( { prop1: 1, @@ -1485,7 +1519,7 @@ test( "Animate Option: step: function( percent, tween )", 1, function() { this.clock.tick( 10 ); } ); -test( "Animate callbacks have correct context", 2, function() { +QUnit.test( "Animate callbacks have correct context", 2, function() { var foo = jQuery( "#foo" ); foo.animate( { height: 10 @@ -1500,7 +1534,7 @@ test( "Animate callbacks have correct context", 2, function() { this.clock.tick( 10 ); } ); -test( "User supplied callback called after show when fx off (#8892)", 2, function() { +QUnit.test( "User supplied callback called after show when fx off (#8892)", 2, function() { var foo = jQuery( "#foo" ); jQuery.fx.off = true; foo.hide(); @@ -1514,7 +1548,7 @@ test( "User supplied callback called after show when fx off (#8892)", 2, functio this.clock.tick( 1000 ); } ); -test( "animate should set display for disconnected nodes", function() { +QUnit.test( "animate should set display for disconnected nodes", function() { expect( 18 ); var env = this, @@ -1563,10 +1597,10 @@ test( "animate should set display for disconnected nodes", function() { jQuery.fn[ name ].apply( this, opt.concat( callback ) ); } ); } ); - clock.tick( 400 ); + clock.tick( 400 ); } ); -test( "Animation callback should not show animated element as :animated (#7157)", 1, function() { +QUnit.test( "Animation callback should not show animated element as :animated (#7157)", 1, function() { var foo = jQuery( "#foo" ); foo.animate( { @@ -1577,7 +1611,7 @@ test( "Animation callback should not show animated element as :animated (#7157)" this.clock.tick( 100 ); } ); -test( "Initial step callback should show element as :animated (#14623)", 1, function() { +QUnit.test( "Initial step callback should show element as :animated (#14623)", 1, function() { var foo = jQuery( "#foo" ); foo.animate( { @@ -1592,7 +1626,7 @@ test( "Initial step callback should show element as :animated (#14623)", 1, func foo.stop(); } ); -test( "hide called on element within hidden parent should set display to none (#10045)", 3, function() { +QUnit.test( "hide called on element within hidden parent should set display to none (#10045)", 3, function() { var hidden = jQuery( ".hidden" ), elems = jQuery( "
hide
hide0
hide1
" ); @@ -1612,7 +1646,7 @@ test( "hide called on element within hidden parent should set display to none (# this.clock.tick( 10 ); } ); -test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", 5, function() { +QUnit.test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", 5, function() { var foo = jQuery( "#foo" ), i = 0, elems = jQuery(); @@ -1641,7 +1675,7 @@ test( "hide, fadeOut and slideUp called on element width height and width = 0 sh this.clock.tick( 400 ); } ); -test( "hide should not leave hidden inline elements visible (#14848)", 2, function() { +QUnit.test( "hide should not leave hidden inline elements visible (#14848)", 2, function() { var el = jQuery( "#simon1" ); el.hide( 1, function() { @@ -1654,7 +1688,7 @@ test( "hide should not leave hidden inline elements visible (#14848)", 2, functi this.clock.tick( 100 ); } ); -test( "Handle queue:false promises", 10, function() { +QUnit.test( "Handle queue:false promises", 10, function() { var foo = jQuery( "#foo" ).clone().addBack(), step = 1; @@ -1705,7 +1739,7 @@ test( "Handle queue:false promises", 10, function() { this.clock.tick( 10 ); } ); -test( "multiple unqueued and promise", 4, function() { +QUnit.test( "multiple unqueued and promise", 4, function() { var foo = jQuery( "#foo" ), step = 1; foo.animate( { @@ -1738,7 +1772,7 @@ test( "multiple unqueued and promise", 4, function() { this.clock.tick( 1000 ); } ); -test( "animate does not change start value for non-px animation (#7109)", 1, function() { +QUnit.test( "animate does not change start value for non-px animation (#7109)", 1, function() { var parent = jQuery( "
" ).css( { width: 284, height: 1 } ).appendTo( "#qunit-fixture" ), child = parent.children().css( { fontSize: "98.6in", width: "0.01em", height: 1 } ), actual = parseFloat( child.css( "width" ) ), @@ -1758,7 +1792,7 @@ test( "animate does not change start value for non-px animation (#7109)", 1, fun this.clock.tick( 10 ); } ); -test( "non-px animation handles non-numeric start (#11971)", 2, function() { +QUnit.test( "non-px animation handles non-numeric start (#11971)", 2, function() { var foo = jQuery( "#foo" ), initial = foo.css( "backgroundPositionX" ); @@ -1875,7 +1909,7 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) { this.clock.tick( 10 ); } ); -test( "Animate properly sets overflow hidden when animating width/height (#12117)", 8, function() { +QUnit.test( "Animate properly sets overflow hidden when animating width/height (#12117)", 8, function() { jQuery.each( [ "height", "width" ], function( _, prop ) { jQuery.each( [ 100, 0 ], function( _, value ) { var div = jQuery( "
" ).css( "overflow", "auto" ), @@ -1891,7 +1925,7 @@ test( "Animate properly sets overflow hidden when animating width/height (#12117 } ); } ); -test( "Each tick of the timer loop uses a fresh time (#12837)", function() { +QUnit.test( "Each tick of the timer loop uses a fresh time (#12837)", function() { var lastVal, tmp = jQuery( { test: 0 @@ -1916,7 +1950,7 @@ test( "Each tick of the timer loop uses a fresh time (#12837)", function() { tmp.stop(); } ); -test( "Animations with 0 duration don't ease (#12273)", 1, function() { +QUnit.test( "Animations with 0 duration don't ease (#12273)", 1, function() { jQuery.easing.test = function() { ok( false, "Called easing" ); }; @@ -1939,7 +1973,7 @@ jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) { // this test would look a lot better if we were using something to override // the default timers var duration = 1500; - test( "toggle state tests: " + method + " (#8685)", function() { + QUnit.test( "toggle state tests: " + method + " (#8685)", function() { function secondToggle() { var stopped = parseFloat( element.css( check ) ); tested = false; @@ -1983,7 +2017,7 @@ jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) { } ); } ); -test( "jQuery.fx.start & jQuery.fx.stop hook points", function() { +QUnit.test( "jQuery.fx.start & jQuery.fx.stop hook points", function() { var oldStart = jQuery.fx.start, oldStop = jQuery.fx.stop, foo = jQuery( { foo: 0 } ); @@ -2012,7 +2046,7 @@ test( "jQuery.fx.start & jQuery.fx.stop hook points", function() { jQuery.fx.stop = oldStop; } ); -test( ".finish() completes all queued animations", function() { +QUnit.test( ".finish() completes all queued animations", function() { var animations = { top: 100, left: 100, @@ -2047,7 +2081,7 @@ test( ".finish() completes all queued animations", function() { jQuery.fx.tick(); } ); -test( ".finish( false ) - unqueued animations", function() { +QUnit.test( ".finish( false ) - unqueued animations", function() { var animations = { top: 100, left: 100, @@ -2082,7 +2116,7 @@ test( ".finish( false ) - unqueued animations", function() { jQuery.fx.tick(); } ); -test( ".finish( \"custom\" ) - custom queue animations", function() { +QUnit.test( ".finish( \"custom\" ) - custom queue animations", function() { var animations = { top: 100, left: 100, @@ -2121,7 +2155,7 @@ test( ".finish( \"custom\" ) - custom queue animations", function() { jQuery.fx.tick(); } ); -test( ".finish() calls finish of custom queue functions", function() { +QUnit.test( ".finish() calls finish of custom queue functions", function() { function queueTester( next, hooks ) { hooks.stop = function( gotoEnd ) { inside++; @@ -2147,7 +2181,7 @@ test( ".finish() calls finish of custom queue functions", function() { div.remove(); } ); -test( ".finish() is applied correctly when multiple elements were animated (#13937)", function() { +QUnit.test( ".finish() is applied correctly when multiple elements were animated (#13937)", function() { expect( 3 ); var elems = jQuery( "012" ); @@ -2164,38 +2198,38 @@ test( ".finish() is applied correctly when multiple elements were animated (#139 this.clock.tick( 1500 ); } ); -test( "slideDown() after stop() (#13483)", 2, function() { - var ul = jQuery( "
    " ) - .appendTo( "#qunit-fixture" ), - origHeight = ul.height(), - clock = this.clock; +QUnit.test( "slideDown() after stop() (#13483)", 2, function() { + var ul = jQuery( "
      " ) + .appendTo( "#qunit-fixture" ), + origHeight = ul.height(), + clock = this.clock; + + // First test. slideUp() -> stop() in the middle -> slideDown() until the end + ul.slideUp( 1000 ); + clock.tick( 500 ); + ul.stop( true ); + ul.slideDown( 1, function() { + equal( ul.height(), origHeight, "slideDown() after interrupting slideUp() with stop(). Height must be in original value" ); - // First test. slideUp() -> stop() in the middle -> slideDown() until the end - ul.slideUp( 1000 ); + // Second test. slideDown() -> stop() in the middle -> slideDown() until the end + ul.slideUp( 1 ); + clock.tick( 10 ); + ul.slideDown( 1000 ); clock.tick( 500 ); ul.stop( true ); - ul.slideDown( 1, function() { - equal( ul.height(), origHeight, "slideDown() after interrupting slideUp() with stop(). Height must be in original value" ); - - // Second test. slideDown() -> stop() in the middle -> slideDown() until the end - ul.slideUp( 1 ); - clock.tick( 10 ); - ul.slideDown( 1000 ); - clock.tick( 500 ); - ul.stop( true ); - ul.slideDown( 1 ); - equal( ul.height(), origHeight, "slideDown() after interrupting slideDown() with stop(). Height must be in original value" ); - - // Cleanup - ul.remove(); - clock.tick( 10 ); - - } ); + ul.slideDown( 1 ); + equal( ul.height(), origHeight, "slideDown() after interrupting slideDown() with stop(). Height must be in original value" ); + // Cleanup + ul.remove(); clock.tick( 10 ); + + } ); + + clock.tick( 10 ); } ); -test( "Respect display value on inline elements (#14824)", 2, function() { +QUnit.test( "Respect display value on inline elements (#14824)", 2, function() { var clock = this.clock, fromStyleSheet = jQuery( "" ), fromStyleAttr = jQuery( "" ); diff --git a/test/unit/event.js b/test/unit/event.js index ab768439f..525a72d13 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1422,7 +1422,7 @@ QUnit.test( "Submit event can be stopped (#11049)", function( assert ) { form.remove(); } ); -// Test beforeunload event only if it supported. +// Test beforeunload event only if it supported (i.e. not Opera) // Support: iOS 7+, Android<4.0 // iOS & old Android have the window.onbeforeunload field but don't support the beforeunload // handler making it impossible to feature-detect the support. @@ -1430,6 +1430,7 @@ if ( window.onbeforeunload === null && !/(ipad|iphone|ipod|android 2\.3)/i.test( navigator.userAgent ) ) { QUnit.asyncTest( "on(beforeunload)", 4, function( assert ) { var win, + forIE6 = 0, fired = false, iframe = jQuery( "