Module:MovementTabs: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local lang_module = require("Module:Lang") | |||
function p.render(frame) | function p.render(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local tabsStr = args[2] and args[2] or args[1] or "" | local tabsStr = args[2] and args[2] or args[1] or "" | ||
local tabs = mw.text.split(tabsStr, "%s*,%s*") | |||
local current = mw.title.getCurrentTitle().fullText | local current = mw.title.getCurrentTitle().fullText | ||
local | local rootPage = args[1] or current | ||
local lang_code = lang_module.get_lang_code() | |||
local lang_suffix = (lang_code ~= "en") and ("/" .. lang_code) or "" | |||
-- Remove lang suffix from root if present | |||
if lang_suffix ~= "" and rootPage:sub(-#lang_suffix) == lang_suffix then | |||
rootPage = rootPage:sub(1, -#lang_suffix - 1) | |||
end | end | ||
| Line 36: | Line 33: | ||
["font-weight"]="bold", | ["font-weight"]="bold", | ||
["font-size"]="15px", | ["font-size"]="15px", | ||
["padding"]=" | ["padding"]="0px" | ||
} | } | ||
for _, tab in ipairs(tabs) do | for _, tab in ipairs(tabs) do | ||
local | local pageTarget | ||
local active = current == | if tab == "Overview" then | ||
pageTarget = rootPage .. lang_suffix | |||
else | |||
pageTarget = rootPage .. "/" .. tab .. lang_suffix | |||
end | |||
local pagePlain = tab == "Overview" and rootPage or (rootPage .. "/" .. tab) | |||
local active = current == pagePlain or current == pagePlain .. lang_suffix | |||
html:tag("div") | local div = html:tag("div") | ||
:css{ | :css{ | ||
["padding"]="4px 8px", | ["padding"]="4px 8px", | ||
["cursor"]="pointer", | ["cursor"]="pointer", | ||
["border-radius"]=active and "4px 4px 0 0" or nil, | ["border-radius"]=active and "4px 4px 0 0" or nil, | ||
["background-color"]=active and "#FFF0D6 | ["background-color"]=active and "#FFF0D6" or nil | ||
} | } | ||
:wikitext(string.format( | |||
if active then | |||
div:wikitext(string.format('[[:%s|<span style="color:#483728;">%s</span>]]', pageTarget, tab)) | |||
else | |||
)) | div:wikitext(string.format('[[:%s|<span style="color:#FFF0D6; text-shadow: 0px 2px 2px black, 0px 0px 2px black;">%s</span>]]', pageTarget, tab)) | ||
end | |||
end | end | ||
Revision as of 00:02, 15 January 2026
Documentation for this module may be created at Module:MovementTabs/doc
local p = {}
local lang_module = require("Module:Lang")
function p.render(frame)
local args = frame:getParent().args
local tabsStr = args[2] and args[2] or args[1] or ""
local tabs = mw.text.split(tabsStr, "%s*,%s*")
local current = mw.title.getCurrentTitle().fullText
local rootPage = args[1] or current
local lang_code = lang_module.get_lang_code()
local lang_suffix = (lang_code ~= "en") and ("/" .. lang_code) or ""
-- Remove lang suffix from root if present
if lang_suffix ~= "" and rootPage:sub(-#lang_suffix) == lang_suffix then
rootPage = rootPage:sub(1, -#lang_suffix - 1)
end
local html = mw.html.create("div")
:css{
["border-radius"]="8px",
["background-image"]="linear-gradient(#987556, #483728)",
["color"]="#FFF5E8",
["display"]="flex",
["flex-wrap"]="wrap",
["justify-content"]="center",
["gap"]="1em",
["font-family"]="Retail Demo, Radiance, sans-serif",
["text-transform"]="uppercase",
["font-weight"]="bold",
["font-size"]="15px",
["padding"]="0px"
}
for _, tab in ipairs(tabs) do
local pageTarget
if tab == "Overview" then
pageTarget = rootPage .. lang_suffix
else
pageTarget = rootPage .. "/" .. tab .. lang_suffix
end
local pagePlain = tab == "Overview" and rootPage or (rootPage .. "/" .. tab)
local active = current == pagePlain or current == pagePlain .. lang_suffix
local div = html:tag("div")
:css{
["padding"]="4px 8px",
["cursor"]="pointer",
["border-radius"]=active and "4px 4px 0 0" or nil,
["background-color"]=active and "#FFF0D6" or nil
}
if active then
div:wikitext(string.format('[[:%s|<span style="color:#483728;">%s</span>]]', pageTarget, tab))
else
div:wikitext(string.format('[[:%s|<span style="color:#FFF0D6; text-shadow: 0px 2px 2px black, 0px 0px 2px black;">%s</span>]]', pageTarget, tab))
end
end
return tostring(html)
end
return p