<?php

/**
* Custom Controls WordPress Customizer
*
* Input Range Control
*
*
* @author Stefano Fattori
* @version 1.0
*
*/

add_action( 'customize_register', 'luxuryconceptfree_wp_customize_range_control' );

function luxuryconceptfree_wp_customize_range_control($wp_customize) {


class luxuryconceptfree_Customizer_Range_Control extends WP_Customize_Control {

	/**
	 * Enqueue scripts/styles.
	 */
	public function enqueue() {
		wp_enqueue_style( 'luxuryconceptfree-customize-control', $this->abs_path_to_url( dirname( __FILE__ ) . '/css/customizer.css' ), array(), rand() );
	}

	/**
	 * Render the control's content.
	 */
	 
	public function render_content() {
		
			$input_id         = '_customize_input_' . $this->id;
			$description_id   = '_customize-description-' . $this->id;
			$describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : '';
			?>
   
                <label class="customize-control-title" for=<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $this->label ); ?></label>
				<?php if ( ! empty( $this->description ) ) : ?>
				<span id="<?php echo esc_attr( $description_id ); ?> class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
				<?php endif; ?>	
				<form oninput="labeloutput.value=parseInt(<?php echo esc_attr( $input_id ); ?>.value)">
					<input
					id="<?php echo esc_attr( $input_id ); ?>"
					type="range"
					<?php echo esc_attr( $describedby_attr ); ?>
					<?php $this->input_attrs(); ?>
					<?php if ( ! isset( $this->input_attrs['value'] ) ) : ?>
						value="<?php echo esc_attr( $this->value() ); ?>"
					<?php endif; ?>
					<?php $this->link(); ?>
				    name="<?php echo esc_attr( $input_id ); ?>"
					class="custom-control-range"
					/>
		            <output name="labeloutput" for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $this->value() ); ?></output>
				</form> 		

		<?php
	}

	/**
	 * Plugin / theme agnostic path to URL
	 *
	 * @see https://wordpress.stackexchange.com/a/264870/14546
	 * @param string $path  file path
	 * @return string       URL
	 */
	private function abs_path_to_url( $path = '' ) {
		$url = str_replace(
			wp_normalize_path( untrailingslashit( ABSPATH ) ),
			esc_url( home_url( '/' ) ), //site_url(),
			wp_normalize_path( $path )
		);
		return esc_url_raw( $url );
	}
}
}