Module:Box: Difference between revisions
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
(output content so subclasses can do what they want with it. I'll need to add content support to the base Box functions later.) |
(add class parameter) |
||
Line 1: | Line 1: | ||
-- This is the base module for creating boxes with common styling. | -- This is the base module for creating boxes with common styling. | ||
-- invoker args: | -- invoker args: | ||
-- | -- class | ||
-- align ('left', 'right', 'center') | -- align ('left', 'right', 'center') | ||
-- width (e.g. '250px') | -- width (e.g. '250px') | ||
Line 31: | Line 31: | ||
local box = mw.html.create( 'div' ) | local box = mw.html.create( 'div' ) | ||
:addClass( dark and 'darkbox' or 'box' ) | :addClass( dark and 'darkbox' or 'box' ) | ||
:addClass( args.class ) | |||
-- box styles | -- box styles |
Revision as of 06:17, 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: -- class -- 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' ) :addClass( args.class ) -- 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