mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +00:00
55 lines
No EOL
1.8 KiB
JavaScript
55 lines
No EOL
1.8 KiB
JavaScript
/*
|
|
* jQuery Mobile Framework: "controlgroup" plugin - corner-rounding for groups of buttons, checks, radios, etc
|
|
* Copyright (c) jQuery Project
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
* http://jquery.org/license
|
|
*/
|
|
(function( $, undefined ) {
|
|
|
|
$.fn.controlgroup = function( options ) {
|
|
|
|
return this.each(function() {
|
|
|
|
var $el = $( this ),
|
|
o = $.extend({
|
|
direction: $el.jqmData( "type" ) || "vertical",
|
|
shadow: false,
|
|
excludeInvisible: true
|
|
}, options ),
|
|
groupheading = $el.find( ">legend" ),
|
|
flCorners = o.direction == "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
|
|
type = $el.find( "input:eq(0)" ).attr( "type" );
|
|
|
|
// Replace legend with more stylable replacement div
|
|
if ( groupheading.length ) {
|
|
$el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
|
|
$( "<div role='heading' class='ui-controlgroup-label'>" + groupheading.html() + "</div>" ).insertBefore( $el.children(0) );
|
|
groupheading.remove();
|
|
}
|
|
|
|
$el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );
|
|
|
|
// TODO: This should be moved out to the closure
|
|
// otherwise it is redefined each time controlgroup() is called
|
|
function flipClasses( els ) {
|
|
els.removeClass( "ui-btn-corner-all ui-shadow" )
|
|
.eq( 0 ).addClass( flCorners[ 0 ] )
|
|
.end()
|
|
.filter( ":last" ).addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
|
|
}
|
|
|
|
flipClasses( $el.find( ".ui-btn" + ( o.excludeInvisible ? ":visible" : "" ) ) );
|
|
flipClasses( $el.find( ".ui-btn-inner" ) );
|
|
|
|
if ( o.shadow ) {
|
|
$el.addClass( "ui-shadow" );
|
|
}
|
|
});
|
|
};
|
|
|
|
//auto self-init widgets
|
|
$( document ).bind( "pagecreate create", function( e ){
|
|
$( ":jqmData(role='controlgroup')", e.target ).controlgroup({ excludeInvisible: false });
|
|
});
|
|
|
|
})(jQuery); |