模块:Test:修订间差异
跳到导航
跳到搜索
无编辑摘要 |
无编辑摘要 |
||
第2行: | 第2行: | ||
local params = {} | local params = {} | ||
params["prefix" ] = {' | params["prefix" ] = {'a'} | ||
params["tab_prefix" ] = 'tab_header' | params["tab_prefix" ] = 'tab_header' | ||
params["display_title" ] = {'false'} | params["display_title" ] = {'false'} | ||
第74行: | 第74行: | ||
function renderHeader(tbl) | function renderHeader(tbl) | ||
local | local row = tbl:tag('tr') | ||
for i=1,1 do | for i=1,1 do | ||
if params["display"][i] == " | if params["display"][i] == "false" then | ||
local header_th = | local header_th = row:tag('th') | ||
header_th | header_th | ||
:wikitext(params["header"][i]) | :wikitext(params["header"][i]) | ||
第93行: | 第93行: | ||
end | end | ||
function | function renderRow(row_id, args, tbl) | ||
local row = tbl:tag('tr') | |||
for i=1,1 do | |||
if params["display"][i] == "true" then | |||
local info = row:tag('td') | |||
info | |||
:wikitext(args[params["rowprefix"][i] .. row_id]) --单元格样式 | |||
:css('padding' ,'10px') | |||
:css('width' , params["col_width" ][i]) | |||
:css('height' , params["col_height" ][i]) | |||
:css('border-width' , params["border_width" ][i]) | |||
:css('border-color' , params["border_color" ][i]) | |||
:css('border-style' , params["border_style" ][i]) | |||
:css('text-align' , params["text" ][i]) | |||
if row_id % 2 == 0 then | |||
info | |||
:css('color' , params["color" ][i]) | |||
:css('background-color' , params["bg_color" ][i]) | |||
else | |||
info | |||
:css('color' , params["color_alt" ][i]) | |||
:css('background-color' , params["bg_color_alt" ][i]) | |||
end | |||
end | |||
end | |||
end | |||
function renderColumn(column_id, args, tbl) | |||
local column = tbl:tag('tr') | local column = tbl:tag('tr') | ||
for i=1, | for i=1,1 do | ||
if params["display"][i] == "true" then | if params["display"][i] == "true" then | ||
local info = column:tag(' | local info = column:tag('td') | ||
info | info | ||
:wikitext(args[params["prefix"][i] .. column_id]) --单元格样式 | :wikitext(args[params["prefix"][i] .. column_id]) --单元格样式 | ||
第121行: | 第149行: | ||
end | end | ||
end | end | ||
--处理表格 | --处理表格 | ||
function renderTable(args, | function renderTable(args, row_ids) | ||
local tbl = mw.html.create('table') | local tbl = mw.html.create('table') | ||
:addClass('wikitable') | :addClass('wikitable') | ||
:addClass('mw-collapsible') | :addClass('mw-collapsible') | ||
:addClass(' | :addClass('plainrowheaders') | ||
:css('overflow-x', 'auto') | :css('overflow-x', 'auto') | ||
:css('width', "fit-content") | :css('width', "fit-content") | ||
第144行: | 第173行: | ||
renderHeader(tbl) | renderHeader(tbl) | ||
for _, a in ipairs( | for _, a in ipairs(row_ids) do | ||
renderRow(a, args, tbl) | |||
end | end | ||
第152行: | 第181行: | ||
function renderTabs(args) | function renderTabs(args) | ||
-- extract | -- extract row_ids in each tables | ||
-- i hate lua why array subscribtion starts at 1 | -- i hate lua why array subscribtion starts at 1 | ||
local | local tot_row_ids = {} | ||
for k, _ in pairs(args) do | for k, _ in pairs(args) do | ||
local anum = ('' .. k):match('^a(%d+)$') | local anum = ('' .. k):match('^a(%d+)$') | ||
if anum then | if anum then | ||
table.insert( | table.insert(tot_row_ids, tonumber(anum)) | ||
end | end | ||
end | end | ||
table.sort( | table.sort(tot_row_ids) | ||
local tab_count = 0 | local tab_count = 0 | ||
local current_item_count = 0 | local current_item_count = 0 | ||
local current_max_item = tonumber(params["item_per_tab"]) | local current_max_item = tonumber(params["item_per_tab"]) | ||
local | local tabs_row_ids = {} | ||
for i, a in ipairs( | for i, a in ipairs(tot_row_ids) do | ||
if current_item_count == 0 then | if current_item_count == 0 then | ||
if tab_count ~= 0 then table.sort( | if tab_count ~= 0 then table.sort(tabs_row_ids[tab_count]) end | ||
tab_count = tab_count + 1 | tab_count = tab_count + 1 | ||
if args["item_in_tab"..tostring(tab_count)] then | if args["item_in_tab"..tostring(tab_count)] then | ||
第176行: | 第205行: | ||
current_max_item = tonumber(params["item_per_tab"]) | current_max_item = tonumber(params["item_per_tab"]) | ||
end | end | ||
tabs_row_ids[tab_count] = {} | |||
end | end | ||
table.insert( | table.insert(tabs_row_ids[tab_count], a) | ||
current_item_count = current_item_count + 1 | current_item_count = current_item_count + 1 | ||
if current_item_count == current_max_item then | if current_item_count == current_max_item then | ||
第192行: | 第221行: | ||
:css("max-height", params["max_height"]) | :css("max-height", params["max_height"]) | ||
:css("box-shadow", params["shadow"]) | :css("box-shadow", params["shadow"]) | ||
local tbl = renderTable(args, | local tbl = renderTable(args, tot_row_ids) | ||
constraint_div:node(tbl) | constraint_div:node(tbl) | ||
return constraint_div | return constraint_div | ||
第213行: | 第242行: | ||
local current_count = 1 | local current_count = 1 | ||
for i, | for i, row_ids in ipairs(tabs_row_ids) do | ||
local list_ele = tab_list:tag("li") | local list_ele = tab_list:tag("li") | ||
if i == 1 then | if i == 1 then | ||
第224行: | 第253行: | ||
ele_title:wikitext(args[params['tab_prefix']..tostring(i)]) | ele_title:wikitext(args[params['tab_prefix']..tostring(i)]) | ||
else | else | ||
ele_title:wikitext(tostring(current_count).."~"..tostring(current_count+tableLength( | ele_title:wikitext(tostring(current_count).."~"..tostring(current_count+tableLength(row_ids)-1)) | ||
end | end | ||
current_count = current_count + tableLength( | current_count = current_count + tableLength(row_ids) | ||
end | end | ||
第235行: | 第264行: | ||
:css("width", "auto") | :css("width", "auto") | ||
:css("height", "auto") | :css("height", "auto") | ||
for i, | for i, row_ids in ipairs(tabs_row_ids) do | ||
local table_ele = tables_list:tag("div") | local table_ele = tables_list:tag("div") | ||
if i == 1 then | if i == 1 then | ||
第250行: | 第279行: | ||
:css("width", "auto") | :css("width", "auto") | ||
:css("height", "auto") | :css("height", "auto") | ||
local content_tbl = renderTable(args, | local content_tbl = renderTable(args, row_ids) | ||
inner_content:node(content_tbl) | inner_content:node(content_tbl) | ||
end | end |