Permalink
Browse files

reference the buttonMarkup text wrapper element through data

  • Loading branch information...
1 parent 0ffaab8 commit a8202d240dca6bb892686b5fdf2c9412c4c1efec @johnbender johnbender committed Oct 31, 2011
Showing with 12 additions and 4 deletions.
  1. +9 −3 js/jquery.mobile.buttonMarkup.js
  2. +3 −1 js/jquery.mobile.forms.button.js
@@ -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,15 +94,15 @@ $.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 ) {
break;
}
element = element.parentNode;
}
-
+
return element;
}
@@ -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() );
}
});

0 comments on commit a8202d2

Please sign in to comment.