Module:Tabber

local p = {}

local util = require 'libraryUtil' local checkType = util.checkType local checkTypeMulti = util.checkTypeMulti

local metatable = {} local methodtable = {}

metatable.__index = methodtable

metatable.__tostring = function( t ) return tostring( t:getHtml ) end

function p.create local tabber = {} setmetatable( tabber, metatable )

tabber.tabs = {}

return tabber end

function methodtable.addTab( t, page, options ) checkType( 'addTab', 1, page, 'string' ) checkType( 'addTab', 2, title, 'table', true ) local options = options or {} t.tabs[#t.tabs+1] = { page = page, title = ( options.title or page ), } if options.active then t.activeTab = #t.tabs end return t end

function methodtable.removeTab( t, index ) checkType( 'removeTab', 1, index, 'number' ) t.tabs[index] = nil return t end

function methodtable.getHtml( t ) local html = mw.html.create( 'div' ) :attr( 'id', 'pageTabber' ) :addClass( 'page-tabber' ) for i,tab in ipairs( t.tabs ) do   html:tag( 'div' ) :addClass( 'page-tabber-tab' ) :wikitext( string.format( '%s', tab.page, tab.title ) ) if i == t.activeTab then html:addClass( 'active-tab' ) else html:addClass( 'inactive-tab' ) end html:done end return html end

return p