jquery-mobile/js/jquery.mobile.forms.button.js

73 lines
1.7 KiB
JavaScript
Raw Normal View History

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
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
2010-09-10 22:23:13 +00:00
*/
(function($, undefined ) {
$.widget( "mobile.button", $.mobile.widget, {
2010-11-11 03:54:57 +00:00
options: {
2010-11-11 04:08:22 +00:00
theme: null,
icon: null,
iconpos: null,
inline: null,
corners: true,
shadow: true,
iconshadow: true
2010-11-11 03:54:57 +00:00
},
_create: function(){
var $el = this.element,
2010-11-11 03:54:57 +00:00
o = this.options,
type = $el.attr('type');
$el
.addClass('ui-btn-hidden')
.attr('tabindex','-1');
//add ARIA role
this.button = $( "<a>", {
"href": "#",
"role": "button",
"aria-label": $el.attr( "type" )
} )
.text( $el.text() || $el.val() )
.insertBefore( $el )
.click(function(e){
if(!o.disabled){
if ( $el.attr("type") !== "reset" ){
var $buttonPlaceholder = $("<input>",
{type: "hidden", name: $el.attr("name"), value: $el.attr("value")})
.insertBefore($el);
}
$el.submit();
$buttonPlaceholder.remove();
}
else{
$el.trigger("click")
}
e.preventDefault();
2010-09-10 22:23:13 +00:00
})
.buttonMarkup({
2010-11-11 03:54:57 +00:00
theme: o.theme,
icon: o.icon,
iconpos: o.iconpos,
inline: o.inline,
corners: o.corners,
shadow: o.shadow,
iconshadow: o.iconshadow
});
},
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);
}
});
})( jQuery );