Module:DisambigPopup

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

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

local util_args = require('Module:ArgsUtil')
local util_cargo = require("Module:CargoUtil")
local util_html = require("Module:HtmlUtil")
local util_table = require("Module:TableUtil")
local util_text = require("Module:TextUtil")
local util_title = require("Module:TitleUtil")
local util_toggle = require("Module:ToggleUtil")

local h = {}

local p = {}
function p.main(frame)
	local args = util_args.merge()
	local popup = util_toggle.popupButton();
	popup.inner:node(h.getDisambigs(args[1]))
		:addClass('popup-disambig-container')
	return popup.button
end

function h.getDisambigs(player)
	local query = h.getQuery(player)
	return h.makeDisambigText(util_cargo.queryAndCast(query))
end

function h.getQuery(player)
	local query = {
		tables = 'Disambiguations',
		where = ('Term="%s"'):format(util_title.target(player)),
		fields = "FinalLocation",
	}
	return query
end

function h.makeDisambigText(data)
	local ul = mw.html.create('ul')
		:addClass('popup-disambig-list')
	for _, row in ipairs(data) do
		h.printRow(ul, row)
	end
	return ul
end

function h.printRow(ul, row)
	ul:tag('li')
		:addClass('popup-disambig')
		:wikitext(util_text.intLinkOrText(row.FinalLocation))
		:tag('div')
			:addClass('copy-button')
			:wikitext('')
end

return p