|
|
(未显示同一用户的110个中间版本) |
第1行: |
第1行: |
| local p = {}
| |
|
| |
|
| local params = {}
| |
| params["prefix" ] = {'a', 'i', 'e'}
| |
| params["tab_prefix" ] = 'tab_header'
| |
| params["display_title" ] = {'false'}
| |
| params["title" ] = "表格默认标题"
| |
| params["item_per_tab" ] = "50"
| |
| params["max_width" ] = "60%"
| |
| params["tab_color" ] = "#004B97"
| |
| params["tab_bg_color" ] = "#FF9224"
| |
| params["header" ] = {'作者', '主题', '简介'}
| |
| params["color" ] = {'#004B97', '#0066CC', '#0066CC'}
| |
| params["bg_color" ] = {'#FF9224', '#FFDCB9', '#FFE4CA'}
| |
| params["color_alt" ] = {'#004B97', '#0066CC', '#0066CC'}
| |
| params["bg_color_alt" ] = {'#FFA042', '#FFE4CA', '#FFFFEA'}
| |
| params["header_color" ] = {'#004B97', '#0066CC', '#0066CC'}
| |
| params["header_bg_color" ] = {'#FF9224', '#FFAD86', '#FFAD86'}
| |
| params["display" ] = {'true', 'true', 'true'}
| |
| params["col_width" ] = {'10%', '40%', '50%'}
| |
| params["border_color" ] = {
| |
| '#D26900 #FF9224 #D26900 #D26900',
| |
| '#D26900 #FFDCB9 #D26900 #FF9224',
| |
| '#D26900 #D26900 #D26900 #FF9224',
| |
| }
| |
| params["header_border_color" ] = {
| |
| '#D26900 #FF9224 #D26900 #D26900',
| |
| '#D26900 #FFAD86 #D26900 #FFAD86',
| |
| '#D26900 #D26900 #D26900 #FF9224',
| |
| }
| |
| params["border_style" ] = {
| |
| "dashed solid double double",
| |
| "dashed double double solid",
| |
| "dashed double double solid",
| |
| }
| |
| params["header_border_style" ] = {
| |
| "double solid dashed double",
| |
| "double double dashed solid",
| |
| "double double dashed solid",
| |
| }
| |
| params["border_width" ] = {
| |
| "5px 1px 3px 5px",
| |
| "5px 1px 3px 1px",
| |
| "5px 5px 3px 1px",
| |
| }
| |
| params["header_border_width" ] = {
| |
| "5px 1px 3px 5px",
| |
| "5px 1px 3px 1px",
| |
| "5px 5px 3px 1px",
| |
| }
| |
|
| |
| local global_param_list = {
| |
| "title",
| |
| "display_title",
| |
| "item_per_tab",
| |
| "max_width",
| |
| "tab_color",
| |
| "tab_bg_color"
| |
| }
| |
|
| |
| local col_param_list = {
| |
| "header" ,
| |
| "color" ,
| |
| "bg_color" ,
| |
| "color_alt" ,
| |
| "bg_color_alt" ,
| |
| "header_color" ,
| |
| "header_bg_color" ,
| |
| "display" ,
| |
| "col_width" ,
| |
| "border_color" ,
| |
| "header_border_color" ,
| |
| "border_style" ,
| |
| "header_border_style" ,
| |
| "border_width" ,
| |
| "header_border_width" ,
| |
| }
| |
|
| |
| function renderHeader(tbl)
| |
| local row = tbl:tag('tr')
| |
| for i=1,3 do
| |
| if params["display"][i] == "true" then
| |
| local header_th = row:tag('th')
| |
| header_th
| |
| :wikitext(params["header"][i])
| |
| :css('padding' ,'10px')
| |
| :css('width' , params["col_width" ][i])
| |
| :css('color' , params["header_color" ][i])
| |
| :css('background-color' , params["header_bg_color" ][i])
| |
| :css('border-width' , params["header_border_width" ][i])
| |
| :css('border-color' , params["header_border_color" ][i])
| |
| :css('border-style' , params["header_border_style" ][i])
| |
| end
| |
| end
| |
| end
| |
|
| |
| function renderRow(row_id, args, tbl)
| |
| local row = tbl:tag('tr')
| |
|
| |
| for i=1,3 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('border-width' , params["border_width" ][i])
| |
| :css('border-color' , params["border_color" ][i])
| |
| :css('border-style' , params["border_style" ][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 renderTable(args, row_ids)
| |
| local tbl = mw.html.create('table')
| |
| :addClass('wikitable')
| |
| :addClass('mw-collapsible')
| |
| :addClass('mw-collapsed')
| |
| :addClass('plainrowheaders')
| |
| :css('overflow-x', 'auto')
| |
| :css('width', "100%")
| |
|
| |
| if params["display_title"] == "true" then
| |
| local caption = tbl:tag('caption')
| |
| caption
| |
| :wikitext(title)
| |
| :css('white-space', 'nowrap')
| |
| end
| |
|
| |
| renderHeader(tbl)
| |
|
| |
| for _, a in ipairs(row_ids) do
| |
| renderRow(a, args, tbl)
| |
| end
| |
|
| |
| return tbl
| |
| end
| |
|
| |
| function renderTabs(args)
| |
| -- extract row_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)
| |
|
| |
| local tab_count = 0
| |
| local current_item_count = 0
| |
| local current_max_item = tonumber(params["item_per_tab"])
| |
| local tabs_row_ids = {}
| |
| for i, a in ipairs(tot_row_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
| |
|
| |
| -- if only one table is needed...
| |
| if tab_count == 1 then
| |
| local constraint_div = mw.html.create('div')
| |
| constraint_div
| |
| :css("max-width", params["max_width"])
| |
| local tbl = renderTable(args, tot_row_ids)
| |
| constraint_div:node(tbl)
| |
| return constraint_div
| |
| end
| |
|
| |
| -- create tabs-container
| |
| local tabs_div = mw.html.create('div')
| |
| tabs_div
| |
| :addClass("tabs-container")
| |
| :css("max-width", params["max_width"])
| |
|
| |
| -- create tab ui list
| |
| local tab_list = tabs_div:tag("ul")
| |
| tab_list
| |
| :addClass("tabs-pages")
| |
| :css("margin", "0")
| |
| :css("overflow-x", "auto")
| |
|
| |
| local current_count = 1
| |
| for i, row_ids in ipairs(tabs_row_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
| |
|
| |
| -- create actual tables
| |
| local tables_list = tabs_div:tag("div")
| |
| tables_list
| |
| :addClass("tabs-contents")
| |
| :css("width", "auto")
| |
|
| |
| for i, row_ids in ipairs(tabs_row_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")
| |
| local inner_content = table_ele:tag("div")
| |
| inner_content
| |
| :addClass("inner-content")
| |
| :css("columns", "1")
| |
| :css("width", "auto")
| |
| local content_tbl = renderTable(args, row_ids)
| |
| inner_content:node(content_tbl)
| |
| end
| |
| return tabs_div
| |
| end
| |
|
| |
| function tableLength(t)
| |
| local count = 0
| |
| for _ in pairs(t) do count = count + 1 end
| |
| return count
| |
| end
| |
|
| |
| function p._historicalActivity(args)
| |
| -- deal with params
| |
| for _, key in ipairs(global_param_list) do
| |
| if args[key] then
| |
| params[key] = args[key]
| |
| end
| |
| end
| |
|
| |
| for _, key in ipairs(col_param_list) do
| |
| for i=1,3 do
| |
| if args[key..tostring(i)] then
| |
| params[key][i] = args[key..tostring(i)]
| |
| end
| |
| end
| |
| end
| |
|
| |
| --处理表格
| |
| local tb1 = renderTabs(args)
| |
|
| |
| local res = mw.html.create()
| |
| res:node(tb1)
| |
|
| |
| return tostring(res)
| |
| end
| |
|
| |
| function p.historicalActivity(frame)
| |
| local args = {}
| |
| local parent_args = frame:getParent().args;--获取页面传来得参数,而不是模板的参数
| |
|
| |
| --将获取的参数传给args
| |
| for k, v in pairs(parent_args) do
| |
| if v ~= '' then
| |
| args[k] = v
| |
| end
| |
| end
| |
| return p._historicalActivity(args)
| |
| end
| |
|
| |
| return p
| |