Module:NavboxMobile: Difference between revisions

No edit summary
No edit summary
Line 305: Line 305:
--  List rows
--  List rows
--
--
local function renderListRow(tbl, listnum)
local function renderListRow(tbl, index, listnum, listnums_size)
     local row = addTableRow(tbl)
     local row = addTableRow(tbl)


     -- Process group
     -- Process group (e.g., `group1`, `group2`)
     if args['group' .. listnum] then
    local group_and_num = format(cfg.arg.group_and_num, listnum)
    local groupstyle_and_num = format(cfg.arg.groupstyle_and_num, listnum)
     if args[group_and_num] then
         local groupCell = row:tag('th')
         local groupCell = row:tag('th')
        -- ID for aria-labelledby attribute if it's the first group with no title or above
        if listnum == 1 and not (args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group2]) then
            groupCell:attr('id', mw.uri.anchorEncode(args[cfg.arg.group1]))
        end
         groupCell
         groupCell
             :attr('scope', 'row')
             :attr('scope', 'row')
Line 316: Line 324:
             :cssText(args.basestyle)
             :cssText(args.basestyle)
             :cssText(args.groupstyle)
             :cssText(args.groupstyle)
             :cssText(args['group' .. listnum .. 'style'])
             :cssText(args[groupstyle_and_num])
             :wikitext(processItem(args['group' .. listnum]))
             :wikitext(processItem(args[group_and_num]))
     end
     end


     -- Add table row for the list
     -- Add list cell
    row = addTableRow(tbl)
     local listCell = row:tag('td')
     local listCell = row:tag('td')
    listCell:attr('colspan', 2)
    listCell:css('width', '100%')


     -- Apply dynamic styling
     -- If there's a group, add a class; otherwise, make the cell span both columns
     local oddEven = cfg.class.navbox_odd_part
     if args[group_and_num] then
     if args['list' .. listnum] and args['list' .. listnum]:sub(1, 12) == '</div><table' then
        listCell:addClass(cfg.class.navbox_list_with_group)
        oddEven = args['list' .. listnum]:find(cfg.pattern.navbox_title) and cfg.marker.restart or
     else
    cfg.class.navbox_odd_part
        listCell:attr('colspan', 2)
    end
 
    -- Set cell width if group width is not specified
    if not args[cfg.arg.groupwidth] then
        listCell:css('width', '100%')
     end
     end
    listCell:addClass(oddEven)


    -- Apply styles for odd/even rows
    local rowstyle = nil
    if index % 2 == 1 then
        rowstyle = args[cfg.arg.oddstyle]
    else
        rowstyle = args[cfg.arg.evenstyle]
    end


     listCell
     -- Handle the list itself
        :addClass('navboxMobile-list-content')
    local list_and_num = format(cfg.arg.list_and_num, listnum)
        :addClass(cfg.class.navbox_list) -- Add styling for lists
    local listText = args[list_and_num]
        :addClass(cfg.class.navbox_part .. ((listnum % 2 == 1) and 'odd' or 'even')) -- Ensure odd/even styles
        :addClass(args[cfg.arg.listclass]) -- Apply any additional classes from args
        :addClass(args['listclass_' .. listnum]) -- Apply list-specific classes
        :cssText(args.liststyle)
        :cssText(args['list' .. listnum .. 'style'])


     -- Check for nested subgroups dynamically
     -- Check for nested subgroups
     if inArray(cfg.keyword.subgroups, args['list' .. listnum]) then
     if inArray(cfg.keyword.subgroups, listText) then
         local childArgs = {
         local childArgs = {
             border = 'subgroup',
             [cfg.arg.border] = cfg.keyword.border_subgroup,
             navbar = 'plain'
             [cfg.arg.navbar] = cfg.keyword.navbar_plain
         }
         }
        local hasChildArgs = false
         for k, v in pairs(args) do
         for k, v in pairs(args) do
             local prefix = 'child' .. listnum .. '_'
             k = tostring(k)
            if k:sub(1, #prefix) == prefix then
            for _, w in ipairs(cfg.keyword.subgroups) do
                childArgs[k:sub(#prefix + 1)] = v
                w = w .. listnum .. "_"
                if (#k > #w) and (k:sub(1, #w) == w) then
                    childArgs[k:sub(#w + 1)] = v
                    hasChildArgs = true
                end
             end
             end
         end
         end
         args['list' .. listnum] = p._navboxMobile(childArgs)
         listText = hasChildArgs and p._navboxMobile(childArgs) or listText
     end
     end


     -- Check for nested lists (e.g., child1_groupX)
     -- Odd/even class and striping
     local nestedGroup = args['child' .. listnum .. '_group1']
     local oddEven = cfg.marker.oddeven
     local nestedList = args['child' .. listnum .. '_list1']
     if listText:sub(1, 12) == '</div><table' then
        -- If listText is for a subgroup navbox, no automatic striping for this row
        oddEven = listText:find(cfg.pattern.navbox_title) and cfg.marker.restart or cfg.class.navbox_odd_part
    end


     if nestedGroup or nestedList then
     -- Apply list-specific styles
        local nestedTbl = mw.html.create('table')
    local liststyle_and_num = format(cfg.arg.liststyle_and_num, listnum)
            :addClass('navboxMobile-subrendermaintabgroup')
    local listclass_and_num = format(cfg.arg.listclass_and_num, listnum)
             :css('width', '100%')
    listCell
        :css('padding', '0')
        :cssText(args[cfg.arg.liststyle])
        :cssText(rowstyle)
        :cssText(args[liststyle_and_num])
        :addClass(cfg.class.navbox_list)
        :addClass(cfg.class.navbox_part .. oddEven)
        :addClass(args[cfg.arg.listclass])
        :addClass(args[listclass_and_num])
        :tag('div')
             :css('padding', args[cfg.arg.list1padding] or args[cfg.arg.listpadding] or '0 0.25em')
            :wikitext(processItem(listText, args[cfg.arg.nowrapitems]))
end


        for i = 1, 10 do -- Assume a max of 10 nested groups/lists
            local nestedGroup = args['child' .. listnum .. '_group' .. i]
            local nestedList = args['child' .. listnum .. '_list' .. i]
            if not nestedGroup and not nestedList then break end
            local nestedRow = addTableRow(nestedTbl)
            if nestedGroup then
                nestedRow:tag('th')
                    :addClass('navboxMobile-group-content')
                    :cssText(args.basestyle)
                    :cssText(args['child' .. listnum .. '_group' .. i .. 'style'])
                    :wikitext(processItem(nestedGroup))
            end
            if nestedList then
                nestedRow:tag('td')
                    :addClass('navboxMobile-list-content hlist')
                    :cssText(args['child' .. listnum .. '_list' .. i .. 'style'])
                    :wikitext(processItem(nestedList))
            end
        end
        listCell:node(nestedTbl)
    else
        listCell
            :addClass('hlist') -- Add hlist for horizontal styling
            :tag('div') -- Wrap in a div to allow padding and better styling
                :css('padding', args[cfg.arg.listpadding] or '0 0.25em')
                :wikitext(processItem(args['list' .. listnum], args.nowrapitems))
    end
end