加帕里图书馆 - 兽娘动物园中文维基
动物朋友 けものフレンズ KemonoFriends百科
模块:TitleCustomizer:修订间差异
跳转到导航
跳转到搜索
创建页面,内容为“local p = {} -- 1. 这是编辑者在内页中调用的函数 function p.getTitleData(frame) -- 获取调用时传入的参数 (即自定义标题文本) local args = frame:getParent().args -- 尝试获取第一个无名参数 ({{{1}}}) 或名为 'text' 的参数 local customText = args[1] or args.text or '' -- 2. 使用 mw.html.create 安全地创建隐藏的 HTML 元素 -- 我们使用 class ".js-custom-title-data" 来代替之前失…” |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
-- | -- 函数:生成带有自定义标题文本的隐藏元素 | ||
function p.getTitleData(frame) | function p.getTitleData(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
-- | -- 确保获取到传入的自定义文本 | ||
local customText = args[1] or args.text or '' | local customText = args[1] or args.text or '' | ||
-- | -- 使用 mw.html.create 安全地创建隐藏的 HTML 元素 | ||
-- | -- 使用 class ".js-custom-title-data" 作为 JavaScript 的数据锚点 | ||
local html = mw.html.create('span') | local html = mw.html.create('span') | ||
:addClass('js-custom-title-data') | :addClass('js-custom-title-data') | ||
:css('display', 'none') -- | :css('display', 'none') -- 强制隐藏元素 | ||
:wikitext(customText) | :wikitext(customText) | ||
return tostring(html) | return tostring(html) | ||
end | end | ||
return p | return p | ||
2025年12月11日 (四) 04:26的最新版本
此模块的文档可以在模块:TitleCustomizer/doc创建
local p = {}
-- 函数:生成带有自定义标题文本的隐藏元素
function p.getTitleData(frame)
local args = frame:getParent().args
-- 确保获取到传入的自定义文本
local customText = args[1] or args.text or ''
-- 使用 mw.html.create 安全地创建隐藏的 HTML 元素
-- 使用 class ".js-custom-title-data" 作为 JavaScript 的数据锚点
local html = mw.html.create('span')
:addClass('js-custom-title-data')
:css('display', 'none') -- 强制隐藏元素
:wikitext(customText)
return tostring(html)
end
return p