Module:Tt/Draft: Difference between revisions
No edit summary |
No edit summary |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 21: | Line 21: | ||
local tooltip = mw.text.decode(args[2], true) | local tooltip = mw.text.decode(args[2], true) | ||
local header = lib.isNotEmpty(args.header) and mw.text.decode(args.header, true) 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 29: | Line 30: | ||
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})) -- 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}) -- external tt for collapsible for the separated clickable | ||
end | end | ||
-- Build | -- Build toggle tooltip | ||
local | 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 | ||
if not options or not options.notoggle then | if not options or not options.notoggle then | ||
| Line 59: | Line 51: | ||
:wikitext(text) | :wikitext(text) | ||
:done() | :done() | ||
toggle | local collapsibleContent = toggle | ||
:tag('span') | :tag('span') | ||
:addClass('mw-collapsible-content custom-tt') | :addClass('mw-collapsible-content custom-tt') | ||
:css{ display = 'none' } | :css{ display = 'none' } | ||
:wikitext(tooltip) | if header then | ||
collapsibleContent | |||
:tag('span') | |||
:addClass('tt-header') | |||
:wikitext(header) | |||
:done() | |||
end | |||
collapsibleContent:wikitext(tooltip) | |||
collapsibleContent:done() | |||
else | else | ||
toggle:wikitext(text) | toggle:wikitext(text) | ||
| Line 77: | Line 76: | ||
local full = tx | local full = tx | ||
local result = tx | local result = tx | ||
for | for display in string.gmatch(full, | ||
'<span[^>]*class="[^"]*custom%-tt%-wrapper[^"]*"[^>]*>' .. | |||
'<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[^>] | 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 | ||