模块:Test:修订间差异

跳到导航 跳到搜索
删除4,099字节 、​ 2023年11月18日 (星期六)
无编辑摘要
无编辑摘要
无编辑摘要
第2行: 第2行:


local params = {}
local params = {}
params["prefix"                ] = {'n', 'i'}
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 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] == "true" 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)
    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["prefix"][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)
function renderColumn(column_id, args, tbl)
     local column = tbl:tag('tr')
     local column = tbl:tag('tr')


     for i=1,2 do
     for i=1,1 do
         if params["display"][i] == "true" then  
         if params["display"][i] == "true" then  
             local info = column:tag('td')
             local info = column:tag('td')
第149行: 第121行:
     end
     end
end
end


--处理表格
--处理表格
function renderTable(args, row_ids)
function renderTable(args, column_ids)
    local tbl = mw.html.create('table')
        :addClass('wikitable')
        :addClass('mw-collapsible')
        :addClass('plainrowheaders')
        :css('overflow-x', 'auto')
        :css('width', "fit-content")
        :css('height', "fit-content")
       
    if args['collapsed'] then tbl:addClass('mw-collapsed') end
 
   
    if params["display_title"] == "true" then
        local caption = tbl:tag('caption')
        caption
            :wikitext(title)
            :css('white-space', 'nowrap')
    end
 
function renderTable(args, columns_ids)
     local tbl = mw.html.create('table')
     local tbl = mw.html.create('table')
         :addClass('wikitable')
         :addClass('wikitable')
         :addClass('mw-collapsible')
         :addClass('mw-collapsible')
         :addClass('plaincolumnsheaders')
         :addClass('plaincolumnheaders')
         :css('overflow-x', 'auto')
         :css('overflow-x', 'auto')
         :css('width', "fit-content")
         :css('width', "fit-content")
第189行: 第141行:
             :css('white-space', 'nowrap')
             :css('white-space', 'nowrap')
     end
     end


     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


第201行: 第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
    local tot_row_ids = {}
    for k, _ in pairs(args) do
        local anum = ('' .. k):match('^a(%d+)$')
        if anum then
            table.insert(tot_row_ids, tonumber(anum))
        end
    end
    table.sort(tot_row_ids)
 
    -- extract columns_ids in each tables
     -- i hate lua why array subscribtion starts at 1
     -- i hate lua why array subscribtion starts at 1
     local tot_columns_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_columns_ids, tonumber(anum))  
             table.insert(tot_column_ids, tonumber(anum))  
         end
         end
     end
     end
     table.sort(tot_columns_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 tab_count ~= 0 then table.sort(tabs_row_ids[tab_count]) end
            tab_count = tab_count + 1
            if args["item_in_tab"..tostring(tab_count)] then
                current_max_item = tonumber(args["item_in_tab"..tostring(tab_count)])
            else
                current_max_item = tonumber(params["item_per_tab"])
            end
            tabs_row_ids[tab_count] = {}
        end
        table.insert(tabs_row_ids[tab_count], a)
        current_item_count = current_item_count + 1
        if current_item_count == current_max_item then
            current_item_count = 0
        end
    end
   
    local tabs_columns_ids = {}
    for i, a in ipairs(tot_columns_ids) do
         if current_item_count == 0 then
         if current_item_count == 0 then
             if tab_count ~= 0 then table.sort(tabs_columns_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
第255行: 第176行:
                 current_max_item = tonumber(params["item_per_tab"])
                 current_max_item = tonumber(params["item_per_tab"])
             end
             end
             tabs_columns_ids[tab_count] = {}
             tabs_column_ids[tab_count] = {}
         end
         end
         table.insert(tabs_columns_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
第271行: 第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)
        local tbl = renderTable(args, tot_columns_ids)
         constraint_div:node(tbl)
         constraint_div:node(tbl)
         return constraint_div
         return constraint_div
第293行: 第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")
        if i == 1 then
            list_ele:addClass("active")
        end
        local ele_title = list_ele
            :addClass("tab")
            :tag("strong")
        if args[params['tab_prefix']..tostring(i)] then
            ele_title:wikitext(args[params['tab_prefix']..tostring(i)])
        else
            ele_title:wikitext(tostring(current_count).."~"..tostring(current_count+tableLength(row_ids)-1))
        end
        current_count = current_count + tableLength(row_ids)
    end
 
    for i, columns_ids in ipairs(tabs_columns_ids) do
         local list_ele = tab_list:tag("li")
         local list_ele = tab_list:tag("li")
         if i == 1 then
         if i == 1 then
第320行: 第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(columns_ids)-1))
             ele_title:wikitext(tostring(current_count).."~"..tostring(current_count+tableLength(column_ids)-1))
         end
         end
         current_count = current_count + tableLength(columns_ids)
         current_count = current_count + tableLength(column_ids)
     end
     end


第331行: 第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")
        if i == 1 then
            table_ele:addClass("active")
        end
        table_ele
            :addClass("tab-c")
            :css("width", "auto")
            :css("height", "auto")
        local inner_content = table_ele:tag("div")
        inner_content
            :addClass("inner-content")
            :css("columns", "2")
            :css("width", "auto")
            :css("height", "auto")
        local content_tbl = renderTable(args, row_ids)
        inner_content:node(content_tbl)
    end
        for i, columns_ids in ipairs(tabs_columns_ids) do
         local table_ele = tables_list:tag("div")
         local table_ele = tables_list:tag("div")
         if i == 1 then
         if i == 1 then
第361行: 第247行:
         inner_content
         inner_content
             :addClass("inner-content")
             :addClass("inner-content")
             :css("columns", "2")
             :css("rows", "1")
             :css("width", "auto")
             :css("width", "auto")
             :css("height", "auto")
             :css("height", "auto")
         local content_tbl = renderTable(args, columns_ids)
         local content_tbl = renderTable(args, column_ids)
         inner_content:node(content_tbl)
         inner_content:node(content_tbl)
     end
     end
第413行: 第299行:
     return p._historicalActivity(args)
     return p._historicalActivity(args)
end
end
end
 
return p
return p
15,487

个编辑

导航菜单