Editing Module:Navbox
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local navbar = require('Module:Navbar')._navbar | local navbar = require('Module:Navbar')._navbar | ||
Line 71: | Line 70: | ||
end | end | ||
-- we will want this later when we want to add tstyles for hlist/plainlist | |||
local function has_navbar() | local function has_navbar() | ||
return args[cfg.arg.navbar] ~= cfg.keyword.navbar_off | return args[cfg.arg.navbar] ~= cfg.keyword.navbar_off | ||
Line 142: | Line 142: | ||
:tag('div') | :tag('div') | ||
-- id for aria-labelledby attribute, if no title | -- id for aria-labelledby attribute, if no title | ||
:attr('id', | :attr('id', args[cfg.arg.title] and nil or mw.uri.anchorEncode(args[cfg.arg.above])) | ||
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems])) | :wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems])) | ||
end | end | ||
Line 262: | Line 262: | ||
end | end | ||
-- uses this now to make the needHlistCategory correct | |||
-- to use later for when we add list styles via navbox | |||
local function has_list_class(htmlclass) | local function has_list_class(htmlclass) | ||
local class_args = { -- rough order of probability of use | |||
cfg.arg.bodyclass, cfg.arg.listclass, cfg.arg.aboveclass, | |||
cfg.arg.belowclass, cfg.arg.titleclass, cfg.arg.navboxclass, | |||
cfg.arg.groupclass, cfg.arg.imageclass | |||
} | |||
local patterns = { | local patterns = { | ||
'^' .. htmlclass .. '$', | '^' .. htmlclass .. '$', | ||
Line 270: | Line 277: | ||
} | } | ||
for arg | for _, arg in ipairs(class_args) do | ||
for _, pattern in ipairs(patterns) do | |||
if mw.ustring.find(args[arg] or '', pattern) then | |||
return true | |||
end | end | ||
end | end | ||
end | end | ||
return false | return false | ||
end | end | ||
Line 413: | Line 387: | ||
end | end | ||
local function add_navbox_styles( | local function add_navbox_styles() | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
-- This is a lambda so that it doesn't need the frame as a parameter | -- This is a lambda so that it doesn't need the frame as a parameter | ||
Line 431: | Line 405: | ||
local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles]) | local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles]) | ||
-- The 'navbox-styles' div exists | -- The 'navbox-styles' div exists for two reasons: | ||
-- | -- 1. To wrap the styles to work around T200206 more elegantly. Instead | ||
-- | -- of combinatorial rules, this ends up being linear number of CSS rules. | ||
-- 2. To allow MobileFrontend to rip the styles out with 'nomobile' such that | |||
-- they are not dumped into the mobile view. | |||
return mw.html.create('div') | return mw.html.create('div') | ||
:addClass(cfg.class.navbox_styles) | :addClass(cfg.class.navbox_styles) | ||
: | :addClass(cfg.class.nomobile) | ||
:wikitext(base_templatestyles .. templatestyles .. child_templatestyles) | |||
:done() | :done() | ||
end | end | ||
function p._navbox(navboxArgs) | function p._navbox(navboxArgs) | ||
args = navboxArgs | args = navboxArgs | ||
local listnums = {} | local listnums = {} | ||
Line 488: | Line 441: | ||
if border == cfg.keyword.border_none then | if border == cfg.keyword.border_none then | ||
res:node(add_navbox_styles( | res:node(add_navbox_styles()) | ||
local nav = res:tag('div') | local nav = res:tag('div') | ||
:attr('role', 'navigation') | :attr('role', 'navigation') | ||
Line 514: | Line 467: | ||
:wikitext('<div>') | :wikitext('<div>') | ||
else | else | ||
res:node(add_navbox_styles( | res:node(add_navbox_styles()) | ||
local nav = res:tag('div') | local nav = res:tag('div') | ||
:attr('role', 'navigation') | :attr('role', 'navigation') |