Pāriet uz saturu

Modulis:Sporta krāsa

Permanently protected module
Vikipēdijas lapa
Dokumentācijas ikona Moduļa dokumentācija[skatīt] [labot] [hronoloģija] [pārlādēt]
Team1234
Klīvlendas "Indians"
Toronto Blue Jays
Bostonas "Bruins"
Sanktpēterburgas SKA
Riga Dinamo
Indianapolis Colts
Philadelphia Flyers
Salavat Yulaev Ufa
Cleveland Browns
Baltimoras "Orioles"
Miami Marlins
Bufalo "Bills"
Los Angeles Kings
Dallas Stars
Prāgas "Lev"
Bendijs
Sanhosē "Sharks"
Tampabejas "Lightning"
Vankūveras "Canucks"
Barys Astana
HK Mogo
Ņujorkas "Rangers"
Astanas "Baris"
HK Riga
Vingrošana
Minnesota Twins
Colorado Rockies
Detroitas "Tigers"
Kansas City Royals
Ņižņekamskas "Neftekhimik"
Rīgas "Prizma"
Tampa Bay Rays
Detroit Lions
Cincinnati Reds
Pittsburgh Pirates
Florida Panthers
New York Giants
HK Zemgale
Losandželosas "Dodgers"
San Francisco 49ers
Bufalo "Sabres"
Čeļabinskas "Traktor"
Ziemas sports
Kolorādo "Avalanche"
Buffalo Bills
Bokss
Ak Bars Kazan
Floridas "Marlins"
Neftekhimik Nizhnekamsk
HK Kurbads
infokaste_miris
Baltimore Orioles
Helsinku "Jokerit"
Calgary Flames
Autosports
Toronto Maple Leafs
Maskavas "Spartak"
San Diego Chargers
Sanfrancisko "Giants"
Arizona Diamondbacks
Dalasas "Stars"
Boston Red Sox
New York Islanders
Kalgari "Flames"
Teniss
Ņujorkas "Islanders"
Karolīnas "Panthers"
Pitsburgas "Pirates"
Jaroslavļas "Lokomotiv"
Magņitogorskas "Metallurg"
Phoenix Coyotes
Maiami "Dolphins"
St. Louis Blues
Vieglatlētika
Dinamo Minsk
Jekaterinburgas "Avtomobilist"
Cīņas sports
F1
Rokasbumba
Mitišču "Atlant"
Cincinnati Bengals
Slovan Bratislava
SKA St.Petersburg
Edmonton Oilers
Novokuzņeckas "Metallurg"
Amur Khabarovsk
Hokejs
Motoru sports
Sibir Novosibirsk
Otavas "Senators"
Čikāgas "Cubs"
Carolina Panthers
Atlantas "Falcons"
Čikāgas "Blackhawks"
Ņūdžersijas "Devils"
Podoļskas "Vitjaz"
Donbass Donetsk
Riteņbraukšana
Admiral Vladivostok
Anaheim Ducks
Detroit Tigers
Arizona Cardinals
Houston Astros
Spartak Moscow
Washington Capitals
Futbols
Avtomobilist Yekaterinburg
Našvilas "Predators"
Hjūstonas "Texans"
Cleveland Indians
New York Jets
Kanzassitijas "Royals"
Doņeckas "Donbass"
Maskavas CSKA
Pludmales volejbols
Oakland Raiders
Džeksonvilas "Jaguars"
Vladivostokas "Admiral"
Buffalo Sabres
HK Rīga
Tampabejas "Rays"
Dalasas "Cowboys"
Losandželosas "Angels" no Anahaimas
Zagrebas "Medveščak"
Severstal Cherepovets
Teksasas "Rangers"
Omskas "Avangard"
Oklendas "Athletics"
Ņujorkas "Giants"
Washington Nationals
Vancouver Canucks
Sentluisas "Blues"
Seattle Mariners
Avangard Omsk
Basketbols
Latvija
Bostonas "Red Sox"
Hantimansijskas "Jugra"
St. Louis Cardinals
Sentluisas "Rams"
Handbols
Čikāgas "White Sox"
New Jersey Devils
Regbijs
Metallurg Novokuznetsk
Denver Broncos
New Orleans Saints
Floridas "Panthers"
Minesotas "Twins"
Chicago Bears
Minskas "Dinamo"
New England Patriots
Ottawa Senators
Indianapolisas "Colts"
Sinsinati "Bengals"
Philadelphia Eagles
Karolīnas "Hurricanes"
San Diego Padres
Ņujorkas "Yankees"
Losandželosas "Kings"
New York Yankees
Baltimore Ravens
Peldēšana
Volejbols
Baltimoras "Ravens"
Kolumbusas "Blue Jackets"
Dallas Cowboys
Loka šaušana
Los Angeles Angels of Anaheim
Denveras "Broncos"
Mākslas vingrošana
Ņižņijnovgorodas "Torpedo"
Ņujorkas "Jets"
Filadelfijas "Flyers"
Filadelfijas "Eagles"
Beisbols
Sanfrancisko "49ers"
Tampabejas "Buccaneers"
Paukošana
New York Mets
Boston Bruins
Ņūorleānas "Saints"
Minesotas "Vikings"
Grīnbejas "Packers"
Sporta vingrošana
Sietlas "Mariners"
Detroitas "Lions"
Čikāgas "Bears"
Washington Redskins
Vašingtonas "Redskins"
Sietlas "Seahawks"
Montreal Canadiens
Vityaz Podolsk
Florida Marlins
Oklendas "Raiders"
Maiami "Marlins"
Kanzassitijas "Chiefs"
Čerepovecas "Severstal"
Tenesī "Titans"
Pitsburgas "Steelers"
Klīvlendas "Browns"
Minnesota Vikings
Seattle Seahawks
Spīdvejs
St. Louis Rams
Tampa Bay Buccaneers
Jokerit Helsinki
Atlanta Falcons
Jaunanglijas "Patriots"
Pittsburgh Penguins
Bratislavas "Slovan"
Green Bay Packers
Kansas City Chiefs
Tennessee Titans
Jacksonville Jaguars
Winnipeg Jets
Chicago Cubs
Oakland Athletics
Miami Dolphins
infokaste_zils
Vašingtonas "Nationals"
Hjūstonas "Astros"
Sentluisas "Cardinals"
Lev Prague
Yugra Khanty-Mansiysk
Sandjego "Padres"
Detroit Red Wings
Filadelfijas "Phillies"
Ņujorkas "Mets"
Medvescak Zagreb
Los Angeles Dodgers
Milvoki "Brewers"
Latvia
Toronto "Blue Jays"
San Jose Sharks
Kolorādo "Rockies"
Lokomotiv Yaroslavl
Atlantas "Braves"
Arizonas "Diamondbacks"
Texas Rangers
San Francisco Giants
Philadelphia Phillies
Pittsburgh Steelers
Arizonas "Cardinals"
Milwaukee Brewers
Houston Texans
Chicago White Sox
Atlanta Braves
HK MOGO
Vinipegas "Jets"
Rīgas Prizma
HK Liepāja
Novosibirskas "Sibir"
Toronto "Maple Leafs"
Ufas "Salavat Julajev"
Kanādiešu futbols
Monreālas "Canadiens"
Habarovskas "Amur"
Nashville Predators
Minnesota Wild
Kazaņas "Ak Bars"
Maskavas "Dinamo"
Anahaimas "Ducks"
Rīgas "Dinamo"
Traktor Chelyabinsk
Torpedo Nizhny Novgorod
Metallurg Magnitogorsk
Minesotas "Wild"
Columbus Blue Jackets
Chicago Blackhawks
Sandjego "Chargers"
Sinsinati "Reds"
Carolina Hurricanes
Pitsburgas "Penguins"
Dynamo Moscow
Atlant Mytishchi
CSKA Moscow
Detroitas "Red Wings"
Tampa Bay Lightning
Edmontonas "Oilers"
New York Rangers
Vašingtonas "Capitals"
Arizonas "Coyotes"
Colorado Avalanche
Free agent
Retired

