Module:Item thumbnail: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
mNo edit summary
Line 10: Line 10:


function p._main(args)
function p._main(args)
local item = string.lower(args['item'])
local item = string.lower(args['item'] or '')
local image = nil
local image = nil
local link = nil
local link = nil

Revision as of 00:07, 2 November 2021



local getArgs   = require('Module:Arguments').getArgs
local data      = mw.loadData('Module:Item Icon/data')

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local item = string.lower(args['item'] or '')
	local image = nil 
	local link = nil
	local count = args['count']
	local icon_size = '80px'

	local item_data = data[item]
	
	if item_data then
		image = item_data['image']
		link = item_data['link']
	end
	image = args['image'] or image or ''
	link = args['link'] or link or ''
	
	local root = mw.html.create('div')
	root:css({
		['position'] = 'relative',
		['height'] = icon_size,
		['width'] = icon_size
	})
		:wikitext(string.format(
			'[[File:%s|80px|link=%s|%s]]',
			image,
			link,
			link
		))
	
	if count and tonumber(count) > 1 then
		root:tag('div')
			:css({
				['bottom'] =  0,
				['right'] = 0,
				['position'] = 'absolute',
				['padding'] = '0 5px',
				['background'] = '#00cdba',
				['border-radius'] = '5px 0 5px 0',
				['user-select'] = 'none'
			})
			:wikitext('x' .. count)
	end
		
	return tostring(root)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.