Module:Storm categories/demo: Difference between revisions

Content deleted Content added
completely hide legend on plain mode
rm extra a
 
(2 intermediate revisions by the same user not shown)
Line 32:
function p.demo(frame)
local plain = (frame.args["plain"] or frame:getParent().args["plain"] or "") ~= ""
local verbose = (frame.args["verbose"] or frame:getParent().args["verbose"] or "") ~= ""
local legend = setmetatable({}, { refgroupname = "" })
Line 103 ⟶ 104:
end
return finalWikitext
end
function colorInfo(color, verbose, extra)
local catColorBlackRatio = colorRatio({ "#" .. color, "black" })
local catColorLinkRatio = colorRatio({ "#" .. color, "#0645ad" })
local catColorVisitedLinkRatio = colorRatio({ "#" .. color, "#0b0080" })
local nc = tostring(mw.html.create("abbr")
color:wikitext(createLegend("NC")
:attr("title", "Does not satisfy the minimum WCAG 2.1 compliance level for color contrast (AA)")
);
local aa = tostring(mw.html.create("abbr")
:wikitext("AA")
:attr("title", "WCAG 2.1 Level AA: Acceptable compliance")
);
local aaa = tostring(mw.html.create("abbr")
:wikitext("AAA")
:attr("title", "WCAG 2.1 Level AAA: Optimal compliance")
);
function contrastLevel(contrast)
return contrast >= 7 and aaa or (contrast >= 4.5 and aa or nc)
end
return mw.html.create("td")
:attr("data-sort-value", math.min(catColorBlackRatio))
:wikitext(
"#" .. color .. (extra or "") .. contrastCheck(color) .. (verbose and ("<br/>"
.. tostring(
mw.html.create("abbr")
:attr("title", "Contrast to black")
:wikitext("CTB")
) .. ": " .. string.format("%.2f", catColorBlackRatio) .. " (" .. contrastLevel(catColorBlackRatio) .. ")<br/>"
.. tostring(
mw.html.create("abbr")
:attr("title", "Contrast to links")
:wikitext("CTL")
) .. ": " .. string.format("%.2f", catColorLinkRatio) .. " (" .. contrastLevel(catColorLinkRatio) .. ")<br/>"
.. tostring(
mw.html.create("abbr")
:attr("title", "Contrast to visited links")
:wikitext("CTVL")
) .. ": " .. string.format("%.2f", catColorVisitedLinkRatio) .. " (" .. contrastLevel(catColorVisitedLinkRatio) .. ")") or "")
)
end
Line 153 ⟶ 198:
local colorPreview = mw.html.create("td")
:attr("style", "background-color: #" .. actualColor .. "; padding: 0; width: 1.8em")
local color = mw.html.createcolorInfo("td")
:wikitext("#" .. actualColor),
verbose,
if actualColor ~= cat["color"] thenand createLegend(
color:wikitext(createLegend(
"Overriden from original color ({{color box|#"
.. cat["color"]
Line 163 ⟶ 207:
.. cat["color"]
.. ")"
)) or ""
):css("width", "0"):css("white-space", "nowrap")
end
-- Perform contrast checks
color:wikitext(contrastCheck(actualColor))
local sortkeyCategory = mw.html.create("td")
Line 268 ⟶ 309:
:node(mw.html.create("td")
:attr("style", "background-color: #" .. color .. "; padding: 0; width: 1.8em"))
:node(mw.html.createcolorInfo("td"color, verbose))
:wikitextcss("#width", .. color"0")
:wikitextcss(contrastCheck(color))"white-space", "nowrap")
:node(mw.html.create("td")
:attr("colspan", "2")