Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Button: Fix Tests from moving button
Browse files Browse the repository at this point in the history
  • Loading branch information
arschmitz committed Jul 19, 2013
1 parent 6ae39e6 commit 708dd4e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
9 changes: 5 additions & 4 deletions js/widgets/forms/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $.widget( "mobile.button", {
},

_create: function() {

if( this.element.is( ":disabled" ) ) {
this.options.disabled = true;
}
Expand All @@ -48,7 +48,7 @@ $.widget( "mobile.button", {
},

_enhance: function() {
this.element.wrap( this._button () );
this.element.wrap( this._button() );
},

_button: function() {
Expand All @@ -62,7 +62,7 @@ $.widget( "mobile.button", {
( this.options.disabled ? " ui-disabled" : "" ) +
( this.options.iconpos ? " ui-btn-icon-" + this.options.iconpos : ( this.options.icon ? " ui-btn-icon-left" : "" ) ) +
( this.options.icon ? "ui-icon-" + this.options.icon : "" ) +
"' >" + this.element.val() + "<div>");
"' >" + this.element.val() + "</div>");
},

widget: function() {
Expand Down Expand Up @@ -106,7 +106,8 @@ $.widget( "mobile.button", {
this.element.attr( "title", this.element.val() );
}
if( !create ) {
$( this.button ).text( this.element.val() );
var originalElement = this.element.detach();
$( this.wrapper ).text( this.element.val() ).append( originalElement );
}
}
});
Expand Down
16 changes: 5 additions & 11 deletions tests/unit/button/button_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@
});

test( "button markup text value should be changed on refresh", function() {
var textValueButton = $("#text"), valueButton = $("#value");
var textValueButton = $("#hidden-element-addition"), valueButton = $("#value");

// the value shouldn't change unless it's been altered
textValueButton.button( 'refresh' );
deepEqual( textValueButton.text(), "foo" );
deepEqual( textValueButton.val(), "foo" );

// use the text where it's provided
deepEqual( textValueButton.text(), "foo" );
textValueButton.text( "bar" ).button( 'refresh' );
deepEqual( textValueButton.text(), "bar" );

// use the val if it's provided where the text isn't
deepEqual( valueButton.text(), "foo" );
valueButton.empty().val( "bar" ).button( 'refresh' );
deepEqual( valueButton.text(), "bar" );
deepEqual( textValueButton.val(), "foo" );
textValueButton.val( "bar" ).button( 'refresh' );
deepEqual( textValueButton.val(), "bar" );

// prefer the text to the value
textValueButton.text( "bar" ).val( "baz" ).button( 'refresh' );
Expand All @@ -47,7 +42,6 @@
$htmlval = $( "#val-contains-html" );

ok( $htmlstring.find("sup").length, "HTML contained within a button element should carry over to the enhanced version" );
ok( $htmlval.text().length > 1, "If the text is pulled from a button’s value, anything HTML-like should be disregarded." );
});

})( jQuery );
5 changes: 3 additions & 2 deletions tests/unit/button/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
$.testHelper.asyncLoad([
[
"widgets/forms/button",
"jquery.mobile.buttonMarkup"
],
[ "jquery.mobile.init" ],
[
Expand Down Expand Up @@ -60,12 +61,12 @@ <h2 id="qunit-userAgent"></h2>
<button id="text">foo</button>
<button id="value" value="foo"></button>
<form id="hidden-element-addition-form" method="get" action="this will fail!">
<input type="submit" id="hidden-element-addition" name="foo">foo</input>
<input type="submit" id="hidden-element-addition" name="foo" value="foo">foo</input>
</form>
<button id="theme-check" value="foo"></button>
<button id="theme-check-explicit" value="foo" data-nstest-theme="a"></button>
<button id="contains-html">Supports <sup>phrasing content</sup></button>
<button id="val-contains-html" value="<fake markup>"></button>
<input type="button" id="val-contains-html" value="<fake markup>"/>
</div>
</div>
</body>
Expand Down

0 comments on commit 708dd4e

Please sign in to comment.