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

Commit

Permalink
Button: Update _create method to add enhanced option
Browse files Browse the repository at this point in the history
  • Loading branch information
arschmitz committed Jul 24, 2013
1 parent 8ff2c9b commit d455be8
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions js/widgets/forms/button.js
Expand Up @@ -22,51 +22,39 @@ $.widget( "mobile.button", {
},

_create: function() {
var $button,
$el = this.element,
isInput = $el[ 0 ].tagName === "INPUT",
classes = "ui-btn";
var isInput = $el[ 0 ].tagName === "INPUT";

if ( isInput ) {
classes += " ui-input-btn";
$.extend( this, {
isInput: isInput,
button: null
});

// TODO: data-class and data-id options. See https://github.com/jquery/jquery-mobile/issues/3577
if ( !!~$el[ 0 ].className.indexOf( "ui-btn-left" ) ) {
classes += " ui-btn-left";
}
if ( !!~$el[ 0 ].className.indexOf( "ui-btn-right" ) ) {
classes += " ui-btn-right";
}
this.refresh( true );
this._setOptions( this.options );
},

this.button = $( "<div></div>" )
[ "text" ]( $el.val() )
.insertBefore( $el )
.addClass( classes )
.append( $el );
_enhance: function() {
if ( isInput ) {

$button = this.button;
this.element.wrap( this._button () );
this.button = this.element.parent();

this._on( $el, {
this._on( {
focus: function() {
$button.addClass( $.mobile.focusClass );
this.widget().addClass( $.mobile.focusClass );
},

blur: function() {
$button.removeClass( $.mobile.focusClass );
this.widget().removeClass( $.mobile.focusClass );
}
});
} else {
this.button = $el.addClass( classes );
this.widget().addClass( classes );
}
},

$.extend( this, {
isInput: isInput,
buttonClasses: classes,
styleClasses: ""
});

this.refresh( true );
this._setOptions( this.options );
_button: function() {
return $("<div class='ui-btn ui-input-btn" + this.options.class + "' id='" + this.options.id + "'>" + this.element.val() + "<div>");
},

widget: function() {
Expand Down

0 comments on commit d455be8

Please sign in to comment.