m (+) Tag: sourceedit |
m (div) Tag: sourceedit |
||
Line 56: | Line 56: | ||
for _,v in ipairs(order) do |
for _,v in ipairs(order) do |
||
if vals[v] then |
if vals[v] then |
||
− | ret:tag(' |
+ | ret:tag('div') |
:addClass('rs-header-icon rs-header-icon-'..v) |
:addClass('rs-header-icon rs-header-icon-'..v) |
||
:attr('title', string.format(sites[v].title, vals[v])) |
:attr('title', string.format(sites[v].title, vals[v])) |
Revision as of 20:16, 12 September 2016
Documentation for this module may be created at Module:Top icons/doc
local p = {}
local sites = {
wp = {
format = '[[wikipedia:%s|W]]',
params = { 'wikipedia', 'wp' },
title = 'Wikipedia also has an article on %s.',
},
os = {
format = '[[2007:%s|OS]]',
params = { 'oldschool', 'osrs', 'os', '2007' },
title = 'The Old School RuneScape Wiki also has an article on %s.',
},
rsc = {
format = '[[w:c:runescapeclassic:%s|RSC]]',
params = { 'rsc', 'classic' },
title = 'The RuneScape Classic Wiki also has an article on %s.',
},
}
local order = { 'os', 'rsc', '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('topright topright-icon')
for _,v in ipairs(order) do
if vals[v] then
ret:tag('div')
:addClass('rs-header-icon rs-header-icon-'..v)
:attr('title', string.format(sites[v].title, vals[v]))
:wikitext(string.format(sites[v].format, vals[v]))
end
end
return tostring(ret)
end
return p