Home
Random
Log in
Settings
About the Deadlock Wiki
Search
Editing
Module
:
HeroTabs
Give feedback
Warning:
You are not logged in. Once you make an edit, a temporary account will be created for you.
Learn more
.
Log in
or
create an account
to continue receiving notifications after this account expires, and to access other features.
Anti-spam check. Do
not
fill this in!
local p = {} local lang_module = require('Module:Lang') local dictionary_module = require('Module:Dictionary') -- Tab bar definition, in display order. -- subpage : subpage name appended to the base page ('' = the base page itself) -- key : translation key -- source : 'dictionary' (via Module:Dictionary) or 'lang' (via Module:Lang, Valve strings) local TABS = { { subpage = '', key = 'Overview', source = 'dictionary' }, { subpage = 'Update_history', key = 'Update history', source = 'dictionary' }, { subpage = 'Strategy', key = 'Strategy', source = 'dictionary' }, { subpage = 'Movement', key = 'Citadel_ShopFilter_Movement', source = 'lang' }, { subpage = 'Lore', key = 'Lore', source = 'dictionary' }, { subpage = 'Voice_lines', key = 'Voice lines', source = 'dictionary' }, { subpage = 'Sounds', key = 'Sounds', source = 'dictionary' }, { subpage = 'Music', key = 'Music', source = 'dictionary' }, } local function lang_suffix() local code = lang_module.get_lang_code() if code == 'en' then return '' end return '/' .. code end local function get_label(tab) if tab.source == 'lang' then return lang_module.get_string(tab.key) end return dictionary_module.translate(tab.key) end -- Returns the title object of the first page that exists, or nil. -- Checks the localized page first, then falls back to the unlocalized one. local function resolve_target(base, subpage, suffix) local path = base if subpage ~= '' then path = path .. '/' .. subpage end if suffix ~= '' then local localized = mw.title.new(path .. suffix) if localized and localized.exists then return localized end end local plain = mw.title.new(path) if plain and plain.exists then return plain end return nil end function p.render(frame) local args = frame.args local current = mw.title.getCurrentTitle() local base = args[1] if not base or base == '' then base = current.rootText end local suffix = lang_suffix() local root = mw.html.create('div') :addClass('hero-tabs') for _, tab in ipairs(TABS) do local target = resolve_target(base, tab.subpage, suffix) if target then local is_active = (target.fullText == current.fullText) root:tag('div') :addClass('hero-tab') :addClass(is_active and 'hero-tab-active' or 'hero-tab-inactive') :wikitext(string.format('[[%s|<span>%s</span>]]', target.fullText, get_label(tab))) end end return frame:extensionTag{ name = 'templatestyles', args = { src = 'HeroTabs/styles.css' } } .. tostring(root) end return p
Summary:
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Deadlock:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Page included on this page:
Module:HeroTabs/doc
(
view source
)