Module:Tt: Difference between revisions

ReisuDesign (talk | contribs)
No edit summary
ReisuDesign (talk | contribs)
No edit summary
Line 25: Line 25:
out:wikitext('‍')
out:wikitext('‍')


local toggle = out:tag('span')
local wrapper = out:tag('span')
:addClass('custom-tt-wrapper')
:addClass('custom-tt-wrapper')
:addClass('toggle-tooltip')
:addClass('mw-collapsible')
:addClass('mw-collapsible')
:addClass('mw-collapsed')
:addClass('mw-collapsed')
Line 32: Line 33:


if args.class and args.class ~= '' then
if args.class and args.class ~= '' then
toggle:addClass(args.class)
wrapper:addClass(args.class)
end
end


-- If a link is supplied, make the visible text a link.
local isLinked = (
if (args.link and args.link ~= '') or (text:find('%[%[') and text:find('%]%]')) then
(args.link and args.link ~= '')
or (text:find('%[%[') and text:find('%]%]'))
)
 
if isLinked then
local link = tostring(args.link or '')
local link = tostring(args.link or '')


-- Visible linked text
if link == '1' then
if link == '1' then
toggle:wikitext('[[' .. text .. ']] ')
wrapper:wikitext('[[' .. text .. ']] ')
elseif link ~= '' then
elseif link ~= '' then
toggle:wikitext('[[' .. link .. '|' .. text .. ']] ')
wrapper:wikitext('[[' .. link .. '|' .. text .. ']] ')
else
else
toggle:wikitext(text .. ' ')
wrapper:wikitext(text .. ' ')
end
end


-- Clean text for screen readers
local cleanText = text
local cleanText = text
:gsub('%[%[?[^|%]]+|', '')
:gsub('%[%[?[^|%]]+|', '')
Line 52: Line 59:
:gsub('%]%]', '')
:gsub('%]%]', '')


text =
-- Store the tooltip label
'<span class="screen-reader-text">Tooltip for '
wrapper:attr(
.. cleanText
'data-tt-text',
.. '</span>ⓘ'
'ⓘ'
)
 
-- Info icon / actual collapsible toggle
wrapper:tag('span')
:addClass('mw-collapsible-toggle')
:addClass('mw-collapsible-toggle-collapsed')
:addClass('custom-tt')
:attr('aria-label', 'Tooltip for ' .. cleanText)
:wikitext(
'<span class="screen-reader-text">Tooltip for '
.. cleanText
.. '</span>ⓘ'
)
:done()
 
else
-- Plain text itself is the toggle
wrapper:attr('data-tt-text', text)
 
wrapper:tag('span')
:addClass('mw-collapsible-toggle')
:addClass('mw-collapsible-toggle-collapsed')
:addClass('custom-tt')
:wikitext(text)
:done()
end
end


toggle:attr('data-tt-text', text)
-- Tooltip content
 
wrapper:tag('span')
-- The actual collapsible content.
toggle:tag('span')
:addClass('mw-collapsible-content')
:addClass('mw-collapsible-content')
:addClass('custom-tt')
:addClass('custom-tt')