| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Layer DOM Content + Steps</title>
- <link rel="stylesheet" href="../demo.css">
- <style>
- .row {
- display: flex;
- flex-wrap: wrap;
- gap: 10px;
- 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.primary { border-color: rgba(63,195,238,0.55); background: rgba(63,195,238,0.12); }
- .btn.success { border-color: rgba(165,220,134,0.55); background: rgba(165,220,134,0.12); }
- .demo-visual { padding: 22px 24px; }
- .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
- /* The DOM blocks below are hidden by default. Layer will move them into popup and temporarily show them. */
- .hidden-dom { display: none; }
- .form {
- width: 100%;
- text-align: left;
- display: grid;
- gap: 10px;
- }
- .field label {
- display: block;
- font-size: 12px;
- color: #777;
- margin-bottom: 6px;
- }
- .field input, .field select {
- width: 100%;
- box-sizing: border-box;
- padding: 10px 12px;
- border-radius: 10px;
- border: 1px solid rgba(0,0,0,0.12);
- outline: none;
- background: #fff;
- color: #111;
- font-size: 14px;
- }
- .error {
- color: #c0392b;
- font-size: 12px;
- min-height: 16px;
- }
- pre {
- width: 100%;
- padding: 12px;
- border-radius: 12px;
- background: rgba(0,0,0,0.06);
- overflow: auto;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="page-top">
- <div class="crumb">UI › LAYER</div>
- <div class="since">DOM + STEPS</div>
- </div>
- <h1>DOM content + Step flow</h1>
- <p class="description">
- Demonstrates <code class="inline">dom</code> (mount/restore hidden DOM into popup) and a multi-step wizard using <code class="inline">step()</code> / <code class="inline">steps()</code>.
- </p>
- <div class="box-container">
- <div class="box-header">
- <div class="box-title">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) Single popup: show a hidden DOM block inside Layer
- xjs.layer({
- title: 'DOM content',
- dom: '#demo_dom_block',
- showCancelButton: true,
- confirmButtonText: 'OK',
- cancelButtonText: 'Close'
- });
- // 2) Step flow (wizard)
- xjs.Layer.$({
- icon: 'info',
- closeOnClickOutside: false,
- closeOnEsc: false,
- confirmButtonColor: '#3085d6',
- cancelButtonColor: '#444'
- })
- .step({
- title: 'Step 1: Basic info',
- dom: '#wizard_step_1',
- showCancelButton: true,
- cancelButtonText: 'Cancel',
- preConfirm(popup) {
- const name = popup.querySelector('input[name="name"]').value.trim();
- const err = popup.querySelector('[data-error]');
- if (!name) { err.textContent = 'Please enter your name.'; return false; }
- err.textContent = '';
- return { name };
- }
- })
- .step({
- title: 'Step 2: Preferences',
- dom: '#wizard_step_2',
- preConfirm(popup) {
- const plan = popup.querySelector('select[name="plan"]').value;
- return { plan };
- }
- })
- .fire()
- .then((res) => {
- if (res.isConfirmed) {
- xjs.layer({
- title: 'Done',
- icon: 'success',
- html: '<pre>' + JSON.stringify(res.value, null, 2) + '</pre>'
- });
- }
- });</pre>
- <pre id="html-code" class="html-view"><button class="btn primary" onclick="openDom()">Open DOM popup</button>
- <button class="btn success" onclick="openWizard()">Open step wizard</button>
- <!-- Hidden DOM blocks (default display:none) -->
- <div id="demo_dom_block" class="hidden-dom">...</div>
- <div id="wizard_step_1" class="hidden-dom">...</div>
- <div id="wizard_step_2" class="hidden-dom">...</div></pre>
- <pre id="css-code" class="css-view">/* This page hides DOM blocks by default:
- .hidden-dom { display: none; }
- Layer will move the element into the popup while open,
- then restore it back (and restore display/hidden state) on close. */</pre>
- <div class="feature-desc">
- <strong>功能说明:</strong>
- <code class="inline">dom</code> 支持把指定 DOM(可默认隐藏)挂进弹窗并在关闭时还原;步骤流通过同一弹窗内平滑切换实现“分步填写”体验,最终 <code class="inline">res.value</code> 返回每一步的 <code class="inline">preConfirm</code> 结果数组。
- </div>
- <div class="demo-visual">
- <div class="row">
- <button class="btn primary" onclick="openDom()">Open DOM popup</button>
- <button class="btn success" onclick="openWizard()">Open step wizard</button>
- </div>
- <div class="hint">
- Tip: step wizard disables backdrop/ESC close to avoid accidental dismiss.
- </div>
- </div>
- </div>
- <!-- Hidden DOM content (these are mounted into Layer) -->
- <div id="demo_dom_block" class="hidden-dom">
- <div class="form">
- <div class="field">
- <label>Quick note</label>
- <input placeholder="This input lives in a hidden DOM block" value="Hello from DOM!">
- </div>
- <div class="hint" style="margin-top: -4px;">
- This DOM node is moved into the popup and restored on close.
- </div>
- </div>
- </div>
- <div id="wizard_step_1" class="hidden-dom">
- <div class="form">
- <div class="field">
- <label>Name</label>
- <input name="name" placeholder="Your name">
- </div>
- <div class="error" data-error></div>
- </div>
- </div>
- <div id="wizard_step_2" class="hidden-dom">
- <div class="form">
- <div class="field">
- <label>Plan</label>
- <select name="plan">
- <option value="free">Free</option>
- <option value="pro">Pro</option>
- <option value="team">Team</option>
- </select>
- </div>
- <div class="hint">Confirm will finish the wizard.</div>
- </div>
- </div>
- <div class="doc-nav" aria-label="Previous and next navigation">
- <a href="#" id="prevLink" onclick="goPrev(); return false;">
- <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
- <span aria-hidden="true">←</span>
- </a>
- <div class="nav-center" id="navCenter">Layer</div>
- <a href="#" id="nextLink" onclick="goNext(); return false;">
- <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
- <span aria-hidden="true">→</span>
- </a>
- </div>
- </div>
- <script src="../highlight_css.js"></script>
- <!-- NOTE: xjs.js bundles an older Layer in some builds.
- For local testing, load standalone layer.js last to ensure this page uses the edited Layer implementation. -->
- <script src="../../xjs.js?v=dev"></script>
- <script src="../../layer.js?v=dev"></script>
- <script>
- const CURRENT = 'layer/test_dom_steps.html';
- 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 openDom() {
- xjs.layer({
- title: 'DOM content',
- dom: '#demo_dom_block',
- showCancelButton: true,
- confirmButtonText: 'OK',
- cancelButtonText: 'Close'
- });
- }
- function openWizard() {
- xjs.Layer.$({
- icon: 'info',
- closeOnClickOutside: false,
- closeOnEsc: false,
- confirmButtonColor: '#3085d6',
- cancelButtonColor: '#444'
- })
- .step({
- title: 'Step 1: Basic info',
- dom: '#wizard_step_1',
- showCancelButton: true,
- cancelButtonText: 'Cancel',
- preConfirm(popup) {
- const name = popup.querySelector('input[name="name"]').value.trim();
- const err = popup.querySelector('[data-error]');
- if (!name) { err.textContent = 'Please enter your name.'; return false; }
- err.textContent = '';
- return { name };
- }
- })
- .step({
- title: 'Step 2: Preferences',
- dom: '#wizard_step_2',
- preConfirm(popup) {
- const plan = popup.querySelector('select[name="plan"]').value;
- return { plan };
- }
- })
- .fire()
- .then((res) => {
- if (res.isConfirmed) {
- xjs.layer({
- title: 'Done',
- icon: 'success',
- html: '<pre>' + JSON.stringify(res.value, null, 2) + '</pre>'
- });
- } else {
- xjs.layer({ title: 'Dismissed', icon: 'info', text: 'Flow cancelled' });
- }
- });
- }
- function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
- function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
- function syncNavLabels() {
- const api = window.parent?.docGetPrevNext;
- if (typeof api !== 'function') return;
- const { prev, next, current } = api(CURRENT) || {};
- const prevLink = document.getElementById('prevLink');
- const nextLink = document.getElementById('nextLink');
- if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
- else { prevLink.style.visibility = 'hidden'; }
- if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
- else { nextLink.style.visibility = 'hidden'; }
- document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
- }
- try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
- syncNavLabels();
- </script>
- </body>
- </html>
|