Module:Top icons: Difference between revisions

From [N8]
Jump to navigation Jump to search
Created page with "--<nowiki> local p = {} local sites = { gsm = { format = 'You can find the Game here.', params = { 'gem', 'game', 'gs' }, abbr = 'gs', title = 'You can find the Game..."
 
No edit summary
Line 23: Line 23:
}
}


local order = { 'os', 'rsc', 'wp', 'wg' }
local order = { 'gsm', 'gsf', 'wp' }


local allparams = {}
local allparams = {}
Line 57: Line 57:
local ret = mw.html.create('div')
local ret = mw.html.create('div')
ret:addClass('rs-external-header-links'):css('display', 'none')
ret:addClass('gs-external-header-links'):css('display', 'none')
for _,v in ipairs(order) do
for _,v in ipairs(order) do
if vals[v] then
if vals[v] then
local span = ret:tag('span')
local span = ret:tag('span')
span:wikitext(string.format(sites[v].format, vals[v]))
span:wikitext(string.format(sites[v].format, vals[v]))
:addClass('rs-header-icon rs-header-icon-'..v)
:addClass('gs-header-icon gs-header-icon-'..v)
:attr({
:attr({
['data-title'] = string.format(sites[v].title, vals[v]),
['data-title'] = string.format(sites[v].title, vals[v]),

Revision as of 16:07, 15 August 2020

Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [purge]

This module does not have any documentation. Please consider adding documentation at Module:Top icons/doc. [edit]


--<nowiki>
local p = {}

local sites = {
	gsm = {
		format = 'You can find the Game here.',
		params = { 'gem', 'game', 'gs' },
		abbr = 'gs',
		title = 'You can find the Game here.',
		},
	gsf = {
		format = 'Visit the Gemini Station Forum.',
		params = { 'gsf', 'gf' },
		abbr = 'Forum',
		title = 'Visit the Gemini Station Forum.',
		},
	wp = { 
		format = 'Wikipedia also has an article on: [[wikipedia:%s]]',
		params = { 'wikipedia', 'wp', 'w' },
		abbr = 'Wikipedia',
		title = 'Wikipedia also has an article on %s.',
		},
	}

local order = { 'gsm', 'gsf', 'wp' }

local allparams = {}

function p.main(frame)
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().fullText
	local vals = {}
	-- create allparams
	for s,t in pairs(sites) do
		for _,v in ipairs(t.params) do
			allparams[v] = s
		end
	end
	
	-- loop named params
	for i,v in pairs(allparams) do
		if args[i] and not vals[v] then
			vals[v] = args[i]
		end
	end
	
	-- loop unnamed params
	local i = 1
	local v
	while args[i] do
		v = allparams[args[i]] 
		if v and not vals[v] then
			vals[v] = pagename
		end
		i = i + 1
	end
	
	local ret = mw.html.create('div')
	ret:addClass('gs-external-header-links'):css('display', 'none')
	for _,v in ipairs(order) do
		if vals[v] then
			local span = ret:tag('span')
			span:wikitext(string.format(sites[v].format, vals[v]))
				:addClass('gs-header-icon gs-header-icon-'..v)
				:attr({
						['data-title'] = string.format(sites[v].title, vals[v]),
						['data-site'] = v,
						['data-text'] = sites[v].abbr,
					})
		end
	end

	return tostring(ret)	
end

return p
--</nowiki>