test_static_fire.html 6.5 KB

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