Fixed price-slider.js trigger and fixed js coding standards
This commit is contained in:
parent
47fbef49c9
commit
9cccf313ba
|
@ -1,3 +1,4 @@
|
||||||
|
/* global woocommerce_price_slider_params */
|
||||||
jQuery( function( $ ) {
|
jQuery( function( $ ) {
|
||||||
|
|
||||||
// woocommerce_price_slider_params is required to continue, ensure the object exists
|
// woocommerce_price_slider_params is required to continue, ensure the object exists
|
||||||
|
@ -13,11 +14,15 @@ jQuery( function( $ ) {
|
||||||
var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
|
var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
|
||||||
max_price = $( '.price_slider_amount #max_price' ).data( 'max' );
|
max_price = $( '.price_slider_amount #max_price' ).data( 'max' );
|
||||||
|
|
||||||
current_min_price = parseInt( min_price, 10 );
|
var current_min_price = parseInt( min_price, 10 );
|
||||||
current_max_price = parseInt( max_price, 10 );
|
var current_max_price = parseInt( max_price, 10 );
|
||||||
|
|
||||||
if ( woocommerce_price_slider_params.min_price ) current_min_price = parseInt( woocommerce_price_slider_params.min_price, 10 );
|
if ( woocommerce_price_slider_params.min_price ) {
|
||||||
if ( woocommerce_price_slider_params.max_price ) current_max_price = parseInt( woocommerce_price_slider_params.max_price, 10 );
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
$( document.body ).bind( 'price_slider_create price_slider_slide', function( event, min, max ) {
|
$( document.body ).bind( 'price_slider_create price_slider_slide', function( event, min, max ) {
|
||||||
if ( woocommerce_price_slider_params.currency_pos === 'left' ) {
|
if ( woocommerce_price_slider_params.currency_pos === 'left' ) {
|
||||||
|
@ -27,8 +32,8 @@ jQuery( function( $ ) {
|
||||||
|
|
||||||
} else if ( woocommerce_price_slider_params.currency_pos === 'left_space' ) {
|
} else if ( woocommerce_price_slider_params.currency_pos === 'left_space' ) {
|
||||||
|
|
||||||
$( '.price_slider_amount span.from' ).html( woocommerce_price_slider_params.currency_symbol + " " + min );
|
$( '.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 );
|
$( '.price_slider_amount span.to' ).html( woocommerce_price_slider_params.currency_symbol + ' ' + max );
|
||||||
|
|
||||||
} else if ( woocommerce_price_slider_params.currency_pos === 'right' ) {
|
} else if ( woocommerce_price_slider_params.currency_pos === 'right' ) {
|
||||||
|
|
||||||
|
@ -37,12 +42,12 @@ jQuery( function( $ ) {
|
||||||
|
|
||||||
} else if ( woocommerce_price_slider_params.currency_pos === 'right_space' ) {
|
} else if ( woocommerce_price_slider_params.currency_pos === 'right_space' ) {
|
||||||
|
|
||||||
$( '.price_slider_amount span.from' ).html( min + " " + woocommerce_price_slider_params.currency_symbol );
|
$( '.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 );
|
$( '.price_slider_amount span.to' ).html( max + ' ' + woocommerce_price_slider_params.currency_symbol );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$( document.body ).trigger( 'price_slider_updated', min, max );
|
$( document.body ).trigger( 'price_slider_updated', [ min, max ] );
|
||||||
});
|
});
|
||||||
|
|
||||||
$( '.price_slider' ).slider({
|
$( '.price_slider' ).slider({
|
||||||
|
@ -51,7 +56,7 @@ jQuery( function( $ ) {
|
||||||
min: min_price,
|
min: min_price,
|
||||||
max: max_price,
|
max: max_price,
|
||||||
values: [ current_min_price, current_max_price ],
|
values: [ current_min_price, current_max_price ],
|
||||||
create : function( event, ui ) {
|
create: function() {
|
||||||
|
|
||||||
$( '.price_slider_amount #min_price' ).val( current_min_price );
|
$( '.price_slider_amount #min_price' ).val( current_min_price );
|
||||||
$( '.price_slider_amount #max_price' ).val( current_max_price );
|
$( '.price_slider_amount #max_price' ).val( current_max_price );
|
||||||
|
@ -68,8 +73,7 @@ jQuery( function( $ ) {
|
||||||
change: function( event, ui ) {
|
change: function( event, ui ) {
|
||||||
|
|
||||||
$( document.body ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
|
$( document.body ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
|
||||||
|
}
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue