Permalink
Browse files

Removed all of the redundant code used to crawl the DOM upward lookin…

…g for a theme to inherit from, and replaced it with a call to the new $.mobile.getInheritedTheme() function.

Also, fixed a bug in textinput.js that was placing a ui-body-null class on the input element when a data-theme was not specified directly on the input.
  • Loading branch information...
jblas committed Oct 17, 2011
1 parent 51b3778 commit af870605ac375dca7ff25ae3bb0b824aa6631765
@@ -22,18 +22,15 @@ $.fn.buttonMarkup = function( options ) {
// Classes Defined
innerClass = "ui-btn-inner",
buttonClass, iconClass,
- themedParent, wrap;
+ wrap;
if ( attachEvents ) {
attachEvents();
}
// if not, try to find closest theme container
if ( !o.theme ) {
- themedParent = el.closest( "[class*='ui-bar-'],[class*='ui-body-']" );
- o.theme = themedParent.length ?
- /ui-(bar|body)-([a-z])/.exec( themedParent.attr( "class" ) )[2] :
- "c";
+ o.theme = $.mobile.getInheritedTheme( el, "c" );
}
buttonClass = "ui-btn ui-btn-up-" + o.theme;
View
@@ -125,6 +125,20 @@
}
return $.camelCase( $.mobile.ns + prop );
+ },
+
+ 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 ] || "" ) || "";

This comment has been minimized.

Show comment
Hide comment
@staabm

staabm Oct 18, 2011

Contributor

should the regex pattern be extracted..?

@staabm

staabm Oct 18, 2011

Contributor

should the regex pattern be extracted..?

+
+ // Return the theme letter we found, if none, return the
+ // specified default.
+
+ return ltr || defaultTheme || "a";
}
});
@@ -29,22 +29,6 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
return $( "<div/>" );
},
- _theme: function(){
- if ( this.options.theme ){
- return this.options.theme;
- }
-
- var themedParent, theme;
- // if no theme is defined, try to find closest theme container
- // TODO move to core as something like findCurrentTheme
- themedParent = this.select.closest( "[class*='ui-bar-'], [class*='ui-body-']" );
- theme = themedParent.length ?
- /ui-(bar|body)-([a-z])/.exec( themedParent.attr( "class" ) )[2] :
- "c";
-
- return theme;
- },
-
_setDisabled: function( value ) {
this.element.attr( "disabled", value );
this.button.attr( "aria-disabled", value );
@@ -69,7 +53,9 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
this.selectID = this.select.attr( "id" );
this.label = $( "label[for='"+ this.selectID +"']" ).addClass( "ui-select" );
this.isMultiple = this.select[ 0 ].multiple;
- this.options.theme = this._theme();
+ if ( !this.options.theme ) {
+ this.options.theme = $.mobile.getInheritedTheme( this.select, "c" );
+ }
},
_create: function() {
@@ -22,13 +22,11 @@ $.widget( "mobile.slider", $.mobile.widget, {
control = this.element,
- parentTheme = control.parents( "[class*='ui-bar-'],[class*='ui-body-']" ).eq( 0 ),
+ parentTheme = $.mobile.getInheritedTheme( control, "c" ),
- parentTheme = parentTheme.length ? parentTheme.attr( "class" ).match( /ui-(bar|body)-([a-z])/ )[ 2 ] : "c",
+ theme = this.options.theme || parentTheme,
- theme = this.options.theme ? this.options.theme : parentTheme,
-
- trackTheme = this.options.trackTheme ? this.options.trackTheme : parentTheme,
+ trackTheme = this.options.trackTheme || parentTheme,
cType = control[ 0 ].nodeName.toLowerCase(),
@@ -18,19 +18,17 @@ $.widget( "mobile.textinput", $.mobile.widget, {
var input = this.element,
o = this.options,
theme = o.theme,
- themedParent, themeclass, themeLetter, focusedEl, clearbtn;
+ themeclass, focusedEl, clearbtn;
if ( !theme ) {
- themedParent = this.element.closest( "[class*='ui-bar-'],[class*='ui-body-']" );
- themeLetter = themedParent.length && /ui-(bar|body)-([a-z])/.exec( themedParent.attr( "class" ) );
- theme = themeLetter && themeLetter[2] || "c";
+ theme = $.mobile.getInheritedTheme( this.element, "c" );
}
themeclass = " ui-body-" + theme;
$( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
- input.addClass("ui-input-text ui-body-"+ o.theme );
+ input.addClass("ui-input-text ui-body-"+ theme );
focusedEl = input;

0 comments on commit af87060

Please sign in to comment.