Editing Module:Aligned table
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 16: | Line 16: | ||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
-- add table style for fullwidth | -- add table style for fullwidth | ||
if isnotempty(args['fullwidth']) then | if isnotempty(args['fullwidth']) then | ||
root | root | ||
:css('width', '100%') | :css('width', '100%') | ||
:css('border-collapse', 'collapse') | :css('border-collapse', 'collapse') | ||
:css('border-spacing', ' | :css('border-spacing', '0px') | ||
:css('border', 'none') | :css('border', 'none') | ||
end | end | ||
Line 39: | Line 39: | ||
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 | ||
colclass[ i ] = colclass[ i ] or '' | colclass[ i ] = colclass[ i ] or '' | ||
colstyle[ i ] = colstyle[ i ] or '' | colstyle[ i ] = colstyle[ i ] or '' | ||
if isnotempty(args['colalign' .. tostring(i)]) then | if isnotempty(args['colalign' .. tostring(i)]) then | ||
colstyle[ i ] = 'text-align:' .. args['colalign' .. tostring(i)] .. ';' .. colstyle[ i ] | colstyle[ i ] = 'text-align:' .. args['colalign' .. tostring(i)] .. ';' .. colstyle[ i ] | ||
elseif isnotempty(args['align' .. tostring(i)]) then | elseif isnotempty(args['align' .. tostring(i)]) then | ||
colstyle[ i ] = 'text-align:' .. args['align' .. tostring(i)] .. ';' .. colstyle[ i ] | colstyle[ i ] = 'text-align:' .. args['align' .. tostring(i)] .. ';' .. colstyle[ i ] | ||
end | end | ||
if isnotempty(args['colnowrap' .. tostring(i)]) then | if isnotempty(args['colnowrap' .. tostring(i)]) then | ||
colstyle[ i ] = 'white-space:nowrap;' .. colstyle[ i ] | colstyle[ i ] = 'white-space:nowrap;' .. colstyle[ i ] | ||
elseif isnotempty(args['nowrap' .. tostring(i)]) then | elseif isnotempty(args['nowrap' .. tostring(i)]) then | ||
colstyle[ i ] = 'white-space:nowrap;' .. colstyle[ i ] | colstyle[ i ] = 'white-space:nowrap;' .. colstyle[ i ] | ||
end | end | ||
if isnotempty(args['colstyle' .. tostring(i)]) then | if isnotempty(args['colstyle' .. tostring(i)]) then | ||
colstyle[ i ] = colstyle[ i ] .. args['colstyle' .. tostring(i)] | colstyle[ i ] = colstyle[ i ] .. args['colstyle' .. tostring(i)] | ||
elseif isnotempty(args['style' .. tostring(i)]) then | elseif isnotempty(args['style' .. tostring(i)]) then | ||
colstyle[ i ] = colstyle[ i ] .. args['style' .. tostring(i)] | colstyle[ i ] = colstyle[ i ] .. args['style' .. tostring(i)] | ||
Line 80: | Line 60: | ||
if isnotempty(args['colclass' .. tostring(i)]) then | if isnotempty(args['colclass' .. tostring(i)]) then | ||
colclass[ i ] = args['colclass' .. tostring(i)] | colclass[ i ] = args['colclass' .. tostring(i)] | ||
elseif isnotempty(args['class' .. tostring(i)]) then | elseif isnotempty(args['class' .. tostring(i)]) then | ||
colclass[ i ] = args['class' .. tostring(i)] | colclass[ i ] = args['class' .. tostring(i)] | ||
Line 95: | Line 73: | ||
-- compute the number of rows | -- compute the number of rows | ||
local rows = math.ceil(cellcount / cols) | local rows = math.ceil(cellcount / cols) | ||
-- build the table content | -- build the table content | ||
for j=1,rows do | for j=1,rows do | ||
-- start a new row | -- start a new row | ||
local row = root:tag('tr') | local row = root:tag('tr') | ||
row:css('vertical-align', 'top') | |||
-- loop over the cells in each row | |||
-- loop over the cells in | |||
for i=1,cols do | for i=1,cols do | ||
local | local cell = row:tag('td') | ||
if args['class' .. tostring(j) .. '.' .. tostring(i)] then | if args['class' .. tostring(j) .. '.' .. tostring(i)] then | ||
cell:addClass(args['class' .. tostring(j) .. '.' .. tostring(i)]) | cell:addClass(args['class' .. tostring(j) .. '.' .. tostring(i)]) | ||
elseif args['rowclass' .. tostring(j)] then | |||
cell:addClass(args['rowclass' .. tostring(j)]) | |||
elseif colclass[i] ~= '' then | |||
cell:addClass(colclass[i]) | |||
end | end | ||
if args['style' .. tostring(j) .. '.' .. tostring(i)] then | if args['style' .. tostring(j) .. '.' .. tostring(i)] then | ||
cell:cssText(args['style' .. tostring(j) .. '.' .. tostring(i)]) | cell:cssText(args['style' .. tostring(j) .. '.' .. tostring(i)]) | ||
elseif args['rowstyle' .. tostring(j)] then | |||
cell:cssText(args['rowstyle' .. tostring(j)]) | |||
elseif colstyle[i] ~= '' then | |||
cell:cssText(colstyle[i]) | |||
end | end | ||
cell:wikitext | cell:wikitext(args[cols*(j - 1) + i] or '') | ||
end | |||
end | |||
-- return the root table | -- return the root table | ||
return tostring(root) | |||
end | end | ||
return p | return p |