Editing Module:Tt/Draft
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 14: | Line 14: | ||
end | end | ||
return p._main(args | return p._main(args) | ||
end | end | ||
function p._main(args, options | function p._main(args, options) | ||
local text = args[1] | local text = args[1] | ||
local tooltip = | local tooltip = args[2] | ||
local header = lib.isNotEmpty(args.header) and | local header = lib.isNotEmpty(args.header) and args.header or nil | ||
local out = mw.html.create() | local out = mw.html.create() | ||
| Line 28: | Line 27: | ||
local link = tostring(args.link) | local link = tostring(args.link) | ||
args.link = nil | args.link = nil | ||
local base = tostring(p._main(args, {notoggle = true} | local base = tostring(p._main(args, {notoggle = true})) -- tt on label for hover as otherwise the <a> default title takes priority | ||
local linkTo = '[[' .. lib.ternary(link == '1', text, link) .. '|' .. base .. ']]' | local linkTo = '[[' .. lib.ternary(link == '1', text, link) .. '|' .. base .. ']]' | ||
return p._main({ linkTo, args[2], header = args.header | return p._main({ linkTo, args[2], header = args.header }, {nohover = true}) -- external tt for collapsible for the separated clickable | ||
end | end | ||
-- | -- Build hover tooltip (desktop only) | ||
if | -- Now uses a css box, not a title | ||
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 | |||
if not options or not options.nohover then | |||
local content = tooltip:tag('span'):addClass('tt-content') | |||
if header then | |||
content:tag('span'):addClass('tt-header'):wikitext(header) | |||
:done() | |||
end | |||
content:wikitext(tooltip) | |||
content:done() | |||
end | end | ||
hover:allDone() | |||
-- Build toggle tooltip | -- Build toggle tooltip (mobile only) | ||
local toggle = out:tag('span'):addClass( | local toggle = out:tag('span'):addClass('custom-tt-wrapper mobile-only 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 58: | Line 70: | ||
local collapsibleContent = toggle | local collapsibleContent = toggle | ||
:tag('span') | :tag('span') | ||
:addClass('mw-collapsible-content custom-tt | :addClass('mw-collapsible-content custom-tt') | ||
:css{ display = 'none' } | |||
if header then | if header then | ||
collapsibleContent | collapsibleContent | ||
| Line 80: | Line 93: | ||
local full = tx | local full = tx | ||
local result = tx | local result = tx | ||
for display in string.gmatch(full, | |||
for display, tooltip in string.gmatch(full, '<span class="text%-tooltip hover%-tooltip">(.-)<span class="tt%-content">(.-)</span></span>') do | |||
local escTooltip = tooltip:gsub("([^%w])", "%%%1") | |||
local escDisplay = display:gsub("([^%w])", "%%%1") | local escDisplay = display:gsub("([^%w])", "%%%1") | ||
search_str = '<span class="text%-tooltip hover%-tooltip">(' .. escDisplay .. ')<span class="tt%-content">' .. escTooltip .. '</span></span><span[^>]+><span[^>]+>' .. escDisplay .. '</span><span[^>]+>' .. escTooltip .. '</span></span>' | |||
result = result:gsub(search_str, display) | result = result:gsub(search_str, display) | ||
end | end | ||