Jump to content

Module:FilterBuilder: Difference between revisions

From The Petit Planet Wiki
Created Module:FilterBuilder
 
(No difference)

Latest revision as of 18:16, 12 November 2025

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

-- Source: https://anothereden.wiki/w/Module:FilterBuilder
local p = {}

function p.filterBuilder(frame)
	local dataKey = mw.text.trim(frame.args[1])
	local dataValues = mw.text.split(frame.args[2], ",")
	local contentValues = mw.text.split(frame.args[3], ",")
	local selectedValues = frame.args[4]
	if selectedValues~=nill then
		selectedValues = string.lower(selectedValues)
	end

	local filterGroup = mw.html.create('div')
		:addClass('mw-ui-button-group')
		:addClass('filter-group-' .. dataKey)
		:css('margin', '0')
		:css('flex-wrap', 'wrap')
	if string.find(dataKey, "strict") then
	    filterGroup:addClass('group-strict')
	end
	
	if dataKey == 'reset' then
			filterGroup:tag('div')
				:addClass('filter-reset')
				:addClass('mw-ui-button')
				:addClass('filter-button')
				:css('height', 'auto')
				:wikitext(contentValues[1])
	else
		for i,value in ipairs(dataValues) do
			button=filterGroup:tag('div')
			button
				:addClass('mw-ui-button')
				:addClass('filter-button')
				:attr('data-key', dataKey)
				:attr('data-value', string.lower(mw.text.trim(value)))
				:css('height', 'auto')
				:wikitext(contentValues[i])
			
			if selectedValues~=nill then 
				if string.find(selectedValues, string.lower(mw.text.trim(value))) then
					button
					    :addClass('filter-button-selected')
					    :addClass("default-selected")
				end
			end
		end
	end
	
	return tostring(filterGroup)
end

return p