Jump to content

Module:Color contrast: Difference between revisions

add option for greatercontrast to form inline css string
imported>Rob Kam
m (1 revision imported: Template:Reflist)
m>Frietjes
(add option for greatercontrast to form inline css string)
Line 121: Line 121:
function p._greatercontrast(args)
function p._greatercontrast(args)
local bias = tonumber(args['bias'] or '0') or 0
local bias = tonumber(args['bias'] or '0') or 0
local css = (args['css'] and args['css'] ~= '') and true or false
local v1 = color2lum(args[1] or '')
local v1 = color2lum(args[1] or '')
local c2 = args[2] or '#FFFFFF'
local c2 = args[2] or '#FFFFFF'
Line 136: Line 137:
ratio2 = (ratio2 < 1) and 1/ratio2 or ratio2
ratio2 = (ratio2 < 1) and 1/ratio2 or ratio2
end
end
if css then
if mw.ustring.match(v1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
mw.ustring.match(v1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then
v1 = '#' .. v1
end
if mw.ustring.match(v2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
mw.ustring.match(v2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then
v2 = '#' .. v2
end
if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then
v3 = '#' .. v3
end
return 'background-color:' .. v1 .. '; color:'
.. ((ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or '') .. ';'
end
return (ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or ''
return (ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or ''
end
end
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.