Module:Navbox Canada

-- This module implements {{Navbox Canada}}
local p = {}

local Navbox = require('Module:Navbox')

local function bordercss(t)
	c = '#CC0000'
	local s = ''
	if t == 'a' then
		s = 'inset 1px 1px 0 ' .. c .. ', inset -1px -1px 0 ' .. c
	elseif t == 't' then
		s = 'inset 0 1px 0 0 ' .. c
	elseif t == 'b' then
		s = 'inset 0 -1px 0 0 ' .. c
	elseif t == 'tb' then
		s = 'inset 0 1px 0 ' .. c .. ', inset 0 -1px 0 ' .. c
	else
		return ''
	end
	
	return '-moz-box-shadow: ' .. s .. '; -webkit-box-shadow: ' .. s .. '; box-shadow: ' .. s .. ';'
end

function p.navbox(frame)
	-- table for args passed to navbox
	local targs = {}
	
	-- helper functions
	local function isnotempty(t) return t and t ~= '' end
	local function prependarg(k, v)	targs[k] = v .. (targs[k] or '') end

	local listcount = 0
	local collapsiblegroups = nil
	local firstnum = 1
	local lastnum = 0
	local leaf = nil
	local borders = ''
	local ischild = nil
	local topborder, notopborder = nil, nil
	local bottomborder, nobottomborder = nil, nil
	
	-- process args, almost all of which are just copied to targs
	for k,v in pairs(frame:getParent().args) do
		if type(k) == 'string' and k:match('^list[0-9][0-9]*$') then
			if isnotempty(v) then
				listcount = listcount + 1
				local num = mw.ustring.gsub(k,'^list([0-9][0-9]*)$', '%1')
				firstnum = (tonumber(num) < firstnum or listcount == 1) and tonumber(num) or firstnum
				lastnum = (tonumber(num) > lastnum or listcount == 1) and tonumber(num) or lastnum
				targs[k] = v
			end
		elseif k == 'leaf' and isnotempty(v) then
			leaf = 1
		elseif k == 'collapsible groups' and isnotempty(v) then
			collapsiblegroups = 1
		elseif k == 'topborder' and isnotempty(v) then
			topborder = 1
		elseif k == 'notopborder' and isnotempty(v) then
			notopborder = 1
		elseif k == 'bottomborder' and isnotempty(v) then
			bottomborder = 1
		elseif k == 'nobottomborder' and isnotempty(v) then
			nobottomborder = 1
		elseif isnotempty(v) then
			targs[k] = v
		end
	end
	-- child or subgroup
	if targs['border'] or targs[1] then
		local v = targs['border'] or targs[1]
		if v == 'child' or v == 'subgroup' then
			ischild = 1
		end
	end

	-- hlist bodyclass
	prependarg('bodyclass', 'hlist ')

	-- leaf
	if leaf then
		prependarg('title', 
				'<span style="vertical-align: 1px; padding-right:0.2em">' ..
				'[[File:Maple Leaf (from roundel).svg|20x20px|link=|alt=]]' .. 
				'</span> ')
	end
	
	-- basestyle
	prependarg('basestyle', 'background-color:white;')
	
	-- liststyle
	prependarg('liststyle', 'background-color:white;')
	
	-- abovestyle
	prependarg('abovestyle', bordercss('t'))
	
	-- groupstyle
	prependarg('groupstyle', bordercss('a'))
	
	-- imagestyle
	if targs['image'] then
		borders = (notopborder == nil and 't' or '')
		if targs['below'] or ischild ~= nil then
			borders = borders .. (nobottomborder == nil and 'b' or '')
		else
			borders = borders .. (bottomborder == 1 and 'b' or '')
		end
		if borders ~= '' then
			prependarg('imagestyle', bordercss(borders))
		end
		if borders ~= '' then
			prependarg('imagestyle', bordercss(borders))
		end
		prependarg('imagestyle', 'background-color:white;')
	end
	
	-- first and last list style
	if lastnum == firstnum then
		borders = ''
		if collapsiblegroups == nil and ischild == nil then
			borders = borders .. (notopborder == nil and 't' or '')
		end
		if targs['below'] or ischild ~= nil then
			borders = borders .. (nobottomborder == nil and 'b' or '')
		else
			borders = borders .. (bottomborder == 1 and 'b' or '')
		end
		if borders ~= '' then
			prependarg('list' .. firstnum .. 'style', bordercss(borders))
		end
	elseif lastnum > firstnum then
		if collapsiblegroups == nil and notopborder == nil then
			prependarg('list' .. firstnum .. 'style', bordercss('t'))
		end
		if (targs['below'] and nobottomborder == nil) or (bottomborder == 1) then
			prependarg('list' .. lastnum .. 'style', bordercss('b'))
		end
	end

	-- pass the process args to navbox or navbox with collapsible groups
	if collapsiblegroups then
		return frame:expandTemplate{ title = 'Navbox with collapsible groups', args = targs }
	else
		return Navbox._navbox(targs)
	end
	
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.