reference the buttonMarkup text wrapper element through data

This commit is contained in:
John Bender 2011-10-31 13:24:17 -07:00
parent 0ffaab8d22
commit a8202d240d
2 changed files with 12 additions and 4 deletions

View file

@ -21,6 +21,7 @@ $.fn.buttonMarkup = function( options ) {
// Classes Defined
innerClass = "ui-btn-inner",
textClass = "ui-btn-text",
buttonClass, iconClass,
wrap;
@ -70,11 +71,16 @@ $.fn.buttonMarkup = function( options ) {
el.attr( "data-" + $.mobile.ns + "theme", o.theme )
.addClass( buttonClass );
wrap = ( "<D class='" + innerClass + "' aria-hidden='true'><D class='ui-btn-text'></D>" +
wrap = ( "<D class='" + innerClass + "' aria-hidden='true'><D class='" + textClass + "'></D>" +
( o.icon ? "<span class='" + iconClass + "'></span>" : "" ) +
"</D>" ).replace( /D/g, o.wrapperEls );
el.wrapInner( wrap );
// TODO obviously it would be nice to pull this element out instead of
// retrieving it from the DOM again, but this change is much less obtrusive
// and 1.0 draws nigh
el.data( 'textWrapper', el.find( "." + textClass ) );
});
};
@ -88,7 +94,7 @@ $.fn.buttonMarkup.defaults = {
function closestEnabledButton( element ) {
var cname;
while ( element ) {
cname = element.className && element.className.split(' ');
if ( cname && $.inArray( "ui-btn", cname ) > -1 && $.inArray( "ui-disabled", cname ) < 0 ) {
@ -96,7 +102,7 @@ function closestEnabledButton( element ) {
}
element = element.parentNode;
}
return element;
}

View file

@ -87,7 +87,9 @@ $.widget( "mobile.button", $.mobile.widget, {
this.enable();
}
this.button.find( ".ui-btn-text" ).text( $el.text() || $el.val() );
// the textWrapper is stored as a data element on the button object
// to prevent referencing by it's implementation details (eg 'class')
this.button.data( 'textWrapper' ).text( $el.text() || $el.val() );
}
});