Module:Tt: Difference between revisions
Appearance
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| Line 27: | Line 27: | ||
local toggle = out:tag('span') | local toggle = out:tag('span') | ||
:addClass('custom-tt-wrapper') | :addClass('custom-tt-wrapper') | ||
:addClass('mw-collapsible') | :addClass('mw-collapsible') | ||
:addClass('mw-collapsed') | :addClass('mw-collapsed') | ||
| Line 36: | Line 35: | ||
end | end | ||
-- | -- If a link is supplied, make the visible text a link. | ||
if (args.link and args.link ~= '') or (text:find('%[%[') and text:find('%]%]')) then | if (args.link and args.link ~= '') or (text:find('%[%[') and text:find('%]%]')) then | ||
local link = tostring(args.link or '') | local link = tostring(args.link or '') | ||
if link == '1' then | if link == '1' then | ||
toggle:wikitext( | toggle:wikitext('[[' .. text .. ']] ') | ||
elseif link ~= '' then | elseif link ~= '' then | ||
toggle:wikitext( | toggle:wikitext('[[' .. link .. '|' .. text .. ']] ') | ||
else | else | ||
toggle:wikitext(text | toggle:wikitext(text .. ' ') | ||
end | end | ||
local cleanText = text | local cleanText = text | ||
:gsub('%[%[?[^|%]]+|', '') | :gsub('%[%[?[^|%]]+|', '') | ||
| Line 67: | Line 60: | ||
toggle:attr('data-tt-text', text) | toggle:attr('data-tt-text', text) | ||
-- | -- The actual collapsible content. | ||
toggle:tag('span') | toggle:tag('span') | ||
:addClass('mw-collapsible-content') | :addClass('mw-collapsible-content') | ||
:addClass('custom-tt') | :addClass('custom-tt') | ||
:wikitext(tooltip) | :wikitext(tooltip) | ||
:done() | :done() | ||
Revision as of 22:23, 1 September 2026
| Main | Documentation | Usage |
This module implements {{Tt}}.
local p = {}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
wrappers = { 'Template:Tt' }
})
args[1] = args[1] or '<i>Missing text</i>'
if args.clean then
return p.CleanTT(args[1])
elseif not args[2] or args[2] == '' then
return args[1]
else
return p._main(args)
end
end
function p._main(args)
local text = args[1]
local tooltip = mw.text.decode(args[2], true)
local out = mw.html.create()
out:wikitext('‍')
local toggle = out:tag('span')
:addClass('custom-tt-wrapper')
:addClass('mw-collapsible')
:addClass('mw-collapsed')
:addClass('giw-collapsible')
if args.class and args.class ~= '' then
toggle:addClass(args.class)
end
-- If a link is supplied, make the visible text a link.
if (args.link and args.link ~= '') or (text:find('%[%[') and text:find('%]%]')) then
local link = tostring(args.link or '')
if link == '1' then
toggle:wikitext('[[' .. text .. ']] ')
elseif link ~= '' then
toggle:wikitext('[[' .. link .. '|' .. text .. ']] ')
else
toggle:wikitext(text .. ' ')
end
local cleanText = text
:gsub('%[%[?[^|%]]+|', '')
:gsub('%[%[', '')
:gsub('%]%]', '')
text =
'<span class="screen-reader-text">Tooltip for '
.. cleanText
.. '</span>ⓘ'
end
toggle:attr('data-tt-text', text)
-- The actual collapsible content.
toggle:tag('span')
:addClass('mw-collapsible-content')
:addClass('custom-tt')
:wikitext(tooltip)
:done()
out:wikitext('‍')
return out
end
function p.CleanTT(tx)
local clean = tx:gsub(
'‍<span class="custom%-tt%-wrapper[^>]-data%-tt%-text="(.-)">.-‍',
'%1'
)
return clean
end
return p