2021-07-25 23:25:02 +00:00
|
|
|
wp.customize.controlConstructor[ 'generatepress-pro-range-slider' ] = wp.customize.Control.extend( {
|
|
|
|
ready() {
|
2020-04-07 13:03:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var control = this,
|
2021-07-25 23:25:02 +00:00
|
|
|
value,
|
2020-04-07 13:03:04 +00:00
|
|
|
controlClass = '.customize-control-generatepress-pro-range-slider',
|
|
|
|
footerActions = jQuery( '#customize-footer-actions' );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Set up the sliders
|
|
|
|
jQuery( '.generatepress-slider' ).each( function() {
|
|
|
|
var _this = jQuery( this );
|
|
|
|
var _input = _this.closest( 'label' ).find( 'input[type="number"]' );
|
|
|
|
var _text = _input.next( '.value' );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
|
|
|
_this.slider( {
|
2020-04-07 13:03:04 +00:00
|
|
|
value: _input.val(),
|
|
|
|
min: _this.data( 'min' ),
|
|
|
|
max: _this.data( 'max' ),
|
|
|
|
step: _this.data( 'step' ),
|
2021-07-25 23:25:02 +00:00
|
|
|
slide( event, ui ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
_input.val( ui.value ).change();
|
|
|
|
_text.text( ui.value );
|
2021-07-25 23:25:02 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Update the range value based on the input value
|
|
|
|
jQuery( controlClass + ' .gp_range_value input[type=number]' ).on( 'input', function() {
|
|
|
|
value = jQuery( this ).attr( 'value' );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
if ( '' == value ) {
|
|
|
|
value = -1;
|
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
|
|
|
|
jQuery( this ).closest( 'label' ).find( '.generatepress-slider' ).slider( 'value', parseFloat( value ) ).change();
|
|
|
|
} );
|
2020-04-07 13:03:04 +00:00
|
|
|
|
|
|
|
// Handle the reset button
|
|
|
|
jQuery( controlClass + ' .generatepress-reset' ).on( 'click', function() {
|
|
|
|
var icon = jQuery( this ),
|
2021-07-25 23:25:02 +00:00
|
|
|
visibleArea = icon.closest( '.gp-range-title-area' ).next( '.gp-range-slider-areas' ).children( 'label:visible' ),
|
|
|
|
input = visibleArea.find( 'input[type=number]' ),
|
|
|
|
sliderValue = visibleArea.find( '.generatepress-slider' ),
|
|
|
|
visualValue = visibleArea.find( '.gp_range_value' ),
|
|
|
|
resetValue = input.attr( 'data-reset_value' );
|
|
|
|
|
|
|
|
input.val( resetValue ).change();
|
|
|
|
visualValue.find( 'input' ).val( resetValue );
|
|
|
|
visualValue.find( '.value' ).text( resetValue );
|
|
|
|
|
|
|
|
if ( '' == resetValue ) {
|
|
|
|
resetValue = -1;
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
|
|
|
|
sliderValue.slider( 'value', parseFloat( resetValue ) );
|
|
|
|
} );
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Figure out which device icon to make active on load
|
|
|
|
jQuery( controlClass + ' .generatepress-range-slider-control' ).each( function() {
|
|
|
|
var _this = jQuery( this );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
_this.find( '.gp-device-controls' ).children( 'span:first-child' ).addClass( 'selected' );
|
|
|
|
_this.find( '.range-option-area:first-child' ).show();
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Do stuff when device icons are clicked
|
|
|
|
jQuery( controlClass + ' .gp-device-controls > span' ).on( 'click', function( event ) {
|
|
|
|
var device = jQuery( this ).data( 'option' );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
jQuery( controlClass + ' .gp-device-controls span' ).each( function() {
|
|
|
|
var _this = jQuery( this );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
|
|
|
if ( device === _this.attr( 'data-option' ) ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
_this.addClass( 'selected' );
|
|
|
|
_this.siblings().removeClass( 'selected' );
|
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
jQuery( controlClass + ' .gp-range-slider-areas label' ).each( function() {
|
|
|
|
var _this = jQuery( this );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
|
|
|
if ( device === _this.attr( 'data-option' ) ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
_this.show();
|
|
|
|
_this.siblings().hide();
|
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Set the device we're currently viewing
|
|
|
|
wp.customize.previewedDevice.set( jQuery( event.currentTarget ).data( 'option' ) );
|
|
|
|
} );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Set the selected devices in our control when the Customizer devices are clicked
|
|
|
|
footerActions.find( '.devices button' ).on( 'click', function() {
|
|
|
|
var device = jQuery( this ).data( 'device' );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
jQuery( controlClass + ' .gp-device-controls span' ).each( function() {
|
|
|
|
var _this = jQuery( this );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
|
|
|
if ( device === _this.attr( 'data-option' ) ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
_this.addClass( 'selected' );
|
|
|
|
_this.siblings().removeClass( 'selected' );
|
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
jQuery( controlClass + ' .gp-range-slider-areas label' ).each( function() {
|
|
|
|
var _this = jQuery( this );
|
2021-07-25 23:25:02 +00:00
|
|
|
|
|
|
|
if ( device === _this.attr( 'data-option' ) ) {
|
2020-04-07 13:03:04 +00:00
|
|
|
_this.show();
|
|
|
|
_this.siblings().hide();
|
|
|
|
}
|
2021-07-25 23:25:02 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Apply changes when desktop slider is changed
|
|
|
|
control.container.on( 'input change', '.desktop-range',
|
|
|
|
function() {
|
2021-07-25 23:25:02 +00:00
|
|
|
control.settings.desktop.set( jQuery( this ).val() );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
);
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Apply changes when tablet slider is changed
|
|
|
|
control.container.on( 'input change', '.tablet-range',
|
|
|
|
function() {
|
2021-07-25 23:25:02 +00:00
|
|
|
control.settings.tablet.set( jQuery( this ).val() );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
);
|
2021-07-25 23:25:02 +00:00
|
|
|
|
2020-04-07 13:03:04 +00:00
|
|
|
// Apply changes when mobile slider is changed
|
|
|
|
control.container.on( 'input change', '.mobile-range',
|
|
|
|
function() {
|
2021-07-25 23:25:02 +00:00
|
|
|
control.settings.mobile.set( jQuery( this ).val() );
|
2020-04-07 13:03:04 +00:00
|
|
|
}
|
|
|
|
);
|
2021-07-25 23:25:02 +00:00
|
|
|
},
|
|
|
|
} );
|