This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
This module depends on the following other modules: |
This module implements template {{Hidden}}.
Usage[Quelltext bearbeiten]
{{#invoke:Hidden|main}}
--[[
This implements Template:Hidden
It recreates functionality of Template:Hidden_begin and Template:Hidden_end
--]]
local p = {}
function buildHTML(args)
-- building main div
div = mw.html.create( 'div' )
div:addClass( 'mw-collapsible' )
if args.showhideLeft then
div:addClass( 'mw-collapsible-leftside-toggle' )
end
if not args.expanded then
div:addClass( 'mw-collapsed' )
end
if args.class then
div:addClass( args.class )
end
local divstyle = 'box-sizing:border-box;width:'
.. args.width .. ';font-size:95%;padding:4px;border:'
.. args.border .. ';' .. args.style
div:cssText(divstyle)
:tag('div')
:css('font-size', '100%')
:css('line-height', '1.6')
:css('font-weight', args.fw1) -- added by me, not in original template
:css('background', args.bg1)
:css('text-align', args.ta1)
:cssText(args.extra1)
:cssText(args.titlestyle)
:wikitext( args.title )
:done()
:tag( 'div' )
:addClass( 'mw-collapsible-content' )
:css( 'background', args.bg2 )
:css( 'text-align', args.ta2 )
:css( 'font-weight', args.fw2 ) -- added by me, not in original template
:cssText(args.extra2)
:cssText( args.bodystyle )
:wikitext( args.content )
:done()
:done()
return div
end
function getArgs(frame)
local args
if frame == mw.getCurrentFrame() then
args = require( 'Module:Arguments' ).getArgs(frame)
else
-- else, "frame" is a table containing arguments,
-- b/c module:hidden was called by another module
args = frame
end
return args
end
function processArgs(args)
-- please note, that some arguments will be set to false or nil
-- this is in fact not necessary, but should improve code readability
local args = args
args.showhide = args.showhide or args.toggle
args.showhideLeft = (args.showhide == 'left')
args.expanded = args.expanded or false
args.class = args.class or false
args.width = args.width or '100%'
args.border = args.border or 'none'
args.style = args.style or args.css or ''
args.bg1 = args.bg1 or 'transparent'
args.ta1 = args.ta1 or 'center'
args.extra1 = args.extra1 or nil -- semi deprecated
args.titlestyle = args.titlestyle or args.headercss or args.headerstyle or nil
args.title = args.title or args.header or -- header is semi deprecated
(args[1] and mw.text.trim(args[1])) or '{{{header}}}'
args.bg2 = args.bg2 or 'transparent'
args.ta2 = args.ta2 or 'left'
args.extra2 = args.extra2 or nil -- semi deprecated
args.bodystyle = args.bodystyle or args.contentstyle or args.contentcss or nil
args.content = args.content or (args[2] and mw.text.trim(args[2])) or '{{{content}}}'
-- added by me, not in original template
args.fw1 = args.fw1 or 'bold'
args.fw2 = args.fw2 or 'normal'
return args
end
function p.main(frame)
local args = getArgs(frame)
args = processArgs(args)
return tostring(buildHTML(args))
end
return p