rating.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {% assign id = include.id | default: include.icon | default: 'default' %}
  2. {% assign icon = include.icon | default: 'star' %}
  3. {% assign color = include.color %}
  4. {% assign size = include.size | default: false %}
  5. {% assign value = include.value %}
  6. <select id="rating-{{ id }}">
  7. <option value="">Select a rating</option>
  8. <option value="5"{% if value == 5 %} selected{% endif %}>Excellent</option>
  9. <option value="4"{% if value == 4 %} selected{% endif %}>Very Good</option>
  10. <option value="3"{% if value == 3 %} selected{% endif %}>Average</option>
  11. <option value="2"{% if value == 2 %} selected{% endif %}>Poor</option>
  12. <option value="1"{% if value == 1 %} selected{% endif %}>Terrible</option>
  13. </select>
  14. {% capture star %}
  15. {% include "ui/icon.html" class="gl-star-full" icon=icon color=color type="filled" size=size %}
  16. {% endcapture %}
  17. {% assign star = star | replace_regex: "[\t\s]+\n", "" | strip %}
  18. {% assign star = star | replace_regex: "[\n\t]{2,}", " " | strip %}
  19. {% assign star = star | replace_regex: "<!--[^-]*-->", "" | strip %}
  20. {% capture_global scripts %}
  21. <script>
  22. // @formatter:off
  23. {% if environment == 'development' %}window.tabler_rating = window.tabler_rating || {};{% endif %}
  24. document.addEventListener("DOMContentLoaded", function () {
  25. const rating = new StarRating('#rating-{{ id }}', {
  26. tooltip: false,
  27. clearable: false,
  28. stars: function (el, item, index) {
  29. el.innerHTML = `{{ star }}`;
  30. },
  31. classNames: {
  32. }
  33. })
  34. {% if environment == 'development' %}window.tabler_rating["rating-{{ id }}"] = rating;{% endif %}
  35. })
  36. // @formatter:on
  37. </script>
  38. {% endcapture_global %}