rating.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. {% capture_global scripts %}
  19. <script>
  20. // @formatter:off
  21. {% if jekyll.environment == 'development' %}window.tabler_rating = window.tabler_rating || {};{% endif %}
  22. document.addEventListener("DOMContentLoaded", function () {
  23. const rating = new StarRating('#rating-{{ id }}', {
  24. tooltip: false,
  25. clearable: false,
  26. stars: function (el, item, index) {
  27. el.innerHTML = `{{ star }}`;
  28. },
  29. })
  30. {% if jekyll.environment == 'development' %}window.tabler_rating["rating-{{ id }}"] = rating;{% endif %}
  31. })
  32. // @formatter:on
  33. </script>
  34. {% endcapture_global %}