Module:Handball color
From EverybodyWiki Bios & Wiki
| This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
This module is used by
- {{Handball color}}, {{Handball color cell}}, {{Handball color cell2}},
- {{THL color}}, {{THL color cell}}, {{THL color cell2}}
- {{Infobox handball biography/style}}
Usage
{{#invoke:Handball color|color}}in any of the various color templates{{#invoke:Handball color|colorcell}}in any of the various color cell templates{{#invoke:Handball color|colorcell2}}in any of the various color cell2 templates{{#invoke:Handball color|check}}to check to see if a team has defined colors
Updating team colors
See Module:Handball color/data.
Test table
| Team | 1 | 2 | 3 | 4 | Contrast | |
|---|---|---|---|---|---|---|
| 1/2 | 4/3 | |||||
| D.C. Diplomats THC Also known as D.C. Diplomats THC (men) Also known as D.C. Diplomats THC (women) | 19.56 | 2.22 | ||||
| Northeast Team Handball League | 8.49 | 4.35 | ||||
| Portland Sasquatch THC | 1.41 | 15.61 | ||||
| USMA-West Point Gold Also known as USMA-West Point Gold (women) Also known as USMA-West Point Gold (men) | 13.4 | 21 | ||||
| USMA-West Point THC Also known as USMA-West Point Black (women) Also known as USMA-West Point Black (men) Also known as USMA-West Point Black | 13.4 | 21 | ||||
| United States National Handball Team | 14.25 | 4.71 | ||||
| United States Women's National Handball Team | 14.25 | 4.71 | ||||
| Western Team Handball League | 4.35 | 8.49 | ||||
| Free agent | X | X | 15.31 | |||
| Retired | X | X | 15.31 | |||
The numeric columns are the calculated contrast ratio for the first/second and the fourth/third colors. Anything lower than 3 is very poor contrast and should be changed in the data module. For more information, see Template:Color contrast ratio.
--
-- This module implements
-- {{THL color}}, {{THL color cell}}, {{THL color cell2}}
--
local p = {}
local data_module = "Module:Handball color/data"
local function stripwhitespace(text)
return text:match("^%s*(.-)%s*$")
end
local function get_colors(team, unknown)
team = stripwhitespace(team or '')
unknown = unknown or {"DCDCDC", "000000", "000000", "FFFFFF"}
local use_default = {
[""] = 1,
["retired"] = 1,
["free agent"] = 1,
}
local colors = nil
if ( team and use_default[team:lower()] ) then
colors = {"DCDCDC", "000000", "DCDCDC", "FFFFFF"}
else
local all_colors = mw.loadData(data_module)
colors = all_colors[team]
if ( colors and type(colors) == 'string' ) then
colors = all_colors[colors]
end
end
return colors or unknown
end
local function team_color(team, num)
local colors = get_colors(team, nil)
num = tonumber(num:match('[1-4]') or '0')
if ( num ) then
return colors[num]
else
return ''
end
end
local function team_colorcell(team, borderwidth, bg, fg, bd)
local colors = get_colors(team, nil)
local border = ''
borderwidth = borderwidth or ''
if (borderwidth ~= '') then
border = 'border:' .. borderwidth .. 'px solid #' .. stripwhitespace(colors[bd]) .. ';'
end
return 'background-color:#' .. stripwhitespace(colors[bg]) .. ';color:#' .. stripwhitespace(colors[fg]) .. ';' .. border
end
local function team_check(team, unknown)
local colors = get_colors(team, unknown)
if type(colors) == 'table' then
return 'known'
else
return unknown
end
end
function p.color(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_color(args[1] or '', args[2] or '')
end
function p.colorcell(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_colorcell(args[1] or '', args['border'] or '', 1, 2, 3)
end
function p.colorcell2(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_colorcell(args[1] or '', args['border'] or '', 3, 4, 1)
end
function p.check(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_check(args[1] or '', args[2] or '')
end
return p
