Module:Tab

local p = {}

function p.tab(frame) -- Name input for convenience local in_args = frame:getParent.args -- Get number of tabs being given as an integer local tabs = tonumber(in_args.tabs) -- Check if the default is set, if not assume tab 1 local default = tonumber(in_args.default) or 1 -- If default is higher than number of tabs, put it back to 1 if default > tabs then default = 1 end -- Create container for the tabs local tabheader = mw.html.create("div") :css("margin", "3px auto 0") :css("display", "table") :css("width", in_args.width)

-- Create tab container (the tabs themselves, the contents come later) local tabcontainer = tabheader:tag("div") :addClass("tabcontainer") for i = 1, tabs do		-- Skip tabs with no content in them if in_args["content" .. i] ~= "" and in_args["content" .. i] ~= nil then local span = tabcontainer:tag("span") :addClass("tab_tab") :wikitext(in_args["tab" .. i]) if i == default then span:addClass("tabselected") end span:done:wikitext(" ") end end tabcontainer:done -- Create tab content container local tabcontents = tabheader:tag("div") :addClass("tabcontents") :cssText(in_args.constyle)

for i = 1, tabs do if in_args["content" .. i] ~= "" and in_args["content" .. i] ~= nil then local content = tabcontents:tag("div") :addClass("tab_content") :wikitext(in_args["content" .. i]) if i == default then content:css("display", "block") else content:css("display", "none") end end end return tabheader end

return p