Module:CSSUtil
Revision as of 14:34, 21 April 2026 by Exe boss (talk | contribs) (Create Module:CSSUtil for use by Module:Factory slot and Module:UI)
Documentation for this module may be created at Module:CSSUtil/doc
-- Utility for dealing with inline styles by checking
-- for CSS classes in a `class` argument.
--
-- Mainly exists to support inline style workarounds
-- until this Wiki gets [[mw:Extension:TemplateStyles|TemplateStyles]]
require("Module:No globals");
local checkType = require("libraryUtil").checkType;
local p = {};
--- Returns whether the space separated
--- `classAttr` contains the `className`
---
--- @param classAttr string|nil the class attribute
--- @param className string the class name to look for
--- @return boolean
function p.hasClass(classAttr, className)
checkType('"Module:CSSUtil".hasClass', 1, classAttr, "string", true);
checkType('"Module:CSSUtil".hasClass', 2, className, "string");
-- assert(not className:find("%s"), 'Class name must not contain whitespace, got: "' .. className .. '"');
if (not classAttr) then
return false;
end
for cls in mw.text.gsplit(classAttr, "%s+") do
if (cls == className) then
return true;
end
end
return false;
end
return p;