{"size": 1584, "ext": "js", "max_stars_repo_path": "vendor/aristath/kirki/controls/js/src/sortable.js", "max_stars_repo_name": "ikoncept/Municipio", "max_stars_repo_stars_event_min_datetime": "2016-08-25T13:11:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T08:57:47.000Z", "max_issues_repo_path": "vendor/aristath/kirki/controls/js/src/sortable.js", "max_issues_repo_name": "ikoncept/Municipio", "max_issues_repo_issues_event_min_datetime": "2016-09-01T14:24:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T11:48:50.000Z", "max_forks_repo_path": "vendor/aristath/kirki/controls/js/src/sortable.js", "max_forks_repo_name": "ikoncept/Municipio", "max_forks_repo_forks_event_min_datetime": "2016-09-01T12:51:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T09:42:03.000Z"}
{"max_stars_count": 23, "max_issues_count": 75, "max_forks_count": 19, "avg_line_length": 23.2941176471, "max_line_length": 112, "alphanum_fraction": 0.6426767677}
/* global kirkiControlLoader */
wp.customize.controlConstructor['kirki-sortable'] = wp.customize.Control.extend( {

	// When we're finished loading continue processing
	ready: function() {

		'use strict';

		var control = this;

		// Init the control.
		if ( ! _.isUndefined( window.kirkiControlLoader ) && _.isFunction( kirkiControlLoader ) ) {
			kirkiControlLoader( control );
		} else {
			control.initKirkiControl();
		}
	},

	initKirkiControl: function() {

		'use strict';

		var control = this;

		control.container.find( '.kirki-controls-loading-spinner' ).hide();

		// Set the sortable container.
		control.sortableContainer = control.container.find( 'ul.sortable' ).first();

		// Init sortable.
		control.sortableContainer.sortable( {

			// Update value when we stop sorting.
			stop: function() {
				control.updateValue();
			}
		} ).disableSelection().find( 'li' ).each( function() {

			// Enable/disable options when we click on the eye of Thundera.
			jQuery( this ).find( 'i.visibility' ).click( function() {
				jQuery( this ).toggleClass( 'dashicons-visibility-faint' ).parents( 'li:eq(0)' ).toggleClass( 'invisible' );
			} );
		} ).click( function() {

			// Update value on click.
			control.updateValue();
		} );
	},

	/**
	 * Updates the sorting list
	 */
	updateValue: function() {

		'use strict';

		var control = this,
			newValue = [];

		this.sortableContainer.find( 'li' ).each( function() {
			if ( ! jQuery( this ).is( '.invisible' ) ) {
				newValue.push( jQuery( this ).data( 'value' ) );
			}
		} );
		control.setting.set( newValue );
	}
} );
