Jump to content

Module:Military navigation and Module:Military navigation/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
give frame priority over parent to avoid script errors
 
sync
 
Line 7: Line 7:
return (not s) or s == ''
return (not s) or s == ''
end
end
local function ifnotblank(s,p,t)
local function isnotblank(s)
return (s and s ~= '') and (p..s) or t
return s and s ~= ''
end
end


Line 14: Line 14:
local args = { }
local args = { }
local pargs = frame:getParent().args
local pargs = frame:getParent().args
local fargs = frame.args
local sargs = {}
local sargs = {}
local tcats = ''
local tcats = ''


-- process bodystyle and titlestyle
-- process bodystyle and titlestyle
local style = fargs['style'] or pargs['style'] or ''
if (pargs['style'] or '') == 'wide' then
if style == 'wide' then
args['titlestyle'] = Styles['nav_box_wide_header']
args['titlestyle'] = Styles['nav_box_wide_header']
args['bodystyle'] = Styles['nav_box_wide']
args['bodystyle'] = Styles['nav_box_wide']
else
else
args['titlestyle'] = Styles['nav_box_header']
args['titlestyle'] = Styles['nav_box_header']
local border = fargs['border'] or pargs['border'] or ''
if (pargs['border'] or '') == 'child' or
if border == 'child' or border == 'subgroup' then
(pargs['border'] or '') == 'subgroup' then
args['bodystyle'] = Styles['nav_box_child']
args['bodystyle'] = Styles['nav_box_child']
tcats = tcats .. '[[Category:Pages using military navigation subgroups without wide style]]'
tcats = tcats .. '[[Category:Pages using military navigation subgroups without wide style]]'
Line 37: Line 35:


-- process groupstyle, abovestyle, belowstyle
-- process groupstyle, abovestyle, belowstyle
args['groupstyle'] = Styles['nav_box_label'] .. (fargs['groupstyle'] or pargs['groupstyle'] or '')
args['groupstyle'] = Styles['nav_box_label'] .. (pargs['groupstyle'] or '')
sargs['groupstyle'] = 1
sargs['groupstyle'] = 1
args['abovestyle'] = Styles['nav_box_label'] .. (fargs['abovestyle'] or pargs['abovestyle'] or '')
args['abovestyle'] = Styles['nav_box_label'] .. (pargs['abovestyle'] or '')
sargs['abovestyle'] = 1
sargs['abovestyle'] = 1
args['belowstyle'] = Styles['nav_box_label'] .. (fargs['belowstyle'] or pargs['belowstyle'] or '')
args['belowstyle'] = Styles['nav_box_label'] .. (pargs['belowstyle'] or '')
sargs['belowstyle'] = 1
sargs['belowstyle'] = 1
-- process oddstyle, evenstyle
-- process oddstyle, evenstyle
args['oddstyle'] = ifnotblank((fargs['odd_color'] or pargs['odd_color']),'background:',nil)
args['oddstyle'] = isnotblank(pargs['odd_color'])
and ('background:' .. pargs['odd_color']) or nil
args['evenstyle'] = ifnotblank((fargs['even_color'] or pargs['even_color']),'background:',nil)
sargs['oddstyle'] = 1
sargs['oddstyle'] = 1
args['evenstyle'] = isnotblank(pargs['even_color'])
and ('background:' .. pargs['even_color']) or nil
sargs['evenstyle'] = 1
sargs['evenstyle'] = 1
-- process name and rawname
-- process name and rawname
args['name'] = ifnotblank((fargs['name'] or pargs['name']),'',(fargs['rawname'] or pargs['rawname']))
args['name'] = (isnotblank(pargs['name']) and pargs['name']) or pargs['rawname']
if isblank(args['name']) then args['navbar'] = 'plain' end
if isblank(args['name']) then args['navbar'] = 'plain' end
sargs['name'] = 1
sargs['name'] = 1
sargs['rawname'] = 1
sargs['rawname'] = 1
-- copy the remaining args, with frame args overriding parent args
-- copy the remaining args
for k, v in pairs(pargs) do
for k, v in pairs(pargs) do
if v and v ~= '' and sargs[k] == nil then
args[k] = v
end
end
for k, v in pairs(fargs) do
if v and v ~= '' and sargs[k] == nil then
if v and v ~= '' and sargs[k] == nil then
args[k] = v
args[k] = v
Line 66: Line 61:
end
end
-- add allow wrap
-- add allow wrap
if args['title'] and style ~= 'wide' then
if args['title'] and (pargs['style'] or '') ~= 'wide' then
if not mw.ustring.match(args['title'], '<span class="wrap">') then
if not mw.ustring.match(args['title'], '<span class="wrap">') then
-- probably a more efficient way to match 15 or more characters
-- probably a more efficient way to match 15 or more characters
Line 81: Line 76:
-- add navbox-vertical for non-wide format
-- add navbox-vertical for non-wide format
if style ~= 'wide' then
if (pargs['style'] or '') ~= 'wide' then
args['bodyclass'] = 'navbox-vertical' .. (args['bodyclass'] and (' ' .. args['bodyclass']) or '')
args['bodyclass'] = 'navbox-vertical' .. (args['bodyclass'] and (' ' .. args['bodyclass']) or '')
end
end