Module:NavboxMobile: Difference between revisions

No edit summary
No edit summary
Tag: Reverted
Line 112: Line 112:
         :done()
         :done()
end
end
local function renderGroupRow(tbl, groupnum, level)
    local groupRow = addTableRow(tbl)
    local groupCell = groupRow:tag('th')
        :attr('scope', 'row')
        :addClass('navboxMobile-group-content')
        :addClass('navboxMobile-group-level' .. level) -- Level 2 for main groups, Level 3 for subgroups
        :cssText(args.basestyle)
        :cssText(args['group' .. groupnum .. 'style'])
        :wikitext(processItem(args['group' .. groupnum]))
end


-- Work around for style markers (similar to Navbox)
-- Work around for style markers (similar to Navbox)
Line 319: Line 332:


local function renderListRow(tbl, listnum)
local function renderListRow(tbl, listnum)
     -- Add a row for the group (if it exists)
     -- Determine level (2 for main groups, 3 for subgroups)
     if args['group' .. listnum] then
     local level = 2
        local groupRow = addTableRow(tbl)
    if border == 'subgroup' then
        local groupCell = groupRow:tag('th')
         level = 3
         groupCell
            :attr('scope', 'row')
            :addClass('navboxMobile-group-content')
            :addClass('navboxMobile-group-level2') -- Ensure correct level
            :css('padding-top', '0.5em') -- Add top padding
            :css('padding-bottom', '0.5em') -- Add bottom padding
            :css('border-left', '2px solid #fdfdfd')
            :wikitext(processItem(args['group' .. listnum]))
     end
     end
 
   
     -- Add a row for the list
     -- Render group row
    renderGroupRow(tbl, listnum, level)
   
    -- Continue with rendering the list
     local listRow = addTableRow(tbl)
     local listRow = addTableRow(tbl)
     local listCell = listRow:tag('td')
     local listCell = listRow:tag('td')
 
        :addClass('navboxMobile-list-content')
    -- Determine if the current list number is odd or even
        :addClass('navboxMobile-' .. ((listnum % 2 == 1) and 'odd' or 'even'))
    local isOdd = (listnum % 2) == 1
    local evenOddClass = isOdd and 'navboxMobile-odd' or 'navboxMobile-even'
 
    listCell
        :addClass('hlist')
        :addClass(evenOddClass) -- Apply the alternating class
         :attr('colspan', 2)
         :attr('colspan', 2)
        :addClass('navboxMobile-list-content hlist ' .. evenOddClass)
         :css('padding', '0 0.25em')
         :css('padding', '0 0.25em')
         :css('width', '100%')
         :css('width', '100%')
         :cssText(args.liststyle)
         :cssText(args.liststyle)
         :cssText(args['list' .. listnum .. 'style'])
         :cssText(args['list' .. listnum .. 'style'])
 
      
     -- Handle nested lists or flat lists
     if args['list' .. listnum] == 'child' then
     if args['list' .. listnum] == 'child' then
         -- Render nested table for child lists within 'navboxMobile-subgroup'
         -- Render nested subgroup as a separate table
         local nestedTbl = mw.html.create('table')
         local nestedTbl = mw.html.create('table')
             :addClass('navboxMobile-subgroup')
             :addClass('navboxMobile-subgroup')
             :css('width', '100%')
             :css('width', '100%')
             :css('border-spacing', '0')
             :css('border-spacing', '0')
             :css('margin-top', '0.25em') -- Add top margin
             :css('margin-top', '0.25em')
             :css('margin-bottom', '0.25em') -- Add bottom margin
             :css('margin-bottom', '0.25em')
 
       
         for i = 1, 10 do
         for i = 1, 10 do
             local nestedGroup = args['child' .. listnum .. '_group' .. i]
             local nestedGroup = args['child' .. listnum .. '_group' .. i]
             local nestedList = args['child' .. listnum .. '_list' .. i]
             local nestedList = args['child' .. listnum .. '_list' .. i]
 
           
             if not nestedGroup and not nestedList then break end -- Stop if no more nested items
             if not nestedGroup and not nestedList then break end
 
           
             local nestedRow = addTableRow(nestedTbl)
            renderGroupRow(nestedTbl, i, 3) -- Level 3 for subgroups
 
             local nestedListRow = addTableRow(nestedTbl)
             -- Add the nested group (if it exists)
             local nestedListCell = nestedListRow:tag('td')
            if nestedGroup then
                 :addClass('navboxMobile-list-content')
                local nestedGroupCell = nestedRow:tag('th')
                :addClass('navboxMobile-' .. ((i % 2 == 1) and 'odd' or 'even'))
                 nestedGroupCell
                 :attr('colspan', 2)
                    :attr('scope', 'row')
                :css('padding', '0 0.25em')
                    :addClass('navboxMobile-group-content navboxMobile-group-level3')
                :cssText(args['child' .. listnum .. '_list' .. i .. 'style'])
                    :cssText(args.basestyle)
                :wikitext(processItem(nestedList))
                    :cssText(args['child' .. listnum .. '_group' .. i .. 'style'])
                    :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 hlist ' .. ((i % 2 == 1) and 'navboxMobile-odd' or 'navboxMobile-even'))
                    :cssText(args['child' .. listnum .. '_list' .. i .. 'style'])
                    :wikitext(processItem(nestedList))
            end
         end
         end
 
          
         -- Add the nested table to the main list cell
         listCell:node(nestedTbl)
         listCell:node(nestedTbl)
     else
     else
         -- Render a flat list
         -- Render flat list
         listCell
         listCell:tag('div')
            :addClass('hlist')
            :css('padding', args.listpadding or '0 0.25em')
            :tag('div')
            :wikitext(processItem(args['list' .. listnum], args.nowrapitems))
                :css('padding', args.listpadding or '0 0.25em')
                :wikitext(processItem(args['list' .. listnum], args.nowrapitems))
     end
     end
end
end