Module:BubbleBox

local p = {}

local siteColor = require('Module:SiteColor')

function p.main(frame) local args = frame:getParent.args -- title is a named parameter and the first unnamed positional parameter. It is the static content. local content = args['title'] or args[1] or '' -- inner is a named parameter and the second unnamed positional parameter. It is the collapsible content. local inner = args['inner'] or args[2] or '' -- background is optional named parameter and defaults to rgba({border}, 0.25) local background = args['background'] or '' -- border is optional named parameter and defaults to Generic local border = args['border'] or siteColor.getSiteColor("Generic") -- collapsed is an optional named parameter; if present it should be true/false -- if inner is defined and collapsed is not, then the inner content will be     -- displayed expanded without the collapse option (similar to how 'open' mode was) local collapsed = args['collapsed'] or '' -- style is an optional named parameter css list to add to the container local style = args['style'] or '' -- tags is an optional named parameter and adds to JS tags local tags = args['tags'] or '' -- pass args to getBox return p.getBox(content, inner, background, border, collapsed, style, tags) end

function p.getBox(content, inner, background, border, collapsed, style, tags) -- Initialize empty tables for classes and styles that will be applied to the div. local classes = {} local styles = {}

-- Link to the table.insert documentation for reference. -- https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#table.insert

-- Background color/style setup. if background ~= '' then -- If the background is specified, insert it into classes. table.insert(classes, background) else -- Else, add a default background color style. table.insert(styles, 'background-color: ' .. (background ~=  and background or 'rgba(' .. (border ~=  and border or siteColor.getSiteColor("Generic")) .. ', 0.25)')) end

-- Collapsible setup. if collapsed ~= '' then -- Add 'mw-collapsible' to classes if collapsed is specified. table.insert(classes, 'mw-collapsible') if collapsed == 'true' then -- Add 'mw-collapsed' to classes if collapsed is set to 'true'. table.insert(classes, 'mw-collapsed') end end

-- Insert any additional specified tags into classes. if tags ~= '' then table.insert(classes, tags) end

-- Add default styles for box shadow, border, etc.   table.insert(styles, 'box-shadow: 0px 0px 15px #ffffff inset') table.insert(styles, 'border-style: outset') -- table.insert(styles, 'border-width: 10px 1px 10px 1px') table.insert(styles, 'border-width: 8px 3px 8px 3px') table.insert(styles, 'border-color: rgb(' .. (border ~= '' and border or siteColor.getSiteColor("Generic")) .. ')')   table.insert(styles, 'border-radius: 9px') table.insert(styles, 'padding: 10px') table.insert(styles, 'margin: 4px')

-- Insert any additional specified styles. -- Note that MediaWiki still gets a say in what can go here - -- you cannot add url(...) styles in this way as it's security blocked. if style ~= '' then table.insert(styles, style) end

-- Assemble the HTML output for the bubble box. local result = ''

-- Insert content and potentially collapsible inner content. if inner and inner ~= '' then result = result .. content -- Insert static content. result = result .. ' ' -- Open mw-collapsible-content div. result = result .. inner -- Insert collapsible content. result = result .. ' ' -- Close mw-collapsible-content div. else result = result .. content -- Insert content only. end result = result .. ' ' -- Close the outer div.

return result end

return p