Content deleted Content added
not needed |
add |
||
Line 11:
local function _row(frame, rargs)
local rtype = mw.ustring.lower(rargs.type or '')
local output = {'|-'}
setmetatable(
local function threeCells(cellType, title, always, shortname)
local centeredCell = function (key)
local name = shortname and p._shortname(rargs[key .. '_name'], rargs[key]) or (rargs[key] or '')
Line 38 ⟶ 39:
output('|- class="sr-only"')
if rargs.ongoing ~= "yes" and (
) and (
notblank(rargs.party1) or notblank(rargs.party2) or notblank(rargs.party2)
Line 90 ⟶ 91:
-- Presidential & by-election nominee --
if notblank(rargs['nominee1']) or notblank(rargs['nominee2']) or notblank(rargs['nominee3']) then
if ({primary = 1, presidential = 1, ['by-election'] = 1})[
threeCells('nominee', '', true) -- nominee, no alternative title, always show
end
Line 97 ⟶ 98:
end
-- Party leader --
if
threeCells('leader')
end
Line 105 ⟶ 106:
threeCells('alliance', '', false, true) -- alliance, not alternative title, don't always show, use shortname
-- Primary or presidential
if
-- Home state --
threeCells('home_state')
-- Running mate --
if
threeCells('running_mate')
-- Electoral vote --
Line 117 ⟶ 118:
threeCells('delegate_count', (rargs.ongoings == 'yes' and 'Estimated d' or 'D') .. 'elegate count')
-- States carried --
threeCells('states_carried',
end
-- Parliamentary or
if
-- Leader since --
threeCells('leader_since')
Line 144 ⟶ 145:
end
-- Primary or not ongoing --
if rargs.ongoing ~= 'yes' or
-- Popular vote --
threeCells('popular_vote', (rargs.vote_type or 'Popular') .. ' vote')
Line 150 ⟶ 151:
threeCells('percentage')
-- Primary or presidential
if
-- Counties won --
threeCells('counties_won')
Line 158 ⟶ 159:
end
-- Swing --
if (
threeCells('swing')
end
Line 167 ⟶ 168:
end
end
return table.concat(output, '\n')
end
Line 188 ⟶ 191:
end
function p.row(frame)
local args = {}
for k,v in pairs(frame:getParent().args) do
if notblank(v) then args[k] = mw.text.trim(v) end
end
for k,v in pairs(frame.args) do
if notblank(v) then args[k] = mw.text.trim(v) end
end
return _row(frame, args)
end
function p.infobox(frame)
local origArgs = {}
for k,v in pairs(frame:getParent().args) do
if notblank(v) then origArgs[k] = mw.text.trim(v) end
end
for k,v in pairs(frame.args) do
if notblank(v) then origArgs[k] = mw.text.trim(v) end
end
local pagetitle = frame:getParent() and frame:getParent():getTitle() or frame:getTitle()
local etype = mw.ustring.lower(origArgs.type or '')
args = {
templatestyles = 'Infobox election/styles.css',
['child templatestyles'] = 'Screen reader-only/styles.css',
child = origArgs.child or origArgs.embed or '',
bodyclass = 'ib-election infobox-table' .. (notblank(origArgs.election_date) and 'vevent' or ''),
bodystyle = '',
titleclass = 'summary',
title = ((origArgs.child or origArgs.embed or '') == 'yes')
and (notblank(origArgs.election_name) and '<div style="background-color:#ddd; font-size:120%; font-weight:bold">'..origArgs.election_name..'</div>') or (notblank(origArgs.election_name
subheader1 = notblank(origArgs.flag_image)
and (InfoboxImage(
frame:newChild{ title = frame:getTitle(), args = {
Line 232 ⟶ 242:
} }
) .. "<hr />") ),
subheader2 = 'TBD',
subheader3 = 'TBD',
subheader4 = 'TBD',
header1 = (etype == 'primary' or etype == 'presidential') and (
notblank(origArgs.votes_for_election) and (
'<hr />' .. origArgs.votes_for_election .. (
notblank(origArgs.needed_votes) and '<br />' .. origArgs.needed_votes .. ' votes needed to win'
)
) or ''
) or (
(etype == 'parliamentary' or etype == 'legislative' or etype == 'by-election') and (
notblank(origArgs.seats_for_election) and (
'<hr />' .. origArgs.seats_for_election .. (
notblank(origArgs.majority_seats) and '<br />' .. origArgs.majority_seats .. ' seats needed for a majority'
)
) or ''
) or ''
),
data2 = notblank(origArgs.opinion_polls) and ('[[' .. origArgs.opinion_polls .. '|Opinion polls]]') or '',
label3 = 'Registered',
data3 = origArgs.registered,
label4 = 'Turnout',
data4 = origArgs.turnout,
label5 = 'Votes counted',
data5 = notblank(origArgs.votes_counted) and (
'<div class="center" style="width:auto;margin-left:auto;margin-right:auto;">' ..
_percentageBar(origArgs.votes_counted, origArgs.votes_counted .. '%', '1BCE0E') ..
"</div>as of '''" .. (origArgs.last_update or '') .. ' ' .. (origArgs.time_zone or '') .. "'''"
) or '',
label6 = 'Reporting',
data6 = notblank(origArgs.reporting) and (
'<div class="center" style="width:auto;margin-left:auto;margin-right:auto;">' ..
_percentageBar(origArgs.reporting, origArgs.reporting .. '%', '1BCE0E') ..
"</div>as of '''" .. (origArgs.last_update or '') .. ' ' .. (origArgs.time_zone or '') .. "'''"
) or '',
label7 = 'Declared',
data7 = notblank(origArgs.declared) and (
'<div class="center" style="width:auto;margin-left:auto;margin-right:auto;">' ..
_percentageBar(origArgs.declared, origArgs.declared .. '%', '1BCE0E') ..
"</div>as of '''" .. (origArgs.last_update or '') .. ' ' .. (origArgs.time_zone or '') .. "'''"
) or '',
}
local width = 0
local map = false
for _, v in ipairs({'', '2', '3', '4'}) do
if notblank(origArgs['map' .. v]) or notblank(origArgs['map' .. v .. '_image']) then
map = true
local nWidth = mw.ustring.gsub(origArgs['map' .. v .. '_size'] or '300', '%s*px%s*$', '')
width = math.max(width, tonumber(nWidth) or 300)
end
end
if map then
args.bodystyle = tostring(math.min(300, width)) .. "px"
end
return require('Module:Infobox').infoboxTemplate(
Line 238 ⟶ 309:
)
end
return p
|