Content deleted Content added
fix color overrides in demo |
incorporate legends into table |
||
Line 1:
local colorRatio = require("Module:Color contrast")._ratio
local p = {}
Line 410:
local color = (colorCode ~= nil and string.len(colorCode) ~= 0) and
string.gsub(string.lower(colorCode), "[^%w]", "")
or defaultCategory
return colors[color] or ((cats[color] or cats[defaultCategory]).color)
Line 445:
end
return n
end▼
return mw.html.create("span")▼
:css("font-weight", "bold")▼
:wikitext("(")▼
:node(▼
mw.html.create("span")▼
:css("text-decoration", "underline")▼
:css("text-decoration-style", "dotted")▼
)▼
end
Line 482 ⟶ 467:
:attr("style", "width: 100%")
out
:node( mw.html.create("tr")
:node(mw.html.create("th"):wikitext("ID")
:attr("rowspan", "2"))
:node(mw.html.create("th"):wikitext("Name")
:attr("colspan", "2"))
:node(mw.html.create("th"):wikitext("Color")
:attr("rowspan", "2")
:attr("colspan", "2"))
:node(mw.html.create("th"):wikitext("Sortkey")
:attr("colspan", "2"))
mw.html.create("tr")
:node(mw.html.create("th"):wikitext("Basin"))
:node(mw.html.create("th"):wikitext("Name"))
:node(mw.html.create("th"):wikitext("Basin"))
:node(mw.html.create("th"):wikitext("Sortkey")
:attr("data-sort-type", "number"))
local legends = {}
for name, cat in pairs(cats) do
Line 513 ⟶ 501:
local color = mw.html.create("td")
:wikitext("#" .. actualColor)
if actualColor ~= cat["color"] then
color
▲ :node(
▲ :css("text-decoration", "underline")
▲ :css("text-decoration-style", "dotted")
:attr("title", "Overriden from original color (#" .. cat["color"] .. ")")
)
legends["*"] = "Overriden from original color."
end
▲ local catColorBlackRatio = colorRatio({ "#" .. actualColor, "black" });
▲ local catColorLinkRatio = colorRatio({ "#" .. actualColor, "#0645ad" });
▲ local catColorVisitedLinkRatio = colorRatio({ "#" .. actualColor, "#0b0080" });
if catColorBlackRatio == "?" or catColorLinkRatio == "?" or catColorVisitedLinkRatio == "?" then
color
:wikitext(" ")
:node(
legends["E"] = "Not a valid hexadecimal color code."
else
if catColorBlackRatio < 4.5 then
color
:wikitext(" ")
:node(
legends["C"] = "Color has contrast issues with black."
end
if catColorLinkRatio < 4.5 then
Line 531 ⟶ 534:
:wikitext(" ")
:node(inlineWarning("This color has contrast issues with links (not WCAG 2.0 AA-compatible).", "L"))
legends["L"] = "Color has contrast issues with links (#0645ad)."
end
if catColorVisitedLinkRatio < 4.5 then
Line 536 ⟶ 540:
:wikitext(" ")
:node(inlineWarning("This color has contrast issues with visited links (not WCAG 2.0 AA-compatible).", "V"))
legends["V"] = "Color has contrast issues with visited links (#0b0080)."
end
end
Line 612 ⟶ 617:
end
local legendsCompiled = mw.html.create("ul")
local showLegend = false
legendsCompiled
:css("list-style-image", "none")
for legend, details in pairs(legends) do
showLegend = true
legendsCompiled:node(
-- en dash
:wikitext("'''" .. legend .. "''' – " .. details)
▲ )
▲ end
return (showLegend and tostring(legendsCompiled) or "") .. tostring(out)
end
|