Module:NavboxMobile: Difference between revisions

No edit summary
No edit summary
Line 309: Line 309:


     -- Process group
     -- Process group
     local group_and_num = format(cfg.arg.group_and_num, listnum)
     if args['group' .. listnum] then
    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')
        -- Handle ARIA attributes for accessibility
        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 324: Line 316:
             :cssText(args.basestyle)
             :cssText(args.basestyle)
             :cssText(args.groupstyle)
             :cssText(args.groupstyle)
             :cssText(args[groupstyle_and_num])
             :cssText(args['group' .. listnum .. 'style'])
             :wikitext(processItem(args[group_and_num]))
             :wikitext(processItem(args['group' .. listnum]))
     end
     end


     -- Add list cell
     -- Add table row for the list
    row = addTableRow(tbl)
     local listCell = row:tag('td')
     local listCell = row:tag('td')
     if args[group_and_num] then
     listCell:attr('colspan', 2)
        listCell:addClass('navboxMobile-list-with-group')
     listCell:css('width', '100%')
     else
        listCell:attr('colspan', 2)
    end


     if not args[cfg.arg.groupwidth] then
    -- Apply dynamic styling
        listCell:css('width', '100%')
    local oddEven = cfg.class.navbox_odd_part
     if args['list' .. listnum] and args['list' .. listnum]:sub(1, 12) == '</div><table' then
        oddEven = args['list' .. listnum]:find(cfg.pattern.navbox_title) and cfg.marker.restart or
    cfg.class.navbox_odd_part
     end
     end
    listCell:addClass(oddEven)


    -- Apply row-specific styles
    local rowstyle = (listnum % 2 == 1) and args[cfg.arg.oddstyle] or args[cfg.arg.evenstyle]
    local list_and_num = format(cfg.arg.list_and_num, listnum)
    local listText = args[list_and_num]


     -- Handle nested subgroups
     listCell
     if inArray(cfg.keyword.subgroups, listText) then
        :addClass('navboxMobile-list-content')
        :addClass(cfg.class.navbox_list) -- Add styling for lists
        :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
     if inArray(cfg.keyword.subgroups, args['list' .. listnum]) then
         local childArgs = {
         local childArgs = {
             [cfg.arg.border] = cfg.keyword.border_subgroup,
             border = 'subgroup',
             [cfg.arg.navbar] = cfg.keyword.navbar_plain,
             navbar = 'plain'
         }
         }
        local hasChildArgs = false
         for k, v in pairs(args) do
         for k, v in pairs(args) do
             local prefix = cfg.keyword.subgroups[1] .. listnum .. "_"
             local prefix = 'child' .. listnum .. '_'
             if k:sub(1, #prefix) == prefix then
             if k:sub(1, #prefix) == prefix then
                 childArgs[k:sub(#prefix + 1)] = v
                 childArgs[k:sub(#prefix + 1)] = v
                hasChildArgs = true
             end
             end
         end
         end
         listText = hasChildArgs and p._navboxMobile(childArgs) or listText
         args['list' .. listnum] = p._navboxMobile(childArgs)
     end
     end


     -- Handle automatic striping for odd/even rows
     -- Check for nested lists (e.g., child1_groupX)
     local oddEven = cfg.marker.oddeven
    local nestedGroup = args['child' .. listnum .. '_group1']
     if listText and listText:sub(1, 12) == '</div><table' then
     local nestedList = args['child' .. listnum .. '_list1']
        oddEven = listText:find(cfg.pattern.navbox_title) and cfg.marker.restart or cfg.class.navbox_odd_part
 
     if nestedGroup or nestedList then
        local nestedTbl = mw.html.create('table')
            :addClass('navboxMobile-subgroup')
            :css('width', '100%')
 
        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
    -- Render list content
    local liststyle_and_num = format(cfg.arg.liststyle_and_num, listnum)
    listCell
        :cssText(args[cfg.arg.liststyle])
        :cssText(rowstyle)
        :cssText(args[liststyle_and_num])
        :addClass('navboxMobile-list-content')
        :addClass(cfg.class.navbox_part .. oddEven)
        :addClass(args[cfg.arg.listclass])
        :tag('div')
            :css('padding', args[cfg.arg.listpadding] or '0 0.25em')
            :wikitext(processItem(listText or '', args[cfg.arg.nowrapitems]))
end
end