Module:Tt
Appearance
Documentation for this module may be created at Module:Tt/doc
local p = {}
local lib = require('Module:Feature')
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]) -- 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 p._main(args)
end
end
function p._main(args, options)
local text = args[1]
local tooltip = mw.text.decode(args[2], true)
local out = mw.html.create()
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
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
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
end
--for modules that need the plain text input
function p.CleanTT(tx)
local clean = tx:gsub('‍<span class="custom%-tt%-wrapper[^>]-data%-tt%-text="(.-)">.-‍', '%1')
-- mw.logObject(clean)
return clean
end
return p