模块:Navbox

Litwak913留言 | 贡献2022年8月6日 (六) 00:00的版本

可在模块:Navbox/doc创建此模块的帮助文档

local p = {}
local function wvar(frame,arg,def)
  if(frame.args[arg]) then
    return frame.args[arg]
  else
    return def
  end
end
local function wif(arg,a,b)
  if(arg) then
    return a
  else
    return b
  end
end
local function wifeq(x,y,a,b)
  if(x==y) then
    return a
  else
    return b
  end
end
local function switchstate(frame)
  local state=wvar(frame,'state','')
  if (state==plain or state==off) then
    return ''
  else
    return 'mw-collapsible '
           .. wif(wvar(frame,'state',''),state,'autocollapse')
  end
end
local function border(frame)
  local arg=wvar(frame,'border',wvar(frame,1,''))
  if(arg=="subgroup" or arg=="child") 
  then
    return "</div>"
  elseif(arg=="none") 
  then
    return ""
  else
    return '<table class="navbox ' 
           .. wvar(frame,'class','') 
           .. '" cellspacing="0" style="' 
           .. wvar(frame,'bodystyle','')
           ..';'
           .. wvar(frame,'style','') 
           .. '"><tr><td style="padding:2px;">'
  end
end
local function switchborder(frame)
  local border=wvar(frame,'border',wvar(frame,1,''))
  if(border == 'subgroup' or border == 'child' or border == 'none') then
    return 'navbox-subgroup" style="display:table;width:100%;'
           .. wvar(frame,'bodystyle','')
           .. ';'
           .. wvar(frame,'style','')
  else
    return ' style="display:table;width:100%;background:transparent;color:inherit'
  end
end
-- '<table cellspacing="0" class="nowraplinks {{#if:{{{title|}}}|{{#switch:{{{state|}}}|plain|off=|#default=mw-collapsible {{#if:{{{state|}}}|{{{state}}}|autocollapse}}}}}} {{#switch:{{{border|{{{1|}}}}}}|subgroup|child|none=navbox-subgroup" style="display:table;width:100%;{{{bodystyle|}}};{{{style|}}}|#default=" style="display:table;width:100%;background:transparent;color:inherit}};{{{innerstyle|}}};">'
local function tablestart(frame)
  return '<table cellspacing="0" class="nowraplinks '
         .. wif(wvar(frame,'title',nil),switchstate(frame),'')
         .. '  '
         .. switchborder(frame)
         .. ';'
         .. wvar(frame,'innerstyle','')
         .. ';">'
end
function p.navbox(frame)
mw.log(switchborder(frame))
return border(frame) .. tablestart(frame)
end
return p