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

Commit d455be8

Browse files
committed
Button: Update _create method to add enhanced option
1 parent 8ff2c9b commit d455be8

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

js/widgets/forms/button.js

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,39 @@ $.widget( "mobile.button", {
2222
},
2323

2424
_create: function() {
25-
var $button,
26-
$el = this.element,
27-
isInput = $el[ 0 ].tagName === "INPUT",
28-
classes = "ui-btn";
25+
var isInput = $el[ 0 ].tagName === "INPUT";
2926

30-
if ( isInput ) {
31-
classes += " ui-input-btn";
27+
$.extend( this, {
28+
isInput: isInput,
29+
button: null
30+
});
3231

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

41-
this.button = $( "<div></div>" )
42-
[ "text" ]( $el.val() )
43-
.insertBefore( $el )
44-
.addClass( classes )
45-
.append( $el );
36+
_enhance: function() {
37+
if ( isInput ) {
4638

47-
$button = this.button;
39+
this.element.wrap( this._button () );
40+
this.button = this.element.parent();
4841

49-
this._on( $el, {
42+
this._on( {
5043
focus: function() {
51-
$button.addClass( $.mobile.focusClass );
44+
this.widget().addClass( $.mobile.focusClass );
5245
},
5346

5447
blur: function() {
55-
$button.removeClass( $.mobile.focusClass );
48+
this.widget().removeClass( $.mobile.focusClass );
5649
}
5750
});
5851
} else {
59-
this.button = $el.addClass( classes );
52+
this.widget().addClass( classes );
6053
}
54+
},
6155

62-
$.extend( this, {
63-
isInput: isInput,
64-
buttonClasses: classes,
65-
styleClasses: ""
66-
});
67-
68-
this.refresh( true );
69-
this._setOptions( this.options );
56+
_button: function() {
57+
return $("<div class='ui-btn ui-input-btn" + this.options.class + "' id='" + this.options.id + "'>" + this.element.val() + "<div>");
7058
},
7159

7260
widget: function() {

0 commit comments

Comments
 (0)