jquery-mobile/js/jQuery.controlGroup.js

39 lines
No EOL
1.3 KiB
JavaScript

/*
* jQuery Mobile Framework : prototype for "controlgroup" plugin - corner-rounding for groups of buttons, checks, radios, etc
* Copyright (c) jQuery Project
* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
* Note: Code is in draft form and is subject to change
*/
(function($){
$.fn.controlgroup = function(options){
var o = $.extend({
direction: 'vertical',
shadow: false
},options);
return $(this).each(function(){
var groupheading = $(this).find('>legend'),
flCorners = o.direction == 'horizontal' ? ['ui-corner-left', 'ui-corner-right'] : ['ui-corner-top', 'ui-corner-bottom'],
type = $(this).find('input:eq(0)').attr('type');
//replace legend with more stylable replacement div
$('<div role="heading" class="ui-controlgroup-label">'+ groupheading.html() +'</div>').insertBefore(groupheading);
groupheading.remove();
$(this).addClass('ui-corner-all ui-controlgroup ui-controlgroup-'+o.direction);
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($(this).find('.ui-btn'));
flipClasses($(this).find('.ui-btn-inner'));
if(o.shadow){
$(this).addClass('ui-shadow');
}
});
};
})(jQuery);