diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | grunt.js | 69 | ||||
-rw-r--r-- | src/css.js | 134 | ||||
-rw-r--r-- | src/effects.js | 141 | ||||
m--------- | src/sizzle | 0 | ||||
-rw-r--r-- | test/data/testinit.js | 2 | ||||
-rw-r--r-- | test/unit/css.js | 184 | ||||
-rw-r--r-- | test/unit/effects.js | 108 | ||||
-rw-r--r-- | test/unit/queue.js | 113 |
9 files changed, 433 insertions, 319 deletions
diff --git a/.gitignore b/.gitignore index 0973197c1..e40d864aa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,5 @@ dist *.patch /*.html .DS_Store -dist/.sizecache.json build/.sizecache.json node_modules @@ -50,7 +50,7 @@ module.exports = function( grunt ) { "src/ajax/jsonp.js", "src/ajax/script.js", "src/ajax/xhr.js", - "src/effects.js", + { flag: "effects", src: "src/effects.js" }, "src/offset.js", "src/dimensions.js", "src/exports.js", @@ -103,7 +103,7 @@ module.exports = function( grunt ) { }); // Default grunt. - grunt.registerTask( "default", "selector build lint min compare_size" ); + grunt.registerTask( "default", "selector build:*:* lint min compare_size" ); grunt.loadNpmTasks("grunt-compare-size"); @@ -159,29 +159,48 @@ module.exports = function( grunt ) { // Special concat/build task to handle various jQuery build requirements - grunt.registerMultiTask( "build", "Concatenate source, embed date/version", function() { - // Concat specified files. - var compiled = "", - name = this.file.dest; + grunt.registerMultiTask( + "build", + "Concatenate source (include/exclude modules with +/- flags), embed date/version", + function() { + // Concat specified files. + var compiled = "", + modules = this.flags, + optIn = !modules["*"], + name = this.file.dest; + + this.file.src.forEach(function( filepath ) { + // Include optional modules per build flags; exclusion trumps inclusion + var flag = filepath.flag; + if ( flag ) { + if ( modules[ "-" + flag ] || + optIn && !modules[ flag ] && !modules[ "+" + flag ] ) { + + log.writeln( "Excluding " + filepath.flag + ": '" + filepath.src + "'." ); + return; + } + log.writeln( "Including " + filepath.flag + ": '" + filepath.src + "'." ); + filepath = filepath.src; + } + + // Unwrap redundant IIFEs + compiled += file.read( filepath ).replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" ); + }); + + // Embed Date + // Embed Version + compiled = compiled.replace( "@DATE", new Date() ) + .replace( "@VERSION", config("pkg.version") ); + + // Write concatenated source to file + file.write( name, compiled ); + + // Fail task if errors were logged. + if ( this.errorCount ) { + return false; + } - this.file.src.forEach(function( filepath ) { - compiled += file.read( filepath ).replace( /.function..jQuery...\{/g, "" ).replace( /\}...jQuery..;/g, "" ); + // Otherwise, print a success message. + log.writeln( "File '" + name + "' created." ); }); - - // Embed Date - // Embed Version - compiled = compiled.replace( "@DATE", new Date() ) - .replace( "@VERSION", config("pkg.version") ); - - // Write concatenated source to file - file.write( name, compiled ); - - // Fail task if errors were logged. - if ( this.errorCount ) { - return false; - } - - // Otherwise, print a success message. - log.writeln( "File '" + name + "' created." ); - }); }; diff --git a/src/css.js b/src/css.js index 214b4a77b..6668ed9b5 100644 --- a/src/css.js +++ b/src/css.js @@ -3,7 +3,8 @@ // order is important! jQuery.cssExpand = [ "Top", "Right", "Bottom", "Left" ]; -var ralpha = /alpha\([^)]*\)/i, +var curCSS, iframe, iframeDoc, + ralpha = /alpha\([^)]*\)/i, ropacity = /opacity=([^)]*)/, // fixed for IE9, see #8346 rupper = /([A-Z]|^ms)/g, @@ -11,14 +12,14 @@ var ralpha = /alpha\([^)]*\)/i, rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i, rrelNum = /^([\-+])=([\-+.\de]+)/, rmargin = /^margin/, - + elemdisplay = {}, cssShow = { position: "absolute", visibility: "hidden", display: "block" }, cssExpand = jQuery.cssExpand, cssPrefixes = [ "Webkit", "O", "Moz", "ms" ], rposition = /^(top|right|bottom|left)$/, - curCSS; + eventsToggle = jQuery.fn.toggle; // return a css property mapped to a potentially vendor prefixed property function vendorPropName( style, name ) { @@ -43,13 +44,83 @@ function vendorPropName( style, name ) { return origName; } -jQuery.fn.css = function( name, value ) { - return jQuery.access( this, function( elem, name, value ) { - return value !== undefined ? - jQuery.style( elem, name, value ) : - jQuery.css( elem, name ); - }, name, value, arguments.length > 1 ); -}; +function showHide( elements, show ) { + var elem, display, + values = [], + index = 0, + length = elements.length; + + for ( ; index < length; index++ ) { + elem = elements[ index ]; + if ( !elem.style ) { + continue; + } + values[ index ] = jQuery._data( elem, "olddisplay" ); + if ( show ) { + // Reset the inline display of this element to learn if it is + // being hidden by cascaded rules or not + if ( !values[ index ] && elem.style.display === "none" ) { + elem.style.display = ""; + } + + // Set elements which have been overridden with display: none + // in a stylesheet to whatever the default browser style is + // for such an element + if ( (elem.style.display === "" && curCSS( elem, "display" ) === "none") || + !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { + values[ index ] = jQuery._data( elem, "olddisplay", jQuery.defaultDisplay(elem.nodeName) ); + } + } else { + display = curCSS( elem, "display" ); + + if ( !values[ index ] && display !== "none" ) { + jQuery._data( elem, "olddisplay", display ); + } + } + } + + // Set the display of most of the elements in a second loop + // to avoid the constant reflow + for ( index = 0; index < length; index++ ) { + elem = elements[ index ]; + if ( !elem.style ) { + continue; + } + if ( !show || elem.style.display === "none" || elem.style.display === "" ) { + elem.style.display = show ? values[ index ] || "" : "none"; + } + } + + return elements; +} + +jQuery.fn.extend({ + css: function( name, value ) { + return jQuery.access( this, function( elem, name, value ) { + return value !== undefined ? + jQuery.style( elem, name, value ) : + jQuery.css( elem, name ); + }, name, value, arguments.length > 1 ); + }, + show: function() { + return showHide( this, true ); + }, + hide: function() { + return showHide( this ); + }, + toggle: function( fn, fn2 ) { + var bool = typeof fn === "boolean"; + + if ( jQuery.isFunction( fn ) && jQuery.isFunction( fn2 ) ) { + return eventsToggle.apply( this, arguments ); + } + + return this.each(function() { + var state = bool ? fn : jQuery( this ).is(":hidden"); + showHide([ this ], state ); + }); + } +}); jQuery.extend({ // Add in style property hooks for overriding the default @@ -200,6 +271,49 @@ jQuery.extend({ } return ret; + }, + + // Try to determine the default display value of an element + defaultDisplay: function( nodeName ) { + if ( elemdisplay[ nodeName ] ) { + return elemdisplay[ nodeName ]; + } + + var elem = jQuery( "<" + nodeName + ">" ).appendTo( document.body ), + display = elem.css("display"); + elem.remove(); + + // If the simple way fails, + // get element's real default display by attaching it to a temp iframe + if ( display === "none" || display === "" ) { + // Use the already-created iframe if possible + iframe = document.body.appendChild( + iframe || jQuery.extend( document.createElement("iframe"), { + frameBorder: 0, + width: 0, + height: 0 + }) + ); + + // Create a cacheable copy of the iframe document on first call. + // IE and Opera will allow us to reuse the iframeDoc without re-writing the fake HTML + // document to it; WebKit & Firefox won't allow reusing the iframe document. + if ( !iframeDoc || !iframe.createElement ) { + iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; + iframeDoc.write("<!doctype html><html><body>"); + iframeDoc.close(); + } + + elem = iframeDoc.body.appendChild( iframeDoc.createElement(nodeName) ); + + display = curCSS( elem, "display" ); + document.body.removeChild( iframe ); + } + + // Store the correct default display + elemdisplay[ nodeName ] = display; + + return display; } }); diff --git a/src/effects.js b/src/effects.js index c213e69d2..c2f04a049 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,7 +1,6 @@ (function( jQuery ) { -var fxNow, timerId, iframe, iframeDoc, - elemdisplay = {}, +var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, rfxnum = /^([\-+]=)?((?:\d*\.)?\d+)([a-z%]*)$/i, rrun = /queueHooks$/, @@ -31,8 +30,7 @@ var fxNow, timerId, iframe, iframeDoc, } return tween; }] - }, - oldToggle = jQuery.fn.toggle; + }; // Animations created synchronously will run synchronously function createFxNow() { @@ -255,7 +253,7 @@ function defaultPrefilter( elem, props, opts ) { // inline-level elements accept inline-block; // block-level elements need to be inline with layout - if ( !jQuery.support.inlineBlockNeedsLayout || defaultDisplay( elem.nodeName ) === "inline" ) { + if ( !jQuery.support.inlineBlockNeedsLayout || jQuery.defaultDisplay( elem.nodeName ) === "inline" ) { style.display = "inline-block"; } else { @@ -290,10 +288,10 @@ function defaultPrefilter( elem, props, opts ) { if ( length ) { dataShow = jQuery._data( elem, "fxshow" ) || jQuery._data( elem, "fxshow", {} ); if ( hidden ) { - showHide([ elem ], true ); + jQuery( elem ).show(); } else { anim.finish(function() { - showHide([ elem ]); + jQuery( elem ).hide(); }); } anim.finish(function() { @@ -400,84 +398,18 @@ function isHidden( elem, el ) { return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument.documentElement, elem ); } -function showHide( elements, show ) { - var elem, display, - values = [], - index = 0, - length = elements.length; - - for ( ; index < length; index++ ) { - elem = elements[ index ]; - if ( !elem.style ) { - continue; - } - values[ index ] = jQuery._data( elem, "olddisplay" ); - if ( show ) { - // Reset the inline display of this element to learn if it is - // being hidden by cascaded rules or not - if ( !values[ index ] && elem.style.display === "none" ) { - elem.style.display = ""; - } - - // Set elements which have been overridden with display: none - // in a stylesheet to whatever the default browser style is - // for such an element - if ( elem.style.display === "" && isHidden( elem ) ) { - values[ index ] = jQuery._data( elem, "olddisplay", defaultDisplay( elem.nodeName ) ); - } - } else { - display = jQuery.css( elem, "display" ); - - if ( !values[ index ] && display !== "none" ) { - jQuery._data( elem, "olddisplay", display ); - } - } - } - - // Set the display of most of the elements in a second loop - // to avoid the constant reflow - for ( index = 0; index < length; index++ ) { - elem = elements[ index ]; - if ( !elem.style ) { - continue; - } - if ( !show || elem.style.display === "none" || elem.style.display === "" ) { - elem.style.display = show ? values[ index ] || "" : "none"; - } - } - - return elements; -} +jQuery.each([ "toggle", "show", "hide" ], function( i, name ) { + var cssFn = jQuery.fn[ name ]; + jQuery.fn[ name ] = function( speed, easing, callback ) { + return speed == null || typeof speed === "boolean" || + // special check for .toggle( handler, handler, ... ) + ( !i && jQuery.isFunction( speed ) && jQuery.isFunction( easing ) ) ? + cssFn.apply( this, arguments ) : + this.animate( genFx( name, true ), speed, easing, callback ); + }; +}); jQuery.fn.extend({ - show: function( speed, easing, callback ) { - return speed || speed === 0 ? - this.animate( genFx( "show", true ), speed, easing, callback ) : - showHide( this, true ); - }, - hide: function( speed, easing, callback ) { - return speed || speed === 0 ? - this.animate( genFx( "hide", true ), speed, easing, callback ) : - showHide( this ); - }, - toggle: function( fn, fn2, callback ) { - var bool = typeof fn === "boolean"; - - if ( jQuery.isFunction( fn ) && jQuery.isFunction( fn2 ) ) { - oldToggle.apply( this, arguments ); - - } else if ( fn == null || bool ) { - this.each(function() { - var state = bool ? fn : isHidden( this ); - showHide([ this ], state ); - }); - - } else { - this.animate( genFx( "toggle", true ), fn, fn2, callback ); - } - - return this; - }, fadeTo: function( speed, to, easing, callback ) { // show any hidden elements after setting opacity to 0 @@ -681,47 +613,4 @@ if ( jQuery.expr && jQuery.expr.filters ) { }; } -// Try to restore the default display value of an element -function defaultDisplay( nodeName ) { - if ( elemdisplay[ nodeName ] ) { - return elemdisplay[ nodeName ]; - } - - var elem = jQuery( "<" + nodeName + ">" ).appendTo( document.body ), - display = elem.css("display"); - elem.remove(); - - // If the simple way fails, - // get element's real default display by attaching it to a temp iframe - if ( display === "none" || display === "" ) { - // Use the already-created iframe if possible - iframe = document.body.appendChild( - iframe || jQuery.extend( document.createElement("iframe"), { - frameBorder: 0, - width: 0, - height: 0 - }) - ); - - // Create a cacheable copy of the iframe document on first call. - // IE and Opera will allow us to reuse the iframeDoc without re-writing the fake HTML - // document to it; WebKit & Firefox won't allow reusing the iframe document. - if ( !iframeDoc || !iframe.createElement ) { - iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; - iframeDoc.write("<!doctype html><html><body>"); - iframeDoc.close(); - } - - elem = iframeDoc.body.appendChild( iframeDoc.createElement(nodeName) ); - - display = jQuery.css( elem, "display" ); - document.body.removeChild( iframe ); - } - - // Store the correct default display - elemdisplay[ nodeName ] = display; - - return display; -} - })( jQuery ); diff --git a/src/sizzle b/src/sizzle -Subproject e844a8c04235cec865dff32af88bc3d498c3cd2 +Subproject feebbd7e053bff426444c7b348c776c99c7490e diff --git a/test/data/testinit.js b/test/data/testinit.js index 85765b75c..9fc91ffb5 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -163,7 +163,7 @@ function url(value) { equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" ); oldFragmentsLength = fragmentsLength; } - if ( jQuery.timers.length !== oldTimersLength ) { + if ( jQuery.timers && jQuery.timers.length !== oldTimersLength ) { equal( jQuery.timers.length, oldTimersLength, "No timers are still running" ); oldTimersLength = jQuery.timers.length; } diff --git a/test/unit/css.js b/test/unit/css.js index ac531f1e0..5e9e109bb 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -411,6 +411,179 @@ test("css(Object) where values are Functions with incoming values", function() { jQuery("#cssFunctionTest").remove(); }); +test("show(); hide()", function() { + expect(22); + + var hiddendiv = jQuery("div.hidden"); + hiddendiv.hide(); + equal( hiddendiv.css("display"), "none", "Non-detached div hidden" ); + hiddendiv.show(); + equal( hiddendiv.css("display"), "block", "Pre-hidden div shown" ); + + var div = jQuery("<div>").hide(); + equal( div.css("display"), "none", "Detached div hidden" ); + div.appendTo("#qunit-fixture").show(); + equal( div.css("display"), "block", "Pre-hidden div shown" ); + + QUnit.reset(); + + hiddendiv = jQuery("div.hidden"); + + equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none"); + + hiddendiv.css("display", "block"); + equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block"); + + hiddendiv.show(); + equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block"); + + hiddendiv.css("display",""); + + var pass = true; + div = jQuery("#qunit-fixture div"); + div.show().each(function(){ + if ( this.style.display == "none" ) pass = false; + }); + ok( pass, "Show" ); + + // #show-tests * is set display: none in CSS + jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>"); + + var old = jQuery("#test-table").show().css("display") !== "table"; + jQuery("#test-table").remove(); + + var test = { + "div" : "block", + "p" : "block", + "a" : "inline", + "code" : "inline", + "pre" : "block", + "span" : "inline", + "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" : old ? "block" : "list-item" + }; + + jQuery.each(test, function(selector, expected) { + var elem = jQuery(selector, "#show-tests").show(); + equal( elem.css("display"), expected, "Show using correct display type for " + selector ); + }); + + // Make sure that showing or hiding a text node doesn't cause an error + jQuery("<div>test</div> text <span>test</span>").show().remove(); + jQuery("<div>test</div> text <span>test</span>").hide().remove(); +}); + +test("show() resolves correct default display #8099", function() { + expect(7); + var tt8099 = jQuery("<tt/>").appendTo("body"), + dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body"); + + equal( tt8099.css("display"), "none", "default display override for all tt" ); + equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); + + equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" ); + + equal( tt8099.hide().css("display"), "none", "default display override for all tt" ); + equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); + + equal( dfn8099.css("display"), "none", "default display override for all dfn" ); + equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" ); + + tt8099.remove(); + dfn8099.remove(); +}); + +test( "show() resolves correct default display, detached nodes (#10006)", function(){ + // Tests originally contributed by Orkel in + // https://github.com/jquery/jquery/pull/458 + expect( 11 ); + + var div, span; + + div = jQuery("<div class='hidden'>"); + div.show().appendTo("#qunit-fixture"); + equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." ); + + div = jQuery("<div style='display: none'>"); + div.show().appendTo("#qunit-fixture"); + equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." ); + + span = jQuery("<span class='hidden'/>"); + span.show().appendTo("#qunit-fixture"); + equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." ); + + span = jQuery("<span style='display: inline'/>"); + span.show().appendTo("#qunit-fixture"); + equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." ); + + div = jQuery("<div><div class='hidden'></div></div>").children("div"); + div.show().appendTo("#qunit-fixture"); + equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." ); + + div = jQuery("<div><div style='display: none'></div></div>").children("div"); + div.show().appendTo("#qunit-fixture"); + equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." ); + + div = jQuery("div.hidden"); + div.detach().show(); + equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." ); + div.remove(); + + span = jQuery("<span>"); + span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" ); + equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." ); + span.remove(); + + div = jQuery("<div>"); + div.show().appendTo("#qunit-fixture"); + ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." ); + + div = jQuery( document.createElement("div") ); + div.show().appendTo("#qunit-fixture"); + equal( div.css("display"), "block", "Make sure a pre-created element has default display." ); + + div = jQuery("<div style='display: inline'/>"); + div.show().appendTo("#qunit-fixture"); + equal( div.css("display"), "inline", "Make sure that element has same display when it was created." ); +}); + +test("toggle()", function() { + expect(6); + var x = jQuery("#foo"); + ok( x.is(":visible"), "is visible" ); + x.toggle(); + ok( x.is(":hidden"), "is hidden" ); + x.toggle(); + ok( x.is(":visible"), "is visible again" ); + + x.toggle(true); + ok( x.is(":visible"), "is visible" ); + x.toggle(false); + ok( x.is(":hidden"), "is hidden" ); + x.toggle(true); + ok( x.is(":visible"), "is visible again" ); +}); + +test("hide hidden elements (bug #7141)", function() { + expect(3); + QUnit.reset(); + + var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture"); + equal( div.css("display"), "none", "Element is hidden by default" ); + div.hide(); + ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); + div.show(); + equal( div.css("display"), "block", "Show a double-hidden element" ); + + div.remove(); +}); + test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () { expect(4); @@ -545,13 +718,8 @@ test("percentage position properties in IE<9 should not be incorrectly transform }); test("Do not append px to 'fill-opacity' #9548", 1, function() { - - var $div = jQuery("<div>").appendTo("#qunit-fixture"); - - $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () { - equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'"); - }); - + var $div = jQuery("<div>").appendTo("#qunit-fixture").css("fill-opacity", 1); + equal( $div.css("fill-opacity"), 1, "Do not append px to 'fill-opacity'"); }); test("outerWidth(true) and css('margin') returning % instead of px in Webkit, see #10639", function() { @@ -609,4 +777,4 @@ test( "cssHooks - expand", function() { }); -});
\ No newline at end of file +}); diff --git a/test/unit/effects.js b/test/unit/effects.js index a2645b106..2b1cff3d3 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -1,3 +1,5 @@ +if ( jQuery.fx ) { + module("effects", { teardown: moduleTeardown }); test("sanity check", function() { @@ -6,7 +8,7 @@ test("sanity check", function() { }); test("show()", function() { - expect(28); + expect(26); var hiddendiv = jQuery("div.hidden"); @@ -42,7 +44,6 @@ test("show()", function() { var speeds = { "null speed": null, "undefined speed": undefined, - "empty string speed": "", "false speed": false }; @@ -167,82 +168,6 @@ test("Persist correct display value", function() { }); }); -test("show() resolves correct default display #8099", function() { - expect(7); - var tt8099 = jQuery("<tt/>").appendTo("body"), - dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body"); - - equal( tt8099.css("display"), "none", "default display override for all tt" ); - equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); - - equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" ); - - equal( tt8099.hide().css("display"), "none", "default display override for all tt" ); - equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); - - equal( dfn8099.css("display"), "none", "default display override for all dfn" ); - equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" ); - - tt8099.remove(); - dfn8099.remove(); - -}); - -test( "show() resolves correct default display, detached nodes (#10006)", function(){ - // Tests originally contributed by Orkel in - // https://github.com/jquery/jquery/pull/458 - expect( 11 ); - - var div, span; - - div = jQuery("<div class='hidden'>"); - div.show().appendTo("#qunit-fixture"); - equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." ); - - div = jQuery("<div style='display: none'>"); - div.show().appendTo("#qunit-fixture"); - equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." ); - - span = jQuery("<span class='hidden'/>"); - span.show().appendTo("#qunit-fixture"); - equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." ); - - span = jQuery("<span style='display: inline'/>"); - span.show().appendTo("#qunit-fixture"); - equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." ); - - div = jQuery("<div><div class='hidden'></div></div>").children("div"); - div.show().appendTo("#qunit-fixture"); - equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." ); - - div = jQuery("<div><div style='display: none'></div></div>").children("div"); - div.show().appendTo("#qunit-fixture"); - equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." ); - - div = jQuery("div.hidden"); - div.detach().show(); - equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." ); - div.remove(); - - span = jQuery("<span>"); - span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" ); - equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." ); - span.remove(); - - div = jQuery("<div>"); - div.show().appendTo("#qunit-fixture"); - ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." ); - - div = jQuery( document.createElement("div") ); - div.show().appendTo("#qunit-fixture"); - equal( div.css("display"), "block", "Make sure a pre-created element has default display." ); - - div = jQuery("<div style='display: inline'/>"); - div.show().appendTo("#qunit-fixture"); - equal( div.css("display"), "inline", "Make sure that element has same display when it was created." ); -}); - - test("animate(Hash, Object, Function)", function() { expect(1); stop(); @@ -480,7 +405,6 @@ asyncTest( "animate option { queue: true }", function() { notEqual( foo.queue().length, 0, "Default queue is not empty" ); }); - asyncTest( "animate option { queue: 'name' }", function() { expect( 5 ); var foo = jQuery( "#foo" ), @@ -1295,20 +1219,6 @@ test("animate with CSS shorthand properties", function(){ }); }); -test("hide hidden elements (bug #7141)", function() { - expect(3); - QUnit.reset(); - - var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture"); - equal( div.css("display"), "none", "Element is hidden by default" ); - div.hide(); - ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); - div.show(); - equal( div.css("display"), "block", "Show a double-hidden element" ); - - div.remove(); -}); - test("hide hidden elements, with animation (bug #7141)", function() { expect(3); QUnit.reset(); @@ -1437,6 +1347,14 @@ test("animate will scale margin properties individually", function() { start(); }); +test("Do not append px to 'fill-opacity' #9548", 1, function() { + var $div = jQuery("<div>").appendTo("#qunit-fixture"); + + $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () { + equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'"); + }); +}); + // Start 1.8 Animation tests asyncTest( "jQuery.Animation( object, props, opts )", 1, function() { var testObject = { @@ -1708,4 +1626,6 @@ asyncTest( "multiple unqueued and promise", 4, function() { strictEqual( step++, 4, "Step 4" ); start(); }); -});
\ No newline at end of file +}); + +} // if ( jQuery.fx )
\ No newline at end of file diff --git a/test/unit/queue.js b/test/unit/queue.js index 6a614edb6..fac74f906 100644 --- a/test/unit/queue.js +++ b/test/unit/queue.js @@ -101,11 +101,13 @@ test("callbacks keep their place in the queue", function() { div.queue(function( next ) { equal( ++counter, 1, "Queue/callback order: first called" ); setTimeout( next, 200 ); - }).show(100, function() { + }).delay( 100 ).queue(function( next ) { equal( ++counter, 2, "Queue/callback order: second called" ); - jQuery(this).hide(100, function() { + jQuery( this ).delay( 100 ).queue(function( next ) { equal( ++counter, 4, "Queue/callback order: fourth called" ); + next(); }); + next(); }).queue(function( next ) { equal( ++counter, 3, "Queue/callback order: third called" ); next(); @@ -133,44 +135,6 @@ test("delay()", function() { equal( run, 0, "The delay delayed the next function from running." ); }); -test("delay() can be stopped", function() { - expect( 3 ); - stop(); - - var foo = jQuery({}), run = 0; - - foo - .queue( "alternate", function( next ) { - run++; - ok( true, "This first function was dequeued" ); - next(); - }) - .delay( 1000, "alternate" ) - .queue( "alternate", function() { - run++; - ok( true, "The function was dequeued immediately, the delay was stopped" ); - }) - .dequeue( "alternate" ) - - // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next - .stop( "alternate", false, false ) - - // this test - .delay( 1000 ) - .queue(function() { - run++; - ok( false, "This queue should never run" ); - }) - - // stop( clearQueue ) should clear the queue - .stop( true, false ); - - equal( run, 2, "Queue ran the proper functions" ); - - setTimeout( start, 2000 ); -}); - - test("clearQueue(name) clears the queue", function() { expect(2); @@ -265,22 +229,63 @@ test( ".promise(obj)", function() { strictEqual( promise, obj, ".promise(type, obj) returns obj" ); }); -asyncTest( "queue stop hooks", 2, function() { - var foo = jQuery( "#foo" ); - foo.queue( function( next, hooks ) { - hooks.stop = function( gotoEnd ) { - equal( !!gotoEnd, false, "Stopped without gotoEnd" ); - }; +if ( jQuery.fn.stop ) { + test("delay() can be stopped", function() { + expect( 3 ); + stop(); + + var foo = jQuery({}), run = 0; + + foo + .queue( "alternate", function( next ) { + run++; + ok( true, "This first function was dequeued" ); + next(); + }) + .delay( 1000, "alternate" ) + .queue( "alternate", function() { + run++; + ok( true, "The function was dequeued immediately, the delay was stopped" ); + }) + .dequeue( "alternate" ) + + // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next + .stop( "alternate", false, false ) + + // this test + .delay( 1000 ) + .queue(function() { + run++; + ok( false, "This queue should never run" ); + }) + + // stop( clearQueue ) should clear the queue + .stop( true, false ); + + equal( run, 2, "Queue ran the proper functions" ); + + setTimeout( start, 2000 ); }); - foo.stop(); - foo.queue( function( next, hooks ) { - hooks.stop = function( gotoEnd ) { - equal( gotoEnd, true, "Stopped with gotoEnd" ); - start(); - }; + asyncTest( "queue stop hooks", 2, function() { + var foo = jQuery( "#foo" ); + + foo.queue( function( next, hooks ) { + hooks.stop = function( gotoEnd ) { + equal( !!gotoEnd, false, "Stopped without gotoEnd" ); + }; + }); + foo.stop(); + + foo.queue( function( next, hooks ) { + hooks.stop = function( gotoEnd ) { + equal( gotoEnd, true, "Stopped with gotoEnd" ); + start(); + }; + }); + + foo.stop( false, true ); }); - foo.stop( false, true ); -}); +} // if ( jQuery.fn.stop )
\ No newline at end of file |