Module:Userbox: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 229: Line 229:
local tableroot = root:tag('table')
local tableroot = root:tag('table')
tableroot
tableroot
:attr('role', 'presentation')
:css('border-collapse', 'collapse')
:css('border-collapse', 'collapse')
:css('width', data.width)
:css('width', data.width)
Line 239: Line 238:
local tablerow = tableroot:tag('tr')
local tablerow = tableroot:tag('tr')
if data.showId then
if data.showId then
tablerow:tag('td')
tablerow:tag('th')
:css('border', '0')
:css('border', '0')
:css('width', data.idWidth)
:css('width', data.idWidth)
Line 246: Line 245:
:css('text-align', data.idTextAlign)
:css('text-align', data.idTextAlign)
:css('font-size', data.idFontSize)
:css('font-size', data.idFontSize)
:css('font-weight', 'bold')
:css('color', data.idColor)
:css('color', data.idColor)
:css('padding', data.idPadding)
:css('padding', data.idPadding)
Line 272: Line 270:
-- Render the second id html.
-- Render the second id html.
if data.showId2 then
if data.showId2 then
tablerow:tag('td')
tablerow:tag('th')
:css('border', '0')
:css('border', '0')
:css('width', data.id2Width)
:css('width', data.id2Width)
Line 279: Line 277:
:css('text-align', data.id2TextAlign)
:css('text-align', data.id2TextAlign)
:css('font-size', data.id2FontSize)
:css('font-size', data.id2FontSize)
:css('font-weight', 'bold')
:css('color', data.id2Color)
:css('color', data.id2Color)
:css('padding', data.id2Padding)
:css('padding', data.id2Padding)
Line 297: Line 294:
end
end


local legible = true
local contrast = require('Module:Color contrast')._ratio
local contrast = require('Module:Color contrast')._ratio


Line 309: Line 307:
wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", get_alt)
wikitext = wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]", get_alt)
return mw.text.trim(wikitext) ~= ""
return mw.text.trim(wikitext) ~= ""
end

if contrast { data.infoColor, data.backgroundColor, error = 0 } < 4.5 then
legible = false
end

if data.showId and contrast { data.idColor, data.idBackgroundColor, error = 0 } < 4.5 then
if has_text(data.id or "") then
legible = false
end
end

if data.showId2 and contrast { data.id2Color, data.id2BackgroundColor, error = 0 } < 4.5 then
if has_text(data.id2 or "") then
legible = false
end
end

if not legible then
root:wikitext('[[Category:Potentially illegible userboxes]]')
end
end