Module:Shortcut: Difference between revisions

Implement merger code by Pppery
m (1 revision imported)
 
(Implement merger code by Pppery)
Line 37: Line 37:
local listItems = {}
local listItems = {}
for i, shortcut in ipairs(shortcuts) do
for i, shortcut in ipairs(shortcuts) do
listItems[i] = frame:expandTemplate{
if yesno(options['target']) then
title = 'No redirect',
listItems[i] = string.format("[[%s]]",shortcut)
args = {shortcut}
else
}
listItems[i] = frame:expandTemplate{
title = 'No redirect',
args = {shortcut}
}
end
end
end
table.insert(listItems, options.msg)
table.insert(listItems, options.msg)
Line 55: Line 59:


local root = mw.html.create()
local root = mw.html.create()
 
root:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Shortcut/styles.css'} })
-- Anchors
-- Anchors
local anchorDiv = root
local anchorDiv = root
:tag('div')
:tag('div')
:css('position', 'relative')
:addClass('module-shortcutanchordiv')
:css('top', '-3em')
for i, shortcut in ipairs(shortcuts) do
for i, shortcut in ipairs(shortcuts) do
local anchor = mw.uri.anchorEncode(shortcut)
local anchor = mw.uri.anchorEncode(shortcut)
anchorDiv:tag('span'):attr('id', anchor)
anchorDiv:tag('span'):attr('id', anchor)
end
end
root:newline() -- To match the old [[Template:Shortcut]]


-- Shortcut heading
-- Shortcut heading
Line 73: Line 74:
local nShortcuts = #shortcuts
local nShortcuts = #shortcuts
if nShortcuts > 0 then
if nShortcuts > 0 then
shortcutHeading = message(cfg['shortcut-heading'], nShortcuts)
local headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
shortcutHeading = message(headingMsg, nShortcuts)
shortcutHeading = frame:preprocess(shortcutHeading)
shortcutHeading = frame:preprocess(shortcutHeading)
shortcutHeading = shortcutHeading .. '\n'
end
end
end
end
Line 82: Line 83:
local shortcutList = root
local shortcutList = root
:tag('div')
:tag('div')
:addClass('shortcutbox plainlist noprint')
:addClass('module-shortcutboxplain plainlist noprint')
:attr('role', 'note')
:attr('role', 'note')
:css('float', 'right')
:css('border', '1px solid #aaa')
:css('background', '#fff')
:css('margin', '0em 0em 0em 1em')
:css('padding', '.3em .6em .2em .6em')
:css('text-align', 'center')
:css('font-size', '85%')
:css('font-weight', 'bold')
if shortcutHeading then
if shortcutHeading then
shortcutList
shortcutList
:tag('div')
:tag('div')
:css('display','inline-block')
:addClass('module-shortcutlist')
:css('border-bottom','1px solid #aaa')
:css('margin-bottom', '.2em')
:css('font-weight', 'normal')
:wikitext(shortcutHeading)
:wikitext(shortcutHeading)
end
end
shortcutList
local list = shortcutList:tag('ul')
:tag('ul')
for i, item in ipairs(listItems) do
for i, item in ipairs(listItems) do
shortcutList:tag('li'):wikitext(item)
list:tag('li'):wikitext(item)
end
end
return tostring(root)
return tostring(root)
end
end


function p.main(frame)
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
local args = require('Module:Arguments').getArgs(frame)
wrappers = 'Template:Shortcut'
})


-- Separate shortcuts from options
-- Separate shortcuts from options
Anonymous user