diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-11 19:56:11 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-11 19:56:11 +0300 |
commit | 87db099ed54d0dac624c4ae6b476328e88aef2d7 (patch) | |
tree | bb63d6e6f218943e30a431650138ba1cb78db17c | |
parent | 88df7676d735b4cf16dd56ac55fbdef3319f66e7 (diff) | |
download | jquery-87db099ed54d0dac624c4ae6b476328e88aef2d7.tar.gz jquery-87db099ed54d0dac624c4ae6b476328e88aef2d7.zip |
Revert "CSS: Make show/hide/toggle methods a module"
This reverts commit 67d7a2eefee768b59eb3d51cb1fb2c671873e58a.
-rw-r--r-- | Gruntfile.js | 1 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | src/css.js | 22 | ||||
-rw-r--r-- | src/css/showHide.js | 27 | ||||
-rw-r--r-- | test/unit/basic.js | 10 | ||||
-rw-r--r-- | test/unit/css.js | 30 | ||||
-rw-r--r-- | test/unit/dimensions.js | 16 | ||||
-rw-r--r-- | test/unit/queue.js | 3 |
8 files changed, 47 insertions, 65 deletions
diff --git a/Gruntfile.js b/Gruntfile.js index dd4b07d30..98e446775 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -70,7 +70,6 @@ module.exports = function( grunt ) { ajax: [ "manipulation/_evalUrl", "event/ajax" ], callbacks: [ "deferred" ], css: [ "effects", "dimensions", "offset" ], - "css/showHide": [ "effects" ], sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ] } } @@ -81,8 +81,7 @@ Some example modules that can be excluded are: - **ajax/xhr**: The XMLHTTPRequest AJAX transport only. - **ajax/script**: The `<script>` AJAX transport only; used to retrieve scripts. - **ajax/jsonp**: The JSONP AJAX transport only; depends on the ajax/script transport. -- **css**: The `.css()` method. Also removes **all** modules depending on css (including **effects**, **dimensions**, and **offset**). -- **css/showHide**: Non-animated `.show()`, `.hide()` and `.toggle()`; can be excluded if you use classes or explicit `.css()` calls to set the `display` property. Also removes the **effects** module. +- **css**: The `.css()` method plus non-animated `.show()`, `.hide()` and `.toggle()`. Also removes **all** modules depending on css (including **effects**, **dimensions**, and **offset**). - **deprecated**: Methods documented as deprecated but not yet removed. - **dimensions**: The `.width()` and `.height()` methods, including `inner-` and `outer-` variations. - **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`. diff --git a/src/css.js b/src/css.js index 9b3a46382..c0cee5baa 100644 --- a/src/css.js +++ b/src/css.js @@ -14,12 +14,13 @@ define( [ "./css/adjustCSS", "./css/addGetHookIf", "./css/support", + "./css/showHide", "./core/init", "./core/ready", "./selector" // contains ], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand, - isHidden, getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) { + isHidden, getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, showHide ) { var @@ -415,6 +416,25 @@ jQuery.fn.extend( { 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( state ) { + if ( typeof state === "boolean" ) { + return state ? this.show() : this.hide(); + } + + return this.each( function() { + if ( isHidden( this ) ) { + jQuery( this ).show(); + } else { + jQuery( this ).hide(); + } + } ); } } ); diff --git a/src/css/showHide.js b/src/css/showHide.js index 327291eb1..35e15bde8 100644 --- a/src/css/showHide.js +++ b/src/css/showHide.js @@ -1,7 +1,6 @@ define( [ - "../data/var/dataPriv", - "../css/var/isHidden" -], function( dataPriv, isHidden ) { + "../data/var/dataPriv" +], function( dataPriv ) { function showHide( elements, show ) { var display, elem, @@ -44,26 +43,6 @@ function showHide( elements, show ) { return elements; } -jQuery.fn.extend( { - show: function() { - return showHide( this, true ); - }, - hide: function() { - return showHide( this ); - }, - toggle: function( state ) { - if ( typeof state === "boolean" ) { - return state ? this.show() : this.hide(); - } - - return this.each( function() { - if ( isHidden( this ) ) { - jQuery( this ).show(); - } else { - jQuery( this ).hide(); - } - } ); - } -} ); +return showHide; } ); diff --git a/test/unit/basic.js b/test/unit/basic.js index 49b518d3f..25e86d1a3 100644 --- a/test/unit/basic.js +++ b/test/unit/basic.js @@ -54,19 +54,11 @@ QUnit.test( "attributes", function( assert ) { if ( jQuery.css ) { QUnit.test( "css", function( assert ) { - assert.expect( 1 ); + assert.expect( 3 ); var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ); assert.strictEqual( div.css( "width", "50px" ).css( "width" ), "50px", ".css getter/setter" ); -} ); -} - -if ( jQuery.fn.show && jQuery.fn.hide ) { -QUnit.test( "show/hide", function( assert ) { - assert.expect( 2 ); - - var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ); div.hide(); assert.strictEqual( div.css( "display" ), "none", "div hidden" ); diff --git a/test/unit/css.js b/test/unit/css.js index a8ab36756..f80eea257 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -471,9 +471,6 @@ QUnit.test( "css(Object) where values are Functions with incoming values", funct jQuery( "#cssFunctionTest" ).remove(); } ); -// .show(), .hide(), can be excluded from the build -if ( jQuery.fn.show && jQuery.fn.hide ) { - QUnit.test( "show(); hide()", function( assert ) { assert.expect( 4 ); @@ -652,21 +649,8 @@ QUnit.test( "hide hidden elements (bug #7141)", function( assert ) { div.remove(); } ); -QUnit.test( "show() after hide() should always set display to initial value (#14750)", function( assert ) { - assert.expect( 1 ); - - var div = jQuery( "<div />" ), - fixture = jQuery( "#qunit-fixture" ); - - fixture.append( div ); - - div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show(); - assert.equal( div.css( "display" ), "list-item", "should get last set display value" ); -} ); - -} +QUnit.test( "toggle()", function( assert ) { -QUnit[ jQuery.find.compile && jQuery.fn.toggle ? "test" : "skip" ]( "toggle()", function( assert ) { assert.expect( 9 ); var div, oldHide, x = jQuery( "#foo" ); @@ -1114,6 +1098,18 @@ QUnit.test( } ); +QUnit.test( "show() after hide() should always set display to initial value (#14750)", function( assert ) { + assert.expect( 1 ); + + var div = jQuery( "<div />" ), + fixture = jQuery( "#qunit-fixture" ); + + fixture.append( div ); + + div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show(); + assert.equal( div.css( "display" ), "list-item", "should get last set display value" ); +} ); + // Support: IE < 11 // We have to jump through the hoops here in order to test work with "order" CSS property, // that some browsers do not support. This test is not, strictly speaking, correct, diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 00139a8c2..20c93f680 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -35,9 +35,9 @@ function testWidth( val, assert ) { $div = jQuery( "#nothiddendiv" ); $div.width( val( 30 ) ); assert.equal( $div.width(), 30, "Test set to 30 correctly" ); - $div.css( "display", "none" ); + $div.hide(); assert.equal( $div.width(), 30, "Test hidden div" ); - $div.css( "display", "" ); + $div.show(); $div.width( val( -1 ) ); // handle negative numbers by setting to 0 #11604 assert.equal( $div.width(), 0, "Test negative width normalized to 0" ); $div.css( "padding", "20px" ); @@ -86,9 +86,9 @@ function testHeight( val, assert ) { $div = jQuery( "#nothiddendiv" ); $div.height( val( 30 ) ); assert.equal( $div.height(), 30, "Test set to 30 correctly" ); - $div.css( "display", "none" ); + $div.hide(); assert.equal( $div.height(), 30, "Test hidden div" ); - $div.css( "display", "" ); + $div.show(); $div.height( val( -1 ) ); // handle negative numbers by setting to 0 #11604 assert.equal( $div.height(), 0, "Test negative height normalized to 0" ); $div.css( "padding", "20px" ); @@ -149,7 +149,7 @@ QUnit.test( "innerWidth()", function( assert ) { assert.equal( $div.innerWidth(), 30, "Test with margin and border" ); $div.css( "padding", "20px" ); assert.equal( $div.innerWidth(), 70, "Test with margin, border and padding" ); - $div.css( "display", "none" ); + $div.hide(); assert.equal( $div.innerWidth(), 70, "Test hidden div" ); // reset styles @@ -183,7 +183,7 @@ QUnit.test( "innerHeight()", function( assert ) { assert.equal( $div.innerHeight(), 30, "Test with margin and border" ); $div.css( "padding", "20px" ); assert.equal( $div.innerHeight(), 70, "Test with margin, border and padding" ); - $div.css( "display", "none" ); + $div.hide(); assert.equal( $div.innerHeight(), 70, "Test hidden div" ); // reset styles @@ -221,7 +221,7 @@ QUnit.test( "outerWidth()", function( assert ) { assert.equal( $div.outerWidth(), 74, "Test with padding, border and margin without margin option" ); $div.css( "position", "absolute" ); assert.equal( $div.outerWidth( true ), 94, "Test with padding, border and margin with margin option" ); - $div.css( "display", "none" ); + $div.hide(); assert.equal( $div.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" ); // reset styles @@ -368,7 +368,7 @@ QUnit.test( "outerHeight()", function( assert ) { $div.css( "margin", "10px" ); assert.equal( $div.outerHeight(), 74, "Test with padding, border and margin without margin option" ); assert.equal( $div.outerHeight( true ), 94, "Test with padding, border and margin with margin option" ); - $div.css( "display", "none" ); + $div.hide(); assert.equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" ); // reset styles diff --git a/test/unit/queue.js b/test/unit/queue.js index fa8b6717a..780e20058 100644 --- a/test/unit/queue.js +++ b/test/unit/queue.js @@ -231,8 +231,6 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function foo.dequeue( "queue" ); } ); -if ( jQuery.fn.animate ) { - QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function( assert ) { var foo = jQuery( "#foo" ), test = 1; @@ -253,7 +251,6 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete befo } ); } ); -} QUnit.test( ".promise(obj)", function( assert ) { assert.expect( 2 ); |