Skip to content

Commit 2b40784

Browse files
committed
Merge pull request jquery-archive#3122 from hpbuniat/closestEnabledButton-speedup
Minor performance optimization for closestEnabledButton in buttonMarkup
2 parents 7c62253 + f3f5ba6 commit 2b40784

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

js/jquery.mobile.buttonMarkup.js

100644100755
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
$.fn.buttonMarkup = function( options ) {
88
options = options || {};
9-
109
for ( var i = 0; i < this.length; i++ ) {
1110
var el = this.eq( i ),
1211
e = el[ 0 ],
@@ -92,7 +91,7 @@ $.fn.buttonMarkup = function( options ) {
9291
}
9392

9493
e.appendChild( buttonInner );
95-
94+
9695
// TODO obviously it would be nice to pull this element out instead of
9796
// retrieving it from the DOM again, but this change is much less obtrusive
9897
// and 1.0 draws nigh
@@ -118,12 +117,11 @@ function closestEnabledButton( element ) {
118117
// handed could be in an SVG DOM where className on SVG elements is defined to
119118
// be of a different type (SVGAnimatedString). We only operate on HTML DOM
120119
// elements, so we look for plain "string".
121-
122-
cname = ( typeof element.className === 'string' ) && element.className.split(' ');
123-
124-
if ( cname && $.inArray( "ui-btn", cname ) > -1 && $.inArray( "ui-disabled", cname ) < 0 ) {
120+
cname = ( typeof element.className === 'string' ) && (element.className + ' ');
121+
if ( cname && cname.indexOf("ui-btn ") > -1 && cname.indexOf("ui-disabled ") < 0 ) {
125122
break;
126123
}
124+
127125
element = element.parentNode;
128126
}
129127

0 commit comments

Comments
 (0)