wp.customize.controlConstructor['pawfect-range-slider'] = wp.customize.Control.extend({

	ready: function() {
		'use strict';

		var control = this,
			slider = control.container.find( '.pawfect-range-slider-range' ),
			output = control.container.find( '.pawfect-range-slider-value' );

		slider.on('input change', function() {
			control.setting.set( this.value );
			output.val( this.value );
		});

		output.on('input change', function() {
			control.setting.set( this.value );
			slider.val( this.value );
		});

		if ( typeof control.params.default !== 'undefined' && control.params.default !== false ) {
			var reset = control.container.find( '.pawfect-range-reset-slider' );

			reset.on('click', function() {
				var def = control.params.default;
				// Fallback if the JS param somehow got lost but it was in PHP
				if (!def && def !== 0) {
					def = output.attr('data-default') || 0;
				}
				control.setting.set( def );
				slider.val( def );
				output.val( def );
			});
		}
	}

});
