Module:MovementTabs: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Gammaton32 (talk | contribs) m Reverted edit by Gammaton32 (talk) to last revision by Monster Domosed Tag: Rollback |
No edit summary |
||
| Line 8: | Line 8: | ||
local current = mw.title.getCurrentTitle().fullText | local current = mw.title.getCurrentTitle().fullText | ||
local rootPage = args[1] or current | local rootPage = args[1] or current | ||
local lang_code = lang_module.get_lang_code() | local lang_code = lang_module.get_lang_code() | ||
local lang_suffix = (lang_code ~= "en") and ("/" .. lang_code) or "" | local lang_suffix = (lang_code ~= "en") and ("/" .. lang_code) or "" | ||
| Line 20: | Line 17: | ||
end | end | ||
local html = mw.html.create("div") | -- Create outer container using your new CSS class | ||
local html = mw.html.create("div"):addClass("hero-tabs") | |||
for _, tab in ipairs(tabs) do | for _, tab in ipairs(tabs) do | ||
| Line 47: | Line 31: | ||
local active = current == pagePlain or current == pagePlain .. lang_suffix | local active = current == pagePlain or current == pagePlain .. lang_suffix | ||
local div = html:tag("div") | local div = html:tag("div"):addClass("hero-tab") | ||
if active then | if active then | ||
div:wikitext(string.format('[[:%s| | div:addClass("hero-tab-active") | ||
div:wikitext(string.format('[[:%s|%s]]', pageTarget, tab)) | |||
else | else | ||
div:wikitext(string.format('[[:%s|<span | div:wikitext(string.format('[[:%s|<span class="hero-tab-inactive">%s</span>]]', pageTarget, tab)) | ||
end | end | ||
end | end | ||
Latest revision as of 11:02, 18 July 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
-- Create outer container using your new CSS class
local html = mw.html.create("div"):addClass("hero-tabs")
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"):addClass("hero-tab")
if active then
div:addClass("hero-tab-active")
div:wikitext(string.format('[[:%s|%s]]', pageTarget, tab))
else
div:wikitext(string.format('[[:%s|<span class="hero-tab-inactive">%s</span>]]', pageTarget, tab))
end
end
return tostring(html)
end
return p