range.html 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. {% assign min = include.min | default: 0 %}
  2. {% assign max = include.max | default: 100 %}
  3. {% assign step = include.step | default: 10 %}
  4. {% assign value = include.value | default: 50 %}
  5. {% assign id = include.id %}
  6. {% if id %}
  7. <div class="form-range mb-2{% if include.class %} {{ include.class }}{% endif %}" id="range-{{ id }}"></div>
  8. {% capture_global scripts %}
  9. <script>
  10. // @formatter:off
  11. {% assign value = value | split: ',' %}
  12. document.addEventListener("DOMContentLoaded", function () {
  13. window.noUiSlider && (noUiSlider.create(document.getElementById('range-{{ id }}'), {
  14. start: {% if value.size > 1 %}[{{ value | join: ', ' }}]{% else %}{{ value }}{% endif %},
  15. {% if value.size > 1 or include.connect %}
  16. connect: [{% for i in (2..value.size) %}{% cycle 'false', 'true' %}, {% endfor %}true, false],
  17. {% endif %}
  18. step: {{ step }},
  19. range: {
  20. min: {{ min }},
  21. max: {{ max }}
  22. }
  23. }));
  24. });
  25. // @formatter:on
  26. </script>
  27. {% endcapture_global %}
  28. {% else %}
  29. <input type="range" class="form-range mb-2{% if include.class %} {{ include.class }}{% endif %}" value="{{ value }}" min="{{ min }}" max="{{ max }}" step="{{ step }}">
  30. {% endif %}