Module:Navbox: Difference between revisions
From Pikmin Fanon
mNo edit summary |
mNo edit summary |
||
Line 25: | Line 25: | ||
if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then | if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then | ||
x = 1 | x = 1 | ||
parents = mw.text.split(item[2], " | parents = mw.text.split(item[2], "&&") | ||
resultItems = "" | resultItems = "" | ||
while parents[x] do | while parents[x] do | ||
Line 32: | Line 32: | ||
end | end | ||
y = 2 | y = 2 | ||
children = mw.text.split(item[1], " | children = mw.text.split(item[1], "&&") | ||
resultSection = children[1] | resultSection = children[1] | ||
Line 67: | Line 67: | ||
if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then | if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then | ||
x = 1 | x = 1 | ||
parents = mw.text.split(item[2], " | parents = mw.text.split(item[2], "&&") | ||
resultItems = "" | resultItems = "" | ||
while parents[x] do | while parents[x] do | ||
Line 74: | Line 74: | ||
end | end | ||
y = 2 | y = 2 | ||
children = mw.text.split(item[1], " | children = mw.text.split(item[1], "&&") | ||
resultSection = children[1] | resultSection = children[1] | ||
Latest revision as of 15:23, 25 January 2022
Documentation for this module may be created at Module:Navbox/doc
local p = {}
function p.list (frame) -- items organized in an inline-list style
local c1, c2, c3, collapse
c1 = frame.args["color1"] -- background color
c2 = frame.args["color2"] -- title bg color
c3 = frame.args["color3"] -- border and section items color
collapse = frame.args["expand"]
if collapse ~= nil or "collapse" or "collapsible" or "collapsed" then collapse = "collapsed" else collapse = "expanded" end
local title = frame.args[1]
local items = frame.args[2]
if items ~= nil then items = mw.text.split(items, "\n") else items = {} end
local result = {}
table.insert(result, ' <div class="module-navbox mw-collapsible mw-'.. collapse ..'" style="background-color:'.. c1 ..'; border: 2px solid '.. c2 ..'; border-radius: 15px"><div style="background-color: '.. c3 ..'; text-align: center; font-weight: bold; border-radius: 15px; margin: 2px; padding: 2px 0">'.. title ..'</div><table class="lua-navbox mw-collapsible-content"> ')
local i = 1
local x = 1
local y = 2
local item = {}
local parents = {}
local children = {}
local resultItems = ""
local resultSection = ""
while items[i] do
item = mw.text.split(items[i], "//")
if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then
x = 1
parents = mw.text.split(item[2], "&&")
resultItems = ""
while parents[x] do
resultItems = resultItems .. '<li>' .. parents[x] .. '</li>'
x = x + 1
end
y = 2
children = mw.text.split(item[1], "&&")
resultSection = children[1]
table.insert(result, '<tr><th style="background:' .. c3 .. ';">' .. resultSection .. '</th><td><ul>' .. resultItems .. '</ul></td></tr>')
end
i = i + 1
end
table.insert(result, '</table></div></div>')
return table.concat(result, '')
end
function p.autolink (frame) -- automatic links
local c1, c2, c3, collapse
c1 = frame.args["color1"] -- background color
c2 = frame.args["color2"] -- title bg color
c3 = frame.args["color3"] -- border and section items color
collapse = frame.args["expand"]
if collapse ~= nil or "collapse" or "collapsible" or "collapsed" then collapse = "collapsed" else collapse = "expanded" end
local title = frame.args[1]
local items = frame.args[2]
if items ~= nil then items = mw.text.split(items, "\n") else items = {} end
local result = {}
table.insert(result, ' <div class="module-navbox mw-collapsible mw-'.. collapse ..'" style="background-color:'.. c1 ..'; border: 2px solid '.. c2 ..'; border-radius: 15px"><div style="background-color: '.. c3 ..'; text-align: center; font-weight: bold; border-radius: 15px; margin: 2px; padding: 2px 0">[['.. title ..']]</div><table class="lua-navbox mw-collapsible-content"> ')
local i = 1
local x = 1
local y = 2
local item = {}
local parents = {}
local children = {}
local resultItems = ""
local resultSection = ""
while items[i] do
item = mw.text.split(items[i], "//")
if item[2] and mw.text.trim(item[1]) ~= "" and mw.text.trim(item[2]) ~= "" then
x = 1
parents = mw.text.split(item[2], "&&")
resultItems = ""
while parents[x] do
resultItems = resultItems .. '<li>[[' .. parents[x] .. ']]</li>'
x = x + 1
end
y = 2
children = mw.text.split(item[1], "&&")
resultSection = children[1]
table.insert(result, '<tr><th style="background:' .. c3 .. ';">' .. resultSection .. '</th><td><ul>' .. resultItems .. '</ul></td></tr>')
end
i = i + 1
end
table.insert(result, '</table></div></div>')
return table.concat(result, '')
end
return p