Dota 2 Wiki
Register
Advertisement

Documentation for Module:Tabber Jump to code ↴ [ edit | purge ]

Reality Rift icon
▶️ Planeshift.
The documentation for this module can be found at Template:Tabber.
You may be forwarded to another wiki language, in case a translation is not available.


Dependencies

local p = {}
local getArgs = require( 'Module:Arguments' ).getArgs


-- Implements Template:Tabs Hero.
function p.hero(frame)
  local args = getArgs(frame, {
    wrappers = {
      'Template:Tabs Hero'
    }
  })
  local hero = args[1] or mw.title.getCurrentTitle().baseText -- Use {{BASEPAGENAME}} if no page is given.
  
  local subpage = function( page ) return hero .. '/' .. page end
  local custom = function( number ) if args['custom' .. number] then return subpage( args['custom' .. number] ) end end
  
  local tabs = { 
    ['this'] = args['this'],
    
    ['link1'] = hero,
    ['name1'] = 'Hero',
    
    ['link2'] = subpage( 'Guide' ),
    ['name2'] = 'Strategy',
    
    --['link3'] = subpage( 'Counters' ),
    --['name3'] = 'Counters',
    
    ['link3'] = subpage( 'Equipment' ),
    ['name3'] = 'Equipment',
    
    ['link4'] = subpage( 'Gear' ),
    ['name4'] = 'Gear',

    ['link5'] = subpage( 'Talents' ),
    ['name5'] = 'Talents',

    ['link6'] = subpage( 'Relics' ),
    ['name6'] = 'Relics',
    
    ['link7'] = subpage( 'Responses' ),
    ['name7'] = 'Responses',
    
    ['link8'] = subpage( 'Sounds' ),
    ['name8'] = 'Sounds',
    
    ['link9'] = subpage( 'Animations' ),
    ['name9'] = 'Animations',
    
    ['link10'] = subpage( 'Lore' ),
    ['name10'] = 'Lore',
    
    ['link11'] = custom( '1' ),
    ['name11'] = args['custom1'],
    
    ['link12'] = custom( '2' ),
    ['name12'] = args['custom2'],
    
    ['link13'] = subpage( 'Old Abilities' ),
    ['name13'] = 'Old Abilities',
    
    ['link14'] = subpage( 'Changelogs' ),
    ['name14'] = 'Changelogs',
    
    ['link15'] = subpage( 'Bugs' ),
    ['name15'] = 'Known Bugs',
  }
  
  return p._main( tabs )
end

-- Implements Template:Tabber.
function p.main(frame)
  local args = getArgs(frame, {
    wrappers = {
      'Template:Tabber'
    }
  })
  return p._main( args )
end

function p._main( args )
  local current_page = args['this'] or mw.title.getCurrentTitle().prefixedText

  local rows = {}
  for n=1,15 do
    if args['link' .. n] then
      -- Use the link as the name if none is given.
      local name = args['name' .. n] or args['link' .. n]
      if args['link' .. n] == current_page then
        -- The active tab.
        table.insert( rows, string.format( '<div class="page-tabber-tab active-tab">%s</div>', name ) )
      else
        -- The inactive tabs.
        local link = string.format( '[[%s|%s]]', args['link' .. n], name )
        table.insert( rows, string.format( '<div class="page-tabber-tab inactive-tab">%s</div>', link ) )
      end
    end
  end
  
  -- The separator is used for the space between two tabs.
  local separator = '\n<div class="page-tabber-separator">&nbsp;</div>\n'
  -- The tail fills the space between the last tab and the end of the line.
  local tail = '<div class="page-tabber-separator tail">&nbsp;</div>'
  
  return string.format( '<div id="pageTabber" class="page-tabber">\n%s\n%s\n</div>', table.concat( rows, separator ), tail )
end

return p
Advertisement