Editing Module:Tt
Appearance
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 mw.text.trim(args[2]) == '' then | |||
return args[1] | return args[1] | ||
else | |||
return p._main(args) | |||
end | end | ||
end | end | ||
| Line 24: | Line 22: | ||
local tooltip = mw.text.decode(args[2], true) | local tooltip = mw.text.decode(args[2], true) | ||
local out = mw.html.create( | local out = mw.html.create() | ||
-- Prevent whitespace/formatting issues around the wrapper | |||
out:wikitext('‍') | |||
-- Main tooltip wrapper | |||
local | local toggle = out:tag('span') | ||
:addClass( | |||
'custom-tt-wrapper mw-collapsible mw-made-collapsible mw-collapsed giw-collapsible ' .. | |||
(args.class or '') | |||
) | |||
-- | -- If a link is supplied, keep the link outside the tooltip toggle. | ||
-- The info icon becomes the actual tooltip toggle. | |||
if args.link and mw.text.trim(tostring(args.link)) ~= '' then | if args.link and mw.text.trim(tostring(args.link)) ~= '' then | ||
local link = tostring(args.link) | local link = tostring(args.link) | ||
toggle:wikitext( | |||
'[[', | |||
'|' | link == '1' and text or link, | ||
text | '|', | ||
']]' | text, | ||
']]', | |||
' ' | |||
) | |||
cleanText = text | local cleanText = text | ||
:gsub('%[%[[^%]|]+|', '') | |||
:gsub('%[%[', '') | |||
:gsub('%]%]', '') | |||
-- | text = | ||
'<span class="screen-reader-text">Tooltip for ' .. | |||
cleanText .. | |||
'</span>ⓘ' | |||
-- If the supplied text is already an internal link, | |||
-- keep it as visible text and put the toggle on the icon. | |||
elseif text:find('%[%[') and text:find('%]%]') then | elseif text:find('%[%[') and text:find('%]%]') then | ||
toggle:wikitext(text, ' ') | |||
cleanText = text | local cleanText = text | ||
:gsub('%[%[[^%]|]+|', '') | :gsub('%[%[[^%]|]+|', '') | ||
:gsub('%[%[', '') | :gsub('%[%[', '') | ||
:gsub('%]%]', '') | :gsub('%]%]', '') | ||
text = | |||
'<span class="screen-reader-text">Tooltip for ' .. | |||
cleanText .. | |||
'</span>ⓘ' | |||
end | end | ||
-- | toggle:attr('data-tt-text', text) | ||
-- Tooltip | -- Tooltip toggle | ||
toggle | |||
:tag('span') | |||
:addClass( | |||
'mw-collapsible-toggle mw-collapsible-toggle-collapsed custom-tt toggle-tooltip' | |||
) | |||
:wikitext(text) | |||
:done() | |||
-- Tooltip | -- Tooltip content | ||
toggle | |||
:tag('span') | |||
:addClass('mw-collapsible-content custom-tt') | |||
:css('display', 'none') | |||
:wikitext(tooltip) | |||
:done() | |||
out:wikitext('‍') | |||
return out | return out | ||
end | end | ||
-- Return only the visible text. | |||
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 | ||