Module:NavboxMobile: Difference between revisions

No edit summary
No edit summary
Line 284: Line 284:
                 :wikitext(addNewline(args.below))
                 :wikitext(addNewline(args.below))
end
end




Line 306: Line 305:
                 :wikitext(processItem(args[groupKey]))
                 :wikitext(processItem(args[groupKey]))


             -- Only render the list row if content exists
             -- Check if the list is non-empty before rendering content
             if args[listKey] and args[listKey]:match("%S") then
             if args[listKey] and args[listKey] ~= "" then
                 local listRow = addTableRow(tbl)
                 if args[listKey] == "child" then
                local listCell = listRow:tag('td')
                    -- Check if the child contains valid groups or lists
                     :attr('colspan', 2)
                    local childHasContent = false
                    :addClass('navboxMobile-list-content') -- Base content class
                     for j = 1, 10 do
                    :addClass('navboxMobile-list-level' .. parentLevel) -- Correct level
                        local childGroupKey = "child" .. (path ~= "" and path .. "_" or "") .. i .. "_group" .. j
                    :addClass((i % 2 == 1) and 'navboxMobile-odd' or 'navboxMobile-even') -- Odd/even class
                        local childListKey = "child" .. (path ~= "" and path .. "_" or "") .. i .. "_list" .. j
                     :addClass('hlist') -- Ensure `hlist` is applied for horizontal lists
                        if args[childGroupKey] or args[childListKey] then
                            childHasContent = true
                            break
                        end
                     end


                if args[listKey] == 'child' then
                    if childHasContent then
                    -- Recursively render child lists
                        -- Recursively render child lists
                    local newPath = (path ~= "" and path .. "_" or "") .. i
                        local newPath = (path ~= "" and path .. "_" or "") .. i
                    renderListRow(tbl, tostring(newPath), parentLevel + 1)
                        renderListRow(tbl, tostring(newPath), parentLevel + 1)
                    end
                 else
                 else
                     -- Render flat lists
                     -- Render flat lists
                     listCell:wikitext(processItem(args[listKey], args.nowrapitems))
                     local listRow = addTableRow(tbl)
                    local listCell = listRow:tag('td')
                        :attr('colspan', 2)
                        :addClass('navboxMobile-list-content') -- Base content class
                        :addClass('navboxMobile-list-level' .. parentLevel) -- Correct level
                        :addClass((i % 2 == 1) and 'navboxMobile-odd' or 'navboxMobile-even') -- Odd/even class
                        :addClass('hlist') -- Ensure `hlist` is applied for horizontal lists
                        :wikitext(processItem(args[listKey], args.nowrapitems))
                 end
                 end
             end
             end
Line 328: Line 339:
     end
     end
end
end