Module:Icons: Difference between revisions

no edit summary
(Use class in place of inline styles)
No edit summary
(2 intermediate revisions by one other user not shown)
Line 850: Line 850:


function p._Currency(fileName, link, altText, amount, maxAmount)
function p._Currency(fileName, link, altText, amount, maxAmount)
local ret = {}
local function numColour(amount)
table.insert(ret, '<span class="img-text">')
if tonumber(amount) < 0 then
local sep = ''
return mw.html.create('span')
:css('color', 'red')
:wikitext(formatnum(amount))
:done()
else
return formatnum(amount)
end
end
local html = mw.html.create('span')
:addClass('img-text')
 
-- Currency amounts
-- Currency amounts
if tonumber(amount) ~= nil then
if tonumber(amount) ~= nil then
sep = '&nbsp;'
html:node(numColour(amount))
local function numColour(amount)
if tonumber(amount) < 0 then
return '<span style="color:red;">' .. formatnum(amount) .. '</span>'
else
return formatnum(amount)
end
end
table.insert(ret, numColour(amount))
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then
table.insert(ret, ' - ' .. numColour(maxAmount))
html:wikitext(' - ' .. numColour(maxAmount))
end
end
end
end
-- Currency icon
-- Currency icon
if fileName ~= nil then
if fileName ~= nil then
table.insert(ret, sep .. '[[File:' .. fileName .. '|25px')
html:wikitext('&nbsp;'):wikitext('[[File:'):wikitext(fileName):wikitext('|25px')
if link ~= nil then
if link ~= nil then
table.insert(ret, '|link=' .. link)
html:wikitext('|link='):wikitext(link)
end
end
table.insert(ret, '|alt=' .. ((altText == nil and '') or altText) .. ']]')
html:wikitext('|alt=')
:wikitext(((altText == nil and '') or altText))
:wikitext(']]')
end
html:done()
if ((amount ~= nil and tonumber(amount) == nil)
or (maxAmount ~= nil and tonumber(maxAmount) == nil)) then
html:wikitext('[[Category:Pages with non-numeric currency arguments]]')
end
end
table.insert(ret, '</span>')
return table.concat(ret)
return tostring(html)
end
end


Line 891: Line 902:
function p.RC(amt, maxamt)
function p.RC(amt, maxamt)
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', amt, maxamt)
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', amt, maxamt)
end
-- p.Currency() is called by various currency templates:
-- [[Template:GP]], [[Template:SC]], [[Template:RC]]
function p.Currency(frame)
local args = frame.args ~= nil and frame.args or frame
local currID, minVal, maxVal, _
currID = args[1]
if args[2] ~= nil and args[2] ~= '' then
minVal, _ = string.gsub(args[2], ',', '')
end
if args[3] ~= nil and args[3] ~= '' then
maxVal, _ = string.gsub(args[3], ',', '')
end
if currID == 'GP' then
return p.GP(minVal, maxVal)
elseif currID == 'SC' then
return p.SC(minVal, maxVal)
elseif currID == 'RC' then
return p.RC(minVal, maxVal)
else
return Shared.printError('Invalid currency: ' .. (currID == nil and 'nil' or currID))
end
end
end


918

edits