jquery-mobile/js/jquery.mobile.forms.button.js
jblas@adobe.com 2c2be3d9c6 Fixes #2659 - buttons don't inherit page-theme
- Insert the fake button container before calling buttonMarkup(). This allows the buttonMarkup() code to accurately calculate theme inheritance.
2011-10-14 16:18:49 -07:00

95 lines
No EOL
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* jQuery Mobile Framework : "button" plugin - links that proxy to native input/buttons
* Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
(function( $, undefined ) {
$.widget( "mobile.button", $.mobile.widget, {
options: {
theme: null,
icon: null,
iconpos: null,
inline: null,
corners: true,
shadow: true,
iconshadow: true,
initSelector: "button, [type='button'], [type='submit'], [type='reset'], [type='image']"
},
_create: function() {
var $el = this.element,
o = this.options,
type,
name,
$buttonPlaceholder;
// Add ARIA role
this.button = $( "<div></div>" )
.text( $el.text() || $el.val() )
.insertBefore( $el )
.buttonMarkup({
theme: o.theme,
icon: o.icon,
iconpos: o.iconpos,
inline: o.inline,
corners: o.corners,
shadow: o.shadow,
iconshadow: o.iconshadow
})
.append( $el.addClass( "ui-btn-hidden" ) );
type = $el.attr( "type" );
name = $el.attr( "name" );
// 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 doesnt already exist.
if( $buttonPlaceholder === undefined ) {
$buttonPlaceholder = $( "<input>", {
type: "hidden",
name: $el.attr( "name" ),
value: $el.attr( "value" )
})
.insertBefore( $el );
// Bind to doc to remove after submit handling
$( document ).submit(function(){
$buttonPlaceholder.remove();
});
}
});
}
this.refresh();
},
enable: function() {
this.element.attr( "disabled", false );
this.button.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
return this._setOption( "disabled", false );
},
disable: function() {
this.element.attr( "disabled", true );
this.button.addClass( "ui-disabled" ).attr( "aria-disabled", true );
return this._setOption( "disabled", true );
},
refresh: function() {
if ( this.element.attr( "disabled" ) ) {
this.disable();
} else {
this.enable();
}
}
});
//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){
$.mobile.button.prototype.enhanceWithin( e.target );
});
})( jQuery );