Module:Box: Difference between revisions
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
(Created page with "-- This is the base module for creating boxes with common styling. -- invoker args: -- content (or [1]) (required) -- align ('left', 'right', 'center') -- width (e.g. '2...") |
(output content so subclasses can do what they want with it. I'll need to add content support to the base Box functions later.) |
||
Line 12: | Line 12: | ||
function p.light( frame ) | function p.light( frame ) | ||
return tostring( p._light( | return tostring( p._light( frame.args ) ) | ||
end | end | ||
function p.dark( frame ) | function p.dark( frame ) | ||
return tostring( p._dark( | return tostring( p._dark( frame.args ) ) | ||
end | end | ||
function p._light( | function p._light( args ) | ||
return p._box( false | return p._box( false, args ) | ||
end | end | ||
function p._dark( | function p._dark( args ) | ||
return p._box( true | return p._box( true, args ) | ||
end | end | ||
-- Constructs the box | -- Constructs the box | ||
function p._box( dark | function p._box( dark, args ) | ||
local box = mw.html.create( 'div' ) | local box = mw.html.create( 'div' ) | ||
:addClass( dark and 'darkbox' or 'box' ) | :addClass( dark and 'darkbox' or 'box' ) | ||
Line 57: | Line 57: | ||
-- content, add toggle classes if necessary | -- content, add toggle classes if necessary | ||
box:tag( 'div' ) | local content = box:tag( 'div' ) | ||
:addClass( args.hide and '_toggle_init' .. args.hide .. ' _toggle' ) | :addClass( args.hide and '_toggle_init' .. args.hide .. ' _toggle' ) | ||
return box | return box, content | ||
end | end | ||
return p | return p |
Revision as of 06:09, February 8, 2017
Documentation for this module may be created at Module:Box/doc
-- This is the base module for creating boxes with common styling. -- invoker args: -- content (or [1]) (required) -- align ('left', 'right', 'center') -- width (e.g. '250px') -- title -- titlealign ('left', 'right', 'center') -- edit (e.g. 'Template:SomeNavbox') - adds an edit link to this page to the title bar -- hide ('hide' or 'show') - adds a toggle button to the title bar which toggles visibility of the content, with the specified default state local p = {} function p.light( frame ) return tostring( p._light( frame.args ) ) end function p.dark( frame ) return tostring( p._dark( frame.args ) ) end function p._light( args ) return p._box( false, args ) end function p._dark( args ) return p._box( true, args ) end -- Constructs the box function p._box( dark, args ) local box = mw.html.create( 'div' ) :addClass( dark and 'darkbox' or 'box' ) -- box styles if args.align == 'right' or args.align == 'left' or args.align == 'center' then box:addClass( args.align ) end if args.width then box:css( 'width', args.width ) end -- title, with edit and toggle links if supplied if args.title then local title = box:tag( 'div' ) :addClass( 'title' ) :css( 'text-align', args.titlealign or 'center' ) :wikitext( args.title ) if args.edit then title:tag( 'span' ) :addClass( 'edit plainlinks' ) :tag( 'a' ) :attr( 'href', tostring( mw.uri.fullUrl( args.edit, { action = 'edit' } ) ) ) :wikitext( '[edit]' ) end if args.hide then title:wikitext( mw.getCurrentFrame():expandTemplate{ title = 'Toggler', args = { default = args.hide } } ) end end -- content, add toggle classes if necessary local content = box:tag( 'div' ) :addClass( args.hide and '_toggle_init' .. args.hide .. ' _toggle' ) return box, content end return p