Widget:CCB-button:修订间差异
来自OTTOWiki
更多操作
![]() OctoberSama(留言 | 贡献) 小 |
![]() OctoberSama(留言 | 贡献) 小 |
||
第1行: | 第1行: | ||
<includeonly> | <includeonly> | ||
<span id="CCB_button" class="mw-ui-button mw-ui-progressive" style="cursor: pointer;"> | <span id="CCB_button" class="mw-ui-button mw-ui-progressive" style="cursor: pointer;"> | ||
<img src="/images/5/5b/%E5%A4%A7%E7%99%BD%E8%B1%A1.webp" | <img src="/images/5/5b/%E5%A4%A7%E7%99%BD%E8%B1%A1.webp" style="width:1em; vertical-align:middle;"> | ||
<span style="margin-left:0.3em;">点我 CCB!!</span> | <span style="margin-left:0.3em;">点我 CCB!!</span> | ||
</span> | </span> | ||
第8行: | 第7行: | ||
<script> | <script> | ||
(function initCCBButton() { | (function initCCBButton() { | ||
// | // 如果还没有 mw.loader,则延迟重试 | ||
if (typeof mw === 'undefined' | if (typeof mw === 'undefined' || typeof mw.loader === 'undefined') { | ||
return setTimeout(initCCBButton, 100); | return setTimeout(initCCBButton, 100); | ||
} | } | ||
// | // 触发加载 ext.gadget.CaoCaoBi 模块 | ||
mw.loader.load('ext.gadget.CaoCaoBi'); | mw.loader.load('ext.gadget.CaoCaoBi'); | ||
// | // 如果你的模块通过 `return { swit_so_CCB, … }` 导出了函数, | ||
// ResourceLoader 会帮你把这些函数挂到 window 上 | |||
if (typeof window.swit_so_CCB !== 'function') { | if (typeof window.swit_so_CCB !== 'function') { | ||
// 未就绪,继续轮询 | // 未就绪,继续轮询 | ||
第22行: | 第22行: | ||
} | } | ||
// | // 模块已加载、函数已定义,绑定按钮点击事件 | ||
var btn = document.getElementById('CCB_button'); | var btn = document.getElementById('CCB_button'); | ||
if (!btn | if (!btn) return; | ||
btn.addEventListener('click', function(e) { | btn.addEventListener('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
window.swit_so_CCB(); | window.swit_so_CCB(); | ||
}); | }); | ||
})();</script></includeonly><noinclude>注意:本 Widget 不应直接插入条目正文,请使用模板 <code>{{tl|CCB-auto}}</code> | })();</script></includeonly><noinclude>注意:本 Widget 不应直接插入条目正文,请使用模板 <code>{{tl|CCB-auto}}</code> 调用。</noinclude> |
2025年6月20日 (五) 21:09的版本
注意:本 Widget 不应直接插入条目正文,请使用模板 {{CCB-auto}}
调用。