Module:Sandbox/User:The Gaffer/Modules/Infobox Switch: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
--Attribution: This module was taken from the Runescape wiki - https://runescape.wiki/w/Module:Switch_infobox - See changes there for a list of contributors
local p = {}
local p = {}
local yesno = require('Module:Yesno')


local yn = require('Module:Yesno')
function p.main(frame)
local hc = require('Module:Paramtest').has_content
mw.loader.load('ext.gadget.switch-infobox')
return '<div class="infobox infobox-switch">This content will be switchable.</div>'
--return frame:preprocess(tostring(p._main(frame:getParent().args)))
end


-- Module access point for infobox switch
-- function p._main(args)
p._infobox_switch = function(args)
-- local contents = {}
-- Prepare content list from arguments
local contents = {}
local i = 1
while args['item'..i] do
table.insert(contents, { text = args['text'..i] or ('Item '..i),
content = '\n' .. args['item'..i],
id = args['switch_id'..i] or i})
i = i + 1
end
-- Create the main table structure for the infobox switch
local structure = mw.html.create('table')
:addClass('infobox-switch')
:tag('caption')
:done();
-- Create the div for the buttons inside the caption
local buttons = structure:tag('div')
:attr('data-default-index', 1)


-- Add buttons for each item in contents
-- local i = 1
for i, v in ipairs(contents) do
-- while args['item'..i] do
buttons:tag('button')
-- table.insert(contents, { text = args['text'..i] or ('Item '..i),
:addClass('button')
-- content = '\n' .. args['item'..i],
:attr('data-switch-index', i)
-- id = args['switch_id'..i] or i})
:attr('data-switch-anchor', '#section' ..i)
-- i = i + 1
:wikitext(v.text)
-- end
:done()
end
local content_body = structure:tag('tbody')
local default_content = contents[1] -- Assuming default index is 1
if default_content then
local row = content_body:tag('tr')
row:tag('td')
:attr('data-attr-param', 'param1')
:wikitext(default_content.content)
:done()
row:done()
end
-- Create the hidden resources section that contains all switchable content
local resources_div = structure:tag('div')
:addClass('infobox-switch-resources')


-- Add each content section to the resources div
-- local ret = mw.html.create('div')
for i, v in ipairs(contents) do
-- :addClass('Gadget-switch-infobox')
local param_div = resources_div:tag('div')
-- :addClass('loading')
:attr('data-attr-param', 'param1')
-- :tag('span')
-- :addClass('loading-button')
-- :addClass('button')
-- :wikitext('Loading...')
-- :done()
-- if args.float then
-- if args.float == 'left' then
-- ret:addClass('tleft')
-- :addClass('thumb')
-- elseif args.float == 'right' then
-- ret:addClass('tright')
-- :addClass('thumb')
-- end
-- end
-- local mah_triggers = ret:tag('div')
-- :addClass('switch-infobox-triggers')
-- local isSelect = yesno(args.select)
-- if isSelect then
-- mah_triggers:addClass('infobox-triggers-select')
-- elseif i > 6 and isSelect ~= false then
-- mah_triggers:addClass('infobox-triggers-select')
-- end


param_div:tag('div')
-- for i, v in ipairs(contents) do
:attr('data-attr-index', i)
-- mah_triggers :tag('span')
:wikitext(v.content)
-- :addClass('trigger')
:done()
-- :addClass('button')
-- :addClass(i==1 and 'button-selected' or '')
-- :attr('data-id',v.id)
-- :wikitext(v.text)
-- :done()


param_div:done()
-- ret :tag('div')
end
-- :addClass('item')
-- :addClass(i==1 and 'showing' or '')
-- :attr('data-id',v.id)
-- :wikitext(v.content)
-- :done()
-- end


mw.logObject(structure)
-- return ret
-- Return the complete HTML structure
-- end
return tostring(structure)
end

p.infobox_switch = function(frame)
return p._infobox_switch(frame:getParent().args)
end


return p
return p

Latest revision as of 22:23, 12 November 2024

Documentation for this module may be created at Module:Sandbox/User:The Gaffer/Modules/Infobox Switch/doc

local p = {}

local yn = require('Module:Yesno')
local hc = require('Module:Paramtest').has_content

-- Module access point for infobox switch
p._infobox_switch = function(args)
	-- Prepare content list from arguments
	local contents = {}
	local i = 1
	while args['item'..i] do
		table.insert(contents, { text = args['text'..i] or ('Item '..i),
					content = '\n' .. args['item'..i],
					id = args['switch_id'..i] or i})
		i = i + 1
	end
	
	-- Create the main table structure for the infobox switch
	local structure = mw.html.create('table')
		:addClass('infobox-switch')
		:tag('caption')
		:done();
				
	-- Create the div for the buttons inside the caption		
	local buttons = structure:tag('div')
		:attr('data-default-index', 1)

	-- Add buttons for each item in contents
	for i, v in ipairs(contents) do
		buttons:tag('button')
			:addClass('button')
			:attr('data-switch-index', i)
			:attr('data-switch-anchor', '#section' ..i)
			:wikitext(v.text)
			:done()
	end
	
	local content_body = structure:tag('tbody')
    local default_content = contents[1]  -- Assuming default index is 1
    if default_content then
        local row = content_body:tag('tr')
        row:tag('td')
            :attr('data-attr-param', 'param1')
            :wikitext(default_content.content)
            :done()
        row:done()
    end
    
    -- Create the hidden resources section that contains all switchable content
    local resources_div = structure:tag('div')
        :addClass('infobox-switch-resources')

    -- Add each content section to the resources div
    for i, v in ipairs(contents) do
        local param_div = resources_div:tag('div')
            :attr('data-attr-param', 'param1')

        param_div:tag('div')
            :attr('data-attr-index', i)
            :wikitext(v.content)
            :done()

        param_div:done()
    end

	mw.logObject(structure)
    -- Return the complete HTML structure
    return tostring(structure)
end

p.infobox_switch = function(frame)
    return p._infobox_switch(frame:getParent().args)
end

return p