rating.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. {% assign id = include.id | default: include.icon | default: 'default' %}
  2. {% assign icon = include.icon | default: 'star-filled' %}
  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 size=size %}
  16. {% endcapture %}
  17. {% assign star = star | strip | replace_regex: "\n\s+", "" %}
  18. {% comment %}
  19. {% capture_global scripts %}
  20. <script>
  21. // @formatter:off
  22. {% if env == 'development' %}window.tabler_rating = window.tabler_rating || {};{% endif %}
  23. document.addEventListener("DOMContentLoaded", function () {
  24. const rating = new StarRating('#rating-{{ id }}', {
  25. tooltip: false,
  26. clearable: false,
  27. stars: function (el, item, index) {
  28. el.innerHTML = `{{ star }}`;
  29. },
  30. })
  31. {% if env == 'development' %}window.tabler_rating["rating-{{ id }}"] = rating;{% endif %}
  32. })
  33. // @formatter:on
  34. </script>
  35. {% endcapture_global %}
  36. {% endcomment %}