slider.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Copyright © 2016 Mageplaza. All rights reserved.
  3. * See https://www.mageplaza.com/LICENSE.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'Magento_Catalog/js/price-utils',
  8. 'jquery/ui',
  9. 'Mageplaza_LayeredNavigation/js/layer'
  10. ], function($, ultil) {
  11. "use strict";
  12. $.widget('mageplaza.layerSlider', $.mageplaza.layer, {
  13. options: {
  14. sliderElement: '#ln_price_slider',
  15. textElement: '#ln_price_text'
  16. },
  17. _create: function () {
  18. var self = this;
  19. $(this.options.sliderElement).slider({
  20. min: self.options.minValue,
  21. max: self.options.maxValue,
  22. values: [self.options.selectedFrom, self.options.selectedTo],
  23. slide: function( event, ui ) {
  24. self.displayText(ui.values[0], ui.values[1]);
  25. },
  26. change: function(event, ui) {
  27. self.ajaxSubmit(self.getUrl(ui.values[0], ui.values[1]));
  28. }
  29. });
  30. this.displayText(this.options.selectedFrom, this.options.selectedTo);
  31. },
  32. getUrl: function(from, to){
  33. return this.options.ajaxUrl.replace(encodeURI('{price_start}'), from).replace(encodeURI('{price_end}'), to);
  34. },
  35. displayText: function(from, to){
  36. $(this.options.textElement).html(this.formatPrice(from) + ' - ' + this.formatPrice(to));
  37. },
  38. formatPrice: function(value) {
  39. return ultil.formatPrice(value, this.options.priceFormat);
  40. }
  41. });
  42. return $.mageplaza.layerSlider;
  43. });