1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Creates collapsible content blocks.
5 //>>css: ../css/themes/default/jquery.mobile.theme.css,../css/structure/jquery.mobile.collapsible.css
7 define( [ "jquery", "./jquery.mobile.widget", "./jquery.mobile.buttonMarkup" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
11 $.widget( "mobile.collapsible", $.mobile.widget, {
13 expandCueText: " click to expand contents",
14 collapseCueText: " click to collapse contents",
16 heading: "h1,h2,h3,h4,h5,h6,legend",
21 initSelector: ":jqmData(role='collapsible')"
25 var $el = this.element,
27 collapsible = $el.addClass( "ui-collapsible" ),
28 collapsibleHeading = $el.children( o.heading ).first(),
29 collapsibleContent = collapsible.wrapInner( "<div class='ui-collapsible-content'></div>" ).find( ".ui-collapsible-content" ),
30 collapsibleSet = $el.closest( ":jqmData(role='collapsible-set')" ).addClass( "ui-collapsible-set" );
32 // Replace collapsibleHeading if it's a legend
33 if ( collapsibleHeading.is( "legend" ) ) {
34 collapsibleHeading = $( "<div role='heading'>"+ collapsibleHeading.html() +"</div>" ).insertBefore( collapsibleHeading );
35 collapsibleHeading.next().remove();
38 // If we are in a collapsible set
39 if ( collapsibleSet.length ) {
40 // Inherit the theme from collapsible-set
42 o.theme = collapsibleSet.jqmData("theme") || $.mobile.getInheritedTheme( collapsibleSet, "c" );
44 // Inherit the content-theme from collapsible-set
45 if ( !o.contentTheme ) {
46 o.contentTheme = collapsibleSet.jqmData( "content-theme" );
49 // Gets the preference icon position in the set
51 o.iconPos = collapsibleSet.jqmData( "iconpos" );
55 o.mini = collapsibleSet.jqmData( "mini" );
58 collapsibleContent.addClass( ( o.contentTheme ) ? ( "ui-body-" + o.contentTheme ) : "");
61 //drop heading in before content
62 .insertBefore( collapsibleContent )
63 //modify markup & attributes
64 .addClass( "ui-collapsible-heading" )
65 .append( "<span class='ui-collapsible-heading-status'></span>" )
66 .wrapInner( "<a href='#' class='ui-collapsible-heading-toggle'></a>" )
72 iconpos: $el.jqmData( "iconpos" ) || o.iconPos || "left",
77 .add( ".ui-btn-inner", $el )
78 .addClass( "ui-corner-top ui-corner-bottom" );
82 .bind( "expand collapse", function( event ) {
83 if ( !event.isDefaultPrevented() ) {
85 event.preventDefault();
87 var $this = $( this ),
88 isCollapse = ( event.type === "collapse" ),
89 contentTheme = o.contentTheme;
92 .toggleClass( "ui-collapsible-heading-collapsed", isCollapse)
93 .find( ".ui-collapsible-heading-status" )
94 .text( isCollapse ? o.expandCueText : o.collapseCueText )
97 .toggleClass( "ui-icon-minus", !isCollapse )
98 .toggleClass( "ui-icon-plus", isCollapse );
100 $this.toggleClass( "ui-collapsible-collapsed", isCollapse );
101 collapsibleContent.toggleClass( "ui-collapsible-content-collapsed", isCollapse ).attr( "aria-hidden", isCollapse );
103 if ( contentTheme && ( !collapsibleSet.length || collapsible.jqmData( "collapsible-last" ) ) ) {
105 .find( "a" ).first().add( collapsibleHeading.find( ".ui-btn-inner" ) )
106 .toggleClass( "ui-corner-bottom", isCollapse );
107 collapsibleContent.toggleClass( "ui-corner-bottom", !isCollapse );
109 collapsibleContent.trigger( "updatelayout" );
112 .trigger( o.collapsed ? "collapse" : "expand" );
115 .bind( "click", function( event ) {
117 var type = collapsibleHeading.is( ".ui-collapsible-heading-collapsed" ) ?
118 "expand" : "collapse";
120 collapsible.trigger( type );
122 event.preventDefault();
127 //auto self-init widgets
128 $( document ).bind( "pagecreate create", function( e ){
129 $.mobile.collapsible.prototype.enhanceWithin( e.target );
133 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
135 //>>excludeEnd("jqmBuildExclude");