From 9191ee3cd806c0e93a2cdf37125ff7b70e738e6b Mon Sep 17 00:00:00 2001 From: Alex Dovenmuehle Date: Thu, 10 Feb 2011 22:11:59 -0500 Subject: [PATCH] Button: Batched class changes to improve performance. Fixes #6934. Button: Batch class changes to improve performance. (cherry picked from commit 5b104dbcefdfa708d80e8babea0539617167012d) --- ui/jquery.ui.button.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index e767fe4e1..a32d3991e 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -290,27 +290,32 @@ $.widget( "ui.button", { .appendTo( buttonElement.empty() ) .text(), icons = this.options.icons, - multipleIcons = icons.primary && icons.secondary; + multipleIcons = icons.primary && icons.secondary, + buttonClasses = []; + if ( icons.primary || icons.secondary ) { - buttonElement.addClass( "ui-button-text-icon" + - ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) ); + buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) ); + if ( icons.primary ) { buttonElement.prepend( "" ); } + if ( icons.secondary ) { buttonElement.append( "" ); } + if ( !this.options.text ) { - buttonElement - .addClass( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" ) - .removeClass( "ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary" ); + buttonClasses.push( 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" ); + if ( !this.hasTitle ) { buttonElement.attr( "title", buttonText ); } } } else { - buttonElement.addClass( "ui-button-text-only" ); + buttonClasses.push( "ui-button-text-only" ); } + buttonElement.addClass( buttonClasses.join( " " ) ); } }); -- 2.39.5