From 9cccf313baaf511f8674da9321f1bb78721d3565 Mon Sep 17 00:00:00 2001 From: optimalab Date: Mon, 29 Jun 2015 21:10:36 +0200 Subject: [PATCH] Fixed price-slider.js trigger and fixed js coding standards --- assets/js/frontend/price-slider.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/assets/js/frontend/price-slider.js b/assets/js/frontend/price-slider.js index 763f2504fb9..efab81d8bc3 100644 --- a/assets/js/frontend/price-slider.js +++ b/assets/js/frontend/price-slider.js @@ -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] ] ); - - }, + } }); });