FANDOM


--[[----------------------------------------------------------------------------
	Module:Input
		For displaying keyboard/mouse inputs
		For documentation, see Template:Input
----------------------------------------------------------------------------]]--
local p = {}
local KEYS = mw.loadData('Module:Input/data')
 
-- Uppercase first char, lowercase rest
local function capitalize(str)
	if not str or str:len() == 0 then return nil
	elseif str:len() == 1 then return str:upper()
	else return str:sub(1,1):upper() .. str:sub(2):lower()
	end
end
 
-- Check if a table contains a value (shallow)
local function has(t, v)
	for _, val in pairs(t or {}) do
		if val == v then return true end
	end
	return false
end
 
-- Replace [key] with kbdtag, fetches info from key data where possible
local function replace(str)
	local label, class, title
	for id, key in pairs(KEYS) do -- Loop through keys
		if has(key.aliases, str:lower()) then -- Key alias found
			label = key.label
			class = string.format('%s %s-%s', key.type, key.type, id)
			title = key.title
			break
		end
	end
	return tostring(mw.html.create('kbd')
		:addClass(class or string.format('key key-%s', str:lower()))
		:attr('title', title or capitalize(str))
		:wikitext(label or capitalize(str)))
end
 
function p.main(frame)
	if not frame then error('Input.main: No frame found') end
	local str = frame.args[1] or ''
	return mw.html.create('span')
		:addClass('key-input')
		:wikitext(str:gsub('%[(.-)%]', replace) or str)
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.