Module:Character cell
Appearance
| You might want to create a documentation page for this Scribunto module. Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this module. |
local p = {}
local function makeDiv(params)
local size = params.size or ""
local deceased = params.deceased or ""
local catlink = params.catlink or ""
local link = params.link or ""
local image = params.image or ""
local text = params.text or ""
local smalltext = params.smalltext or ""
local smallnonlinktext = params.smallnonlinktext or ""
local unlinkedtext = params.unlinkedtext or ""
local related = params.related or ""
local lines = tonumber(params.lines) or 2
local namespace = mw.title.getCurrentTitle().nsText
local isSmall = size == "small"
local width = isSmall and "60px" or "100px"
local height = isSmall and "75px" or "127px"
local fontsize = isSmall and "80px" or "125px"
local imgsize = isSmall and "60px" or "100px"
local padding = isSmall and "2px" or "5px"
local margin = isSmall and "2px" or "5px"
local opacityStyle = deceased ~= "" and 'filter:alpha(opacity=50);opacity:.50;' or ''
local linkTarget = catlink ~= "" and (namespace == "Category" and catlink or link) or link
local displayText = smalltext ~= "" and smalltext or text
local finalText = deceased ~= "" and "<span style='color:silver;'><i>[" .. linkTarget .. "|" .. displayText .. "]</i></span>" or "[[" .. linkTarget .. "|" .. displayText .. "]]"
local linesBreak = string.rep("<br> ", lines > 0 and lines - 1 or 1)
local html = mw.html.create("div")
:css("border", "1px gray solid")
:css("padding", padding)
:css("margin", margin)
:css("width", width)
:css("background-color", "white")
:tag("div")
:css("position", "relative")
:css("height", height)
:css("overflow", "hidden")
:node(
mw.html.create("div")
:css("position", "absolute")
:css("top", "0px")
:css("left", "0px")
:css("font-size", fontsize)
:css("width", width)
:css("overflow", "hidden")
:css("line-height", height)
:css("z-index", "3")
:wikitext("[[" .. linkTarget .. "| ]]")
)
:node(
mw.html.create("div")
:css("position", "absolute")
:css("top", "0px")
:css("left", "0px")
:css("z-index", "2")
:cssText(opacityStyle)
:wikitext("[[File:" .. image .. "|" .. link .. "|" .. imgsize .. "]]")
)
:done()
:node(
mw.html.create("div")
:css("position", "relative")
:css("width", "100%")
:css("text-align", "center")
:wikitext(linesBreak)
:node(mw.html.create("div")
:css("position", "absolute")
:css("top", "0px")
:css("left", "0px")
:css("width", "100%")
:css("text-align", "center")
:wikitext(finalText ..
(unlinkedtext ~= "" and unlinkedtext or "") ..
(related ~= "" and "<br><small>''[[" .. related .. "/Related Articles|related pages]]''</small>" or "")
)
)
)
return tostring(html)
end
function p.render(frame)
local args = frame:getParent().args
return makeDiv(args)
end
return p