Module:Color contrast: Difference between revisions

m
m>Frietjes
(add option for greatercontrast to form inline css string)
m (2 revisions imported from wikipedia:Module:Color_contrast: see Topic:Vtixlm0q28eo6jtf)
 
(7 intermediate revisions by 7 users not shown)
Line 63: Line 63:
return ''
return ''
end
end
-- html '#' entity
c = c:gsub("#", "#")
-- whitespace
-- whitespace
c = c:match( '^%s*(.-)[%s;]*$' )
c = c:match( '^%s*(.-)[%s;]*$' )
Line 139: Line 143:
if css then
if css then
if mw.ustring.match(v1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
local c1 = args[1] 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
if mw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
v1 = '#' .. v1
mw.ustring.match(c1, '^[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
c1 = '#' .. c1
end
end
if mw.ustring.match(v2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
if mw.ustring.match(c2, '^[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
mw.ustring.match(c2, '^[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
c2 = '#' .. c2
end
end
if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or
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
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
c3 = '#' .. c3
end
end
return 'background-color:' .. v1 .. '; color:'  
return 'background-color:' .. c1 .. '; color:' .. ((ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or '') .. ';'
.. ((ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or '') .. ';'
end
end