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

Commit 4a90506

Browse files
committed
Button: Remove button element from button widget
1 parent d455be8 commit 4a90506

File tree

1 file changed

+37
-51
lines changed

1 file changed

+37
-51
lines changed

js/widgets/forms/button.js

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ $.widget( "mobile.button", {
1818
corners: true,
1919
shadow: true,
2020
inline: null,
21-
mini: null
21+
mini: null,
22+
wrapperClass: null
2223
},
2324

2425
_create: function() {
2526
var isInput = $el[ 0 ].tagName === "INPUT";
2627

2728
$.extend( this, {
28-
isInput: isInput,
2929
button: null
3030
});
3131

@@ -34,80 +34,66 @@ $.widget( "mobile.button", {
3434
},
3535

3636
_enhance: function() {
37-
if ( isInput ) {
38-
39-
this.element.wrap( this._button () );
40-
this.button = this.element.parent();
41-
42-
this._on( {
43-
focus: function() {
44-
this.widget().addClass( $.mobile.focusClass );
45-
},
46-
47-
blur: function() {
48-
this.widget().removeClass( $.mobile.focusClass );
49-
}
50-
});
51-
} else {
52-
this.widget().addClass( classes );
53-
}
37+
this.element.wrap( this._button () );
38+
this.button = this.element.parent();
39+
40+
this._on( {
41+
focus: function() {
42+
this.widget().addClass( $.mobile.focusClass );
43+
},
44+
45+
blur: function() {
46+
this.widget().removeClass( $.mobile.focusClass );
47+
}
48+
});
5449
},
5550

5651
_button: function() {
57-
return $("<div class='ui-btn ui-input-btn" + this.options.class + "' id='" + this.options.id + "'>" + this.element.val() + "<div>");
52+
return $("<div class='ui-btn ui-input-btn" + this.options.wrapperClass + "' >" + this.element.val() + "<div>");
5853
},
5954

6055
widget: function() {
6156
return this.button;
6257
},
6358

6459
_destroy: function() {
65-
var $button, removeClasses;
66-
if ( this.isInput ) {
67-
$button = this.button;
68-
69-
this.element.insertBefore( $button );
60+
this.element.insertBefore( this.button );
7061

71-
$button.remove();
72-
} else {
73-
removeClasses = this.buttonClasses + " " + this.styleClasses;
74-
75-
this.button.removeClass( removeClasses );
76-
}
62+
this.button.remove();
7763
},
7864

79-
_setOptions: function( o ) {
80-
if ( o.theme !== undefined ) {
81-
this.widget().removeClass( this.options.theme ).addClass( "ui-btn-" + o.theme );
65+
_setOptions: function( options ) {
66+
if ( options.theme !== undefined ) {
67+
this.widget().removeClass( this.options.theme ).addClass( "ui-btn-" + options.theme );
8268
}
83-
if ( o.corners !== undefined ) {
84-
this.widget().toggleClass( "ui-corner-all", o.corners );
69+
if ( options.corners !== undefined ) {
70+
this.widget().toggleClass( "ui-corner-all", options.corners );
8571
}
86-
if ( o.shadow !== undefined ) {
87-
this.widget().toggleClass( "ui-shadow", o.shadow );
72+
if ( options.shadow !== undefined ) {
73+
this.widget().toggleClass( "ui-shadow", options.shadow );
8874
}
89-
if ( o.inline !== undefined ) {
90-
this.widget().toggleClass( "ui-btn-inline", o.inline );
75+
if ( options.inline !== undefined ) {
76+
this.widget().toggleClass( "ui-btn-inline", options.inline );
9177
}
92-
if ( o.mini !== undefined ) {
93-
this.widget().toggleClass( "ui-mini", o.mini );
78+
if ( options.mini !== undefined ) {
79+
this.widget().toggleClass( "ui-mini", options.mini );
9480
}
95-
if( o.iconpos !== undefined ) {
96-
this.widget().removeClass( "ui-btn-icon-" + o.iconpos );
81+
if( options.iconpos !== undefined ) {
82+
this.widget().removeClass( "ui-btn-icon-" + options.iconpos );
9783
}
98-
if( o.icon !== undefined ) {
99-
if( !this.options.iconpos && !o.iconpos ){
100-
this.widget.toggleClass( "ui-btn-icon-left", o.icon );
84+
if( options.icon !== undefined ) {
85+
if( !this.options.iconpos && !options.iconpos ){
86+
this.widget.toggleClass( "ui-btn-icon-left", options.icon );
10187
}
102-
this.widget().removeClass( "ui-icon-" + this.options.icon ).toggleClass( "ui-icon-" + o.icon, o.icon );
88+
this.widget().removeClass( "ui-icon-" + this.options.icon ).toggleClass( "ui-icon-" + options.icon, options.icon );
10389
}
10490
},
10591

10692
refresh: function( create ) {
107-
var o = this.options,
93+
var options = this.options,
10894
$el = this.element;
10995

110-
if ( o.icon && o.iconpos === "notext" && !$el.attr( "title" ) ) {
96+
if ( options.icon && options.iconpos === "notext" && !$el.attr( "title" ) ) {
11197
$el.attr( "title", ( this.isInput ? $el.val() : $el.getEncodedText() ) );
11298
}
11399

@@ -126,7 +112,7 @@ $.widget( "mobile.button", {
126112
}
127113
});
128114

129-
$.mobile.button.initSelector = "button, [type='button'], [type='submit'], [type='reset']";
115+
$.mobile.button.initSelector = "type='button'], [type='submit'], [type='reset']";
130116

131117
//auto self-init widgets
132118
$.mobile._enhancer.add( "mobile.button" );

0 commit comments

Comments
 (0)