Module:Navigation header: Difference between revisions
Appearance
Content deleted Content added
No edit summary Tag: Reverted |
|||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
-- Import the standard icons and shortcut modules |
|||
⚫ | |||
local standardIcons = require('Module:Standard icons') |
|||
⚫ | |||
local shortcut = require('Module:Shortcut') |
|||
⚫ | |||
⚫ | |||
function p.getIcon(key) |
|||
while parent.args['page' .. index] or parent.args['content' .. index] do |
|||
local iconTable = standardIcons.getIconTable() |
|||
return iconTable[key] or key |
|||
local content = parent.args['content' .. index] |
|||
end |
|||
local sectionName = parent.args['section' .. index] |
|||
local pageDiv = mw.html.create('div'):addClass('blocks-block') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local label = {} |
|||
editLink = mw.uri.makeFullUrl(pageName, {action = 'edit', section = tostring(index)}) |
|||
local itemType = {} |
|||
elseif content then |
|||
⚫ | |||
editLink = mw.uri.makeFullUrl(mw.title.getCurrentTitle().prefixedText, {action = 'edit', section = tostring(index)}) |
|||
⚫ | |||
local editButton = mw.html.create('span') |
|||
:addClass('mw-editsection') |
|||
:wikitext('[' .. editLink .. ' edit]') |
|||
pageDiv:wikitext('\n==' .. sectionName .. '== ' .. tostring(editButton)) |
|||
⚫ | |||
while parentFrame.args["icon" .. i] or parentFrame.args["type" .. i] or parentFrame.args["label" .. i] do |
|||
⚫ | |||
icon[i] = parentFrame.args["icon" .. i] or p.getIcon(parentFrame.args["type" .. i]) |
|||
local transcludedContent = frame:expandTemplate{title = pageName} |
|||
label[i] = parentFrame.args["label" .. i] or "" |
|||
itemType[i] = parentFrame.args["type" .. i] or "" |
|||
elseif content then |
|||
i = i + 1 |
|||
end |
|||
local theme = parentFrame.args["theme"] or "blue-theme" |
|||
table.insert(pages, pageDiv) |
|||
if theme ~= "gray-theme" and theme ~= "blue-theme" then |
|||
index = index + 1 |
|||
theme = "blue-theme" |
|||
end |
end |
||
local output = {} |
|||
output[#output + 1] = string.format('<div class="navigation-header %s"><div role="navigation" class="navigation-header-tabs">', theme) |
|||
⚫ | |||
-- Add shortcut box if shortcut parameter is provided |
|||
local shortcutParam = parentFrame.args["shortcut"] |
|||
if shortcutParam then |
|||
local shortcutBox = shortcut._main({shortcutParam}) |
|||
output[#output + 1] = string.format('<div class="navigation-header-shortcut">%s</div>', shortcutBox) |
|||
end |
end |
||
output[#output + 1] = '<ul>' |
|||
local mainDiv = mw.html.create('div') |
|||
for _, pageDiv in ipairs(pages) do |
|||
-- Add leadtab if leadtab-label is defined |
|||
mainDiv:node(pageDiv) |
|||
local leadtabLabel = parentFrame.args["leadtab-label"] |
|||
⚫ | |||
local leadtabIcon = parentFrame.args["leadtab-icon"] |
|||
⚫ | |||
output[#output + 1] = string.format( |
|||
'<li id="leadtab"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div> %s</li>', |
|||
leadtabIcon, |
|||
leadtabLabel |
|||
⚫ | |||
⚫ | |||
output[#output + 1] = string.format( |
|||
'<li id="leadtab">%s</li>', |
|||
leadtabLabel |
|||
⚫ | |||
⚫ | |||
end |
end |
||
for j = 1, #icon do |
|||
return tostring(mainDiv) |
|||
output[#output + 1] = string.format( |
|||
'<li id="%s"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div> %s</li>', |
|||
itemType[j], |
|||
icon[j], |
|||
label[j] |
|||
⚫ | |||
end |
|||
output[#output + 1] = '</ul>' |
|||
output[#output + 1] = '</div></div>' |
|||
return table.concat(output, '\n') |
|||
end |
end |
||
Revision as of 23:15, 9 May 2023
![]() | This module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
Implements Template:Navigation header.
Functions
main
main(frame: table) -> string
Takes a frame object containing the template's arguments and generates a navigation header.
frame: A table containing the arguments passed to the module.
Returns: A string representing the generated HTML for the navigation header.
_main
_main(args: table) -> string
Takes an args object containing another module's arguments into this module and does the same as above.
local p = {}
-- Import the standard icons and shortcut modules
local standardIcons = require('Module:Standard icons')
local shortcut = require('Module:Shortcut')
function p.getIcon(key)
local iconTable = standardIcons.getIconTable()
return iconTable[key] or key
end
function p.navigationHeader(frame)
local parentFrame = frame:getParent()
local icon = {}
local label = {}
local itemType = {}
local i = 1
while parentFrame.args["icon" .. i] or parentFrame.args["type" .. i] or parentFrame.args["label" .. i] do
icon[i] = parentFrame.args["icon" .. i] or p.getIcon(parentFrame.args["type" .. i])
label[i] = parentFrame.args["label" .. i] or ""
itemType[i] = parentFrame.args["type" .. i] or ""
i = i + 1
end
local theme = parentFrame.args["theme"] or "blue-theme"
if theme ~= "gray-theme" and theme ~= "blue-theme" then
theme = "blue-theme"
end
local output = {}
output[#output + 1] = string.format('<div class="navigation-header %s"><div role="navigation" class="navigation-header-tabs">', theme)
-- Add shortcut box if shortcut parameter is provided
local shortcutParam = parentFrame.args["shortcut"]
if shortcutParam then
local shortcutBox = shortcut._main({shortcutParam})
output[#output + 1] = string.format('<div class="navigation-header-shortcut">%s</div>', shortcutBox)
end
output[#output + 1] = '<ul>'
-- Add leadtab if leadtab-label is defined
local leadtabLabel = parentFrame.args["leadtab-label"]
if leadtabLabel then
local leadtabIcon = parentFrame.args["leadtab-icon"]
if leadtabIcon then
output[#output + 1] = string.format(
'<li id="leadtab"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div> %s</li>',
leadtabIcon,
leadtabLabel
)
else
output[#output + 1] = string.format(
'<li id="leadtab">%s</li>',
leadtabLabel
)
end
end
for j = 1, #icon do
output[#output + 1] = string.format(
'<li id="%s"><div class="navigation-header-icon">[[File:%s|x18px|link=]]</div> %s</li>',
itemType[j],
icon[j],
label[j]
)
end
output[#output + 1] = '</ul>'
output[#output + 1] = '</div></div>'
return table.concat(output, '\n')
end
return p