datepicker.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. {% assign value = include.value | default: '2020-06-20' %}
  2. {% assign placeholder = include.placeholder | default: 'Select a date' %}
  3. {% assign id = include.id %}
  4. {% if id %}
  5. {% capture input %}
  6. <input class="form-control{% if include.class %} {{ include.class }}{% endif %}"{% if placeholder %} placeholder="{{ placeholder }}"{% endif %} id="datepicker-{{ id }}" value="{{ value }}"/>
  7. {% endcapture %}
  8. {% if include.inline %}
  9. <div class="datepicker-inline" id="datepicker-{{ id }}"></div>
  10. {% elsif include.layout == 'icon' %}
  11. <div class="input-icon{% if include.class %} {{ include.class }}{% endif %}">
  12. {{ input | replace: include.class, '' }}
  13. <span class="input-icon-addon">{% include ui/icon.html icon="calendar" %}</span>
  14. </div>
  15. {% elsif include.layout == 'icon-prepend' %}
  16. <div class="input-icon{% if include.class %} {{ include.class }}{% endif %}">
  17. <span class="input-icon-addon">{% include ui/icon.html icon="calendar" %}</span>
  18. {{ input | replace: include.class, '' }}
  19. </div>
  20. {% else %}
  21. {{ input }}
  22. {% endif %}
  23. {% capture script %}
  24. <script>
  25. // @formatter:off
  26. document.addEventListener("DOMContentLoaded", function () {
  27. {% if jekyll.environment == 'development' %}
  28. window.tabler_datepicker = window.tabler_datepicker || {};
  29. {% endif %}
  30. window.Litepicker && ({% if jekyll.environment == 'development' %}window.tabler_datepicker["datepicker-{{ id }}"] = {% endif %}new Litepicker({
  31. element: document.getElementById('datepicker-{{ id }}'),
  32. buttonText: {
  33. previousMonth: `{% capture icon %}{% include ui/icon.html icon="chevron-left" %}{% endcapture %}{{ icon | strip }}`,
  34. nextMonth: `{% capture icon %}{% include ui/icon.html icon="chevron-right" %}{% endcapture %}{{ icon | strip }}`,
  35. },
  36. {% if include.inline %}inlineMode: true,{% endif %}
  37. }));
  38. });
  39. // @formatter:on
  40. </script>
  41. {% endcapture %}
  42. {% if include.show-scripts %}
  43. {{ script }}
  44. {% else %}
  45. {% capture_global scripts %}
  46. {{ script }}
  47. {% endcapture_global %}
  48. {% endif %}
  49. {% endif %}