Module:Keys

From Miranda NG
Revision as of 22:01, 27 November 2015 by Goraf (talk | contribs) (to produce keys sequences)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
Todo: Add ability to wrap line

This module implements {{Hotkey}}. Please see the template page for documentation.

local p = {}
p.keys = function(f)
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	local keys = {}
	
	for _, key in ipairs(args) do
		key = mw.text.trim(key)
		table.insert(keys, p.key(key))
	end
	
	return table.concat(keys, '+')
end
p.key = function(key)
	if not key then
		return ''
	end
	
	local symbols = mw.loadData('Module:Keys/Symbols')
	return '<kbd class="key nowrap" style="' .. table.concat({
		'border: 1px solid #AAA',
		'background-color: #F9F9F9',
		'background-image: -webkit-linear-gradient(#EEE, #F9F9F9, #EEE)',
		'background-image: -o-linear-gradient(#EEE, #F9F9F9, #EEE)',
		'background-image: linear-gradient(#EEE, #F9F9F9, #EEE)',
		'padding: 0.1em 0.3em',
		'font-family: inherit',
		'font-size: 85%'
	}, ';') .. '">' .. (symbols[key:lower()] or key) .. '</kbd>'
end
return p