Module:Tt: Difference between revisions

ReisuDesign (talk | contribs)
No edit summary
ReisuDesign (talk | contribs)
No edit summary
Line 22: 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()
out:wikitext('‍')


local toggle = out:tag('span')
local toggle = out:tag('span')
:addClass('custom-tt-wrapper')
:addClass('custom-tt-wrapper')
:addClass('toggle-tooltip')
:addClass('mw-collapsible')
:addClass('mw-collapsed')
:addClass('giw-collapsible')
:addClass('giw-collapsible')
:addClass(args.class or '')
 
if args.class and args.class ~= '' then
toggle:addClass(args.class)
end


-- Make the text clickable if a link is provided,
-- Make the text clickable if a link is provided,
-- or if the text already contains a wiki link.
-- or if the text already contains a wiki link.
if args.link and args.link ~= '' or (text:find('%[%[') and text:find('%]%]')) then
if (args.link and args.link ~= '') or (text:find('%[%[') and text:find('%]%]')) then
local link = tostring(args.link or '')
local link = tostring(args.link or '')


if link == '1' then
if link == '1' then
toggle:wikitext(
toggle:wikitext(
'[[', text, ']]'
'[[', text, ']]', ' '
)
)
elseif link ~= '' then
elseif link ~= '' then
toggle:wikitext(
toggle:wikitext(
'[[', link, '|', text, ']]'
'[[', link, '|', text, ']]', ' '
)
)
else
else
toggle:wikitext(text)
toggle:wikitext(text, ' ')
end
end


toggle:wikitext(' ')
-- Add accessible text and an info icon.
 
-- Use an info icon when the text itself is clickable.
local cleanText = text
local cleanText = text
:gsub('%[%[?[^|%]]+|', '')
:gsub('%[%[?[^|%]]+|', '')
Line 61: Line 67:
toggle:attr('data-tt-text', text)
toggle:attr('data-tt-text', text)


-- Tooltip toggle
-- Toggle
toggle:tag('span')
toggle:tag('span')
:addClass('mw-collapsible-toggle')
:addClass('mw-collapsible-toggle')
Line 69: Line 75:
:done()
:done()


-- Tooltip content
-- Tooltip
toggle:tag('span')
toggle:tag('span')
:addClass('mw-collapsible-content')
:addClass('mw-collapsible-content')
Line 82: Line 88:
end
end


-- Return the visible text without tooltip markup.
function p.CleanTT(tx)
function p.CleanTT(tx)
local clean = tx:gsub(
local clean = tx:gsub(