Permalink
Browse files

Reworked getInheritedTheme() to avoid closest() and attr(). This new …

…version shaves off 200ms of page enhancement time on the forms gallery page on a Droid X (Android 2.1).
  • Loading branch information...
1 parent 2b2b8bf commit 0b5f6dab5d9d9def4f2f8cc64f7b3a26365afa3c @jblas jblas committed Nov 4, 2011
Showing with 20 additions and 6 deletions.
  1. +20 −6 js/jquery.mobile.core.js
@@ -130,13 +130,27 @@
},
getInheritedTheme: function( el, defaultTheme ) {
- // Find the closest parent with a theme class on it.
- var themedParent = el.closest( "[class*='ui-bar-'],[class*='ui-body-']" ),
-
- // If there's a themed parent, extract the theme letter
- // from the theme class .
- ltr = ( themedParent.length && /ui-(bar|body)-([a-z])\b/.exec( themedParent.attr( "class" ) )[ 2 ] || "" ) || "";
+ // Find the closest parent with a theme class on it. Note that
+ // we are not using $.fn.closest() on purpose here because this
+ // method gets called quite a bit and we need it to be as fast
+ // as possible.
+
+ var e = el[ 0 ],
+ ltr = "",
+ re = /ui-(bar|body)-([a-z])\b/,
+ c, m;
+
+ while ( e ) {
+ var c = e.className || "";
+ if ( ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
+ // We found a parent with a theme class
+ // on it so bail from this loop.
+ break;
+ }
+ e = e.parentNode;
+ }
+
// Return the theme letter we found, if none, return the
// specified default.

0 comments on commit 0b5f6da

Please sign in to comment.