Module:College color/sandbox: Difference between revisions

Content deleted Content added
match main module
sync
 
(21 intermediate revisions by 6 users not shown)
Line 10:
local function stripwhitespace(text)
return text:match("^%s*(.-)%s*$")
end
local function ucfirst(s)
local first = s:sub(1, 1)
local others = s:sub(2, -1)
return first:upper() .. others
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 sRGB ( v )
Line 117 ⟶ 122:
 
local color = '#' .. (colors[3] or colors[2] or '')
if fontcolor and fontcolor == 'auto' then
-- compute the luminosity of the background
local lum = color2lum(colors[1] or '')
-- compute the contrast with white and black
local wcontrast = (1 + 0.05)/(lum + 0.05)
local bcontrast = (lum + 0.05)/(0 + 0.05)
-- select the text color with the best contrast
if( bcontrast > wcontrast + 1.25 ) then
fontcolor = '#000000'
else
fontcolor = '#FFFFFF'
end
end
local style = 'background-color:#' .. (colors[1] or '') .. ';color:' .. (fontcolor or color) .. ';'
-- remove the border if it's nearly white
Line 134 ⟶ 152:
 
local color = '#' .. (colors[1] or '')
if fontcolor and fontcolor == 'auto' then
-- compute the luminosity of the background
local lum = color2lum(colors[3] or colors[2] or '')
-- compute the contrast with white and black
local wcontrast = (1 + 0.05)/(lum + 0.05)
local bcontrast = (lum + 0.05)/(0 + 0.05)
-- select the text color with the best contrast
if( bcontrast > wcontrast + 1.25 ) then
fontcolor = '#000000'
else
fontcolor = '#FFFFFF'
end
end
local style = 'background-color:#' .. (colors[3] or colors[2] or '') .. ';color:' .. (fontcolor or color) .. ';'
-- remove the border if it's nearly white
Line 223 ⟶ 254:
local function team_table_head(args, team, ctype)
local colors = get_colors(team, nil)
local borderwidth = tonumber(args['border']) or 0
-- set the default background
local background = (ctype == 'p') and
Line 228 ⟶ 260:
(colors[3] or colors[2] or 'FFFFFF'):upper()
-- now pick a font color
local fontcolor = '000000'
-- compute the luminosity of the background
local lum = color2lum(background)
Line 236 ⟶ 268:
-- select the text color with the best contrast
if( bcontrast > wcontrast + 1.25 ) then
fontcolor = '#000000'
else
fontcolor = '#FFFFFF'
end
local s = 'background-color:#' .. background .. ';color:#' .. (args['color'] or fontcolor) .. ';'
if borderwidth > 0 then
local bc = (ctype == 'p') and
(colors[3] or colors[2] or '') or (colors[1] or '')
if bc ~= 'FFFFFF' then
s = s .. bordercss('#' .. bc, borderwidth)
end
end
local s = 'background-color:#' .. background .. ';color:#' .. fontcolor .. ';'
 
local res = '|-\n'
Line 248 ⟶ 287:
if args['col' .. i .. 'span'] ~= nil then
cstyle = cstyle .. ' colspan=' .. args['col' .. i .. 'span']
end
if args['class' .. i ] ~= nil then
cstyle = cstyle .. ' class="' .. args['class' .. i] .. '"'
end
res = res .. '! ' .. cstyle .. ' |' .. args[i] .. '\n'
Line 307 ⟶ 349:
local r = mw.html.create('')
r:tag('span')
:addClass('legend-color')
:css('background-color', '#' .. (h or ''))
:wikitext('    ')
:css('border', '1px solid #000')
:wikitext('    ')
return tostring(r)
end
Line 339 ⟶ 381:
 
if (#colorboxes > 0) then
return frame:extensionTag{ name = 'templatestyles', args = { src = 'Legend/styles.css'} } .. table.concat(colorboxes, sep)
end
 
Line 349 ⟶ 391:
local r = mw.html.create('')
r:tag('span')
:addClass('legend-color')
:css('background-color', '#' .. (h or ''))
:wikitext('    ')
:css('border', '1px solid #000')
:wikitext('    ')
return tostring(r)
end
Line 386 ⟶ 428:
 
local res = ''
if (#colornames ==> 10) then
rescolornames[1] = ucfirst(colornames[1])
elseif (#colornames == 2) then
res = colornames[1] .. ' and ' .. colornames[2]
elseif (#colornames > 2) then
res = colornames[1]
for i=2,#colornames do
if( i < #colornames ) then
res = res .. ',&nbsp;' .. colornames[i]
else
res = res .. ',&nbsp;and&nbsp;' .. colornames[i]
end
end
end
res = mw.text.listToText(
res = colornames[1],
',&nbsp;',
#colornames == 2 and '&nbsp;and&nbsp;' or ',&nbsp;and&nbsp;'
)
 
if (colors['cite']) then
Line 416 ⟶ 453:
 
if (#colorboxes > 0) then
res = res .. frame:extensionTag{ name = 'templatestyles', args = { src = 'Legend/styles.css'} }
res = res .. table.concat(colorboxes, '&nbsp;')
end