select.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. {% assign id = include.id | default: include.key %}
  2. {% assign value = include.value %}
  3. {% if id %}
  4. {% assign key = include.key | default: 'people' %}
  5. {% assign data = site.data.selects[key] %}
  6. <select type="text" class="form-select{% if include.class %} {{ include.class }}{% endif %}{% if include.state %} is-{{ include.state }}{% endif %}"{% if include.placeholder %} placeholder="{{ include.placeholder }}"{% endif %} id="select-{{ id }}" value="{{ value }}"{% if include.multiple or data.multiple %} multiple{% endif %}>
  7. {% if include.values %}
  8. {% assign values = include.values | split: ',' %}
  9. {% for value in values %}
  10. <option value="{{ value }}">{{ value }}</option>
  11. {% endfor %}
  12. {% else %}
  13. {% assign options = data.options %}
  14. {% if data.data == 'people' %}
  15. {% for person in site.data.people limit: 20 %}
  16. <option value="{{ person.id }}"{% if include.indicator == 'avatar' %} data-custom-properties="{% capture indicator %}{% include "ui/avatar.html" size='xs' person=person %}{% endcapture %}{{ indicator | strip | escape }}"{% endif %}>{{ person.full_name }}</option>
  17. {% endfor %}
  18. {% elsif data.data == 'optgroup' %}
  19. {% for group in options %}
  20. <optgroup label="{{ group.title }}">
  21. {% for option in group.options %}
  22. <option value="{{ option }}">{{ option }}</option>
  23. {% endfor %}
  24. </optgroup>
  25. {% endfor %}
  26. {% else %}
  27. {% for option in options %}
  28. {% if option.first %}
  29. {% if include.indicator == 'flag' %}
  30. {% capture indicator-html %}
  31. {% assign country = option[1].flag %}
  32. {% include "ui/flag.html" size="xs" flag=country %}
  33. {% endcapture %}
  34. {% elsif include.indicator == 'label' %}
  35. {% capture indicator-html %}
  36. {% assign label = option[1].label %}
  37. <span class="badge bg-primary-lt">{{ label }}</span>
  38. {% endcapture %}
  39. {% endif %}
  40. <option value="{{ option[0] }}"{% if include.indicator %} data-custom-properties="{{ indicator-html | strip | escape }}"{% endif %}{% if option[1].selected %} selected{% endif %}>{{ option[1].name }}</option>
  41. {% else %}
  42. <option value="{{ option }}">{{ option }}</option>
  43. {% endif %}
  44. {% endfor %}
  45. {% endif %}
  46. {% endif %}
  47. </select>
  48. {% comment %}
  49. {% capture script %}
  50. <script>
  51. // @formatter:off
  52. document.addEventListener("DOMContentLoaded", function () {
  53. {% if env == 'development' %}
  54. window.tabler_select = window.tabler_select || {};
  55. {% endif %}
  56. var el;
  57. window.TomSelect && ({% if env == 'development' %}window.tabler_select["select-{{ id }}"] = {% endif %}new TomSelect(el = document.getElementById('select-{{ id }}'), {
  58. copyClassesToDropdown: false,
  59. dropdownParent: 'body',
  60. {% unless include.show-search %}
  61. controlInput: '<input>',
  62. {% endunless %}
  63. render:{
  64. item: function(data,escape) {
  65. if( data.customProperties ){
  66. return '<div><span class="dropdown-item-indicator">' + data.customProperties + '</span>' + escape(data.text) + '</div>';
  67. }
  68. return '<div>' + escape(data.text) + '</div>';
  69. },
  70. option: function(data,escape){
  71. if( data.customProperties ){
  72. return '<div><span class="dropdown-item-indicator">' + data.customProperties + '</span>' + escape(data.text) + '</div>';
  73. }
  74. return '<div>' + escape(data.text) + '</div>';
  75. },
  76. },
  77. }));
  78. });
  79. // @formatter:on
  80. </script>
  81. {% endcapture %}
  82. {% endcomment %}
  83. {% if include.show-scripts %}
  84. {{ script }}
  85. {% else %}
  86. {% comment %}
  87. {% capture_global scripts %}
  88. {{ script }}
  89. {% endcapture_global %}
  90. {% endcomment %}
  91. {% endif %}
  92. {% endif %}