Module:Sandbox/PhantomCaleb

local p = {}

local utilsArg = require("Module:UtilsArg")

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Collapsible"]) local categories = err and err.categoryText or "" if args.content == nil or args.content == "" then return "", categories end local expanded = args.collapse ~= true and not (args.frame and args.collapse ~= false) local expandText = args.buttonShow.." ▼" local collapseText = args.buttonHide.." ▲" -- This module depends on the jQuery.makeCollapsible that ships with MediaWiki -- See https://www.mediawiki.org/wiki/Manual:Collapsible_elements local html = mw.html.create("div") :addClass("zw-collapsible mw-collapsible") :attr("data-expandtext", expandText) :attr("data-collapsetext", collapseText) if not expanded then html:addClass("mw-collapsed") end if args.frame then html:addClass("zw-collapsible--framed") end if args.stretch and args.frame then html:addClass("zw-collapsible--stretch") end

if not args.header then html:wikitext(args.content) else html:attr("id", args.id or args.header) local header = html:tag("div"):addClass("zw-collapsible__header mw-collapsible-toggle") local button = mw.html.create("span") :addClass("zw-collapsible__toggle-button") :tag("span") :addClass("zw-collapsible__toggle-button-text mw-collapsible-text") :wikitext(expanded and collapseText or nil) -- for some reason MediaWiki doesn't show the collapsetext when content is expanded by default :done :done if args.headerAlign == "center" then header:css("text-align", "center") header:tag("span") :attr("aria-hidden", "true") :css({					["float"] = "left",					["visibility"] = "hidden !important"				}) :node(button) end header:tag("span") :addClass("zw-collapsible__header-text") :wikitext(args.header or "") :done :node(button) :done html:tag("div") :addClass("zw-collapsible__content mw-collapsible-content") :wikitext("\n"..args.content) :done end

return tostring(html), categories end

function p.Infofield(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Infofield Collapsible"]) local categories = err and err.categoryText or ""

if not args.header or not args.content then return categories end local html = mw.html.create("div") :addClass("zw-infofield-collapsible mw-collapsible mw-collapsed") :attr("data-expandtext", "show ▼") :attr("data-collapsetext", "hide ▲") :tag("span") :addClass("zw-infofield-collapsible__header") :wikitext(args.header.." ") :done :tag("span") :addClass("mw-collapsible-toggle") :tag("span") :addClass("zw-infofield-collapsible__toggle-button") :tag("span") :addClass("zw-infofield-collapsible__toggle-button-text mw-collapsible-text") :done :done :done :tag("div") :addClass("mw-collapsible-content") :wikitext(args.content) :done return tostring(html), categories end

p.Templates = { ["Collapsible"] = { format = "block", description = "Makes content collapsible.", purpose = "Makes content collapsible. Used for large lists and tables as well as other supplementary content such as companion comments. It has also been used to describe plots with forking paths (see The Crystal Trap and The Subspace Emissary).", paramOrder = {"id", "header", "frame", "collapse", "stretch", "headerAlign", "buttonHide", "buttonShow", "content"}, params = { header = { suggested = true, type = "content", desc = "The title of the collapsible content.", trim = true, nilIfEmpty = true, },			content = { required = true, type = "content", desc = "The content to be made collapsible.", trim = true, },			id = { type = "string", desc = "Sets the ID attribute of the collapsible content so that it can be linked as a section. Defaults to .", trim = true, nilIfEmpty = true, },			frame = { type = "boolean", desc = "If present, a border is added around the collapsible content and header.", },			collapse = { type = "boolean", desc = " If present, the content starts off in the collapsed state on page load. Content is collapsed by default when   is set. To override this, set   to  . ", },			stretch = { type = "boolean", desc = "If present, the header stretches to fill the screen rather than fitting itself to its content. Works only when  is enabled.", },			headerAlign = { type = "string", default = "left", enum = {"left", "center"}, desc = "Center-aligns the header text if set to . Applicable when using  ", },			buttonHide = { type = "string", default = "hide", desc = 'Text to use for the "hide" button label', },			buttonShow = { type = "string", default = "show", desc = 'Text to use for the "show" button label', },		}	},	["Infofield Collapsible"] = { format = "block", params = { [1] = {				name = "header", type = "content", required = true, desc = "A title for the collapsible content.", trim = true, nilIfEmpty = true, },			[2] = {				name = "content", type = "content", required = true, desc = "The content to be made collapsible.", trim = true, nilfIfEmpty = true, },		},	}, }

return p