Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki
mNo edit summary
m (Protected "Module:UtilsLayout/Navbox": Critical wiki page ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
(5 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
local utilsCode = require("Module:UtilsCode")
 
local utilsCode = require("Module:UtilsCode")
   
  +
local SMALLEST_DESKTOP_SIZE = 600
function p.CreateNavbox(content, title, collapsed)
 
  +
 
function p.CreateNavbox(content, title, options)
 
local collapsed = options and options.collapsed
 
local thick = options and options.thick
 
local class = "navbox mw-collapsible"
 
local class = "navbox mw-collapsible"
  +
if thick then
if collapsed == true or collapsed == nil then -- For backwards compability, navboxes are collapsed by default
 
class = "navbox mw-collapsible mw-collapsed"
+
class = class .. " navbox-thick"
  +
end
  +
if collapsed ~= false then --collapsed is the default unless explicitly set to false.
  +
class = class .. " mw-collapsed"
 
end
 
end
 
result = mw.html.create("div")
 
result = mw.html.create("div")
Line 20: Line 27:
 
end
 
end
   
function p.CreateRowNavbox(rows, title, collapsed)
+
function p.CreateRowNavbox(rows, title, options)
 
local result = mw.html.create("table")
 
local result = mw.html.create("table")
 
:addClass("navbox-table")
 
:addClass("navbox-table")
Line 33: Line 40:
 
end
 
end
 
 
return p.CreateNavbox(tostring(result), title, collapsed)
+
return p.CreateNavbox(tostring(result), title, options)
 
end
 
end
   
Line 39: Line 46:
 
local defaultTab = options and options.defaultTab
 
local defaultTab = options and options.defaultTab
 
local minTabWidth = options and options.minTabWidth
 
local minTabWidth = options and options.minTabWidth
local minContainerWidth = options and options.minContainerWidth
 
 
local tabsPerRow = options and options.tabsPerRow
 
local tabsPerRow = options and options.tabsPerRow
 
if not tabsPerRow and minTabWidth then
local tabsWidth = options and options.tabsWidth
 
local contentAlign = options and options.contentAlign or "center"
 
local collapsed = options and options.collapsed
 
if not tabsPerRow and minTabWidth and minContainerWidth then
 
 
-- Calculate the number of tabs per row
 
-- Calculate the number of tabs per row
 
local rows = 0
 
local rows = 0
Line 50: Line 53:
 
rows = rows + 1
 
rows = rows + 1
 
local rowWidth = (minTabWidth * #tabs) / rows
 
local rowWidth = (minTabWidth * #tabs) / rows
until rowWidth <= minContainerWidth
+
until rowWidth <= SMALLEST_DESKTOP_SIZE
 
tabsPerRow = math.ceil(#tabs / rows)
 
tabsPerRow = math.ceil(#tabs / rows)
 
end
 
end
 
local tabbed = tab2.Main(tabs, defaultTab, "top", tabsPerRow, nil, nil, nil, "center")
local tabFormat = "top"
 
 
return p.CreateNavbox(tostring(tabbed), title, options)
local contentWidth = "100%"
 
local tabbed = tab2.Main(tabs, defaultTab, "top", tabsPerRow, tabsWidth, contentWidth, nil, contentAlign)
 
return p.CreateNavbox(tostring(tabbed), title, collapsed)
 
 
end
 
end
 
 

Revision as of 18:34, 4 August 2020

Lua error in package.lua at line 80: module 'Module:Tab2' not found.


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