Module:NavboxMobile: Difference between revisions

No edit summary
No edit summary
Line 310: Line 310:




--
--  List rows
--
local function renderListRow(tbl, listnum)
local function renderListRow(tbl, listnum)
     -- Add a row for the group (if it exists)
    local row = addTableRow(tbl)
 
     --[[if listnum == 1 and args.imageleft then
        row
            :tag('td')
                :addClass('navboxMobile-image')
                :addClass(args.imageclass)
                :css('width', '0%')
                :css('padding', '0px 2px 0px 0px')
                :cssText(args.imageleftstyle)
                :attr('rowspan', 2 * #listnums - 1)
                :tag('div')
                    :wikitext(addNewline(args.imageleft))
    end]]
 
     if args['group' .. listnum] then
     if args['group' .. listnum] then
        local groupRow = addTableRow(tbl)
         local groupCell = row:tag('th')
         local groupCell = groupRow:tag('th')
 
         groupCell
         groupCell
             :attr('scope', 'row')
             :attr('scope', 'row')
             :addClass('navboxMobile-group-content')
             :addClass('navboxMobile-group')
             :css('text-align', 'left') -- Ensure left alignment like desktop
             :addClass(args.groupclass)
            :css('padding', args.groupPadding or '0.5em') -- Add padding for groups
            :css('border-left', '2px solid #fdfdfd') -- Similar border as desktop
             :cssText(args.basestyle)
             :cssText(args.basestyle)
        if args.groupwidth then
            groupCell:css('width', args.groupwidth)
        end
        groupCell
             :cssText(args.groupstyle)
             :cssText(args.groupstyle)
             :cssText(args['group' .. listnum .. 'style'])
             :cssText(args['group' .. listnum .. 'style'])
             :wikitext(processItem(args['group' .. listnum]))
             :wikitext(args['group' .. listnum])
     end
     end


     -- Add a row for the list
     local row = addTableRow(tbl) -- added
    local listRow = addTableRow(tbl) -- Use a different variable name
   
     local listCell = listRow:tag('td')
     local listCell = row:tag('td')
 
    if args['group' .. listnum] then
        listCell
            :css('text-align', 'left')
            :css('border-left-width', '2px')
            :css('border-left-style', 'solid')
    else
        listCell:attr('colspan', 2)
    end
 
    if not args.groupwidth then
        listCell:css('width', '100%')
    end


    -- Determine if the current list is even or odd
     local isOdd = (listnum % 2) == 1
     local isOdd = (listnum % 2) == 1
     local evenOdd = isOdd and 'odd' or 'even'
     local rowstyle = args.evenstyle
    if isOdd then rowstyle = args.oddstyle end
 
    local evenOdd
    if args.evenodd == 'swap' then
        if isOdd then evenOdd = 'even' else evenOdd = 'odd' end
    else
        if isOdd then evenOdd = args.evenodd or 'odd' else evenOdd = args.evenodd or 'even' end
    end


     listCell
     listCell
         :attr('colspan', 2)
         :css('padding', '0px')
        :addClass('navboxMobile-list-content')
        :addClass('hlist')
        :addClass('navboxMobile-' .. evenOdd) -- **Added Line**
         :cssText(args.liststyle)
         :cssText(args.liststyle)
        :cssText(rowstyle)
         :cssText(args['list' .. listnum .. 'style'])
         :cssText(args['list' .. listnum .. 'style'])
         :wikitext(processItem(args['list' .. listnum], args.nowrapitems))
         :addClass('navboxMobile-list')
 
         :addClass('navboxMobile-' .. evenOdd)
    -- Handle nested lists (`childX_groupY`, `childX_listY`)
        :addClass(args.listclass)
    if args['list' .. listnum] == 'child' then
        :tag('div')
        local nestedTbl = mw.html.create('table')
             :css('padding', (listnum == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
         nestedTbl
            :wikitext(addNewline(args['list' .. listnum]))
            :addClass('navboxMobile-subgroup')
            :css('width', '100%')
            :css('border-spacing', '0')
             :css('padding', args.nestedPadding or '0.25em') -- **Modified Line**
 
        for i = 1, 10 do -- Assume up to 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 -- Stop if no more nested items
 
            local nestedRow = addTableRow(nestedTbl)
 
            -- Add the nested group (if it exists)
            if nestedGroup then
                local nestedGroupCell = nestedRow:tag('th')
                nestedGroupCell
                    :attr('scope', 'row')
                    :addClass('navboxMobile-group-content')
                    :addClass('navboxMobile-subgroup-group') -- **Added Line**
                    :cssText(args.basestyle)
                    :cssText(args['child' .. listnum .. '_group' .. i .. 'style'])
                    :css('padding-bottom', '0.25em') -- **Added Line**
                    :wikitext(processItem(nestedGroup))
            end
 
            -- Add the nested list (if it exists)
            if nestedList then
                local nestedListCell = nestedRow:tag('td')
                nestedListCell
                    :attr('colspan', 2)
                    :addClass('navboxMobile-list-content')
                    :addClass('hlist')
                    :addClass('navboxMobile-' .. (i % 2 == 1 and 'odd' or 'even')) -- **Optional: Handle nested even/odd**
                    :cssText(args['child' .. listnum .. '_list' .. i .. 'style'])
                    :wikitext(processItem(nestedList))
            end
        end


        -- Add the nested table to the main list cell
    --[[if listnum == 1 and args.image then
         listCell:node(nestedTbl)
         row
    else
            :tag('td')
        -- Render a flat list if no nested lists exist
                :addClass('navboxMobile-image')
        listCell
                :addClass(args.imageclass)
            :addClass('hlist')
                :css('width', '0%')
            :tag('div')
                 :css('padding', '0px 0px 0px 2px')
                 :css('padding', args.listpadding or '0 0.25em')
                :cssText(args.imagestyle)
                 :wikitext(processItem(args['list' .. listnum], args.nowrapitems))
                :attr('rowspan', 2 * #listnums - 1)
     end
                 :tag('div')
                    :wikitext(addNewline(args.image))
     end ]]
end
end