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 1: | Line 1: | ||
local p = {} | local p = {} | ||
local lib = require('Module:Feature') | |||
function p.main(frame) | function p.main(frame) | ||
local args = require('Module:Arguments').getArgs(frame, { | local args = require('Module:Arguments').getArgs(frame, { | ||
parentFirst = true, | parentFirst = true, | ||
wrappers = {'Template:Tt'} | wrappers = { 'Template:Tt' } | ||
}) | }) | ||
args[1] = args[1] or '<i>Missing text</i>' | args[1] = args[1] or '<i>Missing text</i>' | ||
if args.clean then | if args.clean then | ||
return p.CleanTT(args[1]) | return p.CleanTT(args[1]) -- Return plain text if tooltip return given | ||
elseif lib.isEmpty(args[2]) then | |||
return args[1] -- Return plain text if no tooltip given | |||
else | |||
return args[1] | return p._main(args) | ||
end | end | ||
end | end | ||
function p._main(args) | function p._main(args, options) | ||
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 = mw.html.create('span') | out:wikitext('‍') | ||
-- Build toggle tooltip | |||
local toggle = out:tag('span'):addClass('custom-tt-wrapper toggle-tooltip mw-collapsible mw-made-collapsible mw-collapsed giw-collapsible ' .. (args.class or '')) | |||
-- move tooltip to detached icon when text is clickable | |||
if lib.isNotEmpty(args.link) or (text:find('%[%[') and text:find('%]%]')) then | |||
-- | |||
if | |||
local link = tostring(args.link) | local link = tostring(args.link) | ||
toggle:wikitext('[[', lib.ternary(link == '1', text, link), '|', text, ']]', ' ') | |||
-- infoicon with semi-hidden text for screen readers | |||
text = '<span class="screen-reader-text">Tooltip for ' .. text:gsub('%[%[?[^|%]]+|', ''):gsub('%[', ''):gsub('%]', '') .. '</span>ⓘ' | |||
end | end | ||
toggle:attr('data-tt-text', text) | |||
-- | toggle | ||
:tag('span') | |||
:addClass('mw-collapsible-toggle mw-collapsible-toggle-collapsed custom-tt toggle-tooltip') | |||
:wikitext(text) | |||
:done() | |||
toggle | |||
:tag('span') | |||
: | :addClass('mw-collapsible-content custom-tt') | ||
:css{ display = 'none' } | |||
:wikitext(tooltip) | |||
:done() | |||
out:wikitext('‍') | |||
return out | return out | ||
end | end | ||
--for modules that need the plain text input | |||
function p.CleanTT(tx) | function p.CleanTT(tx) | ||
local clean = tx:gsub('‍<span class="custom%-tt%-wrapper[^>]-data%-tt%-text="(.-)">.-‍', '%1') | |||
-- mw.logObject(clean) | |||
return clean | |||
) | |||
end | end | ||
return p | return p | ||