2010-09-10 22:23:13 +00:00
|
|
|
|
/*
|
2011-11-08 23:43:36 +00:00
|
|
|
|
* "button" plugin - links that proxy to native input/buttons
|
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,
|
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
|
|
|
|
|
|
|
|
|
|
// 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" ) );
|
|
|
|
|
|
|
|
|
|
|
|
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-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
|
|
|
|
});
|
|
|
|
|
|
|
2010-10-28 00:43:27 +00:00
|
|
|
|
})( jQuery );
|