Skip to content

Commit da185a6

Browse files
committed
Accordion: Use .uniqueId() and move animation properties into the widget prototype.
1 parent dbbf3a9 commit da185a6

File tree

1 file changed

+32
-39
lines changed

1 file changed

+32
-39
lines changed

ui/jquery.ui.accordion.js

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
*/
1515
(function( $, undefined ) {
1616

17-
var uid = 0,
18-
hideProps = {},
19-
showProps = {};
20-
21-
hideProps.height = hideProps.paddingTop = hideProps.paddingBottom =
22-
hideProps.borderTopWidth = hideProps.borderBottomWidth = "hide";
23-
showProps.height = showProps.paddingTop = showProps.paddingBottom =
24-
showProps.borderTopWidth = showProps.borderBottomWidth = "show";
25-
2617
$.widget( "ui.accordion", {
2718
version: "@VERSION",
2819
options: {
@@ -42,6 +33,22 @@ $.widget( "ui.accordion", {
4233
beforeActivate: null
4334
},
4435

36+
hideProps: {
37+
borderTopWidth: "hide",
38+
borderBottomWidth: "hide",
39+
paddingTop: "hide",
40+
paddingBottom: "hide",
41+
height: "hide"
42+
},
43+
44+
showProps: {
45+
borderTopWidth: "show",
46+
borderBottomWidth: "show",
47+
paddingTop: "show",
48+
paddingBottom: "show",
49+
height: "show"
50+
},
51+
4552
_create: function() {
4653
var options = this.options;
4754
this.prevShow = this.prevHide = $();
@@ -99,31 +106,27 @@ $.widget( "ui.accordion", {
99106

100107
// clean up headers
101108
this.headers
102-
.removeClass( "ui-accordion-header ui-accordion-header-active ui-state-default ui-corner-all ui-state-active ui-state-disabled ui-corner-top" )
109+
.removeClass( "ui-accordion-header ui-accordion-header-active ui-state-default " +
110+
"ui-corner-all ui-state-active ui-state-disabled ui-corner-top" )
103111
.removeAttr( "role" )
104112
.removeAttr( "aria-selected" )
105113
.removeAttr( "aria-controls" )
106114
.removeAttr( "tabIndex" )
107-
.each(function() {
108-
if ( /^ui-accordion/.test( this.id ) ) {
109-
this.removeAttribute( "id" );
110-
}
111-
});
115+
.removeUniqueId();
116+
112117
this._destroyIcons();
113118

114119
// clean up content panels
115120
contents = this.headers.next()
121+
.removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom " +
122+
"ui-accordion-content ui-accordion-content-active ui-state-disabled" )
116123
.css( "display", "" )
117124
.removeAttr( "role" )
118125
.removeAttr( "aria-expanded" )
119126
.removeAttr( "aria-hidden" )
120127
.removeAttr( "aria-labelledby" )
121-
.removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active ui-state-disabled" )
122-
.each(function() {
123-
if ( /^ui-accordion/.test( this.id ) ) {
124-
this.removeAttribute( "id" );
125-
}
126-
});
128+
.removeUniqueId();
129+
127130
if ( this.options.heightStyle !== "content" ) {
128131
contents.css( "height", "" );
129132
}
@@ -259,9 +262,7 @@ $.widget( "ui.accordion", {
259262
var maxHeight,
260263
options = this.options,
261264
heightStyle = options.heightStyle,
262-
parent = this.element.parent(),
263-
accordionId = this.accordionId = "ui-accordion-" +
264-
(this.element.attr( "id" ) || ++uid);
265+
parent = this.element.parent();
265266

266267
this.active = this._findActive( options.active )
267268
.addClass( "ui-accordion-header-active ui-state-active ui-corner-top" )
@@ -272,19 +273,11 @@ $.widget( "ui.accordion", {
272273

273274
this.headers
274275
.attr( "role", "tab" )
275-
.each(function( i ) {
276+
.each(function() {
276277
var header = $( this ),
277-
headerId = header.attr( "id" ),
278+
headerId = header.uniqueId().attr( "id" ),
278279
panel = header.next(),
279-
panelId = panel.attr( "id" );
280-
if ( !headerId ) {
281-
headerId = accordionId + "-header-" + i;
282-
header.attr( "id", headerId );
283-
}
284-
if ( !panelId ) {
285-
panelId = accordionId + "-panel-" + i;
286-
panel.attr( "id", panelId );
287-
}
280+
panelId = panel.uniqueId().attr( "id" );
288281
header.attr( "aria-controls", panelId );
289282
panel.attr( "aria-labelledby", headerId );
290283
})
@@ -520,14 +513,14 @@ $.widget( "ui.accordion", {
520513
duration = duration || options.duration || animate.duration;
521514

522515
if ( !toHide.length ) {
523-
return toShow.animate( showProps, duration, easing, complete );
516+
return toShow.animate( this.showProps, duration, easing, complete );
524517
}
525518
if ( !toShow.length ) {
526-
return toHide.animate( hideProps, duration, easing, complete );
519+
return toHide.animate( this.hideProps, duration, easing, complete );
527520
}
528521

529522
total = toShow.show().outerHeight();
530-
toHide.animate( hideProps, {
523+
toHide.animate( this.hideProps, {
531524
duration: duration,
532525
easing: easing,
533526
step: function( now, fx ) {
@@ -536,7 +529,7 @@ $.widget( "ui.accordion", {
536529
});
537530
toShow
538531
.hide()
539-
.animate( showProps, {
532+
.animate( this.showProps, {
540533
duration: duration,
541534
easing: easing,
542535
complete: complete,

0 commit comments

Comments
 (0)