Module:Icons: Difference between revisions

Icon: Implement noicon option for obtaining only link; Link: Implement shortcut for Icon() with noicon = true
(added Cyclops and Wizard to the list of ambiguous overrides)
(Icon: Implement noicon option for obtaining only link; Link: Implement shortcut for Icon() with noicon = true)
Line 49: Line 49:
   ["Thiever's Cape"] = 'png',
   ["Thiever's Cape"] = 'png',
   ["Thief's Moneysack"] = 'png',
   ["Thief's Moneysack"] = 'png',
   ["Swordfish (Perfect)"] = 'png',
   ["Swordfish (Perfect)"] = 'mpng',
   ["Strawberry Cupcake (Perfect)"] = 'png',
   ["Strawberry Cupcake (Perfect)"] = 'png',
   ["Strawberry Cupcake"] = 'png',
   ["Strawberry Cupcake"] = 'png',
Line 195: Line 195:
   local notext = args.notext ~= nil and args.notext ~= ''
   local notext = args.notext ~= nil and args.notext ~= ''
   local nolink = args.nolink ~= nil and args.nolink ~= ''
   local nolink = args.nolink ~= nil and args.nolink ~= ''
  local noicon = args.noicon ~= nil and args.noicon ~= ''
   local menu = args.menu ~= nil and args.menu ~= ''
   local menu = args.menu ~= nil and args.menu ~= ''
   local imgSize = args.size ~= nil and args.size or 25
   local imgSize = args.size ~= nil and args.size or 25
Line 239: Line 240:
   if Shared.contains(ambiguousOverrides, link) then
   if Shared.contains(ambiguousOverrides, link) then
     if text == nil then text = link end
     if text == nil then text = link end
     link = link..' ('..iconType..')'
     link = link..' ('..(iconType == 'mark' and 'item' or iconType)..')'
   end
   end


   --Creating the image...
   local result = ''
  local result = '[[File:'..img
  if not noicon then
  --Add in type if one is set
--Creating the image...
  if iconType ~= nil and iconType ~= '' then result = result..'_('..iconType..')' end
result = '[[File:'..img
  --Add in extension and image size
--Add in type if one is set
  result = result..'.'..ext..'|'..tostring(imgSize)..'x'..tostring(imgSize)..'px'  
if iconType ~= nil and iconType ~= '' then result = result..'_('..iconType..')' end
  --Include a link unless no link -and- no text was requested
--Add in extension and image size
  if not (nolink and notext) then result = result..'|link='..link end
result = result..'.'..ext..'|'..tostring(imgSize)..'x'..tostring(imgSize)..'px'  
  result = result..']]'
--Include a link unless no link -and- no text was requested
if not (nolink and notext) then result = result..'|link='..link end
result = result..']]'
  end
    
    
   --Add Quantity to the front if requested
   --Add Quantity to the front if requested
   if qty ~= nil and qty ~= '' then result = Shared.formatnum(qty)..' '..result end
   if qty ~= nil and qty ~= '' then result = Shared.formatnum(qty)..' '..result end


   if not notext then  
   if not notext then
  -- If the result is currently empty then there's no need to pad with whitespace
  local padStr = (string.len(result) > 0 and ' ' or '')
     if nolink then
     if nolink then
       if text ~= nil and text ~= '' then
       if text ~= nil and text ~= '' then
         result = result..' '..text
         result = result..padStr..text
       else
       else
         result = result..' '..link
         result = result..padStr..link
       end
       end
     else
     else
       result = result..' [['..link
       result = result..padStr..'[['..link
       if text ~= nil and text ~= '' and text ~= link then
       if text ~= nil and text ~= '' and text ~= link then
         result = result..'|'..text
         result = result..'|'..text
Line 270: Line 276:
     end
     end
   end
   end
 
 
   result = '<span style="display:inline-block">'..result..'</span>'
   if not noicon then
    result = '<span style="display:inline-block">'..result..'</span>'
  end


   if menu then
   if menu then
Line 279: Line 287:


   return result
   return result
end
-- Wrapper for p.Icon(), uses the same parameters but forces noicon = true
function p.Link(frame)
local args = frame.args ~= nil and frame.args or frame
args.noicon = true
return p.Icon({['args'] = args})
end
end