ATLAS Wiki
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 4: Line 4:
   
 
local listtype, extrastyle = 'ul', ''
 
local listtype, extrastyle = 'ul', ''
local commas = false
 
 
local iconsize = args.iconsize or '20px'
 
local iconsize = args.iconsize or '20px'
 
local showOne = args.showQuantityOne or false
 
local showOne = args.showQuantityOne or false
Line 24: Line 23:
 
if args.listtype == 'ol' then
 
if args.listtype == 'ol' then
 
listtype = 'ol'
 
listtype = 'ol'
elseif args.listtype == 'comma' then
 
commas = true
 
 
else -- none
 
else -- none
 
extrastyle = extrastyle..'list-style:none;margin-left:0;'
 
extrastyle = extrastyle..'list-style:none;margin-left:0;'
Line 69: Line 66:
 
-- output itemList
 
-- output itemList
 
local output = {}
 
local output = {}
 
local widestItem = 0
 
local quantitySign = asPerCent and '% ' or ' × '
 
local quantitySign = asPerCent and '% ' or ' × '
 
for _, item in ipairs(itemList) do
 
for _, item in ipairs(itemList) do
 
local fileName = string.gsub(item[1],':',' ')
 
local fileName = string.gsub(item[1],':',' ')
if commas then
+
if string.len(item[1]) > widestItem then
  +
widestItem = string.len(item[1])
table.insert(output, ', '..(item[2] ~= nil and item[2]..quantitySign or '')..'<span style="white-space:nowrap;">[[File:'..fileName..'.png|'..iconsize..']] '..'[['..(item[1])..']]</span>')
 
else
 
table.insert(output, '<li>'..(item[2] ~= nil and item[2]..quantitySign or '')..'[[File:'..fileName..'.png|'..iconsize..']] '..'[['..(item[1])..']]'..'</li>')
 
 
end
 
end
  +
 
table.insert(output, '<li>'..(item[2] ~= nil and item[2]..quantitySign or '')..'[[File:'..fileName..'.png|'..iconsize..']] '..'[['..(item[1])..']]'..'</li>')
 
end
 
end
   
Line 83: Line 81:
 
end
 
end
   
-- if maxRows is specified and columns is not specified, break into new columns at given intervals
+
--[[ If maxRows is specified and columns is not specified; break into new columns at given intervals.
  +
Then if columnWidth is not specified sets column-width to fit the longest item.
 
 
if args.maxRows ~= nil and args.columns == nil then
 
if args.maxRows ~= nil and args.columns == nil then
extrastyle = extrastyle..'column-count:'..math.ceil(#output/args.maxRows)..';'
+
extrastyle = extrastyle..'column-count:'..math.ceil(#output/args.maxRows)..';'
 
if args.columnWidth ~= nil then
  +
extrastyle = extrastyle..'column-width: calc('..widestItem..'em+1em+'..iconsize..');'
 
end
 
end
 
end
  +
]]
   
 
-- if the list is long and has no explicit style, break it into columns automatically
 
-- if the list is long and has no explicit style, break it into columns automatically
if #output > 5 and extrastyle == '' and not commas then
+
if #output > 5 and extrastyle == '' then
 
extrastyle = 'column-width:15em;'
 
extrastyle = 'column-width:15em;'
 
end
 
end
  +
if commas then
 
 
return '<'..listtype..(extrastyle ~= '' and ' style="'..extrastyle..'"' or '')..'>'..table.concat(output, '')..'</'..listtype..'>'
output[1] = output[1]:sub(3, #output[1])
 
return '<div'..(extrastyle ~= '' and ' style="'..extrastyle..'"' or '')..'>'..table.concat(output, '')..'</div>'
 
else
 
return '<'..listtype..(extrastyle ~= '' and ' style="'..extrastyle..'"' or '')..'>'..table.concat(output, '')..'</'..listtype..'>'
 
end
 
 
end
 
end
   
Please note that all contributions to the ATLAS Wiki are considered to be released under the CC BY-NC-SA
Cancel Editing help (opens in new window)

Template used on this page:

  • Module:Sandbox/Vemsvims/doc (edit)