2016-12-20 13:11:09 +00:00
|
|
|
/* global woocommerce_price_slider_params, accounting */
|
2014-03-19 22:54:38 +00:00
|
|
|
jQuery( function( $ ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2013-12-04 19:15:24 +00:00
|
|
|
// woocommerce_price_slider_params is required to continue, ensure the object exists
|
2014-03-19 22:54:38 +00:00
|
|
|
if ( typeof woocommerce_price_slider_params === 'undefined' ) {
|
2013-12-04 19:15:24 +00:00
|
|
|
return false;
|
2014-03-19 22:54:38 +00:00
|
|
|
}
|
2013-12-04 19:15:24 +00:00
|
|
|
|
2020-10-20 13:56:43 +00:00
|
|
|
$( document.body ).on( 'price_slider_create price_slider_slide', function( event, min, max ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2016-12-20 13:11:09 +00:00
|
|
|
$( '.price_slider_amount span.from' ).html( accounting.formatMoney( min, {
|
|
|
|
symbol: woocommerce_price_slider_params.currency_format_symbol,
|
|
|
|
decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
|
|
|
|
thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
|
|
|
|
precision: woocommerce_price_slider_params.currency_format_num_decimals,
|
|
|
|
format: woocommerce_price_slider_params.currency_format
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
$( '.price_slider_amount span.to' ).html( accounting.formatMoney( max, {
|
|
|
|
symbol: woocommerce_price_slider_params.currency_format_symbol,
|
|
|
|
decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
|
|
|
|
thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
|
|
|
|
precision: woocommerce_price_slider_params.currency_format_num_decimals,
|
|
|
|
format: woocommerce_price_slider_params.currency_format
|
|
|
|
} ) );
|
2013-06-06 11:30:55 +00:00
|
|
|
|
2015-06-29 19:10:36 +00:00
|
|
|
$( document.body ).trigger( 'price_slider_updated', [ min, max ] );
|
2012-02-16 18:12:14 +00:00
|
|
|
});
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
function init_price_filter() {
|
|
|
|
$( 'input#min_price, input#max_price' ).hide();
|
|
|
|
$( '.price_slider, .price_label' ).show();
|
2017-09-16 19:37:29 +00:00
|
|
|
|
2019-01-23 18:29:33 +00:00
|
|
|
var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
|
|
|
|
max_price = $( '.price_slider_amount #max_price' ).data( 'max' ),
|
|
|
|
step = $( '.price_slider_amount' ).data( 'step' ) || 1,
|
2017-09-16 19:37:29 +00:00
|
|
|
current_min_price = $( '.price_slider_amount #min_price' ).val(),
|
|
|
|
current_max_price = $( '.price_slider_amount #max_price' ).val();
|
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
$( '.price_slider:not(.ui-slider)' ).slider({
|
|
|
|
range: true,
|
|
|
|
animate: true,
|
|
|
|
min: min_price,
|
|
|
|
max: max_price,
|
2019-01-23 18:29:33 +00:00
|
|
|
step: step,
|
2017-09-16 19:16:43 +00:00
|
|
|
values: [ current_min_price, current_max_price ],
|
|
|
|
create: function() {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
$( '.price_slider_amount #min_price' ).val( current_min_price );
|
|
|
|
$( '.price_slider_amount #max_price' ).val( current_max_price );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
$( document.body ).trigger( 'price_slider_create', [ current_min_price, current_max_price ] );
|
|
|
|
},
|
|
|
|
slide: function( event, ui ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
$( 'input#min_price' ).val( ui.values[0] );
|
|
|
|
$( 'input#max_price' ).val( ui.values[1] );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
$( document.body ).trigger( 'price_slider_slide', [ ui.values[0], ui.values[1] ] );
|
|
|
|
},
|
|
|
|
change: function( event, ui ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
$( document.body ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2017-09-16 19:16:43 +00:00
|
|
|
init_price_filter();
|
2020-10-20 13:56:02 +00:00
|
|
|
$( document.body ).on( 'init_price_filter', init_price_filter );
|
2017-09-16 19:16:43 +00:00
|
|
|
|
2017-09-21 20:24:34 +00:00
|
|
|
var hasSelectiveRefresh = (
|
2017-09-16 19:16:43 +00:00
|
|
|
'undefined' !== typeof wp &&
|
|
|
|
wp.customize &&
|
|
|
|
wp.customize.selectiveRefresh &&
|
|
|
|
wp.customize.widgetsPreview &&
|
|
|
|
wp.customize.widgetsPreview.WidgetPartial
|
|
|
|
);
|
|
|
|
if ( hasSelectiveRefresh ) {
|
2021-02-24 18:28:55 +00:00
|
|
|
wp.customize.selectiveRefresh.on( 'partial-content-rendered', function() {
|
2017-09-16 19:16:43 +00:00
|
|
|
init_price_filter();
|
|
|
|
} );
|
|
|
|
}
|
2013-12-04 19:15:24 +00:00
|
|
|
});
|