shortener.hbs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <main>
  2. <div id="shorturl">
  3. {{#if link}}
  4. <div class="clipboard">
  5. <button
  6. type="button"
  7. aria-label="Copy"
  8. hx-on:click="handleShortURLCopyLink(this);"
  9. data-url="{{url}}"
  10. >
  11. {{> icons/copy}}
  12. </button>
  13. {{> icons/check}}
  14. </div>
  15. <h1
  16. class="link"
  17. hx-on:click="handleShortURLCopyLink(this);"
  18. data-url="{{url}}"
  19. >
  20. {{link}}
  21. </h1>
  22. {{/if}}
  23. {{#unless link}}
  24. <h1>Kutt your links <span>shorter</span>.</h1>
  25. {{/unless}}
  26. </div>
  27. <form
  28. id="shortener-form"
  29. hx-post="/api/links"
  30. hx-trigger="submit queue:none"
  31. hx-target="closest main"
  32. hx-swap="outerHTML"
  33. autocomplete="off"
  34. >
  35. <div class="target-wrapper {{#if errors.target}}error{{/if}}">
  36. <input
  37. id="target"
  38. name="target"
  39. type="text"
  40. placeholder="Paste your long URL"
  41. aria-label="target"
  42. autofocus="true"
  43. data-lpignore="true"
  44. hx-preserve="true"
  45. />
  46. <button class="submit">
  47. {{> icons/send}}
  48. {{> icons/spinner}}
  49. </button>
  50. {{#if errors.target}}<p class="error">{{errors.target}}</p>{{/if}}
  51. {{#unless errors}}
  52. {{#if error}}
  53. <p class="error">{{error}}</p>
  54. {{/if}}
  55. {{/unless}}
  56. </div>
  57. <label id="advanced" class="checkbox">
  58. <input
  59. name="show_advanced"
  60. type="checkbox"
  61. hx-on:change="htmx.toggleClass('#advanced-options', 'hidden')"
  62. {{#if show_advanced}}checked="true"{{/if}}
  63. />
  64. Show advanced options
  65. </label>
  66. <section id="advanced-options" class="{{#unless show_advanced}}hidden{{/unless}}">
  67. <div class="advanced-input-wrapper">
  68. <label class="{{#if errors.domain}}error{{/if}}">
  69. Domain:
  70. <select
  71. id="domain"
  72. name="domain"
  73. hx-preserve="true"
  74. hx-on:change="
  75. const elm = document.querySelector('#customurl-label span');
  76. if (!elm) return;
  77. elm.textContent = event.target.value + '/';
  78. "
  79. >
  80. <option value={{default_domain}}>{{default_domain}}</option>
  81. {{#each domains}}
  82. <option value={{address}}>{{address}}</option>
  83. {{/each}}
  84. </select>
  85. {{#if errors.domain}}<p class="error">{{errors.domain}}</p>{{/if}}
  86. </label>
  87. <label id="customurl-label" class="{{#if errors.customurl}}error{{/if}}">
  88. <span id="customurl-label-value" hx-preserve="true">{{default_domain}}/</span>
  89. <input
  90. type="text"
  91. id="customurl"
  92. name="customurl"
  93. placeholder="Custom address..."
  94. hx-preserve="true"
  95. autocomplete="off"
  96. />
  97. {{#if errors.customurl}}<p class="error">{{errors.customurl}}</p>{{/if}}
  98. </label>
  99. <label class="{{#if errors.password}}error{{/if}}">
  100. Password:
  101. <input
  102. type="password"
  103. id="password"
  104. name="password"
  105. placeholder="Password..."
  106. hx-preserve="true"
  107. autocomplete="off"
  108. />
  109. {{#if errors.password}}<p class="error">{{errors.password}}</p>{{/if}}
  110. </label>
  111. </div>
  112. <div class="advanced-input-wrapper">
  113. <label class="expire-in {{#if errors.expire_in}}error{{/if}}">
  114. Expire in:
  115. <input
  116. type="text"
  117. id="expire_in"
  118. name="expire_in"
  119. placeholder="2 minutes/hours/days"
  120. hx-preserve="true"
  121. />
  122. {{#if errors.expire_in}}<p class="error">{{errors.expire_in}}</p>{{/if}}
  123. </label>
  124. <label class="description {{#if errors.description}}error{{/if}}">
  125. Description:
  126. <input
  127. type="text"
  128. id="description"
  129. name="description"
  130. placeholder="Description..."
  131. hx-preserve="true"
  132. />
  133. {{#if errors.description}}<p class="error">{{errors.description}}</p>{{/if}}
  134. </label>
  135. </div>
  136. </section>
  137. </form>
  138. </main>