Module:Navbox Tabs

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
This is the main module for the following templates:
local p = {}

local Tabs = require("Module:Tabs")
local utilsArg = require("Module:UtilsArg")

function p.Main(frame)
	local args, err = utilsArg.parse(frame:getParent().args, p.Templates["Navbox Tabs"])
	local categories = err and err.categoryText or ""
	
	local tabs = Tabs.printTabs(args)
	
	local navbox = frame:expandTemplate({
		title = "Navbox",
		args = {
			id = args.id,
			title = args.header,
			footer = args.footer,
			links1 = tabs,
		}
	})

	local html = mw.html.create("div")
		:addClass("zw-navbox-tabs")
		:wikitext(navbox)
		:done()
	html = tostring(html)
	
	if mw.title.getCurrentTitle().nsText == "Template" then
		return html, categories
	else
		return html
	end
end

p.Templates = {
	["Navbox Tabs"] = {
		format = "block",
		repeatedGroup = {
			name = "tabs",
			params = {"tab", "content"},
			counts = {4, 8, 16, 32, 64},
		},
		paramOrder = {"id", "header", "default", "tab", "content", "footer"},
		params = {
			id = {
				type = "string",
				desc = "A unique ID for the navbox. Sets the [https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id id HTML attribute] so that the navbox can be linked to. Defaults to the navbox title.",
				trim = true,
				nilIfEmpty = true,
			},
			header = {
				required = true,
				type = "content",
				desc = "The title for the navbox.",
				trim = true,
				nilIfEmpty = true,
			},
			footer = {
				type = "content",
				desc = "The navbox footer. Usually contains links to relevant categories.",
				trim = true,
				nilIfEmpty = true,
			},
			default = {
				type = "number",
				default = 1,
				desc = "A number. The index of the default tab.",
				trim = true,
				nilIfEmpty = true,
			},
			tab = {
				type = "string",
				required = true,
				desc = "The label for the tab button.",
				trim = true,
				nilIfEmpty = true,
			},
			content = {
				type = "string",
				required = true,
				desc = "The content to display for the tab.",
				trim = true,
				nilIfEmpty = true,
			},
		},
	},
}

return p