Module:SubpageTabs

--[=[-- SubPageTabs Module

Creates Set of Tabs linking to Sub-Pages The first Tab is the main page.

* Fully CSS styled (inline styles possible but not default) * Supports unlimited tabs

By User:Effan_R from disneymagickingdomswiki.fandom.com Adapted from WikiText Template 'Parent Tab Template' from godofhighschool.fandom.com

--]=]--

local p = {}

--- Get Arguments --- Frame Arguments have preference over Parent Arguments local function getArgs(frame) local tArgs = {}

if frame == mw.getCurrentFrame then tArgs = frame.args if not frame.args[1] then fParent = frame:getParent if (fParent.args[1]) then tArgs = fParent.args end end else tArgs = frame end

return tArgs end

local function addTab(tabRow, data, curTitle, tArgs) local tabTab = tabRow:tag("div") :addClass('SubpagetabsTab')

if tArgs.minwidth then tabTab:css('min-width', tArgs.minwidth .. 'em') end if tArgs.maxwidth then tabTab:css('max-width', tArgs.maxwidth .. 'em') end if tArgs.height then tabTab:css('height', tArgs.height .. 'em') end if tArgs.bordercolor then tabTab:css('border-color', tArgs.bordercolor) end if tArgs.borderradius then tabTab:css('border-top-left-radius', tArgs.borderradius .. 'px') tabTab:css('border-top-right-radius', tArgs.borderradius .. 'px') tabTab:css('-moz-border-radius-topleft', tArgs.borderradius .. 'px') tabTab:css('-moz-border-radius-topright', tArgs.borderradius .. 'px') tabTab:css('-webkit-border-top-left-radius', tArgs.borderradius .. 'px') tabTab:css('-webkit-border-top-right-radius', tArgs.borderradius .. 'px') end

local tLink = {, , , , , , , , ''}

local chkCur = data[1] if not chkCur or chkCur == "" then if tArgs.basepage and tArgs.basepage ~="" then chkCur = tArgs.basepage else chkCur = curTitle.text end end

if curTitle.subpageText == chkCur then --Active Tab tabTab:addClass('SubpagetabsActive') if tArgs.backcolor then tabTab:css('background-color', tArgs.backcolor) end else if tArgs.altbackcolor then tabTab:css('background-color', tArgs.altbackcolor) end

tLink[1] = 		tLink[9] =  end

tLink[8] = ((data[2] ~= "") and data[2]				or ((data[1] ~= "" and data[1]) or tLink[4])) tabTab:wikitext(table.concat(tLink)) end

-- Utility functions -- trim spaces from start and end local function trim(s) return s and mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1") or '' end

--- Main module entry point. -- To be called with or directly from another module. -- -- @param frame The frame passed to the module via the #invoke. If called from another --             module directly, this should be a table with the parameter definition. function p.main(frame) local tArgs = getArgs(frame)

-- current page local curTitle = mw.title.getCurrentTitle --Below line For Testing Only --curTitle = {nsText='', text='pagename/Part 2', subpageText='Part 2', baseText ='pagename'}

-- table of tabs local tabs = {} local tabsData = {}

local nMain = nil -- Tab number of the main/base page

-- Loop over all the args for k, v in pairs(tArgs) do		local num = tostring(k):match('^[Tt]ab([1-9]%d*)$')

num = tonumber(num)

if num then local page, name = mw.ustring.match(v, "([^%$]*)%$?([^%$]*)")

if not page or page == '' then nMain = num if not name or name == '' then name = 'Main' end end

tabsData[num] = {trim(page), trim(name)}

table.insert(tabs, num) end end

table.sort(tabs, function(a,b) return a > b end)

-- main wrapper local tabRow = mw.html.create('div') :addClass('Subpagetabs')

if nMain then addTab(tabRow, tabsData[nMain], curTitle, tArgs) end

for _, n in ipairs(tabs) do		if tabsData[n][1] and tabsData[n][1] ~= "" then addTab(tabRow, tabsData[n], curTitle, tArgs) end end

return tabRow end

return p