Module:InfoboxPosition
Documentation for this module may be created at Module:InfoboxPosition/doc
local p = {}
local function row(th, val)
if val and val ~= "" then
return string.format(
'<tr><th style="text-align:left;">%s</th><td>%s</td></tr>',
th, val
)
end
return ""
end
function p.infobox(frame)
local args = frame:getParent().args
local name = args.name or mw.title.getCurrentTitle().text
local image = args.image
local caption = args.caption
local holder = args.holder
local time = args.time
local style = args.style
local typ = args.type
local abbreviation = args.abbreviation
local member_of = args.member_of
local office = args.office
local appointer = args.appointer
local first_holder = args.first_holder
local succession = args.succession
local salary = args.salary
local known_for = args.known_for
local notable_works = args.notable_works
local website = args.website
local html = mw.html.create("div")
:addClass("infobox vcard")
:css({
width = "22em",
border = "1px solid #FF5722",
margin = "10px",
float = "right",
background = "#f9f9f9"
})
local tbl = html:tag("table")
:css({
width = "100%",
["border-collapse"] = "collapse"
})
-- Title
tbl:tag("tr")
:tag("th")
:attr("colspan", "2")
:css({
background = "#FF5722",
color = "white",
["text-align"] = "center",
["font-size"] = "16px",
padding = "6px"
})
:wikitext(name)
-- Image
if image and image ~= "" then
tbl:tag("tr")
:tag("td")
:attr("colspan", "2")
:css("text-align", "center")
:wikitext(string.format("[[File:%s|250px]]", image))
end
-- Caption
if caption and caption ~= "" then
tbl:tag("tr")
:tag("td")
:attr("colspan", "2")
:css({
["text-align"] = "center",
["font-style"] = "italic",
padding = "4px"
})
:wikitext(caption)
end
-- Holder header
if holder and holder ~= "" then
tbl:tag("tr")
:tag("th")
:attr("colspan", "2")
:css({
background = "#ff7043",
color = "white",
["text-align"] = "center"
})
:wikitext(holder)
end
-- Time
if time and time ~= "" then
tbl:tag("tr")
:tag("td")
:attr("colspan", "2")
:css("text-align", "center")
:wikitext(time)
end
-- Section header
tbl:tag("tr")
:tag("th")
:attr("colspan", "2")
:css({
background = "#FF5722",
color = "white",
["text-align"] = "center"
})
:wikitext("Official Information")
-- Data rows
tbl:wikitext(row("Style", style))
tbl:wikitext(row("Type", typ))
tbl:wikitext(row("Abbreviation", abbreviation))
tbl:wikitext(row("Member of", member_of))
tbl:wikitext(row("Office", office))
tbl:wikitext(row("Appointer", appointer))
tbl:wikitext(row("First holder", first_holder))
tbl:wikitext(row("Succession", succession))
tbl:wikitext(row("Salary", salary))
tbl:wikitext(row("Known for", known_for))
tbl:wikitext(row("Notable works", notable_works))
if website and website ~= "" then
tbl:wikitext(
string.format(
'<tr><th style="text-align:left;">Website</th><td>%s</td></tr>',
website
)
)
end
return tostring(html)
end
return p