Module:Navbar/sandbox: Difference between revisions

Content deleted Content added
no reason to stand up an entirely new object
some more refactors
Line 2:
local cfg = mw.loadData('Module:Navbar/configuration')
 
local function addItem get_title_arg(link_description, ul, is_miniis_collapsible, font_styletemplate)
local titleArgtitle_arg = 1
if is_collapsible then title_arg = 2 end
localif template then title_arg = args.'template' end
return title_arg
end
 
local function choose_links(template, remove_edit_link)
-- The show table indicates the default displayed items.
-- view, talk, edit, hist, move, watch
-- TODO: Move to configuration.
local show = {true, true, true, false, false, false}
if template then
show[2] = false
show[3] = false
local index = {t = 2, d = 2, e = 3, h = 4, m = 5, w = 6,
talk = 2, edit = 3, hist = 4, move = 5, watch = 6}
-- TODO: Consider removing TableTools dependency.
for _, v in ipairs(require ('Module:TableTools').compressSparseArray(args)) do
local num = index[v]
if num then show[num] = true end
end
end
if remove_edit_link then show[3] = false end
return show
end
 
local function addItem(link_description, ul, is_mini, font_style)
local l
if link_description.url then
Line 22 ⟶ 51:
 
function p._navbar(args)
-- TODO: We probably don't need both fontstyle and fontcolor...
local font_style = args.fontstyle
Line 29 ⟶ 59:
local is_plain = args.plain
local titleArg = 1
local collapsible_class = nil
if is_collapsible then
collapsible_class = cfg.classes.collapsible
titleArg = 2
if not is_plain then is_mini = 1 end
if font_color then
Line 39 ⟶ 67:
end
end
-- The show table indicates the default displayed items.
-- view, talk, edit, hist, move, watch
-- TODO: Move to configuration.
local show = {true, true, true, false, false, false}
local template = args.template
if template then
titleArg = 'template'
show[2] = false
show[3] = false
local index = {t = 2, d = 2, e = 3, h = 4, m = 5, w = 6,
talk = 2, edit = 3, hist = 4, move = 5, watch = 6}
-- TODO: Consider removing TableTools dependency.
for _, v in ipairs(require ('Module:TableTools').compressSparseArray(args)) do
local num = index[v]
if num then show[num] = true end
end
end
local remove_edit_link = args.noedit
if remove_edit_link then show[3] = false end
local navbar_style = args.style
Line 82 ⟶ 89:
end
local template = args.template
local titleArg = get_title_arg(is_collapsible, template)
local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
local title = mw.title.new(mw.text.trim(titleText), cfg.title_namespace)
Line 112 ⟶ 121:
:cssText(font_style)
end
 
local remove_edit_link = args.noedit
local displayed_links = choose_links(template, remove_edit_link)
for i, _ in ipairs(showdisplayed_links) do
if showdisplayed_links[i] then addItem(link_descriptions[i], ul, is_mini, font_style) end
end
ul:done()