FANDOM


-- <nowiki>
-- Switchinfobox implementation that doesn't suck
--
 
local p = {}
local isSwitch = true
 
--[=[
{{Infobox monster
 | version1         = Normal
 | version2         = God Wars Dungeon
 | name             = Hellhound
 | image            = [[File:Hellhound.png|200px]]
 | release1         = [[27 February]] [[2002]]
 | release2         = [[28 August]] [[2007]]
 | update1          = Latest RuneScape News (27 February 2002)
 | update2          = God Wars Dungeon
 | level1           = 92
 | level2           = 95
 | LP1              = 3300
 | LP2              = 6800
 | experience1      = 361.3
 | experience2      = 836
 | slaylvl          = 1
 | slayxp1          = 93.6
 | slayxp2          = 218
 | Sumona           = yes
 | Lapalok          = yes
 | Kuradal          = yes
 | members1         = No
 | members2         = yes
 | aggressive1      = Yes
 | aggressive2      = Yes (unless wearing Zamorak item)
 | poisonous        = No
 | immune to stun1  = No
 | immune to stun2  = Indeed
 | immune to poison = No
 | attack1          = 66
 | attack2          = 68
 | defence1         = 66
 | defence2         = 68
 | ranged           = 1
 | magic            = 1
 | attack style     = Melee
 | attack speed1    = 6
 | attack speed2    = 9.5
 | max hit1         = 224
 | max hit2         = 272
 | weakness1        = Slash, Darklight
 | weakness2        = Water
 | always drops     = [[Bones]]
 | examine1 = 
*Hello, nice doggy...
*A savage beast.
*From the maws of hell.
|examine2           = From the maws of hell.
}}
]=]
 
--
-- Extracts switches from arguments table and converts them to a table data-switchX attributes
-- for use in mw.html.attr
--
-- @param args {table} Arguments table
-- @return {table} Attributes to be used for creation of the switches in the infobox
--
local function getSwitches(args)
    local paramPrefix = 'version'
    local switches = {}
 
    for i = 1, 10 do
        param = paramPrefix .. tostring(i)
 
        if args[param] then
            switches['data-switch' .. tostring(i)] = args[param]
        else
            if i == 1 then
                isSwitch = false
            end
 
            break
        end
    end
 
    return switches
end
 
--
-- Creates the start of the infobox table and implements the caption
-- Also adds a placeholder for the switches if this is a switch infobox
--
-- @param args {table}
-- @param params {table}
--
local function startInfobox(args, params)
    -- extract switches from arguments
    local switches = getSwitches(args)
 
    -- create infobox
    local infobox = mw.html.create('table')
        :addClass('infobox')
        :addClass('wikitable')
        -- add a class so it's obvous which tye of infobox it is that we're using
        :addClass(params.class)
 
    -- create the caption
    local caption = mw.html.create('caption')
        :tag('b')
            -- don't change the main caption for the switch
            -- that's handled below
            :wikitext(args.name or mw.title.getCurrentTitle().fullText)
            :done()
 
    if isSwitch then
        caption
            :tag('div')
                :addClass('switch-select')
                :attr(switches)
                :done()
    end
 
    -- add caption to infobox
    infobox
        :node(caption)
        :done()
 
    return infobox
end
 
local function fillRows(infobox, args, params)
    local tr, param, th
 
    for i = 1, #params do
        tr = infobox:tag('tr')
        param = params[i]
 
        if param.title then
            th = tr
                :tag('th')
                    :addClass('infobox-th')
 
            if param.title.colspan then
                th:attr('colspan', param.title.colspan)
            end
 
            th
                :wikitext(param.title.text)
                :done()
        end
    end
end
 
function p.main(frame)
    local args = frame:getParent().args
    local infoboxType = args.type
    local params = mw.loadData('Module:Sandbox/Cqm/SwitchInfobox/' .. infoboxType)
    local infobox = startInfobox(args, params)
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.