<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FAhecht%2FGridiron_color</id>
	<title>Module:Sandbox/Ahecht/Gridiron color - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FAhecht%2FGridiron_color"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Ahecht/Gridiron_color&amp;action=history"/>
	<updated>2026-05-24T07:22:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/Ahecht/Gridiron_color&amp;diff=145039&amp;oldid=prev</id>
		<title>imported&gt;Ahecht: simplify, make more robust</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Ahecht/Gridiron_color&amp;diff=145039&amp;oldid=prev"/>
		<updated>2018-06-19T22:14:52Z</updated>

		<summary type="html">&lt;p&gt;simplify, make more robust&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- This module implements&lt;br /&gt;
-- {{Gridiron primary color}} -- {{Gridiron primary color raw}} -- {{Gridiron primary style}}&lt;br /&gt;
-- {{Gridiron secondary color}} -- {{Gridiron secondary color raw}}&lt;br /&gt;
-- {{Gridiron tertiary color raw}}&lt;br /&gt;
-- {{Gridiron alt primary color}} -- {{Gridiron alt primary style}} -- {{Gridiron alt secondary color}}&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local color_data = mw.loadData(&amp;quot;Module:Gridiron color/data/sandbox&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local prefixes = {&lt;br /&gt;
	&amp;quot;background: &amp;quot;,&lt;br /&gt;
	&amp;quot;color: &amp;quot;,&lt;br /&gt;
	&amp;quot;&amp;quot;,&lt;br /&gt;
	&amp;quot;background: &amp;quot;,&lt;br /&gt;
	&amp;quot;color: &amp;quot;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
local function get_year(colors, year)&lt;br /&gt;
	year = tonumber(year)&lt;br /&gt;
	if year and (year &amp;gt; 0) and colors and colors[6] and type(colors[6] == &amp;#039;table&amp;#039;) then&lt;br /&gt;
		local end_year = nil&lt;br /&gt;
		for k in pairs(colors[6]) do&lt;br /&gt;
			if (year &amp;lt;= k) and (k &amp;lt; (end_year or 32767)) then end_year = k end&lt;br /&gt;
		end&lt;br /&gt;
		if end_year then return colors[6][end_year] end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return colors&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function get_colors(team, unknown, year)&lt;br /&gt;
	team = (team or &amp;#039;&amp;#039;):match(&amp;quot;^%s*(.-)%s*$&amp;quot;)&lt;br /&gt;
	year = tonumber(year)&lt;br /&gt;
	unknown = unknown or color_data[&amp;quot;#default&amp;quot;] or {&amp;quot;#DCDCDC&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;none&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;}&lt;br /&gt;
	&lt;br /&gt;
	local use_default = {&lt;br /&gt;
		[&amp;quot;&amp;quot;] = 1,&lt;br /&gt;
		[&amp;quot;retired&amp;quot;] = 1,&lt;br /&gt;
		[&amp;quot;free agent&amp;quot;] = 1,&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	local colors = nil&lt;br /&gt;
	&lt;br /&gt;
	if ( team and use_default[team:lower()] ) then&lt;br /&gt;
		colors = unknown&lt;br /&gt;
	else&lt;br /&gt;
		if mw.ustring.find(team, &amp;quot;%d?%d?%d%dthru%d?%d?%d%d$&amp;quot;) then&lt;br /&gt;
			if (not year or year &amp;lt;= 0) then&lt;br /&gt;
				team, year = mw.ustring.match(team, &amp;quot;^(.-)(%d?%d?%d%d)thru%d?%d?%d%d$&amp;quot;)&lt;br /&gt;
				team, year = team:match(&amp;quot;^%s*(.-)%s*$&amp;quot;), tonumber(year)&lt;br /&gt;
				&lt;br /&gt;
				if year &amp;gt;= 20 and year &amp;lt; 100 then -- Two-digit years were deprecated in 2018&lt;br /&gt;
					year = year + 1900&lt;br /&gt;
				elseif year &amp;lt; 20 then&lt;br /&gt;
					year = year + 2000&lt;br /&gt;
				elseif year &amp;lt; 1000 then&lt;br /&gt;
					year = nil&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				team = mw.ustring.match(team, &amp;quot;^(.-) -%d?%d?%d%dthru%d?%d?%d%d$&amp;quot;)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		colors = get_year(color_data[team], year)&lt;br /&gt;
		&lt;br /&gt;
		if ( colors and type(colors) == &amp;#039;string&amp;#039; ) then&lt;br /&gt;
			-- follow alias recursively&lt;br /&gt;
			return  get_colors (colors, unknown, year)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return colors or unknown&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function bordercss(c, w)&lt;br /&gt;
	local s = &amp;#039;inset &amp;#039; .. w .. &amp;#039;px &amp;#039; .. w .. &amp;#039;px 0 &amp;#039; .. c &lt;br /&gt;
		.. &amp;#039;, inset -&amp;#039; .. w .. &amp;#039;px -&amp;#039; .. w .. &amp;#039;px 0 &amp;#039; .. c&lt;br /&gt;
	return &amp;#039;-moz-box-shadow: &amp;#039; .. s .. &amp;#039;; -webkit-box-shadow: &amp;#039; .. s .. &amp;#039;; box-shadow: &amp;#039; .. s .. &amp;#039;;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
	&lt;br /&gt;
function p.test(frame)&lt;br /&gt;
	local args = frame.args.team and frame.args or frame:getParent().args&lt;br /&gt;
	local colors = get_colors((args.team or args[1]), nil, args.year)&lt;br /&gt;
	return &amp;#039;[&amp;quot;&amp;#039; .. args.team .. &amp;#039;&amp;quot;] = { &amp;quot;&amp;#039; .. colors[1] .. &amp;#039;&amp;quot;, &amp;#039;.. colors[2] ..&lt;br /&gt;
		&amp;#039;&amp;quot;, &amp;#039;.. colors[3] .. &amp;#039;&amp;quot;, &amp;#039;.. colors[4] .. &amp;#039;&amp;quot;, &amp;#039;.. colors[5] .. &amp;#039;&amp;quot;}&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.color(frame, column, altcolumn)&lt;br /&gt;
	local args = frame.args.team and frame.args or frame:getParent().args&lt;br /&gt;
	local colors = get_colors((args.team or args[1]), nil, args.year)&lt;br /&gt;
&lt;br /&gt;
	column = (column or tonumber(frame.args.column)) or 1&lt;br /&gt;
	altcolumn = altcolumn or tonumber(frame.args.altcolumn)&lt;br /&gt;
	if ((not colors[column]) or (colors[column] == &amp;#039;&amp;#039;)) and altcolumn then&lt;br /&gt;
		column = altcolumn&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return (yesno(frame.args.raw) and &amp;quot;&amp;quot; or prefixes[column]) .. &lt;br /&gt;
		mw.ustring.gsub(colors[column],&amp;quot;#&amp;quot;,frame:extensionTag(&amp;#039;nowiki&amp;#039;, &amp;#039;#&amp;#039;))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.style(frame)&lt;br /&gt;
	local team = frame.args.team or frame:getParent().args.team&lt;br /&gt;
	local border = frame.args.border or frame:getParent().args.border&lt;br /&gt;
	local alt = frame.args.alt or frame:getParent().args.alt&lt;br /&gt;
	local s = yesno(alt) and (p.color(frame, 4, 1) .. &amp;quot;; &amp;quot; .. p.color(frame, 5, 2) .. &amp;quot;; &amp;quot;) or (p.color(frame, 1) .. &amp;quot;; &amp;quot; .. p.color(frame, 2) .. &amp;quot;; &amp;quot;)&lt;br /&gt;
	if tonumber(border) or yesno(border) then&lt;br /&gt;
		border = (tonumber(border) and (tonumber(border) &amp;gt; 0)) and tostring(border) or &amp;quot;2&amp;quot;&lt;br /&gt;
		s = s .. bordercss(p.color(frame, 3), border)&lt;br /&gt;
	end&lt;br /&gt;
	return s&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Ahecht</name></author>
	</entry>
</feed>