Editing Module:Aligned table
From MINR.ORG 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 save 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 43: | Line 43: | ||
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 76: | 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 91: | 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 |