Browse files

Decoupled collapsible and collapsible-set

That fixes issue #2905 as well
  • Loading branch information...
1 parent 94389bd commit 6d4274fd6ce0c767cd206619d177fe6b8f0a37f0 Ghislain Seguin committed Nov 9, 2011
Showing with 85 additions and 2 deletions.
  1. +1 −0 js/index.php
  2. +4 −2 js/jquery.mobile.collapsible.js
  3. +80 −0 js/jquery.mobile.collapsibleSet.js
View
1 js/index.php
@@ -18,6 +18,7 @@
'jquery.mobile.dialog.js',
'jquery.mobile.page.sections.js',
'jquery.mobile.collapsible.js',
+ 'jquery.mobile.collapsibleSet.js',
'jquery.mobile.fieldContain.js',
'jquery.mobile.grid.js',
'jquery.mobile.navbar.js',
View
6 js/jquery.mobile.collapsible.js
@@ -59,10 +59,12 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
iconPos: "left",
icon: "plus",
theme: o.theme
- });
+ })
+ .add( ".ui-btn-inner" )
+ .addClass( "ui-corner-top ui-corner-bottom" );
collapsibleHeading
- .find( "a" ).first().add( collapsibleHeading.find( ".ui-btn-inner" ) )
+ .find( "a:eq(0), .ui-btn-inner" )
.addClass( "ui-corner-top ui-corner-bottom" );
//events
View
80 js/jquery.mobile.collapsibleSet.js
@@ -0,0 +1,80 @@
+/*
+* "collapsibleset" plugin
+*/
+
+(function( $, undefined ) {
+
+$.widget( "mobile.collapsibleset", $.mobile.widget, {
+ options: {
+ initSelector: ":jqmData(role='collapsible-set')"
+ },
+ _create: function() {
+ console.debug( "collapsibleset.create()" );
+ var $el = this.element.addClass( "ui-collapsible-set" ),
+ o = this.options,
+ collapsiblesInSet = $el.children( ":jqmData(role='collapsible')" );
+
+ // Inherit the theme from collapsible-set
+ if ( !o.theme ) {
+ o.theme = $el.jqmData( "theme" );
+ }
+ // Inherit the content-theme from collapsible-set
+ if ( !o.contentTheme ) {
+ o.contentTheme = $el.jqmData( "content-theme" );
+ }
+
+ $el.find( ".ui-collapsible-content" ).addClass( ( o.contentTheme ) ? ( "ui-body-" + o.contentTheme ) : "");
+ // Initialize the collapsible set if it's not already initialized
+ if ( !$el.jqmData( "collapsiblebound" ) ) {
+
+ $el
+ .jqmData( "collapsiblebound", true )
+ .bind( "expand collapse", function( event ) {
+ var isCollapse = ( event.type === "collapse" ),
+ collapsible = $( event.target ).closest( ".ui-collapsible" ),
+ widget = collapsible.data( "collapsible" ),
+ contentTheme = widget.options.contentTheme;
+ if ( contentTheme && collapsible.jqmData( "collapsible-last" ) ) {
+ collapsible.find( widget.options.heading ).eq( 0 )
+ .find( "a:eq(0), .ui-btn-inner" )
+ .toggleClass( "ui-corner-bottom", isCollapse );
+ collapsible.find( ".ui-collapsible-content" ).toggleClass( "ui-corner-bottom", !isCollapse );
+ }
+ })
+ .bind( "expand", function( event ) {
+ $( event.target )
+ .closest( ".ui-collapsible" )
+ .siblings( ".ui-collapsible" )
+ .trigger( "collapse" );
+
+ });
+
+ // clean up borders
+ collapsiblesInSet.each( function() {
+ $( this ).find( $.mobile.collapsible.prototype.options.heading )
+ .find( "a:eq(0), .ui-btn-inner" )
+ .removeClass( "ui-corner-top ui-corner-bottom" );
+ });
+
+ collapsiblesInSet.first()
+ .find( "a:eq(0)" )
+ .addClass( "ui-corner-top" )
+ .find( ".ui-btn-inner" )
+ .addClass( "ui-corner-top" );
+
+ collapsiblesInSet.last()
+ .jqmData( "collapsible-last", true )
+ .find( "a:eq(0)" )
+ .addClass( "ui-corner-bottom" )
+ .find( ".ui-btn-inner" )
+ .addClass( "ui-corner-bottom" );
+ }
+ }
+});
+
+//auto self-init widgets
+$( document ).bind( "pagecreate create", function( e ){
+ $( $.mobile.collapsibleset.prototype.options.initSelector, e.target ).collapsibleset();
+});
+
+})( jQuery );

0 comments on commit 6d4274f

Please sign in to comment.