Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 561090d

Browse files
author
Gabriel Schulhof
committed
Collapsible: Implement _destroy().
1 parent 01301cc commit 561090d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

js/widgets/collapsible.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $.widget( "mobile.collapsible", {
3232
},
3333

3434
_create: function() {
35-
var anchor,
35+
var anchor, placeholder,
3636
$el = this.element.addClass( "ui-collapsible" ),
3737
opts = this.options,
3838
heading = $el.children( opts.heading ).first(),
@@ -43,6 +43,7 @@ $.widget( "mobile.collapsible", {
4343
// Replace collapsibleHeading if it's a legend
4444
if ( heading.is( "legend" ) ) {
4545
replacementHeading = $( "<div role='heading'>"+ heading.html() +"</div>" );
46+
placeholder = $( "<div><!-- placeholder for legend --></div>" ).insertBefore( heading );
4647
heading.remove();
4748
}
4849

@@ -65,6 +66,8 @@ $.widget( "mobile.collapsible", {
6566
_elClasses: "",
6667
_contentTheme: "",
6768
_ui: {
69+
placeholder: placeholder,
70+
originalHeading: heading,
6871
anchor: anchor,
6972
content: content,
7073
heading: replacementHeading
@@ -159,6 +162,29 @@ $.widget( "mobile.collapsible", {
159162
this._handleExpandCollapse( true );
160163
},
161164

165+
_destroy: function() {
166+
var ui = this._ui;
167+
168+
if ( ui.placeholder ) {
169+
ui.originalHeading.insertBefore( ui.placeholder );
170+
ui.placeholder.remove();
171+
ui.heading.remove();
172+
} else {
173+
ui.heading
174+
.removeClass( "ui-collapsible-heading ui-collapsible-heading-collapsed" )
175+
.find( ".ui-collapsible-heading-status" )
176+
.remove()
177+
.end()
178+
.children()
179+
.contents()
180+
.unwrap();
181+
}
182+
183+
ui.anchor.contents().unwrap();
184+
ui.content.contents().unwrap();
185+
this.element.removeClass( "ui-collapsible " + this._elClasses + ( this.options.collapsed ? " ui-collapsible-collapsed" : "" ) );
186+
},
187+
162188
_setOptions: function( options ) {
163189
var key,
164190
opts = $.extend( {}, this.options, options ),

0 commit comments

Comments
 (0)