Editing Module:Tt
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 4: | Line 4: | ||
local args = require('Module:Arguments').getArgs(frame, { | local args = require('Module:Arguments').getArgs(frame, { | ||
parentFirst = true, | parentFirst = true, | ||
wrappers = {'Template:Tt'} | wrappers = { 'Template:Tt' } | ||
}) | }) | ||
| Line 11: | Line 11: | ||
if args.clean then | if args.clean then | ||
return p.CleanTT(args[1]) | return p.CleanTT(args[1]) | ||
elseif not args[2] or args[2] == '' then | |||
return args[1] | return args[1] | ||
else | |||
return p._main(args) | |||
end | end | ||
end | end | ||
| Line 23: | Line 21: | ||
local text = args[1] | local text = args[1] | ||
local tooltip = mw.text.decode(args[2], true) | local tooltip = mw.text.decode(args[2], true) | ||
local out = mw.html.create() | |||
local out | out:wikitext('‍') | ||
local toggle = out:tag('span') | |||
:addClass('custom-tt-wrapper') | :addClass('custom-tt-wrapper') | ||
:addClass( | :addClass('toggle-tooltip') | ||
:addClass('mw-collapsible') | |||
:addClass('mw-collapsed') | |||
:addClass('giw-collapsible') | |||
if args.class and args.class ~= '' then | |||
toggle:addClass(args.class) | |||
end | |||
if args. | |||
-- Make the text clickable if a link is provided, | |||
-- or if the text already contains a wiki 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 | |||
-- Add accessible text and an info icon. | |||
local cleanText = text | |||
:gsub('%[%[?[^|%]]+|', '') | |||
cleanText = text | |||
:gsub('%[%[[^%] | |||
:gsub('%[%[', '') | :gsub('%[%[', '') | ||
:gsub('%]%]', '') | :gsub('%]%]', '') | ||
text = | |||
'<span class="screen-reader-text">Tooltip for ' | |||
.. cleanText | |||
.. '</span>ⓘ' | |||
end | end | ||
-- | toggle:attr('data-tt-text', text) | ||
-- | -- Toggle | ||
toggle:tag('span') | |||
:addClass(' | :addClass('mw-collapsible-toggle') | ||
: | :addClass('mw-collapsible-toggle-collapsed') | ||
: | :addClass('custom-tt') | ||
: | :wikitext(text) | ||
: | :done() | ||
-- Tooltip | -- Tooltip | ||
toggle:tag('span') | |||
:addClass('custom-tt | :addClass('mw-collapsible-content') | ||
:addClass('custom-tt') | |||
:css('display', 'none') | |||
:wikitext(tooltip) | :wikitext(tooltip) | ||
:done() | |||
out:wikitext('‍') | |||
return out | return out | ||
| Line 73: | Line 89: | ||
function p.CleanTT(tx) | function p.CleanTT(tx) | ||
local clean = tx:gsub( | |||
'<span class="custom%-tt%-wrapper[^>] | '‍<span class="custom%-tt%-wrapper[^>]-data%-tt%-text="(.-)">.-‍', | ||
'' | '%1' | ||
) | ) | ||
return clean | |||
end | end | ||
return p | return p | ||