Module:Tt/Draft: Difference between revisions

Kuhlau (talk | contribs)
No edit summary
Kuhlau (talk | contribs)
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 14: Line 14:
end
end
     return p._main(args)
     return p._main(args, nil, frame)
end
end


function p._main(args, options)
function p._main(args, options, frame)
local text = args[1]
local text = args[1]
local tooltip = args[2]
local tooltip = mw.text.decode(args[2], true)
local header = lib.isNotEmpty(args.header) and args.header or nil
local header = lib.isNotEmpty(args.header) and mw.text.decode(args.header, true) or nil
local class = lib.isNotEmpty(args.class) and args.class .. ' custom-tt-wrapper toggle-tooltip' or 'custom-tt-wrapper toggle-tooltip'
local out = mw.html.create()
local out = mw.html.create()
Line 27: Line 28:
local link = tostring(args.link)
local link = tostring(args.link)
args.link = nil
args.link = nil
local base = tostring(p._main(args, {notoggle = true})) -- tt on label for hover as otherwise the <a> default title takes priority
local base = tostring(p._main(args, {notoggle = true}, frame)) -- 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 }, {nohover = true}) -- external tt for collapsible for the separated clickable
return p._main({ linkTo, args[2], header = args.header, class = args.class }, {nohover = true}, frame) -- external tt for collapsible for the separated clickable
end
-- preprocess tooltip text
if lib.isNotEmpty(tooltip) then
tooltip = frame:preprocess(tooltip)
end
end
-- Build toggle tooltip
-- Build toggle tooltip
local toggle = out:tag('span'):addClass('custom-tt-wrapper toggle-tooltip')
local toggle = out:tag('span'):addClass(class)
-- Optional toggleable text but plain text must be there for gadget
-- Optional toggleable text but plain text must be there for gadget
Line 52: Line 58:
local collapsibleContent = toggle
local collapsibleContent = toggle
:tag('span')
:tag('span')
:addClass('mw-collapsible-content custom-tt')
:addClass('mw-collapsible-content custom-tt mobileonly')
:css{ display = 'none' }
if header then
if header then
collapsibleContent
collapsibleContent
Line 75: Line 80:
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
'<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 class="text%-tooltip hover%-tooltip">(' .. escDisplay .. ')<span class="tt%-content">' .. escTooltip .. '</span></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