Module:Aligned table: Difference between revisions

m
(should work now)
m (59 revisions imported from wikipedia:Module:Aligned_table: see Topic:Vtixlm0q28eo6jtf)
 
(7 intermediate revisions by 3 users not shown)
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 40: Line 39:
colstyle[1] = 'text-align:left;'
colstyle[1] = 'text-align:left;'
colstyle[2] = 'text-align:right;'
colstyle[2] = 'text-align:right;'
end
if isnotempty(args['rightleft']) then
colstyle[1] = 'text-align:right;'
colstyle[2] = 'text-align:left;'
end
end
for i = 1,cols do
for i = 1,cols do
Line 114: Line 117:
row:css('vertical-align', 'top')
row:css('vertical-align', 'top')
end
end
-- skip blank rows, if feature is enabled
if isnotempty(args['rowclass']) then
local showrow = 1
row:addClass(args['rowclass'])
if isnotempty(noblankrows) then
showrow = 0
for i=1,cols do
if isnotempty(args[cols*(j - 1) + i] or '') then
showrow = 1
break
end
end
end
end
-- loop over the cells in the row
-- loop over the cells in the row
if showrow then
for i=1,cols do
for i=1,cols do
local cell
local cell
Line 143: Line 137:
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'])
elseif args['rowevenclass'] and math.fmod(j,2) == 0 then
cell:addClass(args['rowevenclass'])
elseif args['rowoddclass'] and math.fmod(j,2) == 1 then
cell:addClass(args['rowoddclass'])
end
end
if colclass[i] ~= '' then
if colclass[i] ~= '' then
Line 153: Line 151:
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['rowevenstyle'] and math.fmod(j,2) == 0 then
cell:cssText(args['rowevenstyle'])
elseif args['rowoddstyle'] and math.fmod(j,2) == 1 then
cell:cssText(args['rowoddstyle'])
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 161: Line 163:
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