Anonymous
×
Create a new article
Write your page title here:
We currently have 496 articles on WIKI - Idle Pixel. Type your article name above or click on one of the titles below and start writing!



WIKI - Idle Pixel

Module:Tabs: Difference between revisions

No edit summary
No edit summary
Line 8: Line 8:
function p.tabs (frame)
function p.tabs (frame)
local args = frame:getParent().args
local args = frame:getParent().args
local id = frame.args[1]
if args["name1"] ~= nil then
if args["name1"] ~= nil then
return p.tableWithNumber(args)
return p.tableWithNumber(args, id)
else
else
return p.tableWithoutNumber(args)
return p.tableWithoutNumber(args, id)
end
end
end
end


function p.tableWithNumber(args)
function p.tableWithNumber(args, id)
local tabCount = 0
local tabCount = 0
local result = ""
local result = ""
local checked = false
local checked = false
math.randomseed(os.time())
local name = math.random(100000, 999999)
for _ in pairs(args) do tabCount = tabCount + 1 end
for _ in pairs(args) do tabCount = tabCount + 1 end
Line 27: Line 26:
for i = 1, tabCount do
for i = 1, tabCount do
result = result .. '<htmltag tagname="input" type="radio" class="dTabsRadio" name="' .. name .. '" id="' .. args['name' .. i] .. '"'
result = result .. '<htmltag tagname="input" type="radio" class="dTabsRadio" name="' .. id .. '" id="' .. args['name' .. i] .. '"'
if not checked then
if not checked then
result = result .. ' checked'
result = result .. ' checked'
Line 37: Line 36:
end
end


function p.tableWithoutNumber(args)
function p.tableWithoutNumber(args, id)
local result = ""
local result = ""
for key, value in pairs(args) do
for key, value in pairs(args) do

Revision as of 14:39, 18 September 2024

Documentation for this module may be created at Module:Tabs/doc

inspect = require("Module:InspectLua")
local p = {}

function p.pp(text)
    return mw.getCurrentFrame():preprocess(text)
end

function p.tabs (frame)
	local args = frame:getParent().args
	local id = frame.args[1]
	if args["name1"] ~= nil then
		return p.tableWithNumber(args, id)
	else
		return p.tableWithoutNumber(args, id)
	end
end

function p.tableWithNumber(args, id)
	local tabCount = 0
	local result = ""
	local checked = false
	
	for _ in pairs(args) do tabCount = tabCount + 1 end
	
	tabCount = math.floor(tabCount / 2)
	
	for i = 1, tabCount do
		result = result .. '<htmltag tagname="input" type="radio" class="dTabsRadio" name="' .. id .. '" id="' .. args['name' .. i] .. '"'
		if not checked then
			result = result .. ' checked'
		end
		result = result .. '></htmltag><htmltag tagname="label" for="' .. args['name' .. i] .. '" class="dTabsLabel">' .. args['name' .. i] .. '</htmltag><div class="dTabsContent dTabsSubcontent">' .. args['tab' .. i] .. '</div>'
		checked = true
	end
	return p.pp('<div class="dTabs">' .. result .. '</div>') .. tostring(math.random(1000000, 9999999)) .. tostring(os.clock() * 1000000)
end

function p.tableWithoutNumber(args, id)
	local result = ""
	for key, value in pairs(args) do
		result = result .. key .. value .. "OOO"
	end
	return result
end

return p