k (1 revision imported) |
(Imported by PageSync) Label: wsps-content-edit-tag |
||
Regel 3: | Regel 3: | ||
local curTitle = mw.title.getCurrentTitle() | local curTitle = mw.title.getCurrentTitle() | ||
--[[ | |||
function p.innerMenu(frame) | |||
debug console tests: | |||
=p.innerMenu(mw.getCurrentFrame():newChild{["args"]={["input"]="Main Page*Home\n\nPages\n\n\n\nSearch*Search"}}) | |||
--]] | |||
function p.innerMenu(frame) | function p.innerMenu(frame) | ||
local theInput = frame:preprocess(frame.args['input']) | local theInput = frame:preprocess(frame.args['input']) | ||
-- Check if empty or nil | |||
if not theInput or theInput:match("^%s*$") then | |||
return '' | |||
end | |||
local result = '' | local result = '' | ||
for MenuItem in mw.text.gsplit(theInput, "\n\n") do | for MenuItem in mw.text.gsplit(theInput, "\n\n+") do | ||
local MenuParts = mw.text.split(MenuItem, "\n") | local MenuParts = mw.text.split(MenuItem, "\n") | ||
if #MenuParts == 1 then -- A simple link | if #MenuParts == 1 then -- A simple link | ||
ws-base-props | |||
---|---|---|---|
Regel 2: | Regel 2: | ||
|Class=Application page | |Class=Application page | ||
|Title=Module:WSNavMenu | |Title=Module:WSNavMenu | ||
|Version history={{Version history item | |||
|Version number=1.0 | |||
|Version description=match more than 2 newlines between menu items, to prevent errors when using for example ifingroup to only show submenus for specific users | |||
|Version date=2024-8-13 11:11:39 | |||
}} | |||
}} | |||
}} | }} |
Huidige versie van 24 mrt 2025 om 09:29
Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:WSNavMenu/doc
local p = {}
local curTitle = mw.title.getCurrentTitle()
--[[
function p.innerMenu(frame)
debug console tests:
=p.innerMenu(mw.getCurrentFrame():newChild{["args"]={["input"]="Main Page*Home\n\nPages\n\n\n\nSearch*Search"}})
--]]
function p.innerMenu(frame)
local theInput = frame:preprocess(frame.args['input'])
-- Check if empty or nil
if not theInput or theInput:match("^%s*$") then
return ''
end
local result = ''
for MenuItem in mw.text.gsplit(theInput, "\n\n+") do
local MenuParts = mw.text.split(MenuItem, "\n")
if #MenuParts == 1 then -- A simple link
result = result .. p.makeNavLink(MenuParts[1], 'nav-link', 'color:#fff', 'nav-item', frame)
else -- A dropdown menu
local dropdownHeader = frame:callParserFunction(
'#widget',
{
'Link',
type='a',
href='#',
class='nav-link dropdown-toggle',
datatoggle='dropdown',
style='color:#fff',
text=MenuParts[1] .. '<b class="caret"></b>'
}
)
local dropdownContent = ''
for i=2,#MenuParts do
if MenuParts[i] == '-' then
dropdownContent = dropdownContent .. '<li class="divider"></li>'
else
dropdownContent = dropdownContent .. p.makeNavLink(
MenuParts[i],
'dropdown-item',
'',
'',
frame
)
end
end
result = result .. '<li class="nav-item dropdown">' .. dropdownHeader .. '<ul class="dropdown-menu" role="menu">' .. dropdownContent .. '</ul></li>'
end
end
return result
end
function p.makeNavLink(inputString, class, style, liClass, frame)
local MenuParts = mw.text.split(inputString, "*")
local linkPart = MenuParts[1]
local textPart = MenuParts[2]
local linkType = MenuParts[3]
if not textPart then
textPart = linkPart
end
if not linkType or linkType == Page then
if not mw.title.new( linkPart ) then
do return "Unknown link: " .. mw.text.jsonEncode(inputString) end
end
linkPart = mw.title.new( linkPart )
if mw.title.compare( curTitle, linkPart) == 0 then
liClass = liClass .. ' navbar-presentpage'
end
linkPart = linkPart:fullUrl({}, 'https')
end
local navLink = frame:callParserFunction(
'#widget',
{
'Link',
type = 'a',
href = linkPart,
class= class,
text = textPart,
style= style
}
)
return '<li class="'..liClass..'">' .. navLink .. '</li>'
end
return p