forked from jquery-archive/jquery-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.mobile.forms.button.js
More file actions
101 lines (86 loc) · 2.47 KB
/
jquery.mobile.forms.button.js
File metadata and controls
101 lines (86 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* "button" plugin - links that proxy to native input/buttons
*/
(function( $, undefined ) {
$.widget( "mobile.button", $.mobile.widget, {
options: {
theme: null,
icon: null,
iconpos: null,
inline: null,
corners: true,
shadow: true,
iconshadow: true,
initSelector: "button, [type='button'], [type='submit'], [type='reset'], [type='image']"
},
_create: function() {
var $el = this.element,
o = this.options,
type,
name,
$buttonPlaceholder;
// Add ARIA role
this.button = $( "<div></div>" )
.text( $el.text() || $el.val() )
.insertBefore( $el )
.buttonMarkup({
theme: o.theme,
icon: o.icon,
iconpos: o.iconpos,
inline: o.inline,
corners: o.corners,
shadow: o.shadow,
iconshadow: o.iconshadow
})
.append( $el.addClass( "ui-btn-hidden" ) );
type = $el.attr( "type" );
name = $el.attr( "name" );
// Add hidden input during submit if input type="submit" has a name.
if ( type !== "button" && type !== "reset" && name ) {
$el.bind( "vclick", function() {
// Add hidden input if it doesn’t already exist.
if( $buttonPlaceholder === undefined ) {
$buttonPlaceholder = $( "<input>", {
type: "hidden",
name: $el.attr( "name" ),
value: $el.attr( "value" )
}).insertBefore( $el );
// Bind to doc to remove after submit handling
$( document ).one("submit", function(){
$buttonPlaceholder.remove();
// reset the local var so that the hidden input
// will be re-added on subsequent clicks
$buttonPlaceholder = undefined;
});
}
});
}
this.refresh();
},
enable: function() {
this.element.attr( "disabled", false );
this.button.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
return this._setOption( "disabled", false );
},
disable: function() {
this.element.attr( "disabled", true );
this.button.addClass( "ui-disabled" ).attr( "aria-disabled", true );
return this._setOption( "disabled", true );
},
refresh: function() {
var $el = this.element;
if ( $el.prop("disabled") ) {
this.disable();
} else {
this.enable();
}
// 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() );
}
});
//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){
$.mobile.button.prototype.enhanceWithin( e.target );
});
})( jQuery );