Fixed price-slider.js trigger and fixed js coding standards

This commit is contained in:
optimalab 2015-06-29 21:10:36 +02:00 committed by Claudio Sanches
parent 47fbef49c9
commit 9cccf313ba
1 changed files with 16 additions and 12 deletions

View File

@ -1,3 +1,4 @@
/* global woocommerce_price_slider_params */
jQuery( function( $ ) {
// 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' ),
max_price = $( '.price_slider_amount #max_price' ).data( 'max' );
current_min_price = parseInt( min_price, 10 );
current_max_price = parseInt( max_price, 10 );
var current_min_price = parseInt( min_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.max_price ) current_max_price = parseInt( woocommerce_price_slider_params.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.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 ) {
if ( woocommerce_price_slider_params.currency_pos === 'left' ) {
@ -27,8 +32,8 @@ jQuery( function( $ ) {
} 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.to' ).html( woocommerce_price_slider_params.currency_symbol + " " + max );
$( '.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 );
} 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' ) {
$( '.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.from' ).html( min + ' ' + 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({
@ -51,7 +56,7 @@ jQuery( function( $ ) {
min: min_price,
max: 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 #max_price' ).val( current_max_price );
@ -68,8 +73,7 @@ jQuery( function( $ ) {
change: function( event, ui ) {
$( document.body ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
},
}
});
});