mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-25 16:44:43 +00:00
Removed all of the redundant code used to crawl the DOM upward looking 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.
This commit is contained in:
parent
51b37789bb
commit
af870605ac
5 changed files with 25 additions and 32 deletions
|
|
@ -22,7 +22,7 @@ $.fn.buttonMarkup = function( options ) {
|
|||
// Classes Defined
|
||||
innerClass = "ui-btn-inner",
|
||||
buttonClass, iconClass,
|
||||
themedParent, wrap;
|
||||
wrap;
|
||||
|
||||
if ( attachEvents ) {
|
||||
attachEvents();
|
||||
|
|
@ -30,10 +30,7 @@ $.fn.buttonMarkup = function( options ) {
|
|||
|
||||
// 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;
|
||||
|
|
|
|||
|
|
@ -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 ] || "" ) || "";
|
||||
|
||||
// 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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue