Jump to content

Editing Module:Tt

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
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 4: Line 4:
local args = require('Module:Arguments').getArgs(frame, {
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
parentFirst = true,
wrappers = {'Template:Tt'}
wrappers = { 'Template:Tt' }
})
})


Line 11: Line 11:
if args.clean then
if args.clean then
return p.CleanTT(args[1])
return p.CleanTT(args[1])
end
elseif not args[2] or mw.text.trim(args[2]) == '' then
 
if not args[2] or mw.text.trim(args[2]) == '' then
return args[1]
return args[1]
else
return p._main(args)
end
end
return p._main(args)
end
end


Line 24: Line 22:
local tooltip = mw.text.decode(args[2], true)
local tooltip = mw.text.decode(args[2], true)


local out = mw.html.create('span')
local out = mw.html.create()
:addClass('custom-tt-wrapper')
 
:addClass(args.class or '')
-- Prevent whitespace/formatting issues around the wrapper
out:wikitext('‍')


local visibleText = text
-- Main tooltip wrapper
local cleanText = text
local toggle = out:tag('span')
:addClass(
'custom-tt-wrapper mw-collapsible mw-made-collapsible mw-collapsed giw-collapsible ' ..
(args.class or '')
)


-- Handle explicit link parameter
-- If a link is supplied, keep the link outside the tooltip toggle.
-- The info icon becomes the actual tooltip toggle.
if args.link and mw.text.trim(tostring(args.link)) ~= '' then
if args.link and mw.text.trim(tostring(args.link)) ~= '' then
local link = tostring(args.link)
local link = tostring(args.link)


visibleText = '[[' ..
toggle:wikitext(
(link == '1' and text or link) ..
'[[',
'|' ..
link == '1' and text or link,
text ..
'|',
']]'
text,
']]',
' '
)


cleanText = text
local cleanText = text
:gsub('%[%[[^%]|]+|', '')
:gsub('%[%[', '')
:gsub('%]%]', '')


-- Handle text that is already an internal link
text =
'<span class="screen-reader-text">Tooltip for ' ..
cleanText ..
'</span>ⓘ'
 
-- If the supplied text is already an internal link,
-- keep it as visible text and put the toggle on the icon.
elseif text:find('%[%[') and text:find('%]%]') then
elseif text:find('%[%[') and text:find('%]%]') then
visibleText = text
toggle:wikitext(text, '&thinsp;')


cleanText = text
local cleanText = text
:gsub('%[%[[^%]|]+|', '')
:gsub('%[%[[^%]|]+|', '')
:gsub('%[%[', '')
:gsub('%[%[', '')
:gsub('%]%]', '')
:gsub('%]%]', '')
text =
'<span class="screen-reader-text">Tooltip for ' ..
cleanText ..
'</span>ⓘ'
end
end


-- Visible text
toggle:attr('data-tt-text', text)
out:wikitext(visibleText)


-- Tooltip trigger
-- Tooltip toggle
local trigger = out:tag('span')
toggle
:addClass('custom-tt-trigger')
:tag('span')
:attr('tabindex', '0')
:addClass(
:attr('role', 'button')
'mw-collapsible-toggle mw-collapsible-toggle-collapsed custom-tt toggle-tooltip'
:attr('aria-label', 'Tooltip for ' .. cleanText)
)
:wikitext('ⓘ')
:wikitext(text)
:done()


-- Tooltip
-- Tooltip content
out:tag('span')
toggle
:addClass('custom-tt-content')
:tag('span')
:wikitext(tooltip)
:addClass('mw-collapsible-content custom-tt')
:css('display', 'none')
:wikitext(tooltip)
:done()
 
out:wikitext('&zwj;')


return out
return out
end
end


-- Return only the visible text.
function p.CleanTT(tx)
function p.CleanTT(tx)
return tx:gsub(
local clean = tx:gsub(
'<span class="custom%-tt%-wrapper[^>]*>.-</span>',
'&zwj;<span class="custom%-tt%-wrapper[^>]-data%-tt%-text="(.-)">.-&zwj;',
''
'%1'
)
)
return clean
end
end


return p
return p
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Petit Planet 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.
File Pages==Summary====Licensing=={{Fairuse}}{{File|}}
Dynamic Page List¦²«»²{¦}²«»«/»«!----»
Array in DPL¹^2{}^2^2{¹}^2
Parser Functions{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}
Markup{{}}|[][[]][[Category:]]#REDIRECT [[]] [[Category:Redirect Pages]]<code></code><includeonly></includeonly><noinclude></noinclude><nowiki></nowiki><!----><br>§
Notices{{Stub|}}{{Stub Dialogue}}{{Upcoming}}{{Under Construction}}{{Placeholder|}}
Magic Words{{!}}{{formatnum:}}{{lc:}}{{uc:}}{{PAGENAME}}{{FULLPAGENAME}}{{ROOTPAGENAME}}{{BASEPAGENAME}}{{SUBPAGENAME}}{{DISPLAYTITLE:|noreplace}}__TOC____NOTOC____EXPECTUNUSEDCATEGORY____HIDDENCAT__
HTML Entities&mdash;&nbsp;&comma;&shy;