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 ) {
|
|
|
|
|
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
//auto self-init widgets
|
2011-07-20 02:44:03 +00:00
|
|
|
$( document ).bind( "pagecreate enhance", function( e ){
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
$( "button, [type='button'], [type='submit'], [type='reset'], [type='image']", e.target )
|
|
|
|
|
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
|
|
|
|
|
.button();
|
|
|
|
|
});
|
|
|
|
|
|
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,
|
|
|
|
|
iconshadow: true
|
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,
|
|
|
|
|
type;
|
|
|
|
|
|
|
|
|
|
// 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" ) );
|
|
|
|
|
|
|
|
|
|
// Add hidden input during submit
|
|
|
|
|
type = $el.attr( "type" );
|
|
|
|
|
|
|
|
|
|
if ( type !== "button" && type !== "reset" ) {
|
|
|
|
|
|
|
|
|
|
$el.bind( "vclick", function() {
|
|
|
|
|
|
|
|
|
|
var $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(){
|
2010-12-06 16:40:28 +00:00
|
|
|
$buttonPlaceholder.remove();
|
|
|
|
|
});
|
2010-10-28 00:43:27 +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() {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})( jQuery );
|