Module:Userbox: Difference between revisions
From Inkipedia, the Splatoon wiki
SuperHamster (talk | contribs) (ruserboxx shouldn't be an ID, as multiple userboxes can appear on a page. Adding ruserboxx as a class; ID should be removed once we know nothing will break) |
(Allow em and px for size params) |
||
Line 2: | Line 2: | ||
function p.main(frame) | function p.main(frame) | ||
-- pass frame args wholly to getBox | |||
local args = frame:getParent().args | local args = frame:getParent().args | ||
return p.getBox(args) | return p.getBox(args) | ||
Line 19: | Line 19: | ||
local infoColor = args["info-color"] or args["info-fc"] or "black" | local infoColor = args["info-color"] or args["info-fc"] or "black" | ||
local infoText = args["info"] or "''info''" | local infoText = args["info"] or "''info''" | ||
local function getSize(value) | |||
if type(value) == "string" and (value:match("em$") or value:match("px$")) then | |||
return value -- value already includes the 'em' or 'px' suffix | |||
else | |||
return value .. "pt" -- default to 'pt' if no 'em' or 'px' suffix found | |||
end | |||
end | |||
local ruserbox = mw.html.create("div") | local ruserbox = mw.html.create("div") | ||
ruserbox:attr("id", "ruserboxx") | ruserbox:attr("id", "ruserboxx") | ||
Line 39: | Line 47: | ||
logoCell:css("background", logoBackground) | logoCell:css("background", logoBackground) | ||
logoCell:css("text-align", "center") | logoCell:css("text-align", "center") | ||
logoCell:css("font-size", logoSize | logoCell:css("font-size", getSize(logoSize)) | ||
logoCell:css("color", logoColor) | logoCell:css("color", logoColor) | ||
logoCell:wikitext("'''" .. logoText .. "'''") | logoCell:wikitext("'''" .. logoText .. "'''") | ||
local infoCell = mw.html.create("td") | local infoCell = mw.html.create("td") | ||
infoCell:css("font-size", infoSize | infoCell:css("font-size", getSize(infoSize)) | ||
infoCell:css("padding", "4pt") | infoCell:css("padding", "4pt") | ||
infoCell:css("line-height", "1.25em") | infoCell:css("line-height", "1.25em") |
Revision as of 22:26, 14 June 2024
For use with Template:Userbox.
A full list of more specific userboxes can be found in Category:User boxes.
Usage
{{Userbox |id = id text or image |id-c = id background color |id-fc = id font color |id-s = id text size |info = info text |info-c = info background color |info-fc = info font color |info-s = info text size |border-c = box color |border-s = border width in pixels }}
- It is suggested that you limit the size of any images in the id box to 40 pixels.
- For a list of colors and the Hex triplet (eg., 007BA7) codes for them, see this Wikipedia page.
- This page is to active userboxes.
Example
{{Userbox |id= [[File:Squidpromo.jpg|48px]] |id-c= #74DF00 |info= This user loves Splatoon! |info-c= #BCF5A9 |border-c= #088A08 }}
Which will give:
local p = {} function p.main(frame) -- pass frame args wholly to getBox local args = frame:getParent().args return p.getBox(args) end function p.getBox(args) local float = args["float"] or "left" local borderWidth = args["border-width"] or args["border-s"] or 1 local borderColor = args["border-color"] or args["border-c"] or args["id-c"] or "#999" local infoBackground = args["info-background"] or args["info-c"] or "#EEE" local logoBackground = args["logo-background"] or args["id-c"] or "#DDD" local logoSize = args["logo-size"] or args["id-s"] or 14 local logoColor = args["logo-color"] or args["id-fc"] or "black" local logoText = args["logo"] or args["id"] or "''id''" local infoSize = args["info-size"] or args["info-s"] or 8 local infoColor = args["info-color"] or args["info-fc"] or "black" local infoText = args["info"] or "''info''" local function getSize(value) if type(value) == "string" and (value:match("em$") or value:match("px$")) then return value -- value already includes the 'em' or 'px' suffix else return value .. "pt" -- default to 'pt' if no 'em' or 'px' suffix found end end local ruserbox = mw.html.create("div") ruserbox:attr("id", "ruserboxx") ruserbox:attr("class", "ruserboxx") ruserbox:css("float", float) ruserbox:css("border", borderWidth .. "px solid " .. borderColor) ruserbox:css("margin", "1px") local table = mw.html.create("table") table:attr("cellspacing", "0") table:css("width", "238px") table:css("background", infoBackground) local row = mw.html.create("tr") local logoCell = mw.html.create("td") logoCell:css("width", "45px") logoCell:css("height", "45px") logoCell:css("background", logoBackground) logoCell:css("text-align", "center") logoCell:css("font-size", getSize(logoSize)) logoCell:css("color", logoColor) logoCell:wikitext("'''" .. logoText .. "'''") local infoCell = mw.html.create("td") infoCell:css("font-size", getSize(infoSize)) infoCell:css("padding", "4pt") infoCell:css("line-height", "1.25em") infoCell:css("color", infoColor) infoCell:wikitext(infoText) row:node(logoCell) row:node(infoCell) table:node(row) ruserbox:node(table) return tostring(ruserbox) end return p