Module:Keys/sandbox: Difference between revisions
Jump to navigation
Jump to search
first RC |
fix for table call using variable |
||
| Line 27: | Line 27: | ||
if type(symbol) == 'table' then | if type(symbol) == 'table' then | ||
if symbol | if symbol[langCode] then | ||
symbol = symbol | symbol = symbol[langCode] | ||
else | else | ||
symbol = symbol | symbol = symbol['default'] | ||
end | end | ||
end | end | ||
Latest revision as of 00:37, 2 December 2015
| This is the module sandbox page for Module:Keys (diff). |
Todo: Add ability to wrap line
This module implements {{Hotkey}}. Please see the template page for documentation.
| The above documentation is transcluded from Module:Keys/doc. (edit | history) Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this module. |
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local langCode = args.lang:lower()
local keys = {}
for _, key in ipairs(args) do
table.insert(keys, p.key(key, langCode))
end
return table.concat(keys, '+')
end
function p.key(key, langCode)
if not key then
return ''
end
local symbols = mw.loadData('Module:Keys/Symbols')
local symbol = (symbols[key:lower()] or key)
if type(symbol) == 'table' then
if symbol[langCode] then
symbol = symbol[langCode]
else
symbol = symbol['default']
end
end
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%'
}, ';') .. '">' .. symbol .. '</kbd>'
end
return p