Jump to content

Editing Module:Tt/Draft

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
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 5: Line 5:
local args = require('Module:Arguments').getArgs(frame, {
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
parentFirst = true,
wrappers = { 'Template:Tt', 'Template:Tt/Draft' }
wrappers = { 'Template:Tt' }
})
})
args[1] = args[1] or '<i>Missing text</i>'
args[1] = args[1] or '<i>Missing text</i>'
Line 14: Line 14:
end
end
     return p._main(args, nil, frame)
     return p._main(args)
end
end


function p._main(args, options, frame)
function p._main(args, options)
local text = args[1]
local text = args[1]
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 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}, frame)) -- 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, class = args.class }, {nohover = true}, frame) -- 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
-- preprocess tooltip text
-- Build hover tooltip
if lib.isNotEmpty(tooltip) then
local hover = out:tag('span')
tooltip = frame:preprocess(tooltip)
hover
end
: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 hover:attr('title', tooltip) end
hover:allDone()
-- Build toggle tooltip
-- Build toggle tooltip
local toggle = out:tag('span'):addClass(class)
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
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 hnaw-collapsible')
toggle:addClass(' mw-collapsible mw-made-collapsible mw-collapsed giw-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 56: Line 59:
:wikitext(text)
:wikitext(text)
:done()
:done()
local collapsibleContent = toggle
toggle
:tag('span')
:tag('span')
:addClass('mw-collapsible-content custom-tt mobileonly')
:addClass('mw-collapsible-content custom-tt')
if header then
:css{ display = 'none' }
collapsibleContent
:wikitext(tooltip)
:tag('span')
:done()
:addClass('tt-header')
:wikitext(header)
:done()
end
collapsibleContent:wikitext(tooltip)
collapsibleContent:done()
else
else
toggle:wikitext(text)
toggle:wikitext(text)
Line 80: Line 77:
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")
local search_str =
search_str = '<span[^>]+title="' .. escTooltip .. '">(' .. escDisplay .. ')</span><span[^>]+><span[^>]+>' .. escDisplay .. '</span><span[^>]+>' .. escTooltip .. '</span></span>'
'<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
Please note that all contributions to Honkai: Nexus Anima Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Honkai Nexus Anima Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template
Below are commonly used wikitext from MediaWiki:Edittools. Click on any to insert them in the edit box.

Parser Functions:{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}





Page included on this page: