Button: Batched class changes to improve performance. Fixes #6934. Button: Batch class changes to improve performance.

This commit is contained in:
Alex Dovenmuehle 2011-02-10 22:11:59 -05:00 committed by Scott González
parent 92bae28dea
commit 5b104dbcef

View File

@ -289,27 +289,32 @@ $.widget( "ui.button", {
.appendTo( buttonElement.empty() ) .appendTo( buttonElement.empty() )
.text(), .text(),
icons = this.options.icons, icons = this.options.icons,
multipleIcons = icons.primary && icons.secondary; multipleIcons = icons.primary && icons.secondary,
buttonClasses = [];
if ( icons.primary || icons.secondary ) { if ( icons.primary || icons.secondary ) {
buttonElement.addClass( "ui-button-text-icon" + buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) );
( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) );
if ( icons.primary ) { if ( icons.primary ) {
buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" ); buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" );
} }
if ( icons.secondary ) { if ( icons.secondary ) {
buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" ); buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" );
} }
if ( !this.options.text ) { if ( !this.options.text ) {
buttonElement buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" );
.addClass( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" ) buttonElement.removeClass( "ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary" );
.removeClass( "ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary" );
if ( !this.hasTitle ) { if ( !this.hasTitle ) {
buttonElement.attr( "title", buttonText ); buttonElement.attr( "title", buttonText );
} }
} }
} else { } else {
buttonElement.addClass( "ui-button-text-only" ); buttonClasses.push( "ui-button-text-only" );
} }
buttonElement.addClass( buttonClasses.join( " " ) );
} }
}); });