Module:Navbox

-- CSS classes used by Navbox that we need to replace w/ colorscheme class: -- navbox-header -- navbox-group -- navbox-title

local p = {}

local function setup_styles(pargs) -- format the style string local val = (pargs['backcolor'] and "background: " .. pargs['backcolor'] or '') .. (pargs['textcolor'] and "color: " .. pargs['textcolor'] or '')

-- apply to the 4 relevant sections, if they haven't been manually set pargs['titlestyle'] = pargs['titlestyle'] or val pargs['abovestyle'] = pargs['abovestyle'] or val pargs['headerstyle'] = pargs['headerstyle'] or val pargs['groupstyle'] = pargs['groupstyle'] or val end

function p.main(frame) -- get color scheme local pargs = frame:getParent.args local cs = pargs['colorscheme'] or '' -- if the colorscheme wasn't specified, set the backcolor and textcolor if not cs then setup_styles(pargs) end

-- not ideal to chain gsub calls, but as far as im aware lua doesn't support regex OR [ie "navbox-(header|group|title)"] -- Steps: -- Replace "navbox-header", "navbox-group", and "navbox-title" with "cs {colorscheme}", applying the colorscheme to the relevant spots (if colorscheme is specified) -- Replace the CSS class "navbox" with "navbox toccolours"; adding the CSS class "toccolours", since it's used in the existing Navibox template. -- The "navbox" CSS class should only be at the top-level of the navbox and could therefore probably be switched out manually; gsub is a bit more future-proof though, so that's what's been used -- Remove any leftover CSS class that begins with "navbox" -- Navbox classes defined in MediaWiki:Common.css, but that aren't used by the old Template:Navibox. For replication purposes, will be taken out here. -- Re-add the "navbox" CSS class where toccolours is located local html = require('Dev:Navbox'):main(frame) if not cs then -- only do the colorscheme replacement if the colorscheme has been set. otherwise backcolor and textcolor are used (see setup_styles) html = html:gsub('navbox%-header', 'cs ' .. cs):gsub('navbox%-group', 'cs ' .. cs):gsub('navbox%-title', 'cs ' .. cs) end return html:gsub('"navbox([%s"])', '"navbox toccolours%1'):gsub('navbox%-.-([%s"])', '%1') end

return p