模块:Test:修订间差异

跳到导航 跳到搜索
无编辑摘要
无编辑摘要
第2行: 第2行:


local params = {}
local params = {}
params["prefix"                ] = {'a'}
params["prefix"                ] = {'n', 'i'}
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 row = tbl:tag('tr')
     local column = tbl:tag('tr')
     for i=1,1 do
     for i=1,1 do
         if params["display"][i] == "false" then  
         if params["display"][i] == "false" then  
             local header_th = row:tag('th')
             local header_th = column:tag('th')
             header_th
             header_th
                 :wikitext(params["header"][i])
                 :wikitext(params["header"][i])
第93行: 第93行:
end
end


function renderRow(row_id, args, tbl)
function rendercolumn(column_id, args, tbl)
     local row = tbl:tag('tr')
     local column = tbl:tag('tr')


     for i=1,1 do
     for i=1,2 do
         if params["display"][i] == "true" then  
         if params["display"][i] == "true" then  
             local info = row:tag('tr')
             local info = column:tag('tr')
             info
             info
                 :wikitext(args[params["prefix"][i] .. row_id]) --单元格样式
                 :wikitext(args[params["prefix"][i] .. column_id]) --单元格样式
                 :css('padding'              ,'10px')
                 :css('padding'              ,'10px')
                 :css('width'                , params["col_width"    ][i])
                 :css('width'                , params["col_width"    ][i])
第108行: 第108行:
                 :css('border-style'        , params["border_style"  ][i])
                 :css('border-style'        , params["border_style"  ][i])
                 :css('text-align'          , params["text"          ][i])
                 :css('text-align'          , params["text"          ][i])
             if row_id % 2 == 0 then
             if column_id % 2 == 0 then
                 info
                 info
                     :css('color'            , params["color"        ][i])
                     :css('color'            , params["color"        ][i])
第123行: 第123行:


--处理表格
--处理表格
function renderTable(args, row_ids)
function renderTable(args, column_ids)
     local tbl = mw.html.create('table')
     local tbl = mw.html.create('table')
         :addClass('wikitable')
         :addClass('wikitable')
         :addClass('mw-collapsible')
         :addClass('mw-collapsible')
         :addClass('plainrowheaders')
         :addClass('plaincolumnheaders')
         :css('overflow-x', 'auto')
         :css('overflow-x', 'auto')
         :css('width', "fit-content")
         :css('width', "fit-content")
第144行: 第144行:
     renderHeader(tbl)
     renderHeader(tbl)
      
      
     for _, a in ipairs(row_ids) do  
     for _, a in ipairs(column_ids) do  
         renderRow(a, args, tbl)
         renderColumn(a, args, tbl)
     end
     end


第152行: 第152行:


function renderTabs(args)
function renderTabs(args)
     -- extract row_ids in each tables
     -- extract column_ids in each tables
     -- i hate lua why array subscribtion starts at 1
     -- i hate lua why array subscribtion starts at 1
     local tot_row_ids = {}
     local tot_column_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(tot_row_ids, tonumber(anum))  
             table.insert(tot_column_ids, tonumber(anum))  
         end
         end
     end
     end
     table.sort(tot_row_ids)
     table.sort(tot_column_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 tabs_row_ids = {}
     local tabs_column_ids = {}
     for i, a in ipairs(tot_row_ids) do
     for i, a in ipairs(tot_column_ids) do
         if current_item_count == 0 then
         if current_item_count == 0 then
             if tab_count ~= 0 then table.sort(tabs_row_ids[tab_count]) end
             if tab_count ~= 0 then table.sort(tabs_column_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行: 第176行:
                 current_max_item = tonumber(params["item_per_tab"])
                 current_max_item = tonumber(params["item_per_tab"])
             end
             end
             tabs_row_ids[tab_count] = {}
             tabs_column_ids[tab_count] = {}
         end
         end
         table.insert(tabs_row_ids[tab_count], a)
         table.insert(tabs_column_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行: 第192行:
             :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, tot_row_ids)
         local tbl = renderTable(args, tot_column_ids)
         constraint_div:node(tbl)
         constraint_div:node(tbl)
         return constraint_div
         return constraint_div
第213行: 第213行:
      
      
     local current_count = 1
     local current_count = 1
     for i, row_ids in ipairs(tabs_row_ids) do
     for i, column_ids in ipairs(tabs_column_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行: 第224行:
             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(row_ids)-1))
             ele_title:wikitext(tostring(current_count).."~"..tostring(current_count+tableLength(column_ids)-1))
         end
         end
         current_count = current_count + tableLength(row_ids)
         current_count = current_count + tableLength(column_ids)
     end
     end


第235行: 第235行:
         :css("width", "auto")
         :css("width", "auto")
         :css("height", "auto")
         :css("height", "auto")
     for i, row_ids in ipairs(tabs_row_ids) do
     for i, column_ids in ipairs(tabs_column_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行: 第250行:
             :css("width", "auto")
             :css("width", "auto")
             :css("height", "auto")
             :css("height", "auto")
         local content_tbl = renderTable(args, row_ids)
         local content_tbl = renderTable(args, column_ids)
         inner_content:node(content_tbl)
         inner_content:node(content_tbl)
     end
     end