Module:Storm categories: Difference between revisions

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
 
function inlineError(details, icon)
return mw.html.create("span")
:css("color", "darkred")
:css("font-weight", "bold")
:wikitext("(")
:node(
mw.html.create("span")
:attr("title", details)
:css("text-decoration", "underline")
:css("text-decoration-style", "dotted")
:wikitext(icon or "?")
)
:wikitext(")")
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"))
):node(
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(
return mw.html.create("span")
:css("text-decoration", "underline")
:css("text-decoration-style", "dotted")
:attr("title", "Overriden from original color (#" .. cat["color"] .. ")")
:wikitext("(*")
)
legends["*"] = "Overriden from original color."
end
local catColorBlackRatio = colorRatio({ "#" .. actualColor, "black" });
local catColorLinkRatio = colorRatio({ "#" .. actualColor, "#0645ad" });
local catColorVisitedLinkRatio = colorRatio({ "#" .. actualColor, "#0b0080" });
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(inlineErrorinlineWarning("This color must be a hexadecimal color.", "E"))
legends["E"] = "Not a valid hexadecimal color code."
else
if catColorBlackRatio < 4.5 then
color
:wikitext(" ")
:node(inlineErrorinlineWarning("This color has contrast issues with black (not WCAG 2.0 AA-compatible).", "C"))
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")
return tostring(out)
local showLegend = false
legendsCompiled
:css("list-style-image", "none")
:css("fontlist-weightstyle-type", "boldnone")
for legend, details in pairs(legends) do
showLegend = true
legendsCompiled:node(
mw.html.create("spanli")
-- en dash
:wikitext("'''" .. legend .. "''' – " .. details)
)
end
return (showLegend and tostring(legendsCompiled) or "") .. tostring(out)
end