Module:Collapsible

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) -- 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("id", args.id or args.header) :attr("data-expandtext", "show ▼") :attr("data-collapsetext", "hide ▲") :tag("div") :addClass("zw-collapsible__header mw-collapsible-toggle") :tag("span") :addClass("zw-collapsible__header-text") :wikitext(args.header or "") :done :tag("span") :addClass("zw-collapsible__toggle-button") :tag("span") :addClass("zw-collapsible__toggle-button-text mw-collapsible-text") :wikitext(expanded and "hide ▲" or nil) -- for some reason MediaWiki doesn't show the expandtext when content is expanded by default :done :done :done :tag("div") :addClass("zw-collapsible__content mw-collapsible-content") :wikitext("\n"..args.content) :done 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

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", "content"}, params = { header = { required = 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.", },		}	} }

return p