Module:Tt/Draft: Difference between revisions
No edit summary |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
local args = require('Module:Arguments').getArgs(frame, { | local args = require('Module:Arguments').getArgs(frame, { | ||
parentFirst = true, | parentFirst = true, | ||
wrappers = { 'Template:Tt' } | wrappers = { 'Template:Tt', 'Template:Tt/Draft' } | ||
}) | }) | ||
args[1] = args[1] or '<i>Missing text</i>' | args[1] = args[1] or '<i>Missing text</i>' | ||
| Line 19: | Line 19: | ||
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 32: | Line 32: | ||
end | end | ||
-- Build | -- Build toggle tooltip | ||
local | 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 | ||
if not options or not options.notoggle then | if not options or not options.notoggle then | ||
toggle:addClass(' mw-collapsible mw-made-collapsible mw-collapsed | toggle:addClass(' mw-collapsible mw-made-collapsible mw-collapsed hnaw-collapsible') | ||
-- move tooltip to detached icon when text is clickable | -- move tooltip to detached icon when text is clickable | ||
if lib.isNotEmpty(args.link) or (text:find('%[%[') and text:find('%]%]')) then | if lib.isNotEmpty(args.link) or (text:find('%[%[') and text:find('%]%]')) then | ||
| Line 59: | Line 50: | ||
: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 75: | ||
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 | ||