<commit_before>//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Creates collapsible content blocks.
//>>label: Collapsible
//>>group: Widgets
//>>css.structure: ../css/structure/jquery.mobile.collapsible.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

define( [
	"jquery",
	"../jquery.mobile.core",
	"../jquery.mobile.widget",
	"../jquery.mobile.registry" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

var rInitialLetter = /([A-Z])/g;

$.widget( "mobile.collapsible", {
	options: {
		expandCueText: null,
		collapseCueText: null,
		collapsed: true,
		heading: "h1,h2,h3,h4,h5,h6,legend",
		collapsedIcon: null,
		expandedIcon: null,
		iconpos: null,
		theme: null,
		contentTheme: null,
		inset: null,
		corners: null,
		mini: null
	},

	_create: function() {
		var anchor,
			$el = this.element.addClass( "ui-collapsible" ),
			opts = this.options,
			heading = $el.children( opts.heading ).first(),
			replacementHeading = heading,
			content = $el.wrapInner( "<div class='ui-collapsible-content'></div>" ).children( ".ui-collapsible-content" ),
			accordion = $el.closest( ":jqmData(role='collapsible-set')" + ( $.mobile.collapsibleset ? ", :mobile-collapsibleset" : "" ) ).addClass( "ui-collapsible-set" );

		// Replace collapsibleHeading if it's a legend
		if ( heading.is( "legend" ) ) {
			replacementHeading = $( "<div role='heading'>"+ heading.html() +"</div>" );
			heading.remove();
		}

		anchor = replacementHeading
			//modify markup & attributes
			.addClass( "ui-collapsible-heading" )
			.append( "<span class='ui-collapsible-heading-status'></span>" )
			.wrapInner( "<a href='#' class='ui-collapsible-heading-toggle'></a>" )
			.find( "a" )
				.first()
				.addClass( "ui-btn" );

			//drop heading in before content
			replacementHeading.insertBefore( content );

		$.extend( this, {
			_accordion: accordion,
			_accordionWidget: null,
			_anchorClasses: "",
			_elClasses: "",
			_contentTheme: "",
			_ui: {
				anchor: anchor,
				content: content,
				heading: replacementHeading
			}
		});

		//events
		this._on({
			"expand": "_handleExpandCollapse",
			"collapse": "_handleExpandCollapse"
		});

		this._on( heading, {
			"tap": function(/* event */) {
				heading.find( "a" ).first().addClass( $.mobile.activeBtnClass );
			},

			"click": function( event ) {
				this._handleExpandCollapse( !heading.hasClass( "ui-collapsible-heading-collapsed" ) );
				event.preventDefault();
				event.stopPropagation();
			}
		});

		this._setOptions( opts );
	},

	_handleExpandCollapse: function( isCollapse ) {
		var key,
			opts = $.extend( {}, this.options );

		// Adjust for inherited values.
		for ( key in opts ) {
			opts[ key ] = this._optionValue( opts, key );
		}

		this._ui.heading
			.toggleClass( "ui-collapsible-heading-collapsed", isCollapse )
			.find( ".ui-collapsible-heading-status" )
			.text( isCollapse ? opts.expandCueText : opts.collapseCueText )
			.end()
			.find( "a" ).first()
			.toggleClass( "ui-icon-" + opts.expandedIcon, !isCollapse )

			// logic or cause same icon for expanded/collapsed state would remove the ui-icon-class
			.toggleClass( "ui-icon-" + opts.collapsedIcon, ( isCollapse || opts.expandedIcon === opts.collapsedIcon ) )
			.removeClass( $.mobile.activeBtnClass );

		this.element.toggleClass( "ui-collapsible-collapsed", isCollapse );
		this._ui.content
			.toggleClass( "ui-collapsible-content-collapsed", isCollapse )
			.attr( "aria-hidden", isCollapse )
			.trigger( "updatelayout" );
		this.options.collapsed = isCollapse;
		this._trigger( isCollapse ? "collapse" : "expand" );
	},

	// Retrieve the option value first from the options object passed in and, if
	// null, from the parent accordion or, if that's null too, or if there's no
	// parent accordion, then from the defaults.
	_optionValue: function( options, name ) {
		var ret,
			accordion = this._accordion,
			accordionWidget = this._accordionWidget;

		if ( accordion.length && !accordionWidget ) {
			this._accordionWidget = accordionWidget = accordion.data( "mobile-collapsibleset" );
		}

		ret =
			( options[ name ] != null ) ? options[ name ] :
			( accordionWidget ) ? accordionWidget.options[ name ] :
			accordion.length ? $.mobile.getAttribute( accordion[ 0 ], name.replace( rInitialLetter, "-$1" ).toLowerCase(), true ):
			null;

		if ( null == ret ) {
			ret = $.mobile.collapsible.defaults[ name ];
		}

		return ret;
	},

	refresh: function() {
		this._setOptions( {} );
	},

	expand: function() {
		this._handleExpandCollapse( false );
	},

	collapse: function() {
		this._handleExpandCollapse( true );
	},

	_setOptions: function( options ) {
		var key,
			opts = $.extend( {}, this.options, options ),
			$el = this.element,
			classes = "",
			anchorClasses = "";

		// Override inheritable options from the accordion or from defaults if
		// unset in this widget
		for ( key in opts ) {
			opts[ key ] = this._optionValue( opts, key );
		}<commit_msg>Collapsible: Implement _destroy().<commit_after>//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Creates collapsible content blocks.
//>>label: Collapsible
//>>group: Widgets
//>>css.structure: ../css/structure/jquery.mobile.collapsible.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

define( [
	"jquery",
	"../jquery.mobile.core",
	"../jquery.mobile.widget",
	"../jquery.mobile.registry" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

var rInitialLetter = /([A-Z])/g;

$.widget( "mobile.collapsible", {
	options: {
		expandCueText: null,
		collapseCueText: null,
		collapsed: true,
		heading: "h1,h2,h3,h4,h5,h6,legend",
		collapsedIcon: null,
		expandedIcon: null,
		iconpos: null,
		theme: null,
		contentTheme: null,
		inset: null,
		corners: null,
		mini: null
	},

	_create: function() {
		var anchor, placeholder,
			$el = this.element.addClass( "ui-collapsible" ),
			opts = this.options,
			heading = $el.children( opts.heading ).first(),
			replacementHeading = heading,
			content = $el.wrapInner( "<div class='ui-collapsible-content'></div>" ).children( ".ui-collapsible-content" ),
			accordion = $el.closest( ":jqmData(role='collapsible-set')" + ( $.mobile.collapsibleset ? ", :mobile-collapsibleset" : "" ) ).addClass( "ui-collapsible-set" );

		// Replace collapsibleHeading if it's a legend
		if ( heading.is( "legend" ) ) {
			replacementHeading = $( "<div role='heading'>"+ heading.html() +"</div>" );
			placeholder = $( "<div><!-- placeholder for legend --></div>" ).insertBefore( heading );
			heading.remove();
		}

		anchor = replacementHeading
			//modify markup & attributes
			.addClass( "ui-collapsible-heading" )
			.append( "<span class='ui-collapsible-heading-status'></span>" )
			.wrapInner( "<a href='#' class='ui-collapsible-heading-toggle'></a>" )
			.find( "a" )
				.first()
				.addClass( "ui-btn" );

			//drop heading in before content
			replacementHeading.insertBefore( content );

		$.extend( this, {
			_accordion: accordion,
			_accordionWidget: null,
			_anchorClasses: "",
			_elClasses: "",
			_contentTheme: "",
			_ui: {
				placeholder: placeholder,
				originalHeading: heading,
				anchor: anchor,
				content: content,
				heading: replacementHeading
			}
		});

		//events
		this._on({
			"expand": "_handleExpandCollapse",
			"collapse": "_handleExpandCollapse"
		});

		this._on( heading, {
			"tap": function(/* event */) {
				heading.find( "a" ).first().addClass( $.mobile.activeBtnClass );
			},

			"click": function( event ) {
				this._handleExpandCollapse( !heading.hasClass( "ui-collapsible-heading-collapsed" ) );
				event.preventDefault();
				event.stopPropagation();
			}
		});

		this._setOptions( opts );
	},

	_handleExpandCollapse: function( isCollapse ) {
		var key,
			opts = $.extend( {}, this.options );

		// Adjust for inherited values.
		for ( key in opts ) {
			opts[ key ] = this._optionValue( opts, key );
		}

		this._ui.heading
			.toggleClass( "ui-collapsible-heading-collapsed", isCollapse )
			.find( ".ui-collapsible-heading-status" )
			.text( isCollapse ? opts.expandCueText : opts.collapseCueText )
			.end()
			.find( "a" ).first()
			.toggleClass( "ui-icon-" + opts.expandedIcon, !isCollapse )

			// logic or cause same icon for expanded/collapsed state would remove the ui-icon-class
			.toggleClass( "ui-icon-" + opts.collapsedIcon, ( isCollapse || opts.expandedIcon === opts.collapsedIcon ) )
			.removeClass( $.mobile.activeBtnClass );

		this.element.toggleClass( "ui-collapsible-collapsed", isCollapse );
		this._ui.content
			.toggleClass( "ui-collapsible-content-collapsed", isCollapse )
			.attr( "aria-hidden", isCollapse )
			.trigger( "updatelayout" );
		this.options.collapsed = isCollapse;
		this._trigger( isCollapse ? "collapse" : "expand" );
	},

	// Retrieve the option value first from the options object passed in and, if
	// null, from the parent accordion or, if that's null too, or if there's no
	// parent accordion, then from the defaults.
	_optionValue: function( options, name ) {
		var ret,
			accordion = this._accordion,
			accordionWidget = this._accordionWidget;

		if ( accordion.length && !accordionWidget ) {
			this._accordionWidget = accordionWidget = accordion.data( "mobile-collapsibleset" );
		}

		ret =
			( options[ name ] != null ) ? options[ name ] :
			( accordionWidget ) ? accordionWidget.options[ name ] :
			accordion.length ? $.mobile.getAttribute( accordion[ 0 ], name.replace( rInitialLetter, "-$1" ).toLowerCase(), true ):
			null;

		if ( null == ret ) {
			ret = $.mobile.collapsible.defaults[ name ];
		}

		return ret;
	},

	refresh: function() {
		this._setOptions( {} );
	},

	expand: function() {
		this._handleExpandCollapse( false );
	},

	collapse: function() {
		this._handleExpandCollapse( true );
	},

	_destroy: function() {
		var ui = this._ui;

		if ( ui.placeholder ) {
			ui.originalHeading.insertBefore( ui.placeholder );
			ui.placeholder.remove();
			ui.heading.remove();
		} else {
			ui.heading
				.removeClass( "ui-collapsible-heading ui-collapsible-heading-collapsed" )
				.find( ".ui-collapsible-heading-status" )
					.remove()
				.end()
				.children()
					.contents()
						.unwrap();
		}

		ui.anchor.contents().unwrap();
		ui.content.contents().unwrap();
		this.element.removeClass( "ui-collapsible " + this._elClasses + ( this.options.collapsed ? " ui-collapsible-collapsed" : "" ) );
	},

	_setOptions: function( options ) {
		var key,
			opts = $.extend( {}, this.options, options ),
			$el = this.element,
			classes = "",
			anchorClasses = "";

		// Override inheritable options from the accordion or from defaults if
		// unset in this widget
		for ( key in opts ) {
			opts[ key ] = this._optionValue( opts, key );
		}
{'fraction_non_alphanumeric': 0.16378273341352828, 'fraction_numerical': 0.0014805218839640973, 'mean_word_length': 3.5146198830409356, 'pattern_counts': {'":': 10, '<': 22, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3711301', 'n_tokens_mistral': 4108, 'n_tokens_neox': 3567, 'n_words': 777}