1 (function( $, undefined ) {
3 $.widget( "mobile.button", $.mobile.widget, {
11 initSelector: "button, [type='button'], [type='submit'], [type='reset']"
14 var $el = this.element,
19 inline = o.inline || $.mobile.getAttrFixed( $el[0], "data-" + $.mobile.ns + "inline" ),
20 mini = o.mini || $.mobile.getAttrFixed( $el[0], "data-" + $.mobile.ns + "mini" ),
24 // if this is a link, check if it's been enhanced and, if not, use the right function
25 if ( $el[ 0 ].tagName === "A" ) {
26 if ( !$el.hasClass( "ui-btn" ) ) {
33 // get the inherited theme
34 // TODO centralize for all widgets
35 if ( !this.options.theme ) {
36 this.options.theme = $.mobile.getInheritedTheme( this.element, "c" );
39 // TODO: Post 1.1--once we have time to test thoroughly--any classes manually applied to the original element should be carried over to the enhanced element, with an `-enhanced` suffix. See https://github.com/jquery/jquery-mobile/issues/3577
40 /* if ( $el[0].className.length ) {
41 classes = $el[0].className;
43 if ( !!~$el[0].className.indexOf( "ui-btn-left" ) ) {
44 classes = "ui-btn-left";
47 if ( !!~$el[0].className.indexOf( "ui-btn-right" ) ) {
48 classes = "ui-btn-right";
51 if ( $el.attr( "type" ) === "submit" || $el.attr( "type" ) === "reset" ) {
52 classes ? classes += " ui-submit" : classes = "ui-submit";
54 $( "label[for='" + $el.attr( "id" ) + "']" ).addClass( "ui-submit" );
57 this.button = $( "<div></div>" )
58 [ $el.html() ? "html" : "text" ]( $el.html() || $el.val() )
67 iconshadow: o.iconshadow,
71 .append( $el.addClass( "ui-btn-hidden" ) );
73 $button = this.button;
74 type = $el.attr( "type" );
75 name = $el.attr( "name" );
77 // Add hidden input during submit if input type="submit" has a name.
78 if ( type !== "button" && type !== "reset" && name ) {
79 $el.bind( "vclick", function() {
80 // Add hidden input if it doesn't already exist.
81 if ( $buttonPlaceholder === undefined ) {
82 $buttonPlaceholder = $( "<input>", {
84 name: $el.attr( "name" ),
85 value: $el.attr( "value" )
86 }).insertBefore( $el );
88 // Bind to doc to remove after submit handling
89 $.mobile.$document.one( "submit", function() {
90 $buttonPlaceholder.remove();
92 // reset the local var so that the hidden input
93 // will be re-added on subsequent clicks
94 $buttonPlaceholder = undefined;
102 $button.addClass( $.mobile.focusClass );
106 $button.removeClass( $.mobile.focusClass );
114 this.element.attr( "disabled", false );
115 this.button.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
116 return this._setOption( "disabled", false );
119 disable: function() {
120 this.element.attr( "disabled", true );
121 this.button.addClass( "ui-disabled" ).attr( "aria-disabled", true );
122 return this._setOption( "disabled", true );
125 refresh: function() {
126 var $el = this.element;
128 if ( $el.prop("disabled") ) {
134 // Grab the button's text element from its implementation-independent data item
135 $( this.button.data( 'buttonElements' ).text )[ $el.html() ? "html" : "text" ]( $el.html() || $el.val() );
139 //auto self-init widgets
140 $.mobile.$document.bind( "pagecreate create", function( e ) {
141 $.mobile.button.prototype.enhanceWithin( e.target, true );