Module:Top icons: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
local sites = { | local sites = { | ||
gsm = { | gsm = { | ||
format = ' | format = 'Return to ship.', | ||
params = { 'gem', 'game', 'gs' }, | params = { 'gem', 'game', 'gs', 'gsm' }, | ||
abbr = 'gs', | abbr = 'gs', | ||
title = ' | title = 'Return to ship.', | ||
}, | }, | ||
gsf = { | gsf = { | ||
Revision as of 16:09, 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 = 'Return to ship.',
params = { 'gem', 'game', 'gs', 'gsm' },
abbr = 'gs',
title = 'Return to ship.',
},
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>