2011-12-16 02:09:25 +00:00
|
|
|
|
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
2012-01-07 00:28:54 +00:00
|
|
|
|
//>>description: Form Buttons
|
|
|
|
|
|
//>>label: links that proxy to native input/buttons
|
|
|
|
|
|
|
2012-01-24 22:43:24 +00:00
|
|
|
|
define( [ "jquery", "./jquery.mobile.widget", "./jquery.mobile.buttonMarkup" ], function( $ ) {
|
2011-12-16 02:09:25 +00:00
|
|
|
|
//>>excludeEnd("jqmBuildExclude");
|
2011-06-29 00:15:43 +00:00
|
|
|
|
(function( $, undefined ) {
|
|
|
|
|
|
|
2010-10-28 00:43:27 +00:00
|
|
|
|
$.widget( "mobile.button", $.mobile.widget, {
|
2010-11-11 03:54:57 +00:00
|
|
|
|
options: {
|
2011-06-29 00:15:43 +00:00
|
|
|
|
theme: null,
|
2010-11-11 04:08:22 +00:00
|
|
|
|
icon: null,
|
|
|
|
|
|
iconpos: null,
|
|
|
|
|
|
inline: null,
|
|
|
|
|
|
corners: true,
|
|
|
|
|
|
shadow: true,
|
2011-07-26 18:22:08 +00:00
|
|
|
|
iconshadow: true,
|
2011-07-27 22:42:16 +00:00
|
|
|
|
initSelector: "button, [type='button'], [type='submit'], [type='reset'], [type='image']"
|
2010-11-11 03:54:57 +00:00
|
|
|
|
},
|
2011-06-29 00:15:43 +00:00
|
|
|
|
_create: function() {
|
2010-11-02 03:53:06 +00:00
|
|
|
|
var $el = this.element,
|
2012-01-10 05:38:12 +00:00
|
|
|
|
$button,
|
2011-06-29 00:15:43 +00:00
|
|
|
|
o = this.options,
|
2011-09-23 22:10:03 +00:00
|
|
|
|
type,
|
|
|
|
|
|
name,
|
|
|
|
|
|
$buttonPlaceholder;
|
2011-06-29 00:15:43 +00:00
|
|
|
|
|
2012-01-10 05:38:12 +00:00
|
|
|
|
// if this is a link, check if it's been enhanced and, if not, use the right function
|
|
|
|
|
|
if( $el[ 0 ].tagName === "A" ) {
|
|
|
|
|
|
if ( !$el.hasClass( "ui-btn" ) ) $el.buttonMarkup();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-06-29 00:15:43 +00:00
|
|
|
|
// Add ARIA role
|
2010-12-06 16:40:28 +00:00
|
|
|
|
this.button = $( "<div></div>" )
|
2010-10-28 00:43:27 +00:00
|
|
|
|
.text( $el.text() || $el.val() )
|
2011-10-14 23:18:49 +00:00
|
|
|
|
.insertBefore( $el )
|
2010-10-28 00:43:27 +00:00
|
|
|
|
.buttonMarkup({
|
2011-06-29 00:15:43 +00:00
|
|
|
|
theme: o.theme,
|
2010-11-11 03:54:57 +00:00
|
|
|
|
icon: o.icon,
|
|
|
|
|
|
iconpos: o.iconpos,
|
|
|
|
|
|
inline: o.inline,
|
|
|
|
|
|
corners: o.corners,
|
|
|
|
|
|
shadow: o.shadow,
|
|
|
|
|
|
iconshadow: o.iconshadow
|
2010-12-06 16:40:28 +00:00
|
|
|
|
})
|
2011-06-29 00:15:43 +00:00
|
|
|
|
.append( $el.addClass( "ui-btn-hidden" ) );
|
|
|
|
|
|
|
2011-12-16 21:58:20 +00:00
|
|
|
|
$button = this.button;
|
2011-06-29 00:15:43 +00:00
|
|
|
|
type = $el.attr( "type" );
|
2011-09-23 22:10:03 +00:00
|
|
|
|
name = $el.attr( "name" );
|
2011-06-29 00:15:43 +00:00
|
|
|
|
|
2011-09-23 22:10:03 +00:00
|
|
|
|
// 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>", {
|
2011-11-11 19:49:31 +00:00
|
|
|
|
type: "hidden",
|
|
|
|
|
|
name: $el.attr( "name" ),
|
|
|
|
|
|
value: $el.attr( "value" )
|
|
|
|
|
|
}).insertBefore( $el );
|
2011-06-29 00:15:43 +00:00
|
|
|
|
|
2011-09-23 22:10:03 +00:00
|
|
|
|
// Bind to doc to remove after submit handling
|
2011-10-31 12:53:01 +00:00
|
|
|
|
$( document ).one("submit", function(){
|
2011-10-28 14:30:58 +00:00
|
|
|
|
$buttonPlaceholder.remove();
|
2011-11-11 19:49:31 +00:00
|
|
|
|
|
|
|
|
|
|
// reset the local var so that the hidden input
|
|
|
|
|
|
// will be re-added on subsequent clicks
|
2011-10-28 14:30:58 +00:00
|
|
|
|
$buttonPlaceholder = undefined;
|
2011-09-23 22:10:03 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2010-12-06 16:40:28 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2011-06-29 00:15:43 +00:00
|
|
|
|
|
2011-12-16 21:58:20 +00:00
|
|
|
|
$el.bind({
|
|
|
|
|
|
focus: function() {
|
|
|
|
|
|
$button.addClass( $.mobile.focusClass );
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
blur: function() {
|
|
|
|
|
|
$button.removeClass( $.mobile.focusClass );
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2011-03-23 22:42:54 +00:00
|
|
|
|
this.refresh();
|
2010-11-17 15:27:35 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
2011-06-29 00:15:43 +00:00
|
|
|
|
enable: function() {
|
|
|
|
|
|
this.element.attr( "disabled", false );
|
|
|
|
|
|
this.button.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
|
|
|
|
|
|
return this._setOption( "disabled", false );
|
2010-11-17 15:27:35 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
2011-06-29 00:15:43 +00:00
|
|
|
|
disable: function() {
|
|
|
|
|
|
this.element.attr( "disabled", true );
|
|
|
|
|
|
this.button.addClass( "ui-disabled" ).attr( "aria-disabled", true );
|
|
|
|
|
|
return this._setOption( "disabled", true );
|
2011-03-23 22:42:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
2011-06-29 00:15:43 +00:00
|
|
|
|
refresh: function() {
|
2011-10-31 18:05:54 +00:00
|
|
|
|
var $el = this.element;
|
|
|
|
|
|
|
2011-10-31 18:44:56 +00:00
|
|
|
|
if ( $el.prop("disabled") ) {
|
2011-03-23 22:42:54 +00:00
|
|
|
|
this.disable();
|
2011-06-29 00:15:43 +00:00
|
|
|
|
} else {
|
2011-03-23 22:42:54 +00:00
|
|
|
|
this.enable();
|
|
|
|
|
|
}
|
2011-10-31 18:05:54 +00:00
|
|
|
|
|
2011-10-31 20:24:17 +00:00
|
|
|
|
// 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() );
|
2010-10-28 00:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2011-07-27 22:42:16 +00:00
|
|
|
|
|
|
|
|
|
|
//auto self-init widgets
|
|
|
|
|
|
$( document ).bind( "pagecreate create", function( e ){
|
2011-10-10 21:12:52 +00:00
|
|
|
|
$.mobile.button.prototype.enhanceWithin( e.target );
|
2011-07-27 22:42:16 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2011-12-16 02:09:25 +00:00
|
|
|
|
})( jQuery );
|
|
|
|
|
|
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
|
2011-10-31 04:59:56 +00:00
|
|
|
|
});
|
2011-12-16 02:09:25 +00:00
|
|
|
|
//>>excludeEnd("jqmBuildExclude");
|