Przejdź do zawartości

Moduł:Navbox/printer/group

Z Wikipedii, wolnej encyklopedii
 Dokumentacja modułu [stwórz] [odśwież]
require ("strict")
local res = mw.loadData('Moduł:Navbox/res')

local function collapsible(node, printlog)
	local c = res.arg.collapsible.name
	local v = node.peek(res.arg.group.name) and node.peek(c) or nil
	if v == res.arg.collapsible.collapsed then
		node.use(c)
		return printlog and '' or 'mw-collapsed'
	elseif v == res.arg.collapsible.expanded then
		node.use(c)
		return ''
	elseif v == res.arg.collapsible.disabled then
		node.use(c)
		return nil
	elseif node.test and (v == res.arg.collapsible.auto) then
		node.use(c)
		return (printlog or node.test()) and '' or 'mw-collapsed'
	elseif v then
		node.use(c)
		return nil
	else
		return nil
	end
end

return {
	
leaf = 'div',

update = function (container, isleaf, node, printlog)
	container
		:addClass(node.peek(res.arg.group.name) and nil or node.address())
		:addClass(isleaf and res.class.hlist or nil)
		:addClass(isleaf and res.class.list or nil)
end,

print = function (container, tree, printList, printlog)
	container:addClass(res.class.innerGroup)
	for i, node in ipairs(tree) do
		if node.peek(res.arg.group.name) then
			local collapse = collapsible(node, printlog)
			local group = container:tag('div')
			group
				:addClass(res.class.pair)
				:addClass(node.address())
			if collapse then
				group
					:addClass('mw-collapsible')
					:attr('data-expandtext', res.aux.expandText)
					:attr('data-collapsetext', res.aux.collapseText)
					:addClass(collapse)
					:tag('span')
						:addClass(res.navbar.fake)
			end
			group:tag('div')
				:addClass(res.class.group)
				:wikitext(node.get(res.arg.group.name))
			printList(group, node, collapse)
		else
			printList(container, node)
		end
	end
end,

}