Content deleted Content added
Switching to note-style legends |
Also run color overrides through contrast check |
||
Line 1:
--
-- This module handles demonstration and list of possible values for all storm
-- category templates! Please test this module on [[Module:Storm categories/demo/doc]]
-- before publishing to avoid errros. Thank you!
--
local colorRatio = require("Module:Color contrast")._ratio
local TableTools = require("Module:TableTools")
local
local cats = require("Module:Storm categories/categories").cats
local colors = require("Module:Storm categories/colors").colors
Line 23 ⟶ 28:
end
--- Generates and renderds the demo table.
-- @param frame The Scribunto frame.
function p.demo(frame)
local legend = setmetatable({}, { refgroupname = "" })
Line 28 ⟶ 35:
local warnings = setmetatable({}, { refgroupname = "W" })
--- Builds the entire reflist
-- @param _group The group to build for. Uses `legend` by default.
function buildReflist(_group)
group = _group or legend
Line 35 ⟶ 44:
end
--- Returns a single <ref> tag containing the legend provided and
-- attaches the note definition to the list of notes.
-- @param details The details of the legend.
-- @param _group The group to write in. Uses `legend` by default.
function createLegend(details, _group)
hash = string.sub(mw.hash.hashValue("md5", details), 0, 8)
Line 55 ⟶ 68:
group = getmetatable(group)["refgroupname"]
} }
--- Checks for color contrast issues and tags accordingly.
-- Returns the refernce tag, so this should be used in conjunction with an
-- HTML node's :wikitext function.
function contrastCheck(color)
local
local finalWikitext = ""
if catColorBlackRatio == "?" or catColorLinkRatio == "?" or catColorVisitedLinkRatio == "?" then▼
finalWikitext = finalWikitext ..
createLegend("This color must be a hexadecimal color.", errors)▼
else▼
if catColorBlackRatio < 4.5 then▼
finalWikitext = finalWikitext ..
createLegend("This color has [[MOS:COLOR|contrast issues]] with black (not WCAG 2.0 AA-compatible). It will be unusable on all infoboxes and storm season summaries.", errors)▼
end▼
if catColorLinkRatio < 4.5 then▼
finalWikitext = finalWikitext ..
createLegend("This color has [[MOS:COLOR|contrast issues]] with links (not WCAG 2.0 AA-compatible). It should not be used in conjunction with a link.", warnings)▼
end▼
if catColorVisitedLinkRatio < 4.5 then
finalWikitext = finalWikitext ..
createLegend("This color has [[MOS:COLOR|contrast issues]] with visited links (not WCAG 2.0 AA-compatible with #0b0080). It should not be used in conjunction with a visited link.", warnings)▼
end▼
if actualCat == "c0c0c0" and cat[sortkey] ~= 0 then▼
finalWikitext = finalWikitext ..
createLegend("This category is using a color reserved specifically for the \"unknown\" category.", warnings)▼
end▼
end
return finalWikitext
end
Line 91 ⟶ 137:
local row = rows[1]
local actualIcon =
local icon = mw.html.create("td")
:wikitext(actualIcon)
Line 102 ⟶ 148:
local id = mw.html.create("td")
:wikitext(name)
local actualColor =
local colorPreview = mw.html.create("td")
:attr("style", "background-color: #" .. actualColor .. "; padding: 0; width: 1.8em")
Line 118 ⟶ 164:
end
-- Perform contrast checks
▲ local catColorBlackRatio = colorRatio({ "#" .. actualColor, "black" })
▲ local catColorVisitedLinkRatio = colorRatio({ "#" .. actualColor, "#0b0080" })
▲ if catColorBlackRatio == "?" or catColorLinkRatio == "?" or catColorVisitedLinkRatio == "?" then
▲ createLegend("This color must be a hexadecimal color.", errors)
▲ else
▲ if catColorBlackRatio < 4.5 then
▲ createLegend("This color has [[MOS:COLOR|contrast issues]] with black (not WCAG 2.0 AA-compatible). It will be unusable on all infoboxes and storm season summaries.", errors)
▲ end
▲ if catColorLinkRatio < 4.5 then
▲ createLegend("This color has [[MOS:COLOR|contrast issues]] with links (not WCAG 2.0 AA-compatible). It should not be used in conjunction with a link.", warnings)
▲ end
▲ if catColorVisitedLinkRatio < 4.5 then
▲ createLegend("This color has [[MOS:COLOR|contrast issues]] with visited links (not WCAG 2.0 AA-compatible with #0b0080). It should not be used in conjunction with a visited link.", warnings)
▲ end
▲ if actualCat == "c0c0c0" and cat[sortkey] ~= 0 then
▲ createLegend("This category is using a color reserved specifically for the \"unknown\" category.", warnings)
▲ end
▲ end
local sortkeyCategory = mw.html.create("td")
Line 229 ⟶ 247:
local row = mw.html.create("tr")
local icon =
row
:node(mw.html.create("td")
Line 239 ⟶ 257:
:node(mw.html.create("td"):wikitext(name))
local color =
-- Add more conditions eventually
if color ~= nil then
Line 249 ⟶ 267:
:attr("style", "background-color: #" .. color .. "; padding: 0; width: 1.8em"))
:node(mw.html.create("td")
:wikitext("#" .. color
:wikitext(contrastCheck(color)))
:node(mw.html.create("td")
:attr("colspan", "2")
|