Module:Aligned table and Module:Aligned table/sandbox: Difference between pages
(Difference between pages)
imported>Plastikspork Optional rowclass |
imported>Great Brightstar mNo edit summary |
||
| Line 12: | Line 12: | ||
local colstyle = {} | local colstyle = {} | ||
local cols = tonumber(args['cols']) or 2 | local cols = tonumber(args['cols']) or 2 | ||
local noblankrows = args['noblankrows'] or '' | |||
-- create the root table | -- create the root table | ||
| Line 39: | Line 40: | ||
colstyle[1] = 'text-align:left;' | colstyle[1] = 'text-align:left;' | ||
colstyle[2] = 'text-align:right;' | colstyle[2] = 'text-align:right;' | ||
end | end | ||
for i = 1,cols do | for i = 1,cols do | ||
| Line 110: | Line 107: | ||
end | end | ||
for j=1,rows do | for j=1,rows do | ||
-- skip blank rows, if feature is enabled | |||
local showrow = 1 | |||
if isnotempty(noblankrows) then | |||
showrow = 0 | |||
for i=1,cols do | |||
if isnotempty(args[cols*(j - 1) + i] or '') then | |||
showrow = 1 | |||
end | |||
end | |||
end | |||
-- start a new row | -- start a new row | ||
local row = root:tag('tr') | local row = root:tag('tr') | ||
| Line 115: | Line 122: | ||
row:cssText(args['rowstyle']) | row:cssText(args['rowstyle']) | ||
else | else | ||
row:css('vertical-align', 'top' | --row:css('vertical-align', 'top') | ||
end | end | ||
-- loop over the cells in the row | -- loop over the cells in the row | ||
if showrow == 1 then | |||
for i=1,cols do | for i=1,cols do | ||
local cell | local cell | ||
| Line 137: | Line 142: | ||
elseif args['row' .. tostring(j) .. 'class'] then | elseif args['row' .. tostring(j) .. 'class'] then | ||
cell:addClass(args['row' .. tostring(j) .. 'class']) | cell:addClass(args['row' .. tostring(j) .. 'class']) | ||
end | end | ||
if colclass[i] ~= '' then | if colclass[i] ~= '' then | ||
| Line 151: | Line 152: | ||
if args['rowstyle' .. tostring(j)] then | if args['rowstyle' .. tostring(j)] then | ||
cell:cssText(args['rowstyle' .. tostring(j)]) | cell:cssText(args['rowstyle' .. tostring(j)]) | ||
elseif args['row' .. tostring(j) .. 'style'] then | elseif args['row' .. tostring(j) .. 'style'] then | ||
cell:cssText(args['row' .. tostring(j) .. 'style']) | cell:cssText(args['row' .. tostring(j) .. 'style']) | ||
| Line 163: | Line 160: | ||
end | end | ||
cell:wikitext(mw.ustring.gsub(args[cols*(j - 1) + i] or '', '^(.-)%s*$', '%1') or '') | cell:wikitext(mw.ustring.gsub(args[cols*(j - 1) + i] or '', '^(.-)%s*$', '%1') or '') | ||
end | |||
end | end | ||
end | end | ||