1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Custom-styled native input/buttons
3 //>>label: Buttons: Input or button-based
5 //>>css: ../css/themes/default/jquery.mobile.theme.css,../css/structure/jquery.mobile.button.css
7 define( [ "jquery", "./jquery.mobile.widget", "./jquery.mobile.buttonMarkup" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
11 $.widget( "mobile.button", $.mobile.widget, {
20 initSelector: "button, [type='button'], [type='submit'], [type='reset'], [type='image']",
24 var $el = this.element,
32 // if this is a link, check if it's been enhanced and, if not, use the right function
33 if( $el[ 0 ].tagName === "A" ) {
34 !$el.hasClass( "ui-btn" ) && $el.buttonMarkup();
38 // get the inherited theme
39 // TODO centralize for all widgets
40 if ( !this.options.theme ) {
41 this.options.theme = $.mobile.getInheritedTheme( this.element, "c" );
44 // 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
45 /* if( $el[0].className.length ) {
46 classes = $el[0].className;
48 if( !!~$el[0].className.indexOf( "ui-btn-left" ) ) {
49 classes = "ui-btn-left";
52 if( !!~$el[0].className.indexOf( "ui-btn-right" ) ) {
53 classes = "ui-btn-right";
57 this.button = $( "<div></div>" )
58 .text( $el.text() || $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 $( 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 ).text( $el.text() || $el.val() );
139 //auto self-init widgets
140 $( document ).bind( "pagecreate create", function( e ){
141 $.mobile.button.prototype.enhanceWithin( e.target, true );
145 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
147 //>>excludeEnd("jqmBuildExclude");