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
|
|
|
|
2011-12-02 11:43:15 +00:00
|
|
|
// Get markup ready for slider
|
2014-03-19 22:54:38 +00:00
|
|
|
$( 'input#min_price, input#max_price' ).hide();
|
|
|
|
$( '.price_slider, .price_label' ).show();
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2011-12-02 11:43:15 +00:00
|
|
|
// Price slider uses jquery ui
|
2014-03-19 22:54:38 +00:00
|
|
|
var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
|
|
|
|
max_price = $( '.price_slider_amount #max_price' ).data( 'max' );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
current_min_price = parseInt( min_price, 10 );
|
|
|
|
current_max_price = parseInt( max_price, 10 );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
if ( woocommerce_price_slider_params.min_price ) current_min_price = parseInt( woocommerce_price_slider_params.min_price, 10 );
|
|
|
|
if ( woocommerce_price_slider_params.max_price ) current_max_price = parseInt( woocommerce_price_slider_params.max_price, 10 );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( 'body' ).bind( 'price_slider_create price_slider_slide', function( event, min, max ) {
|
|
|
|
if ( woocommerce_price_slider_params.currency_pos === 'left' ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( '.price_slider_amount span.from' ).html( woocommerce_price_slider_params.currency_symbol + min );
|
|
|
|
$( '.price_slider_amount span.to' ).html( woocommerce_price_slider_params.currency_symbol + max );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
} else if ( woocommerce_price_slider_params.currency_pos === 'left_space' ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( '.price_slider_amount span.from' ).html( woocommerce_price_slider_params.currency_symbol + " " + min );
|
|
|
|
$( '.price_slider_amount span.to' ).html( woocommerce_price_slider_params.currency_symbol + " " + max );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
} else if ( woocommerce_price_slider_params.currency_pos === 'right' ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( '.price_slider_amount span.from' ).html( min + woocommerce_price_slider_params.currency_symbol );
|
|
|
|
$( '.price_slider_amount span.to' ).html( max + woocommerce_price_slider_params.currency_symbol );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
} else if ( woocommerce_price_slider_params.currency_pos === 'right_space' ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( '.price_slider_amount span.from' ).html( min + " " + woocommerce_price_slider_params.currency_symbol );
|
|
|
|
$( '.price_slider_amount span.to' ).html( max + " " + woocommerce_price_slider_params.currency_symbol );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2012-02-16 17:16:27 +00:00
|
|
|
}
|
2013-06-06 11:30:55 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( 'body' ).trigger( 'price_slider_updated', min, max );
|
2012-02-16 18:12:14 +00:00
|
|
|
});
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( '.price_slider' ).slider({
|
2011-12-02 11:43:15 +00:00
|
|
|
range: true,
|
|
|
|
animate: true,
|
|
|
|
min: min_price,
|
|
|
|
max: max_price,
|
2014-03-19 22:54:38 +00:00
|
|
|
values: [ current_min_price, current_max_price ],
|
2011-12-02 11:43:15 +00:00
|
|
|
create : function( event, ui ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +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
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( 'body' ).trigger( 'price_slider_create', [ current_min_price, current_max_price ] );
|
2011-12-02 11:43:15 +00:00
|
|
|
},
|
|
|
|
slide: function( event, ui ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( 'input#min_price' ).val( ui.values[0] );
|
|
|
|
$( 'input#max_price' ).val( ui.values[1] );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( 'body' ).trigger( 'price_slider_slide', [ ui.values[0], ui.values[1] ] );
|
2012-02-16 18:12:14 +00:00
|
|
|
},
|
|
|
|
change: function( event, ui ) {
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2014-03-19 22:54:38 +00:00
|
|
|
$( 'body' ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2012-02-16 18:12:14 +00:00
|
|
|
},
|
2011-12-02 11:43:15 +00:00
|
|
|
});
|
2013-04-23 14:37:19 +00:00
|
|
|
|
2013-12-04 19:15:24 +00:00
|
|
|
});
|