| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Layer (popup / bind click) - Animal.js</title>
- <link rel="stylesheet" href="../demo.css">
- <style>
- .demo-visual {
- gap: 14px;
- align-items: stretch;
- }
- .row {
- display: flex;
- gap: 12px;
- flex-wrap: wrap;
- align-items: center;
- }
- .btn {
- appearance: none;
- border: 1px solid rgba(255,255,255,0.12);
- background: rgba(255,255,255,0.04);
- color: #fff;
- border-radius: 999px;
- padding: 10px 14px;
- font-weight: 650;
- cursor: pointer;
- transition: border-color 0.15s ease, background 0.15s ease;
- }
- .btn:hover {
- border-color: rgba(255,255,255,0.22);
- background: rgba(255,255,255,0.06);
- }
- .btn.danger {
- border-color: rgba(255,75,75,0.5);
- background: rgba(255,75,75,0.12);
- }
- .btn.danger:hover {
- border-color: rgba(255,75,75,0.7);
- background: rgba(255,75,75,0.18);
- }
- .hint {
- font-size: 12px;
- color: #8c8c8c;
- line-height: 1.5;
- }
- .pill {
- display: inline-flex;
- align-items: center;
- gap: 8px;
- border: 1px solid rgba(255,255,255,0.08);
- background: rgba(255,255,255,0.03);
- border-radius: 999px;
- padding: 8px 12px;
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
- font-size: 12px;
- color: #b7b7b7;
- overflow-x: auto;
- max-width: 100%;
- white-space: nowrap;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="page-top">
- <div class="crumb">EXAMPLES</div>
- <div class="since">LAYER</div>
- </div>
- <h1>Layer</h1>
- <p class="description">
- <code class="inline">layer.js</code> exposes a global <code class="inline">Layer</code>.
- <code class="inline">animal.js</code> adds <code class="inline">Selection.layer()</code> to bind click-to-popup.
- </p>
- <div class="box-container">
- <div class="box-header">
- <div class="box-title">Layer example</div>
- <div class="tabs">
- <div class="tab active" onclick="switchTab('js')">JavaScript</div>
- <div class="tab" onclick="switchTab('html')">HTML</div>
- <div class="tab" onclick="switchTab('css')">CSS</div>
- </div>
- </div>
- <pre id="js-code" class="code-view active">// 1) Bind click popup (recommended for buttons / links)
- xjs('.btn-delete').layer({
- title: 'Delete item?',
- text: 'This action cannot be undone.',
- icon: 'warning',
- showCancelButton: true
- });
- // 2) Bind from data-* (no JS options needed)
- xjs('.btn-data').layer(); // reads data-layer-* attributes
- // 3) Fire directly (manual usage)
- document.querySelector('.btn-direct').addEventListener('click', () => {
- xjs.layer({ title: 'Hello from xjs.layer()', icon: 'success' });
- });</pre>
- <pre id="html-code" class="html-view"><button class="btn danger btn-delete">Delete (bind .layer)</button>
- <button
- class="btn btn-data"
- data-layer-title="Data-driven popup"
- data-layer-text="Configured via data-layer-* attributes"
- data-layer-icon="success"
- >Open (data-layer-*)</button>
- <button class="btn btn-direct">Open (xjs.layer)</button></pre>
- <pre id="css-code" class="css-view">.demo-visual {
- gap: 14px;
- align-items: stretch;
- }
- .row {
- display: flex;
- gap: 12px;
- flex-wrap: wrap;
- align-items: center;
- }
- .btn {
- appearance: none;
- border: 1px solid rgba(255,255,255,0.12);
- background: rgba(255,255,255,0.04);
- color: #fff;
- border-radius: 999px;
- padding: 10px 14px;
- font-weight: 650;
- cursor: pointer;
- transition: border-color 0.15s ease, background 0.15s ease;
- }
- .btn:hover {
- border-color: rgba(255,255,255,0.22);
- background: rgba(255,255,255,0.06);
- }
- .btn.danger { border-color: rgba(255,75,75,0.5); background: rgba(255,75,75,0.12); }
- .btn.danger:hover { border-color: rgba(255,75,75,0.7); background: rgba(255,75,75,0.18); }
- .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; }
- .pill {
- display: inline-flex;
- align-items: center;
- gap: 8px;
- border: 1px solid rgba(255,255,255,0.08);
- background: rgba(255,255,255,0.03);
- border-radius: 999px;
- padding: 8px 12px;
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
- font-size: 12px;
- color: #b7b7b7;
- overflow-x: auto;
- max-width: 100%;
- white-space: nowrap;
- }</pre>
- <div class="feature-desc">
- <strong>功能说明:</strong>演示 <code class="inline">Selection.layer()</code> 的三种用法:选择器绑定弹窗、data-* 配置、以及直接调用 <code class="inline">xjs.layer()</code>。
- </div>
- <div class="demo-visual">
- <div class="row">
- <button class="btn danger btn-delete">Delete (bind .layer)</button>
- <button
- class="btn btn-data"
- data-layer-title="Data-driven popup"
- data-layer-text="Configured via data-layer-* attributes"
- data-layer-icon="success"
- >Open (data-layer-*)</button>
- <button class="btn btn-direct">Open (xjs.layer)</button>
- </div>
- <div class="hint">
- Make sure you included both <code class="inline">animal.js</code> and <code class="inline">layer.js</code>.
- For click-binding, <span class="pill">xjs('.btn').layer(options)</span> will de-dupe old handlers if called again.
- </div>
- </div>
- <div class="action-bar">
- <button class="play-btn" onclick="runDemo()">RE-BIND</button>
- </div>
- </div>
- </div>
- <script src="../highlight_css.js"></script>
- <script src="../../xjs.js"></script>
- <script>
- function switchTab(tab) {
- document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
- document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
- if (tab === 'js') {
- document.querySelector('.tabs .tab:nth-child(1)').classList.add('active');
- document.getElementById('js-code').classList.add('active');
- } else if (tab === 'html') {
- document.querySelector('.tabs .tab:nth-child(2)').classList.add('active');
- document.getElementById('html-code').classList.add('active');
- } else {
- document.querySelector('.tabs .tab:nth-child(3)').classList.add('active');
- document.getElementById('css-code').classList.add('active');
- }
- }
- function runDemo() {
- // bind 1) explicit options
- xjs('.btn-delete').layer({
- title: 'Delete item?',
- text: 'This action cannot be undone.',
- icon: 'warning',
- showCancelButton: true
- });
- // bind 2) data-* driven
- xjs('.btn-data').layer();
- // 3) direct fire
- const direct = document.querySelector('.btn-direct');
- if (direct) {
- direct.onclick = () => {
- xjs.layer({ title: 'Hello from xjs.layer()', text: 'Direct call (alias of xjs.fire)', icon: 'success' });
- };
- }
- }
- setTimeout(runDemo, 300);
- </script>
- </body>
- </html>
|