Modul:Hidden: Unterschied zwischen den Versionen

Permanently protected module
ZIM HilfeWiki - das Wiki
imported>Oetterer
K (Schützte „Modul:Hidden“: Automatic protection of selected project pages ([Bearbeiten=Nur Administratoren erlauben] (unbeschränkt) [Verschieben=Nur Administratoren erlauben] (unbeschränkt)))
 
Zeile 1: Zeile 1:
 +
--[[
 +
This implements Template:Hidden
 +
It recreates functionality of Template:Hidden_begin and Template:Hidden_end
 +
--]]
 +
 
local p = {}
 
local p = {}
local getArgs = require( 'Module:Arguments' ).getArgs
 
  
function p._main(args)
+
function buildHTML(args)
 
 
 +
-- building main div
 
div = mw.html.create( 'div' )
 
div = mw.html.create( 'div' )
div:addClass( 'NavFrame' )
+
div:addClass( 'mw-collapsible' )
 +
if args.showhideLeft then
 +
div:addClass( 'mw-collapsible-leftside-toggle' )
 +
end
 
if not args.expanded then
 
if not args.expanded then
div:addClass( 'collapsed' )
+
div:addClass( 'mw-collapsed' )
 
end
 
end
 
if args.class then
 
if args.class then
 
div:addClass( args.class )
 
div:addClass( args.class )
 
end
 
end
div:css ( 'border', args.border )
+
local divstyle = 'box-sizing:border-box;width:'
:cssText ( args.style )
+
.. args.width .. ';font-size:95%;padding:4px;border:'
:tag( 'div' )
+
.. args.border .. ';' .. args.style
:addClass( 'NavHead' )
+
div:cssText(divstyle)
:css( 'font-weight', args.fw1 )
+
:tag('div')
:css( 'background', args.bg1 )
+
:css('font-size', '100%')
:css( 'text-align', args.ta1 )
+
:css('line-height', '1.6')
:cssText( args.headerstyle )
+
:css('font-weight', args.fw1) -- added by me, not in original template
:wikitext( args.header )
+
:css('background', args.bg1)
 +
:css('text-align', args.ta1)
 +
:cssText(args.extra1)
 +
:cssText(args.titlestyle)
 +
:wikitext( args.title )
 
:done()
 
:done()
 
:tag( 'div' )
 
:tag( 'div' )
:addClass( 'NavContent' )
+
:addClass( 'mw-collapsible-content' )
:css( 'font-weight', args.fw2 )
 
 
:css( 'background', args.bg2 )
 
:css( 'background', args.bg2 )
 
:css( 'text-align', args.ta2 )
 
:css( 'text-align', args.ta2 )
:cssText( args.contentstyle )
+
:css( 'font-weight', args.fw2 ) -- added by me, not in original template
 +
:cssText(args.extra2)
 +
:cssText( args.bodystyle )
 
:wikitext( args.content )
 
:wikitext( args.content )
 
:done()
 
:done()
 
:done()
 
:done()
 
 
return tostring(div)
+
return div
 
end
 
end
  
function p.main(frame)
+
function getArgs(frame)
local args
+
local args
 
if frame == mw.getCurrentFrame() then
 
if frame == mw.getCurrentFrame() then
args = getArgs(frame)
+
args = require( 'Module:Arguments' ).getArgs(frame)
 
else
 
else
 +
-- else, "frame" is a table containing arguments,
 +
-- b/c module:hidden was called by another module
 
args = frame
 
args = frame
 
end
 
end
+
return args
args.header = args.header or args.title or (args[1] and mw.text.trim(args[1])) or '{{{header}}}'
+
end
args.content = args.content or (args[2] and mw.text.trim(args[2])) or '{{{content}}}'
+
 
 +
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.style = args.style or args.css or ''
args.border = args.border or 'none'
 
args.headerstyle = args.headerstyle or args.titlestyle or args.headercss or ''
 
args.contentstyle = args.contentstyle or args.contentcss or ''
 
args.fw1 = args.fw1 or 'bold'
 
args.fw2 = args.fw2 or 'normal'
 
 
args.bg1 = args.bg1 or 'transparent'
 
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.bg2 = args.bg2 or 'transparent'
args.ta1 = args.ta1 or 'center'
 
 
args.ta2 = args.ta2 or 'left'
 
args.ta2 = args.ta2 or 'left'
+
args.extra2 = args.extra2 or nil -- semi deprecated
return p._main(args)
+
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
 
end
  
 
return p
 
return p

Aktuelle Version vom 7. Oktober 2022, 16:56 Uhr

Documentation icon Module documentation

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
Cookies helfen uns bei der Bereitstellung des ZIM HilfeWikis. Bei der Nutzung vom ZIM HilfeWiki werden die in der Datenschutzerklärung beschriebenen Cookies gespeichert.