Nessuna descrizione

price-slider.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* global woocommerce_price_slider_params, accounting */
  2. jQuery( function( $ ) {
  3. // woocommerce_price_slider_params is required to continue, ensure the object exists
  4. if ( typeof woocommerce_price_slider_params === 'undefined' ) {
  5. return false;
  6. }
  7. $( document.body ).on( 'price_slider_create price_slider_slide', function( event, min, max ) {
  8. $( '.price_slider_amount span.from' ).html( accounting.formatMoney( min, {
  9. symbol: woocommerce_price_slider_params.currency_format_symbol,
  10. decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
  11. thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
  12. precision: woocommerce_price_slider_params.currency_format_num_decimals,
  13. format: woocommerce_price_slider_params.currency_format
  14. } ) );
  15. $( '.price_slider_amount span.to' ).html( accounting.formatMoney( max, {
  16. symbol: woocommerce_price_slider_params.currency_format_symbol,
  17. decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
  18. thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
  19. precision: woocommerce_price_slider_params.currency_format_num_decimals,
  20. format: woocommerce_price_slider_params.currency_format
  21. } ) );
  22. $( document.body ).trigger( 'price_slider_updated', [ min, max ] );
  23. });
  24. function init_price_filter() {
  25. $( 'input#min_price, input#max_price' ).hide();
  26. $( '.price_slider, .price_label' ).show();
  27. var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
  28. max_price = $( '.price_slider_amount #max_price' ).data( 'max' ),
  29. step = $( '.price_slider_amount' ).data( 'step' ) || 1,
  30. current_min_price = $( '.price_slider_amount #min_price' ).val(),
  31. current_max_price = $( '.price_slider_amount #max_price' ).val();
  32. $( '.price_slider:not(.ui-slider)' ).slider({
  33. range: true,
  34. animate: true,
  35. min: min_price,
  36. max: max_price,
  37. step: step,
  38. values: [ current_min_price, current_max_price ],
  39. create: function() {
  40. $( '.price_slider_amount #min_price' ).val( current_min_price );
  41. $( '.price_slider_amount #max_price' ).val( current_max_price );
  42. $( document.body ).trigger( 'price_slider_create', [ current_min_price, current_max_price ] );
  43. },
  44. slide: function( event, ui ) {
  45. $( 'input#min_price' ).val( ui.values[0] );
  46. $( 'input#max_price' ).val( ui.values[1] );
  47. $( document.body ).trigger( 'price_slider_slide', [ ui.values[0], ui.values[1] ] );
  48. },
  49. change: function( event, ui ) {
  50. $( document.body ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
  51. }
  52. });
  53. }
  54. init_price_filter();
  55. $( document.body ).on( 'init_price_filter', init_price_filter );
  56. var hasSelectiveRefresh = (
  57. 'undefined' !== typeof wp &&
  58. wp.customize &&
  59. wp.customize.selectiveRefresh &&
  60. wp.customize.widgetsPreview &&
  61. wp.customize.widgetsPreview.WidgetPartial
  62. );
  63. if ( hasSelectiveRefresh ) {
  64. wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
  65. init_price_filter();
  66. } );
  67. }
  68. });