mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-22 15:14:44 +00:00
Merge pull request #1953 from rwldrn/jquery.mobile.controlGroup.js
jQuery core style guide conformance: jquery.mobile.controlGroup.js
This commit is contained in:
commit
988045c65e
1 changed files with 33 additions and 28 deletions
|
|
@ -5,38 +5,43 @@
|
|||
* http://jquery.org/license
|
||||
*/
|
||||
(function($, undefined ) {
|
||||
$.fn.controlgroup = function(options){
|
||||
|
||||
return this.each(function(){
|
||||
var o = $.extend({
|
||||
direction: $( this ).jqmData( "type" ) || "vertical",
|
||||
shadow: false
|
||||
},options);
|
||||
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
|
||||
if( groupheading.length ){
|
||||
$(this).wrapInner('<div class="ui-controlgroup-controls"></div>');
|
||||
$('<div role="heading" class="ui-controlgroup-label">'+ groupheading.html() +'</div>').insertBefore( $(this).children(0) );
|
||||
groupheading.remove();
|
||||
|
||||
$.fn.controlgroup = function( options ) {
|
||||
|
||||
return this.each(function() {
|
||||
var $el = $( this ),
|
||||
o = $.extend({
|
||||
direction: $el.jqmData( "type" ) || "vertical",
|
||||
shadow: false
|
||||
}, 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();
|
||||
}
|
||||
|
||||
$(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])
|
||||
$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');
|
||||
.filter( ":last" ).addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
|
||||
}
|
||||
flipClasses($(this).find('.ui-btn'+(o.dontFilterOutInvisible?'':':visible')));
|
||||
flipClasses($(this).find('.ui-btn-inner'));
|
||||
if(o.shadow){
|
||||
$(this).addClass('ui-shadow');
|
||||
|
||||
flipClasses( $el.find( ".ui-btn" + ( o.dontFilterOutInvisible ? "" : ":visible" ) ) );
|
||||
flipClasses( $el.find( ".ui-btn-inner" ) );
|
||||
|
||||
if ( o.shadow ) {
|
||||
$el.addClass( "ui-shadow" );
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
})(jQuery);
|
||||
Loading…
Reference in a new issue