July 25, 2020

👭 Knight Challenge #11 👬

Want to try your hand at these challenges? There's a couple of things you can do!
From writing, to research, to images, find your preferred way to contribute with our eleventh theme: Couples!

Latest Announcements

Module:UtilsLayout/Navbox

From Zelda Wiki, the Zelda encyclopedia
Jump to: navigation, search

local p = {}

local tab2 = require("Module:Tab2")
local utilsCode = require("Module:UtilsCode")

local SMALLEST_DESKTOP_SIZE = 600

function p.CreateNavbox(content, title, options)
	local collapsed = options and options.collapsed
	local thick = options and options.thick
	local class = "navbox mw-collapsible"
	if thick then
		class = class .. " navbox-thick"
	end
	if collapsed ~= false then --collapsed is the default unless explicitly set to false.
		class = class .. " mw-collapsed"
	end
	result = mw.html.create("div")
		:addClass(class)
		:node(mw.html.create("div")
			:addClass("navbox-title")
			:wikitext(title))
		:node(mw.html.create("div")
			:addClass("navbox-links mw-collapsible-content")
			:wikitext(content))
	return tostring(result)
end

function p.CreateRowNavbox(rows, title, options)
	local result = mw.html.create("table")
		:addClass("navbox-table")
	for key, row in ipairs(rows) do
		if not utilsCode.IsEmpty(row["content"]) then
			result:node(mw.html.create("tr")
				:node(mw.html.create("th")
					:wikitext(row["title"])
				:node(mw.html.create("td")
					:wikitext(row["content"]))))
		end
	end
	
	return p.CreateNavbox(tostring(result), title, options)
end

function p.CreateTabbedNavbox(title, tabs, options)
	local defaultTab = options and options.defaultTab
	local minTabWidth = options and options.minTabWidth
	local tabsPerRow = options and options.tabsPerRow
	if not tabsPerRow and minTabWidth then
		-- Calculate the number of tabs per row
		local rows = 0
		repeat
			rows = rows + 1
			local rowWidth = (minTabWidth * #tabs) / rows
		until rowWidth <= SMALLEST_DESKTOP_SIZE
		tabsPerRow = math.ceil(#tabs / rows)
	end
	local tabbed = tab2.Main(tabs, defaultTab, "top", tabsPerRow, nil, nil, nil, "center")
	return p.CreateNavbox(tostring(tabbed), title, options)
end
	
return p