Module:Shortcut: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
m
9 revisions imported: Originally imported from Wikipedia.
(make code nicer)
m (9 revisions imported: Originally imported from Wikipedia.)
 
(8 intermediate revisions by 5 users not shown)
Line 24:
frame = frame or mw.getCurrentFrame()
cfg = cfg or mw.loadData(CONFIG_MODULE)
local isCategorizedtemplateMode = options.template and yesno(options.categorytemplate) ~= false
local redirectMode = options.redirect and yesno(options.redirect)
local isCategorized = not options.category or yesno(options.category) ~= false
 
-- Validate shortcuts
Line 37 ⟶ 39:
local listItems = {}
for i, shortcut in ipairs(shortcuts) do
local templatePath, prefix
listItems[i] = frame:expandTemplate{
if templateMode then
title = 'No redirect',
-- Namespace detection
args = {shortcut}
local titleObj = mw.title.new(shortcut, 10)
}
if titleObj.namespace == 10 then
templatePath = titleObj.fullText
else
args templatePath = {shortcut}
end
prefix = options['pre' .. i] or options.pre or ''
end
if options.target and yesno(options.target) then
listItems[i] = templateMode
and string.format("{{%s[[%s|%s]]}}", prefix, templatePath, shortcut)
or string.format("[[%s]]", shortcut)
else
listItems[i] = frame:expandTemplate{
title = 'No redirect',
args = templateMode and {templatePath, shortcut} or {shortcut, shortcut}
}
if templateMode then
listItems[i] = string.format("{{%s%s}}", prefix, listItems[i])
end
end
end
table.insert(listItems, options.msg)
Line 55 ⟶ 77:
 
local root = mw.html.create()
root:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Shortcut/styles.css'} })
 
-- Anchors
local anchorDiv = root
:tag('div')
:addClass('module-shortcutanchordiv')
:css('position', 'relative')
:css('top', '-3em')
for i, shortcut in ipairs(shortcuts) do
local anchor = mw.uri.anchorEncode(shortcut)
anchorDiv:tag('span'):attr('id', anchor)
end
 
root:newline() -- To match the old [[Template:Shortcut]]
 
-- Shortcut heading
Line 73 ⟶ 92:
local nShortcuts = #shortcuts
if nShortcuts > 0 then
shortcutHeadinglocal headingMsg = message(cfgoptions['shortcut-heading'], nShortcuts)or
redirectMode and cfg['redirect-heading'] or
cfg['shortcut-heading']
shortcutHeading = shortcutHeadingmessage(headingMsg, .. '\n'nShortcuts)
shortcutHeading = frame:preprocess(shortcutHeading)
shortcutHeading = shortcutHeading .. '\n'
end
end
Line 82 ⟶ 103:
local shortcutList = root
:tag('div')
:addClass('shortcutboxmodule-shortcutboxplain plainlist noprint')
:attr('role', 'note')
if options.float and options.float:lower() == 'left' then
:css('float', 'right')
shortcutList:addClass('module-shortcutboxleft')
:css('border', '1px solid #aaa')
end
:css('background', '#fff')
if options.clear and options.clear ~= '' then
:css('margin', '0em 0em 0em 1em')
shortcutList:css('paddingclear', 'options.3em .6em .2em .6em'clear)
end
:css('text-align', 'center')
:css('font-size', '85%')
:css('font-weight', 'bold')
if shortcutHeading then
shortcutList
:tag('div')
:cssaddClass('display','inlinemodule-blockshortcutlist')
:css('border-bottom','1px solid #aaa')
:css('margin-bottom', '.2em')
:css('font-weight', 'normal')
:wikitext(shortcutHeading)
end
Line 109 ⟶ 125:
 
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {)
wrappers = 'Template:Shortcut'
})
 
-- Separate shortcuts from options
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu