Skip to content

Commit 94a1786

Browse files
committed
Accordion: API Redesign. Made style changes and changed 'fill' implementation to use $.siblings()
1 parent 490792b commit 94a1786

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

tests/unit/accordion/accordion_options.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ test("{ fillSpace: true } with sibling", function() {
129129
equalHeights($('#navigation').accordion({ fillSpace: true}), 320, 332);
130130
});
131131

132+
test("{ fillSpace: true } with multiple siblings", function() {
133+
$("#navigationWrapper").height(500);
134+
var sibling = $("<p>Lorem Ipsum</p>");
135+
$("#navigationWrapper").prepend( sibling.height(100) );
136+
$("#navigationWrapper").prepend( sibling.clone().height(50) );
137+
//sibling.outerHeight(true) == 126
138+
equalHeights($('#navigation').accordion({ fillSpace: true}), 244, 256);
139+
});
140+
132141
test("{ header: '> li > :first-child,> :not(li):even' }, default", function() {
133142
state($("#list1").accordion(), 1, 0, 0);
134143
state($("#navigation").accordion(), 1, 0, 0);

ui/jquery.ui.accordion.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ $.widget( "ui.accordion", {
1717
options: {
1818
active: 0,
1919
animated: "slide",
20-
autoHeight: true,
21-
clearStyle: false,
20+
autoHeight: true, //DEPRECATED - use heightStyle: "auto"
21+
clearStyle: false, //DEPRECATED - use heightStyle: "content"
2222
collapsible: false,
2323
event: "click",
24-
fillSpace: false,
24+
fillSpace: false, //DEPRECATED - use heightStyle: "fill"
2525
//heightStyle: "auto",
2626
header: "> li > :first-child,> :not(li):even",
2727
icons: {
@@ -30,19 +30,6 @@ $.widget( "ui.accordion", {
3030
}
3131
},
3232

33-
_mergeHeightStyle: function() {
34-
options = this.options;
35-
36-
if (options.fillSpace)
37-
return "fill";
38-
39-
if (options.clearStyle)
40-
return "content";
41-
42-
if (options.autoHeight)
43-
return "auto";
44-
},
45-
4633
_create: function() {
4734
var self = this,
4835
options = self.options;
@@ -182,13 +169,29 @@ $.widget( "ui.accordion", {
182169
.css( "display", "" )
183170
.removeAttr( "role" )
184171
.removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active ui-accordion-disabled ui-state-disabled" );
185-
if ( options.heightStyle != "content" ) {
172+
if ( options.heightStyle !== "content" ) {
186173
contents.css( "height", "" );
187174
}
188175

189176
return $.Widget.prototype.destroy.call( this );
190177
},
191178

179+
_mergeHeightStyle: function() {
180+
var options = this.options;
181+
182+
if ( options.fillSpace ) {
183+
return "fill";
184+
}
185+
186+
if ( options.clearStyle ) {
187+
return "content";
188+
}
189+
190+
if ( options.autoHeight ) {
191+
return "auto";
192+
}
193+
},
194+
192195
_setOption: function( key, value ) {
193196
$.Widget.prototype._setOption.apply( this, arguments );
194197

@@ -249,13 +252,15 @@ $.widget( "ui.accordion", {
249252
var options = this.options,
250253
maxHeight;
251254

252-
if ( options.heightStyle == "fill" ) {
255+
if ( options.heightStyle === "fill" ) {
253256
if ( $.browser.msie ) {
254257
var defOverflow = this.element.parent().css( "overflow" );
255258
this.element.parent().css( "overflow", "hidden");
256259
}
257-
parent = this.element.parent();
258-
maxHeight = parent.height() - parent.children(':visible').not(this.element).outerHeight(true);
260+
maxHeight = this.element.parent().height();
261+
this.element.siblings( ":visible" ).each(function() {
262+
maxHeight -= $( this ).outerHeight( true );
263+
});
259264
if ($.browser.msie) {
260265
this.element.parent().css( "overflow", defOverflow );
261266
}
@@ -270,7 +275,7 @@ $.widget( "ui.accordion", {
270275
$( this ).innerHeight() + $( this ).height() ) );
271276
})
272277
.css( "overflow", "auto" );
273-
} else if ( options.heightStyle == "auto" ) {
278+
} else if ( options.heightStyle === "auto" ) {
274279
maxHeight = 0;
275280
this.headers.next()
276281
.each(function() {
@@ -493,7 +498,7 @@ $.widget( "ui.accordion", {
493498
return;
494499
}
495500

496-
if ( this.options.heightStyle == "content" ) {
501+
if ( this.options.heightStyle === "content" ) {
497502
this.toShow.add( this.toHide ).css({
498503
height: "",
499504
overflow: ""

0 commit comments

Comments
 (0)