local p = {}

local data_module = "Module:Sporta krāsa/dati"

local function stripwhitespace(text)
	return text:match("^%s*(.-)%s*$")
end

local function get_colors(team, unknown)
	team = stripwhitespace(team or '')
	unknown = unknown or {"CFE1FF", "000000", "000000", "CFE1FF"}
	
	local use_default = {
		[""] = 1,
--		["retired"] = 1,
--		["free agent"] = 1,
	}
	
	local colors = nil
	
	if ( team and use_default[team:lower()] ) then
--		colors = {"DCDCDC", "000000", "000000", "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)

	-- hack for NBA Eastern Conference and NBA Western Conference
	if (team:match("Eastern Conference") or team:match("Western Conference")) then
		if(num == '') then
			num = '1'
			local track = mw.loadData("Module:Basketball color/tracking")
		end
	end
	
	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 #' .. colors[bd] .. ';'
	end
	
	return 'background-color:#' .. colors[bg] .. ';color:#' .. colors[fg] .. ';' .. border
end

--krasu kodu dabusana, pagaidam neveiksmigi
--local function my_func(team, bg)
--	local colors = get_colors(team, nil)
--	return  .. colors[bg] .. 
--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

local function team_testtable(args, style, data)
	local teamlist = {}
	local t = ''
	local style = 'font-size:90%; line-height:100%;' .. (style or '')
	if ( data ) then data_module = data end

    -- helper function
	local function table_row(t, c)
		local res = ''
		if( c[1] and c[2] and c[3] and c[4] ) then
			res = res .. '<tr><td>' .. t .. '</td>'
		else
			res = res .. '<tr><td>' .. t .. ' <span class=error>ERROR</span></td>'
		end
		res = res .. '<td style="background:#' .. (c[1] or 'ERROR') .. '"></td>'
		res = res .. '<td style="background:#' .. (c[2] or 'ERROR') .. '"></td>'
		res = res .. '<td style="background:#' .. (c[3] or 'ERROR') .. '"></td>'
		res = res .. '<td style="background:#' .. (c[4] or 'ERROR') .. '"></td>'
		res = res .. '</tr>\n'
		
		return res
	end

    -- list of teams
	if( args and args[1] ) then
		for k, team in pairs(args) do
			if type(k) == 'number' then
				table.insert(teamlist, team)
			end
		end
	else
		local all_colors = mw.loadData(data_module)
		for team, colors in pairs( all_colors ) do
			table.insert(teamlist, team)
		end
		table.insert(teamlist, 'Free agent')
		table.insert(teamlist, 'Retired')
	end
	
	-- build table
	t = t .. '<table class=\"wikitable sortable\" style=\"' ..  style .. '\">\n'
	t = t .. '<tr><th>Team</th><th class="unsortable">1</th><th class="unsortable">2</th>'
	t = t .. '<th class="unsortable">3</th><th class="unsortable">4</th></tr>\n'
	for k, team in pairs( teamlist ) do
		t = t .. table_row(team, get_colors(team))
	end
	t = t .. '</table>'
	
	return t
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

function p.testtable(frame)
	return team_testtable((frame.args[1] ~= nil) and frame.args or frame:getParent().args, frame.args['style'] or '', frame.args['data'])
end

return p