Module:Box: Difference between revisions

Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
1,403 bytes removed ,  June 22, 2020
switch to zdw selectors
(doesn't like a tags I guess)
(switch to zdw selectors)
 
(3 intermediate revisions by the same user not shown)
Line 24: Line 24:
function Box:render()
function Box:render()
   local root = mw.html.create( 'div' )
   local root = mw.html.create( 'div' )
     :addClass( self.boxType == 'dark' and 'darkbox' or 'box' )
     :addClass( self.boxType == 'dark' and 'zdw-box--dark' or 'zdw-box' )
     :addClass( self.args.class )
     :addClass( self.args.class )


Line 53: Line 53:
function Box:renderHeader()
function Box:renderHeader()
   local header = mw.html.create( 'div' )
   local header = mw.html.create( 'div' )
     :addClass( 'title' )
     :addClass( 'zdw-box__title' )
     :css( 'text-align', 'center' )
     :css( 'text-align', 'center' )
     :wikitext( self.args.title )
     :wikitext( self.args.title )
Line 60: Line 60:
     header:tag( 'span' )
     header:tag( 'span' )
       :addClass( 'edit plainlinks' )
       :addClass( 'edit plainlinks' )
       :tag( 'a' )
       :wikitext( '[' .. tostring( mw.uri.fullUrl( self.args.edit, { action = 'edit' } ) ) .. ' [edit]]' )
        :attr( 'href', tostring( mw.uri.fullUrl( self.args.edit, { action = 'edit' } ) ) )
        :wikitext( '[edit]' )
   end
   end


Line 69: Line 67:
   end
   end


   return tostring( header )
   return header
end
end


Line 86: Line 84:
function Box:renderFooter()
function Box:renderFooter()
   local footer = mw.html.create( 'div' )
   local footer = mw.html.create( 'div' )
     :addClass( 'title hlist' )
     :addClass( 'zdw-box__title zdw-hlist' )
     :css( 'text-align', 'center' )
     :css( 'text-align', 'center' )


Line 98: Line 96:
end
end


local p, mt = Box, {}
local p, mt = {}, {}
 
p.Box = Box


function p._main( boxType, args )
function p._main( boxType, args )
   local box = Box.new( boxType, args )
   local box = Box.new( boxType, args )
   return box:render()
   return box:render()
end
-- TODO deprecated, use p._main instead
function p._light( args )
    return p._box( false, args )
end
-- TODO deprecated, use p._main instead
function p._dark( args )
  return p._box( true, args )
end
-- TODO deprecated
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' )
                :wikitext( '[' .. tostring( mw.uri.fullUrl( args.edit, { action = 'edit' } ) ) .. ' [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
end


Navigation menu