test_static_fire.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 Static API - Animal.js</title>
  7. <link rel="stylesheet" href="../demo.css">
  8. <link rel="stylesheet" href="../../xjs.css">
  9. <style>
  10. .row {
  11. display: flex;
  12. flex-wrap: wrap;
  13. gap: 10px;
  14. align-items: center;
  15. }
  16. .btn {
  17. appearance: none;
  18. border: 1px solid rgba(255,255,255,0.12);
  19. background: rgba(255,255,255,0.04);
  20. color: #fff;
  21. border-radius: 999px;
  22. padding: 10px 14px;
  23. font-weight: 650;
  24. cursor: pointer;
  25. transition: border-color 0.15s ease, background 0.15s ease;
  26. }
  27. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  28. .btn.primary { border-color: rgba(48,133,214,0.55); background: rgba(48,133,214,0.18); }
  29. .btn.primary:hover { border-color: rgba(48,133,214,0.8); background: rgba(48,133,214,0.24); }
  30. .demo-visual { padding: 22px 24px; }
  31. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
  32. .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
  33. </style>
  34. </head>
  35. <body>
  36. <div class="container">
  37. <div class="page-top">
  38. <div class="crumb">UI › LAYER</div>
  39. <div class="since">STATIC API</div>
  40. </div>
  41. <h1>Static API / Builder API</h1>
  42. <p class="description">
  43. Layer supports <code class="inline">Layer.fire()</code> and <code class="inline">Layer.$(...).fire()</code> (builder style), and returns a Promise result.
  44. </p>
  45. <div class="box-container">
  46. <div class="demo-visual">
  47. <div class="row">
  48. <button class="btn primary" onclick="openFire()">Layer.fire()</button>
  49. <button class="btn" onclick="openBuilder()">Builder fire()</button>
  50. </div>
  51. <div class="hint">
  52. Promise result is printed to <span class="mono">console</span>.
  53. </div>
  54. </div>
  55. <div class="box-header">
  56. <div class="box-title">Examples</div>
  57. <div class="tabs">
  58. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  59. <div class="tab" onclick="switchTab('html')">HTML</div>
  60. <div class="tab" onclick="switchTab('css')">CSS</div>
  61. </div>
  62. </div>
  63. <pre id="js-code" class="code-view active">// 1) Static fire
  64. Layer.fire({ title: 'Hello', text: 'Layer.fire(...)', icon: 'info' });
  65. // 2) Builder style
  66. Layer.$()
  67. .config({ title: 'Confirm?', icon: 'warning', showCancelButton: true })
  68. .fire()
  69. .then((res) => console.log(res));</pre>
  70. <pre id="html-code" class="html-view">&lt;button class="btn primary"&gt;Layer.fire()&lt;/button&gt;
  71. &lt;button class="btn"&gt;Layer.$().config().fire()&lt;/button&gt;</pre>
  72. <pre id="css-code" class="css-view">/* Local styles for buttons only */</pre>
  73. <div class="feature-desc">
  74. <strong>功能说明:</strong>验证 Layer 自身的静态入口(不依赖 Selection.layer 绑定),以及 builder 模式的链式配置。
  75. </div>
  76. </div>
  77. <div class="doc-nav" aria-label="Previous and next navigation">
  78. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  79. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  80. <span aria-hidden="true">←</span>
  81. </a>
  82. <div class="nav-center" id="navCenter">Layer</div>
  83. <a href="#" id="nextLink" onclick="goNext(); return false;">
  84. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  85. <span aria-hidden="true">→</span>
  86. </a>
  87. </div>
  88. </div>
  89. <script src="../highlight_css.js"></script>
  90. <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
  91. <script>
  92. (function () {
  93. var b = Date.now();
  94. document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
  95. document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
  96. document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
  97. })();
  98. </script>
  99. <script>
  100. const CURRENT = 'layer/test_static_fire.html';
  101. function switchTab(tab) {
  102. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  103. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  104. if (tab === 'js') {
  105. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  106. document.getElementById('js-code')?.classList.add('active');
  107. } else if (tab === 'html') {
  108. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  109. document.getElementById('html-code')?.classList.add('active');
  110. } else {
  111. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  112. document.getElementById('css-code')?.classList.add('active');
  113. }
  114. }
  115. function openFire() {
  116. Layer.fire({ title: 'Hello', text: 'Layer.fire(...)', icon: 'info', popupAnimation: true })
  117. .then((res) => console.log('[Layer.fire] result:', res));
  118. }
  119. function openBuilder() {
  120. Layer.$()
  121. .config({
  122. title: 'Confirm?',
  123. text: 'Builder style API',
  124. icon: 'warning',
  125. popupAnimation: true,
  126. showCancelButton: true
  127. })
  128. .fire()
  129. .then((res) => {
  130. console.log('[Layer.builder] result:', res);
  131. if (res.isConfirmed) xjs.layer({ title: 'Confirmed', icon: 'success', popupAnimation: true });
  132. });
  133. }
  134. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  135. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  136. function syncNavLabels() {
  137. const api = window.parent?.docGetPrevNext;
  138. if (typeof api !== 'function') return;
  139. const { prev, next, current } = api(CURRENT) || {};
  140. const prevLink = document.getElementById('prevLink');
  141. const nextLink = document.getElementById('nextLink');
  142. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  143. else { prevLink.style.visibility = 'hidden'; }
  144. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  145. else { nextLink.style.visibility = 'hidden'; }
  146. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  147. }
  148. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  149. syncNavLabels();
  150. </script>
  151. </body>
  152. </html>