layer.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Layer (popup / bind click) - Animal.js</title>
  7. <link rel="stylesheet" href="../demo.css">
  8. <style>
  9. .demo-visual {
  10. gap: 14px;
  11. align-items: stretch;
  12. }
  13. .row {
  14. display: flex;
  15. gap: 12px;
  16. flex-wrap: wrap;
  17. align-items: center;
  18. }
  19. .btn {
  20. appearance: none;
  21. border: 1px solid rgba(255,255,255,0.12);
  22. background: rgba(255,255,255,0.04);
  23. color: #fff;
  24. border-radius: 999px;
  25. padding: 10px 14px;
  26. font-weight: 650;
  27. cursor: pointer;
  28. transition: border-color 0.15s ease, background 0.15s ease;
  29. }
  30. .btn:hover {
  31. border-color: rgba(255,255,255,0.22);
  32. background: rgba(255,255,255,0.06);
  33. }
  34. .btn.danger {
  35. border-color: rgba(255,75,75,0.5);
  36. background: rgba(255,75,75,0.12);
  37. }
  38. .btn.danger:hover {
  39. border-color: rgba(255,75,75,0.7);
  40. background: rgba(255,75,75,0.18);
  41. }
  42. .hint {
  43. font-size: 12px;
  44. color: #8c8c8c;
  45. line-height: 1.5;
  46. }
  47. .pill {
  48. display: inline-flex;
  49. align-items: center;
  50. gap: 8px;
  51. border: 1px solid rgba(255,255,255,0.08);
  52. background: rgba(255,255,255,0.03);
  53. border-radius: 999px;
  54. padding: 8px 12px;
  55. font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  56. font-size: 12px;
  57. color: #b7b7b7;
  58. overflow-x: auto;
  59. max-width: 100%;
  60. white-space: nowrap;
  61. }
  62. </style>
  63. </head>
  64. <body>
  65. <div class="container">
  66. <div class="page-top">
  67. <div class="crumb">EXAMPLES</div>
  68. <div class="since">LAYER</div>
  69. </div>
  70. <h1>Layer</h1>
  71. <p class="description">
  72. <code class="inline">layer.js</code> exposes a global <code class="inline">Layer</code>.
  73. <code class="inline">animal.js</code> adds <code class="inline">Selection.layer()</code> to bind click-to-popup.
  74. </p>
  75. <div class="box-container">
  76. <div class="box-header">
  77. <div class="box-title">Layer example</div>
  78. <div class="tabs">
  79. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  80. <div class="tab" onclick="switchTab('html')">HTML</div>
  81. </div>
  82. </div>
  83. <pre id="js-code" class="code-view active">const $ = animal;
  84. // 1) Bind click popup (recommended for buttons / links)
  85. $('.btn-delete').layer({
  86. title: 'Delete item?',
  87. text: 'This action cannot be undone.',
  88. icon: 'warning',
  89. showCancelButton: true
  90. });
  91. // 2) Bind from data-* (no JS options needed)
  92. $('.btn-data').layer(); // reads data-layer-* attributes
  93. // 3) Fire directly (manual usage)
  94. document.querySelector('.btn-direct').addEventListener('click', () =&gt; {
  95. $.layer({ title: 'Hello from $.layer()', icon: 'success' });
  96. });</pre>
  97. <pre id="html-code" class="html-view">&lt;button class="btn danger btn-delete"&gt;Delete (bind .layer)&lt;/button&gt;
  98. &lt;button
  99. class="btn btn-data"
  100. data-layer-title="Data-driven popup"
  101. data-layer-text="Configured via data-layer-* attributes"
  102. data-layer-icon="success"
  103. &gt;Open (data-layer-*)&lt;/button&gt;
  104. &lt;button class="btn btn-direct"&gt;Open ($.layer)&lt;/button&gt;</pre>
  105. <div class="demo-visual">
  106. <div class="row">
  107. <button class="btn danger btn-delete">Delete (bind .layer)</button>
  108. <button
  109. class="btn btn-data"
  110. data-layer-title="Data-driven popup"
  111. data-layer-text="Configured via data-layer-* attributes"
  112. data-layer-icon="success"
  113. >Open (data-layer-*)</button>
  114. <button class="btn btn-direct">Open ($.layer)</button>
  115. </div>
  116. <div class="hint">
  117. Make sure you included both <code class="inline">animal.js</code> and <code class="inline">layer.js</code>.
  118. For click-binding, <span class="pill">$('.btn').layer(options)</span> will de-dupe old handlers if called again.
  119. </div>
  120. </div>
  121. <div class="action-bar">
  122. <button class="play-btn" onclick="runDemo()">RE-BIND</button>
  123. </div>
  124. </div>
  125. </div>
  126. <script src="../../animal.js"></script>
  127. <script src="../../layer.js"></script>
  128. <script>
  129. function switchTab(tab) {
  130. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  131. document.querySelectorAll('.code-view, .html-view').forEach(v => v.classList.remove('active'));
  132. if (tab === 'js') {
  133. document.querySelector('.tabs .tab:nth-child(1)').classList.add('active');
  134. document.getElementById('js-code').classList.add('active');
  135. } else {
  136. document.querySelector('.tabs .tab:nth-child(2)').classList.add('active');
  137. document.getElementById('html-code').classList.add('active');
  138. }
  139. }
  140. function runDemo() {
  141. const $ = animal;
  142. // bind 1) explicit options
  143. $('.btn-delete').layer({
  144. title: 'Delete item?',
  145. text: 'This action cannot be undone.',
  146. icon: 'warning',
  147. showCancelButton: true
  148. });
  149. // bind 2) data-* driven
  150. $('.btn-data').layer();
  151. // 3) direct fire
  152. const direct = document.querySelector('.btn-direct');
  153. if (direct) {
  154. direct.onclick = () => {
  155. $.layer({ title: 'Hello from $.layer()', text: 'Direct call (alias of $.fire)', icon: 'success' });
  156. };
  157. }
  158. }
  159. setTimeout(runDemo, 300);
  160. </script>
  161. </body>
  162. </html>