2010-09-10 22:23:13 +00:00
|
|
|
|
/*
|
2010-11-10 00:55:52 +00:00
|
|
|
|
* jQuery Mobile Framework : "button" plugin - links that proxy to native input/buttons
|
2010-09-10 22:23:13 +00:00
|
|
|
|
* Copyright (c) jQuery Project
|
2010-11-20 03:47:47 +00:00
|
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
|
|
* http://jquery.org/license
|
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() )
|
|
|
|
|
|
.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
|
|
|
|
})
|
|
|
|
|
|
.insertBefore( $el )
|
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>", {
|
|
|
|
|
|
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
|
|
|
|
|
|
$( document ).submit(function(){
|
|
|
|
|
|
$buttonPlaceholder.remove();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
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() {
|
|
|
|
|
|
if ( this.element.attr( "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();
|
|
|
|
|
|
}
|
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 );
|