Module:Navbox: Difference between revisions
From MiiWiki
Jump to navigationJump to search
mNo edit summary |
SuperHamster (talk | contribs) (Adding clear to autolink function too) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 12: | Line 12: | ||
if items ~= nil then items = mw.text.split(items, "\n") else items = {} end | if items ~= nil then items = mw.text.split(items, "\n") else items = {} end | ||
local result = {} | 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"> | table.insert(result, ' <div class="module-navbox mw-collapsible mw-'.. collapse ..'" style="clear: both; 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 i = 1 | ||
local x = 1 | local x = 1 | ||
Line 22: | Line 22: | ||
local resultSection = "" | local resultSection = "" | ||
while items[i] do | while items[i] do | ||
item = mw.text.split(items[i], "/") | item = mw.text.split(items[i], "//") | ||
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 | ||
Line 54: | Line 54: | ||
if items ~= nil then items = mw.text.split(items, "\n") else items = {} end | if items ~= nil then items = mw.text.split(items, "\n") else items = {} end | ||
local result = {} | 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"> ') | table.insert(result, ' <div class="module-navbox mw-collapsible mw-'.. collapse ..'" style="clear: both; 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 i = 1 | ||
local x = 1 | local x = 1 | ||
Line 64: | Line 64: | ||
local resultSection = "" | local resultSection = "" | ||
while items[i] do | while items[i] do | ||
item = mw.text.split(items[i], "/") | item = mw.text.split(items[i], "//") | ||
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 |
Latest revision as of 03:12, 2 October 2023
This module generates a navbox in an easier way and allows to select a mode and colors.
Basic example
{{#invoke:navbox|MODE|color1=BACKGROUND|color2=BORDER|color3=HEADER-CELLS|TITLE| Head // Item, Item, Item, Item Head // Item, Item, Item ... }}
MODE
defines the mode of the items. The available modes arelist
: items are defined normally, so you can place a link, or something else, individually.autolink
: each item is turned into a link automatically. This is better suited for specific situations where all the pages do not need any modifications to the link.
color1
defines the background color of the navbox.color2
defines the border color.color3
defines the background color of the header cells.TITLE
defines the title of the navbox.
After the title, press enter to jump to the next line and then type the title of the section, the head-cell (Head
), then insert two forward slashes and start typing the items (Item
). Split each item with a comma.
All of the items need to be in one single line along the head-cell, if you break a line this will create a new section.
View
{{#invoke:navbox|list|color1=beige|color2=green|color3=cyan|My navbox| Head // Item, Item, Item, Item Head // Item, Item, Item }}
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="clear: both; 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="clear: both; 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