Module:Clade/labels: Difference between revisions
Appearance
Content deleted Content added
switch to parent arguments for template use |
add some width control |
||
Line 20: | Line 20: | ||
local bottomStyle = args['bottom'] |
local bottomStyle = args['bottom'] |
||
]] |
]] |
||
local width = args['width'] -- or "5em;" |
|||
local longestString = 0 |
|||
while args['label'..i] do |
while args['label'..i] do |
||
local label = args['label'..i] or "" |
local label = args['label'..i] or "" |
||
if #label > longestString then longestString = #label end |
|||
local style = args['style'..i] or args['style'] or "" |
local style = args['style'..i] or args['style'] or "" |
||
Line 39: | Line 42: | ||
--background-color:#ffccff;top:75%;"> |
--background-color:#ffccff;top:75%;"> |
||
i=i+1 |
i=i+1 |
||
end |
|||
if output ~= "" then |
|||
local widthStr = "" |
|||
--widthStr = 'width:' .. (longestString*0.5)..'em;' -- can't take account of formatting or <br/> |
|||
if width then widthStr = 'width:' .. width end |
|||
output = '<div style="background-color:#ffffaa;'.. widthStr ..'">' .. output .. '</div>' |
|||
end |
end |
||
return output |
return output |
Revision as of 10:28, 10 November 2019
![]() | This Lua module is used on approximately 260 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
local p = {}
--local args =frame:getParent().args -- get parent arguments
--local args = {}
p.getArgs = function(frame)
--return frame.args -- use frame arguments
return frame:getParent().args -- use parent arguments
end
p.main = function(frame)
args = p.getArgs(frame)
local i = 1 -- index for labels
local output = ""
--[[local groupStyle = args['style']
local topStyle = args['top']
local leftStyle = args['left']
local rightStyle = args['right']
local bottomStyle = args['bottom']
]]
local width = args['width'] -- or "5em;"
local longestString = 0
while args['label'..i] do
local label = args['label'..i] or ""
if #label > longestString then longestString = #label end
local style = args['style'..i] or args['style'] or ""
local top = args['top'..i] or args['top'] or ""
local left = args['left'..i] or args['left'] or ""
local right = args['right'..i] or args['right'] or ""
local bottom = args['bottom'..i] or args['bottom'] or ""
if top ~= "" then top = 'top:' .. top .. ';' end
if left ~= "" then left = 'left:' .. left .. ';' end
if right ~= "" then right = 'right:' .. right .. ';' end
if bottom ~= "" then bottom = 'bottom:' .. bottom .. ';' end
local position = top .. left .. right .. bottom
output = output .. '<div style="position:absolute;' .. style .. position .. '">' .. label .. '</div>'
--background-color:#ffccff;top:75%;">
i=i+1
end
if output ~= "" then
local widthStr = ""
--widthStr = 'width:' .. (longestString*0.5)..'em;' -- can't take account of formatting or <br/>
if width then widthStr = 'width:' .. width end
output = '<div style="background-color:#ffffaa;'.. widthStr ..'">' .. output .. '</div>'
end
return output
end
return p