Module:Storm categories/demo: Difference between revisions

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 tccstormcats = require("Module:Storm categories")
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"]
} }
end
--- 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 catColorBlackRatio = colorRatio({ "#" .. actualColorcolor, "black" })
local catColorVisitedLinkRatiocatColorLinkRatio = colorRatio({ "#" .. actualColorcolor, "#0b00800645ad" })
iflocal catColorVisitedLinkRatio <= colorRatio({ "#" 4.5. color, "#0b0080" then})
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 = tccstormcats._icon(name)
local icon = mw.html.create("td")
:wikitext(actualIcon)
Line 102 ⟶ 148:
local id = mw.html.create("td")
:wikitext(name)
local actualColor = tccstormcats._color(name)
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 catColorLinkRatio = colorRatiocolor:wikitext(contrastCheck({ "#" .. actualColor, "#0645ad" }))
local catColorVisitedLinkRatio = colorRatio({ "#" .. actualColor, "#0b0080" })
if catColorBlackRatio == "?" or catColorLinkRatio == "?" or catColorVisitedLinkRatio == "?" then
color:wikitext(
createLegend("This color must be a hexadecimal color.", errors)
)
else
if catColorBlackRatio < 4.5 then
color:wikitext(
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
color:wikitext(
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
color:wikitext(
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
color:wikitext(
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 = tccstormcats._icon(name, true)
row
:node(mw.html.create("td")
Line 239 ⟶ 257:
:node(mw.html.create("td"):wikitext(name))
local color = tccstormcats._color(name, true)
-- 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")