mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Revert "CSS: Make show/hide/toggle methods a module"
This reverts commit 3842246024
.
This commit is contained in:
parent
82d10848c6
commit
079e0796ae
@ -67,9 +67,7 @@ module.exports = function( grunt ) {
|
|||||||
removeWith: {
|
removeWith: {
|
||||||
ajax: [ "manipulation/_evalUrl", "event/ajax" ],
|
ajax: [ "manipulation/_evalUrl", "event/ajax" ],
|
||||||
callbacks: [ "deferred" ],
|
callbacks: [ "deferred" ],
|
||||||
css: [ "effects", "dimensions", "offset" ],
|
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/xhr**: The XMLHTTPRequest AJAX transport only.
|
||||||
- **ajax/script**: The `<script>` AJAX transport only; used to retrieve scripts.
|
- **ajax/script**: The `<script>` AJAX transport only; used to retrieve scripts.
|
||||||
- **ajax/jsonp**: The JSONP AJAX transport only; depends on the ajax/script transport.
|
- **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**: The `.css()` method plus non-animated `.show()`, `.hide()` and `.toggle()`. 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.
|
|
||||||
- **deprecated**: Methods documented as deprecated but not yet removed.
|
- **deprecated**: Methods documented as deprecated but not yet removed.
|
||||||
- **dimensions**: The `.width()` and `.height()` methods, including `inner-` and `outer-` variations.
|
- **dimensions**: The `.width()` and `.height()` methods, including `inner-` and `outer-` variations.
|
||||||
- **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
|
- **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
|
||||||
|
22
src/css.js
22
src/css.js
@ -13,12 +13,13 @@ define( [
|
|||||||
"./css/adjustCSS",
|
"./css/adjustCSS",
|
||||||
"./css/addGetHookIf",
|
"./css/addGetHookIf",
|
||||||
"./css/support",
|
"./css/support",
|
||||||
|
"./css/showHide",
|
||||||
|
|
||||||
"./core/init",
|
"./core/init",
|
||||||
"./core/ready",
|
"./core/ready",
|
||||||
"./selector" // contains
|
"./selector" // contains
|
||||||
], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand,
|
], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand,
|
||||||
isHidden, swap, curCSS, adjustCSS, addGetHookIf, support ) {
|
isHidden, swap, curCSS, adjustCSS, addGetHookIf, support, showHide ) {
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
||||||
@ -505,6 +506,25 @@ jQuery.fn.extend( {
|
|||||||
jQuery.style( elem, name, value ) :
|
jQuery.style( elem, name, value ) :
|
||||||
jQuery.css( elem, name );
|
jQuery.css( elem, name );
|
||||||
}, name, value, arguments.length > 1 );
|
}, 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();
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
define( [
|
define( [], function() {
|
||||||
"../core",
|
|
||||||
"../css/var/isHidden"
|
|
||||||
], function( jQuery, isHidden ) {
|
|
||||||
|
|
||||||
function showHide( elements, show ) {
|
function showHide( elements, show ) {
|
||||||
var display, elem,
|
var display, elem,
|
||||||
values = [],
|
values = [],
|
||||||
@ -44,26 +40,6 @@ function showHide( elements, show ) {
|
|||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery.fn.extend( {
|
return showHide;
|
||||||
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();
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
@ -54,19 +54,11 @@ QUnit.test( "attributes", function( assert ) {
|
|||||||
|
|
||||||
if ( jQuery.css ) {
|
if ( jQuery.css ) {
|
||||||
QUnit.test( "css", function( assert ) {
|
QUnit.test( "css", function( assert ) {
|
||||||
assert.expect( 1 );
|
assert.expect( 3 );
|
||||||
|
|
||||||
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
|
var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
|
||||||
|
|
||||||
assert.strictEqual( div.css( "width", "50px" ).css( "width" ), "50px", ".css getter/setter" );
|
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();
|
div.hide();
|
||||||
assert.strictEqual( div.css( "display" ), "none", "div hidden" );
|
assert.strictEqual( div.css( "display" ), "none", "div hidden" );
|
||||||
|
@ -520,9 +520,6 @@ QUnit.test( "css(Object) where values are Functions with incoming values", funct
|
|||||||
jQuery( "#cssFunctionTest" ).remove();
|
jQuery( "#cssFunctionTest" ).remove();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// .show(), .hide(), can be excluded from the build
|
|
||||||
if ( jQuery.fn.show && jQuery.fn.hide ) {
|
|
||||||
|
|
||||||
QUnit.test( "show(); hide()", function( assert ) {
|
QUnit.test( "show(); hide()", function( assert ) {
|
||||||
assert.expect( 4 );
|
assert.expect( 4 );
|
||||||
|
|
||||||
@ -686,35 +683,6 @@ QUnit.test( "show() resolves correct default display for detached nodes", functi
|
|||||||
span.remove();
|
span.remove();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "hide hidden elements (bug #7141)", function( assert ) {
|
|
||||||
assert.expect( 3 );
|
|
||||||
|
|
||||||
var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
|
|
||||||
assert.equal( div.css( "display" ), "none", "Element is hidden by default" );
|
|
||||||
div.hide();
|
|
||||||
assert.ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" );
|
|
||||||
div.show();
|
|
||||||
assert.equal( div.css( "display" ), "block", "Show a double-hidden element" );
|
|
||||||
|
|
||||||
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" );
|
|
||||||
} );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( jQuery.fn.toggle ) {
|
|
||||||
|
|
||||||
QUnit.test( "toggle()", function( assert ) {
|
QUnit.test( "toggle()", function( assert ) {
|
||||||
assert.expect( 9 );
|
assert.expect( 9 );
|
||||||
var div, oldHide,
|
var div, oldHide,
|
||||||
@ -748,7 +716,18 @@ QUnit.test( "toggle()", function( assert ) {
|
|||||||
jQuery.fn.hide = oldHide;
|
jQuery.fn.hide = oldHide;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
}
|
QUnit.test( "hide hidden elements (bug #7141)", function( assert ) {
|
||||||
|
assert.expect( 3 );
|
||||||
|
|
||||||
|
var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
|
||||||
|
assert.equal( div.css( "display" ), "none", "Element is hidden by default" );
|
||||||
|
div.hide();
|
||||||
|
assert.ok( !jQuery._data( div, "display" ), "display data is undefined after hiding an already-hidden element" );
|
||||||
|
div.show();
|
||||||
|
assert.equal( div.css( "display" ), "block", "Show a double-hidden element" );
|
||||||
|
|
||||||
|
div.remove();
|
||||||
|
} );
|
||||||
|
|
||||||
QUnit.test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) {
|
QUnit.test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) {
|
||||||
assert.expect( 4 );
|
assert.expect( 4 );
|
||||||
@ -1223,6 +1202,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
|
// Support: IE < 11
|
||||||
// We have to jump through the hoops here in order to test work with "order" CSS property,
|
// 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,
|
// that some browsers do not support. This test is not, strictly speaking, correct,
|
||||||
|
@ -35,9 +35,9 @@ function testWidth( val, assert ) {
|
|||||||
$div = jQuery( "#nothiddendiv" );
|
$div = jQuery( "#nothiddendiv" );
|
||||||
$div.width( val( 30 ) );
|
$div.width( val( 30 ) );
|
||||||
assert.equal( $div.width(), 30, "Test set to 30 correctly" );
|
assert.equal( $div.width(), 30, "Test set to 30 correctly" );
|
||||||
$div.css( "display", "none" );
|
$div.hide();
|
||||||
assert.equal( $div.width(), 30, "Test hidden div" );
|
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
|
$div.width( val( -1 ) ); // handle negative numbers by setting to 0 #11604
|
||||||
assert.equal( $div.width(), 0, "Test negative width normalized to 0" );
|
assert.equal( $div.width(), 0, "Test negative width normalized to 0" );
|
||||||
$div.css( "padding", "20px" );
|
$div.css( "padding", "20px" );
|
||||||
@ -56,6 +56,8 @@ function testWidth( val, assert ) {
|
|||||||
assert.equal( blah.width(), null, "Make sure 'null' is returned on an empty set" );
|
assert.equal( blah.width(), null, "Make sure 'null' is returned on an empty set" );
|
||||||
|
|
||||||
assert.equal( jQuery( window ).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
|
assert.equal( jQuery( window ).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
|
||||||
|
|
||||||
|
assert.expectJqData( this, $div[ 0 ], "display" );
|
||||||
}
|
}
|
||||||
|
|
||||||
QUnit.test( "width()", function( assert ) {
|
QUnit.test( "width()", function( assert ) {
|
||||||
@ -86,9 +88,9 @@ function testHeight( val, assert ) {
|
|||||||
$div = jQuery( "#nothiddendiv" );
|
$div = jQuery( "#nothiddendiv" );
|
||||||
$div.height( val( 30 ) );
|
$div.height( val( 30 ) );
|
||||||
assert.equal( $div.height(), 30, "Test set to 30 correctly" );
|
assert.equal( $div.height(), 30, "Test set to 30 correctly" );
|
||||||
$div.css( "display", "none" );
|
$div.hide();
|
||||||
assert.equal( $div.height(), 30, "Test hidden div" );
|
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
|
$div.height( val( -1 ) ); // handle negative numbers by setting to 0 #11604
|
||||||
assert.equal( $div.height(), 0, "Test negative height normalized to 0" );
|
assert.equal( $div.height(), 0, "Test negative height normalized to 0" );
|
||||||
$div.css( "padding", "20px" );
|
$div.css( "padding", "20px" );
|
||||||
@ -107,6 +109,8 @@ function testHeight( val, assert ) {
|
|||||||
assert.equal( blah.height(), null, "Make sure 'null' is returned on an empty set" );
|
assert.equal( blah.height(), null, "Make sure 'null' is returned on an empty set" );
|
||||||
|
|
||||||
assert.equal( jQuery( window ).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
|
assert.equal( jQuery( window ).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
|
||||||
|
|
||||||
|
assert.expectJqData( this, $div[ 0 ], "display" );
|
||||||
}
|
}
|
||||||
|
|
||||||
QUnit.test( "height()", function( assert ) {
|
QUnit.test( "height()", function( assert ) {
|
||||||
@ -149,7 +153,7 @@ QUnit.test( "innerWidth()", function( assert ) {
|
|||||||
assert.equal( $div.innerWidth(), 30, "Test with margin and border" );
|
assert.equal( $div.innerWidth(), 30, "Test with margin and border" );
|
||||||
$div.css( "padding", "20px" );
|
$div.css( "padding", "20px" );
|
||||||
assert.equal( $div.innerWidth(), 70, "Test with margin, border and padding" );
|
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" );
|
assert.equal( $div.innerWidth(), 70, "Test hidden div" );
|
||||||
|
|
||||||
// reset styles
|
// reset styles
|
||||||
@ -161,6 +165,7 @@ QUnit.test( "innerWidth()", function( assert ) {
|
|||||||
assert.equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
|
assert.equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
|
||||||
|
|
||||||
div.remove();
|
div.remove();
|
||||||
|
assert.expectJqData( this, $div[ 0 ], "display" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "innerHeight()", function( assert ) {
|
QUnit.test( "innerHeight()", function( assert ) {
|
||||||
@ -183,7 +188,7 @@ QUnit.test( "innerHeight()", function( assert ) {
|
|||||||
assert.equal( $div.innerHeight(), 30, "Test with margin and border" );
|
assert.equal( $div.innerHeight(), 30, "Test with margin and border" );
|
||||||
$div.css( "padding", "20px" );
|
$div.css( "padding", "20px" );
|
||||||
assert.equal( $div.innerHeight(), 70, "Test with margin, border and padding" );
|
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" );
|
assert.equal( $div.innerHeight(), 70, "Test hidden div" );
|
||||||
|
|
||||||
// reset styles
|
// reset styles
|
||||||
@ -195,6 +200,7 @@ QUnit.test( "innerHeight()", function( assert ) {
|
|||||||
assert.equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
|
assert.equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
|
||||||
|
|
||||||
div.remove();
|
div.remove();
|
||||||
|
assert.expectJqData( this, $div[ 0 ], "display" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "outerWidth()", function( assert ) {
|
QUnit.test( "outerWidth()", function( assert ) {
|
||||||
@ -221,7 +227,7 @@ QUnit.test( "outerWidth()", function( assert ) {
|
|||||||
assert.equal( $div.outerWidth(), 74, "Test with padding, border and margin without margin option" );
|
assert.equal( $div.outerWidth(), 74, "Test with padding, border and margin without margin option" );
|
||||||
$div.css( "position", "absolute" );
|
$div.css( "position", "absolute" );
|
||||||
assert.equal( $div.outerWidth( true ), 94, "Test with padding, border and margin with margin option" );
|
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" );
|
assert.equal( $div.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" );
|
||||||
|
|
||||||
// reset styles
|
// reset styles
|
||||||
@ -233,6 +239,7 @@ QUnit.test( "outerWidth()", function( assert ) {
|
|||||||
assert.equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
|
assert.equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
|
||||||
|
|
||||||
div.remove();
|
div.remove();
|
||||||
|
assert.expectJqData( this, $div[ 0 ], "display" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) {
|
QUnit.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) {
|
||||||
@ -376,7 +383,7 @@ QUnit.test( "outerHeight()", function( assert ) {
|
|||||||
$div.css( "margin", "10px" );
|
$div.css( "margin", "10px" );
|
||||||
assert.equal( $div.outerHeight(), 74, "Test with padding, border and margin without margin option" );
|
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" );
|
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" );
|
assert.equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" );
|
||||||
|
|
||||||
// reset styles
|
// reset styles
|
||||||
@ -388,6 +395,7 @@ QUnit.test( "outerHeight()", function( assert ) {
|
|||||||
assert.equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
|
assert.equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
|
||||||
|
|
||||||
div.remove();
|
div.remove();
|
||||||
|
assert.expectJqData( this, $div[ 0 ], "display" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "passing undefined is a setter #5571", function( assert ) {
|
QUnit.test( "passing undefined is a setter #5571", function( assert ) {
|
||||||
|
@ -223,8 +223,6 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function
|
|||||||
foo.dequeue( "queue" );
|
foo.dequeue( "queue" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( jQuery.fn.animate ) {
|
|
||||||
|
|
||||||
QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function( assert ) {
|
QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function( assert ) {
|
||||||
var foo = jQuery( "#foo" ),
|
var foo = jQuery( "#foo" ),
|
||||||
test = 1;
|
test = 1;
|
||||||
@ -245,7 +243,6 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete befo
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
}
|
|
||||||
|
|
||||||
QUnit.test( ".promise(obj)", function( assert ) {
|
QUnit.test( ".promise(obj)", function( assert ) {
|
||||||
assert.expect( 2 );
|
assert.expect( 2 );
|
||||||
|
Loading…
Reference in New Issue
Block a user