Module:Gridiron color/sandbox
![]() | This is the module sandbox page for Module:Gridiron color (diff). |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively 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 subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 37,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | The accessibility of this module is in question. The specific issue is: insufficient color contrast for some teams. Relevant discussion may be found on the talk page. |
![]() | This module depends on the following other modules: |
Implements:
- {{Gridiron primary color}}
- {{Gridiron primary style}}
- {{Gridiron alt primary style}}
- {{Gridiron secondary color}}
- {{Gridiron alt primary color}}
- {{Gridiron alt secondary color}}
Uses color data from Module:Gridiron color/data.
Usage
Debugging
Displays entire row from Module:Gridiron color/data for team and year passed in template call or using |team=
and |year=
(if omitted from invoke, module will take values from the template call):
{{#invoke:Gridiron color|test|team=team name (optional)|year=#### (optional)}}
Script error: The function "test" does not exist.
Return team color
Returns either raw color value or prefixed color value. |column=
uses the following values:
- Primary color (background)
- Secondary color (text)
- Tertiary color raw (border)
- Alt primary color
- Alt secondary color
Set |raw=true
to display raw hex values. Team name and year passed in template call or specified using |team=
and |year=
:
{{#invoke:Gridiron color|color|column=#|raw=true (optional)|team=team name (optional)|year=#### (optional)}}
Return team style
Returns complete CSS style for given team. A border will be displayed using the tertiary color if |border=
is set to "true" (in which case the border will be 2px wide) or to a positive integer value (in which case the width will be the value specified in pixels). Team name and year passed in template call or specified using |team=
and |year=
:
{{#invoke:Gridiron color|style|border=# or yes (optional)|team=team name (optional)|year=#### (optional)}}
Script error: The function "style" does not exist.
--
-- This module implements
-- {{Gridiron primary color}} -- {{Gridiron primary color raw}} -- {{Gridiron primary style}}
-- {{Gridiron secondary color}} -- {{Gridiron secondary color raw}}
-- {{Gridiron tertiary color raw}}
-- {{Gridiron alt primary color}} -- {{Gridiron alt secondary color}}
--
local p = {}
local data_module = "Module:Gridiron 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", "", "", "", ""}
local use_default = {
[""] = 1,
["retired"] = 1,
["free agent"] = 1,
}
local colors = nil
if ( team and use_default[team:lower()] ) then
colors = unknown
elseif tonumber(year) and tonumber(year) > 0 then
-- code for handling year parameter
elseif mw.ustring.find(team, "%d%dthru%d%d") then
-- code for handling 2-digit year parameter
elseif mw.ustring.find(team, "%d%d%d%dthru%d%d%d%d") then
-- code for handling 4-digit year parameter
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 bordercss(c, w)
local s = 'inset ' .. w .. 'px ' .. w .. 'px 0 #' .. c
.. ', inset -' .. w .. 'px -' .. w .. 'px 0 #' .. c
return '-moz-box-shadow: ' .. s .. '; -webkit-box-shadow: ' .. s .. '; box-shadow: ' .. s .. ';'
end
local function team_colorcell(team, borderwidth, bg, fg, bd, simple)
local colors = get_colors(team, nil)
local border = ''
borderwidth = borderwidth or ''
if (borderwidth ~= '') then
if simple then
border = 'border:' .. borderwidth .. 'px solid #' .. stripwhitespace(colors[bd]) .. ';'
else
border = bordercss(stripwhitespace(colors[bd]), borderwidth)
end
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, args['simple'] and 1 or nil )
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, args['simple'] and 1 or nil )
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