Module:Tt/Draft: Difference between revisions

Kuhlau (talk | contribs)
adding in optional headers to support extra effect (so they can be individually styled) and changing "title"-style hovertext to css. my god this cleanTT is kind of terrible
Kuhlau (talk | contribs)
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 19: Line 19:
function p._main(args, options)
function p._main(args, options)
local text = args[1]
local text = args[1]
local tooltip = mw.text.decode(args[2], true)
local tooltip = args[2]
local header = lib.isNotEmpty(args.header) and mw.text.decode(args.header, true) or nil
local header = lib.isNotEmpty(args.header) and args.header or nil
local out = mw.html.create()
local out = mw.html.create()
Line 31: Line 31:
return p._main({ linkTo, args[2], header = args.header }, {nohover = true}) -- external tt for collapsible for the separated clickable
return p._main({ linkTo, args[2], header = args.header }, {nohover = true}) -- external tt for collapsible for the separated clickable
end
end
-- Build hover tooltip
local hover = out:tag('span')
hover
:addClass('text-tooltip hover-tooltip')
:wikitext(text)
-- Optional hover text but plain text must be there for gadget
-- Now uses a css box, not a title
if not options or not options.nohover then
local content = hover:tag('span'):addClass('tt-content')
if header then
content:tag('span'):addClass('tt-header'):wikitext(header)
:done()
end
content:wikitext(tooltip)
content:done()
end
hover:allDone()
-- Build toggle tooltip
-- Build toggle tooltip
local toggle = out:tag('span'):addClass('custom-tt-wrapper mobile-only toggle-tooltip')
local toggle = out:tag('span'):addClass('custom-tt-wrapper toggle-tooltip')
-- Optional toggleable text but plain text must be there for gadget
-- Optional toggleable text but plain text must be there for gadget
Line 72: Line 54:
:addClass('mw-collapsible-content custom-tt')
:addClass('mw-collapsible-content custom-tt')
:css{ display = 'none' }
:css{ display = 'none' }
:wikitext(tooltip)
:done()
if header then
if header then
collapsibleContent
collapsibleContent
Line 95: Line 75:
local full = tx
local full = tx
local result = tx
local result = tx
for display in string.gmatch(full,
for tooltip, display in string.gmatch(full, '<span[^>]+title="([^>]-)">(.-)</span>') do
'<span[^>]*class="[^"]*custom%-tt%-wrapper[^"]*"[^>]*>' ..
local escTooltip = tooltip:gsub("([^%w])", "%%%1")
'<span[^>]*class="[^"]*mw%-collapsible%-toggle[^"]*"[^>]*>(.-)</span>' ..
'<span[^>]*class="[^"]*mw%-collapsible%-content[^"]*"[^>]*>.-</span></span>'
) do
local escDisplay = display:gsub("([^%w])", "%%%1")
local escDisplay = display:gsub("([^%w])", "%%%1")
search_str = '<span[^>]+title="' .. escTooltip .. '">(' .. escDisplay .. ')</span><span[^>]+><span[^>]+>' .. escDisplay .. '</span><span[^>]+>' .. escTooltip .. '</span></span>'
local search_str =
'<span[^>]*class="[^"]*custom%-tt%-wrapper[^"]*"[^>]*>' ..
'<span[^>]*class="[^"]*mw%-collapsible%-toggle[^"]*"[^>]*>' .. escDisplay .. '</span>' ..
'<span[^>]*class="[^"]*mw%-collapsible%-content[^"]*"[^>]*>.-</span></span>'
result = result:gsub(search_str, display)
result = result:gsub(search_str, display)
end
end