Module:Military navigation: Difference between revisions

Jump to navigation Jump to search
imported>Frietjes
(don't auto wrap lines with br tags)
m (Protected "Module:Military navigation": Important page ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(8 intermediate revisions by one other user not shown)
Line 14: Line 14:
     local args = { }
     local args = { }
     local pargs = frame:getParent().args
     local pargs = frame:getParent().args
    local sargs = {}
    local tcats = ''


-- process bodystyle and titlestyle
-- process bodystyle and titlestyle
Line 21: Line 23:
else
else
args['titlestyle'] = Styles['nav_box_header']
args['titlestyle'] = Styles['nav_box_header']
if (pargs['border'] or '') == 'child' then
if (pargs['border'] or '') == 'child' or
(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]]'
else
else
args['bodystyle'] = Styles['nav_box']
args['bodystyle'] = Styles['nav_box']
end
end
end
end
pargs['titlestyle'] = ''
sargs['titlestyle'] = 1
pargs['bodystyle'] = ''
sargs['bodystyle'] = 1


-- process groupstyle, abovestyle, belowstyle
-- process groupstyle, abovestyle, belowstyle
args['groupstyle'] = Styles['nav_box_label'] .. (pargs['groupstyle'] or '')
args['groupstyle'] = Styles['nav_box_label'] .. (pargs['groupstyle'] or '')
sargs['groupstyle'] = 1
args['abovestyle'] = Styles['nav_box_label'] .. (pargs['abovestyle'] or '')
args['abovestyle'] = Styles['nav_box_label'] .. (pargs['abovestyle'] or '')
sargs['abovestyle'] = 1
args['belowstyle'] = Styles['nav_box_label'] .. (pargs['belowstyle'] or '')
args['belowstyle'] = Styles['nav_box_label'] .. (pargs['belowstyle'] or '')
sargs['belowstyle'] = 1
-- process oddstyle, evenstyle
-- process oddstyle, evenstyle
args['oddstyle'] = isnotblank(pargs['odd_color'])
args['oddstyle'] = isnotblank(pargs['odd_color'])
and ('background:' .. pargs['odd_color']) or nil
and ('background:' .. pargs['odd_color']) or nil
sargs['oddstyle'] = 1
args['evenstyle'] = isnotblank(pargs['even_color'])
args['evenstyle'] = isnotblank(pargs['even_color'])
and ('background:' .. pargs['even_color']) or nil
and ('background:' .. pargs['even_color']) or nil
pargs['oddstyle'] = ''
sargs['evenstyle'] = 1
pargs['evenstyle'] = ''
-- process name and rawname
-- process name and rawname
args['name'] = (isnotblank(pargs['name']) and pargs['name']) 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
pargs['name'] = ''
sargs['name'] = 1
pargs['rawname'] = ''
sargs['rawname'] = 1
     -- copy the remaining args
     -- copy the remaining args
     for k, v in pairs(pargs) do
     for k, v in pairs(pargs) do
         if v and v ~= '' then
         if v and v ~= '' and sargs[k] == nil then
             args[k] = v
             args[k] = v
         end
         end
Line 56: Line 63:
if args['title'] and (pargs['style'] or '') ~= '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
local p = '[^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|]'
-- probably a more efficient way to match 15 or more characters
local p = p .. p .. p
local m = '[^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|]'
m = m .. m .. m
args['title'] = mw.ustring.gsub(args['title'],  
args['title'] = mw.ustring.gsub(args['title'],  
'%[%[(' .. p .. '[^%[%]<>|]*)%]%]',  
'%[%[(' .. m .. '[^%[%]<>|]*)%]%]',  
'[[%1|<span class="wrap">%1</span>]]')
'[[%1|<span class="wrap">%1</span>]]')
args['title'] = mw.ustring.gsub(args['title'],  
args['title'] = mw.ustring.gsub(args['title'],  
'%[%[([^%[%]<>|]*)|(' .. p .. '[^%[%]<>|]*)%]%]',  
'%[%[([^%[%]<>|]*)|(' .. m .. '[^%[%]<>|]*)%]%]',  
'[[%1|<span class="wrap">%2</span>]]')
'[[%1|<span class="wrap">%2</span>]]')
end
end
end
end
     return Navbox._navbox(args)
-- add navbox-vertical for non-wide format
if (pargs['style'] or '') ~= 'wide' then
args['bodyclass'] = 'navbox-vertical' .. (args['bodyclass'] and (' ' .. args['bodyclass']) or '')
end
     return tcats .. Navbox._navbox(args)


end   
end   


return p
return p

Latest revision as of 03:34, 15 September 2023

Documentation for this module may be created at Module:Military navigation/doc

local p = { }

local Navbox = require('Module:Navbox')
local Styles = require('Module:WPMILHIST Infobox style')

local function isblank(s)
	return (not s) or s == ''
end
local function isnotblank(s)
	return s and s ~= ''
end

function p.main(frame)
    local args = { }
    local pargs = frame:getParent().args
    local sargs = {}
    local tcats = ''

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

	-- process groupstyle, abovestyle, belowstyle
	args['groupstyle'] = Styles['nav_box_label'] .. (pargs['groupstyle'] or '')
	sargs['groupstyle'] = 1
	args['abovestyle'] = Styles['nav_box_label'] .. (pargs['abovestyle'] or '')
	sargs['abovestyle'] = 1
	args['belowstyle'] = Styles['nav_box_label'] .. (pargs['belowstyle'] or '')
	sargs['belowstyle'] = 1
	-- process oddstyle, evenstyle
	args['oddstyle'] = isnotblank(pargs['odd_color'])
		and ('background:' .. pargs['odd_color']) or nil
	sargs['oddstyle'] = 1
	args['evenstyle'] = isnotblank(pargs['even_color'])
		and ('background:' .. pargs['even_color']) or nil
	sargs['evenstyle'] = 1
	-- process name and rawname
	args['name'] = (isnotblank(pargs['name']) and pargs['name']) or pargs['rawname']
	if isblank(args['name']) then args['navbar'] = 'plain' end
	sargs['name'] = 1
	sargs['rawname'] = 1
	
    -- copy the remaining args
    for k, v in pairs(pargs) do
        if v and v ~= '' and sargs[k] == nil then
            args[k] = v
        end
    end
	-- add allow wrap
	if args['title'] and (pargs['style'] or '') ~= 'wide' then
		if not mw.ustring.match(args['title'], '<span class="wrap">') then
			-- probably a more efficient way to match 15 or more characters
			local m = '[^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|]'
			m = m .. m .. m
			args['title'] = mw.ustring.gsub(args['title'], 
				'%[%[(' .. m .. '[^%[%]<>|]*)%]%]', 
				'[[%1|<span class="wrap">%1</span>]]')
			args['title'] = mw.ustring.gsub(args['title'], 
				'%[%[([^%[%]<>|]*)|(' .. m .. '[^%[%]<>|]*)%]%]', 
				'[[%1|<span class="wrap">%2</span>]]')
		end
	end
	
	-- add navbox-vertical for non-wide format
	if (pargs['style'] or '') ~= 'wide' then
		args['bodyclass'] = 'navbox-vertical' .. (args['bodyclass'] and (' ' .. args['bodyclass']) or '')
	end
	
    return tcats .. Navbox._navbox(args)

end  

return p