layer.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 class="tab" onclick="switchTab('css')">CSS</div>
  82. </div>
  83. </div>
  84. <pre id="js-code" class="code-view active">// 1) Bind click popup (recommended for buttons / links)
  85. xjs('.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. xjs('.btn-data').layer(); // reads data-layer-* attributes
  93. // 3) Fire directly (manual usage)
  94. document.querySelector('.btn-direct').addEventListener('click', () =&gt; {
  95. xjs.layer({ title: 'Hello from xjs.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 (xjs.layer)&lt;/button&gt;</pre>
  105. <pre id="css-code" class="css-view">.demo-visual {
  106. gap: 14px;
  107. align-items: stretch;
  108. }
  109. .row {
  110. display: flex;
  111. gap: 12px;
  112. flex-wrap: wrap;
  113. align-items: center;
  114. }
  115. .btn {
  116. appearance: none;
  117. border: 1px solid rgba(255,255,255,0.12);
  118. background: rgba(255,255,255,0.04);
  119. color: #fff;
  120. border-radius: 999px;
  121. padding: 10px 14px;
  122. font-weight: 650;
  123. cursor: pointer;
  124. transition: border-color 0.15s ease, background 0.15s ease;
  125. }
  126. .btn:hover {
  127. border-color: rgba(255,255,255,0.22);
  128. background: rgba(255,255,255,0.06);
  129. }
  130. .btn.danger { border-color: rgba(255,75,75,0.5); background: rgba(255,75,75,0.12); }
  131. .btn.danger:hover { border-color: rgba(255,75,75,0.7); background: rgba(255,75,75,0.18); }
  132. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; }
  133. .pill {
  134. display: inline-flex;
  135. align-items: center;
  136. gap: 8px;
  137. border: 1px solid rgba(255,255,255,0.08);
  138. background: rgba(255,255,255,0.03);
  139. border-radius: 999px;
  140. padding: 8px 12px;
  141. font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  142. font-size: 12px;
  143. color: #b7b7b7;
  144. overflow-x: auto;
  145. max-width: 100%;
  146. white-space: nowrap;
  147. }</pre>
  148. <div class="feature-desc">
  149. <strong>功能说明:</strong>演示 <code class="inline">Selection.layer()</code> 的三种用法:选择器绑定弹窗、data-* 配置、以及直接调用 <code class="inline">xjs.layer()</code>。
  150. </div>
  151. <div class="demo-visual">
  152. <div class="row">
  153. <button class="btn danger btn-delete">Delete (bind .layer)</button>
  154. <button
  155. class="btn btn-data"
  156. data-layer-title="Data-driven popup"
  157. data-layer-text="Configured via data-layer-* attributes"
  158. data-layer-icon="success"
  159. >Open (data-layer-*)</button>
  160. <button class="btn btn-direct">Open (xjs.layer)</button>
  161. </div>
  162. <div class="hint">
  163. Make sure you included both <code class="inline">animal.js</code> and <code class="inline">layer.js</code>.
  164. For click-binding, <span class="pill">xjs('.btn').layer(options)</span> will de-dupe old handlers if called again.
  165. </div>
  166. </div>
  167. <div class="action-bar">
  168. <button class="play-btn" onclick="runDemo()">RE-BIND</button>
  169. </div>
  170. </div>
  171. </div>
  172. <script src="../highlight_css.js"></script>
  173. <script src="../../xjs.js"></script>
  174. <script>
  175. function switchTab(tab) {
  176. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  177. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  178. if (tab === 'js') {
  179. document.querySelector('.tabs .tab:nth-child(1)').classList.add('active');
  180. document.getElementById('js-code').classList.add('active');
  181. } else if (tab === 'html') {
  182. document.querySelector('.tabs .tab:nth-child(2)').classList.add('active');
  183. document.getElementById('html-code').classList.add('active');
  184. } else {
  185. document.querySelector('.tabs .tab:nth-child(3)').classList.add('active');
  186. document.getElementById('css-code').classList.add('active');
  187. }
  188. }
  189. function runDemo() {
  190. // bind 1) explicit options
  191. xjs('.btn-delete').layer({
  192. title: 'Delete item?',
  193. text: 'This action cannot be undone.',
  194. icon: 'warning',
  195. showCancelButton: true
  196. });
  197. // bind 2) data-* driven
  198. xjs('.btn-data').layer();
  199. // 3) direct fire
  200. const direct = document.querySelector('.btn-direct');
  201. if (direct) {
  202. direct.onclick = () => {
  203. xjs.layer({ title: 'Hello from xjs.layer()', text: 'Direct call (alias of xjs.fire)', icon: 'success' });
  204. };
  205. }
  206. }
  207. setTimeout(runDemo, 300);
  208. </script>
  209. </body>
  210. </html>