Module:NavboxMobile: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 455: Line 455:
end
end


--
--  Main navboxMobile tables
--
--
--
--  Main navboxMobile tables
--  Main navboxMobile tables
Line 461: Line 464:
     local tbl = mw.html.create('table')
     local tbl = mw.html.create('table')
         :addClass('nowraplinks')
         :addClass('nowraplinks')
        :addClass(cfg.class.navbox_list)
         :addClass(args.bodyclass)
         :addClass(args.bodyclass)
        :cssText(args.bodystyle)
        :cssText(args.style)


    --[[if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
        tbl
            :addClass('collapsible')
            :addClass(args.state or 'autocollapse')
    end]]
    tbl:css('border-spacing', 0)
     if border == 'subgroup' or border == 'child' or border == 'none' then
     if border == 'subgroup' or border == 'child' or border == 'none' then
         tbl
         tbl
             :addClass('navbox-subgroup') -- Align with desktop naming conventions
             :addClass('navboxMobile-subgroup')
             :css('width', '100%')
             :cssText(args.bodystyle)
             :css('border-spacing', '0')
             :cssText(args.style)
     else
     else -- regular navobx - bodystyle and style will be applied to the wrapper table
         tbl
         tbl
             :addClass('navbox-inner') -- Align with desktop naming conventions
             :addClass('navboxMobile-inner')
             :css('background', 'transparent')
             :css('background', 'transparent')
             :css('color', 'inherit')
             :css('color', 'inherit')
            :css('border-spacing', '0')
     end
     end
     tbl:cssText(args.innerstyle)
     tbl:cssText(args.innerstyle)


     renderTitleRow(tbl)
     renderTitleRow(tbl)
     renderAboveRow(tbl)
     renderAboveRow(tbl)
     for _, listnum in ipairs(listnums) do
     for i, listnum in ipairs(listnums) do
         renderListRow(tbl, listnum)
         renderListRow(tbl, listnum)
     end
     end
Line 495: Line 500:
     args = navboxMobileArgs
     args = navboxMobileArgs


    -- Reset state variables to prevent state leakage between invocations
    tableRowAdded = false
    listnums = {}
    -- Move and collect hiding templatestyles
    local hiding_templatestyles = move_hiding_templatestyles(args)
    -- Collect list numbers
     for k, v in pairs(args) do
     for k, v in pairs(args) do
         if type(k) == 'string' then
         local listnum = ('' .. k):match('^list(%d+)$')
            local listnum = k:match('^list(%d+)$')
        if listnum then table.insert(listnums, tonumber(listnum)) end
            if listnum then table.insert(listnums, tonumber(listnum)) end
        end
     end
     end
     table.sort(listnums)
     table.sort(listnums)


     border = trim(args.border or args[1] or '')
     border = trim(args.border or args[1] or '')
    if border == cfg.keyword.border_child then
        border = cfg.keyword.border_subgroup
    end


     -- Render the main body of the navboxMobile
     -- render the main body of the navboxMobile
     local tbl = renderMainTable()
     local tbl = renderMainTable()


     -- Create the final HTML with styles
     -- render the appropriate wrapper around the navboxMobile, depending on the border param
     local res = mw.html.create()
     local res = mw.html.create()
 
     if border == 'none' then
     -- Inject styles analogous to Module:Navbox
        res:node(tbl)
    res:node(add_navbox_mobile_styles(hiding_templatestyles))
    elseif border == 'subgroup' or border == 'child' then
 
        -- We assume that this navboxMobile is being rendered in a list cell of a parent navboxMobile, and is
    -- Align the outer wrapper with desktop structure
        -- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
    local navWrapper = mw.html.create('div')
         -- padding being applied, and at the end add a <div> to balance out the parent's </div>
         :attr('role', 'navigation')
         res
         :addClass('navbox') -- Use consistent naming with desktop
            :wikitext('</div>') -- XXX: hack due to lack of unclosed support in mw.html.
 
            :node(tbl)
    if args.title or args.above or (args.group1 and not args.group2) then
            :wikitext('<div>') -- XXX: hack due to lack of unclosed support in mw.html.
        navWrapper:attr(
            'aria-labelledby',
            mw.uri.anchorEncode(args.title or args.above or args.group1)
        )
     else
     else
         navWrapper:attr('aria-label', cfg.aria_label)
         res
            :tag('table')
                :addClass('navboxMobile')
                :css('border-spacing', 0)
                :cssText(args.bodystyle)
                :cssText(args.style)
                :tag('tr')
                    :tag('td')
                        :css('padding', '2px')
                        :node(tbl)
     end
     end


    -- Add the rendered table to the wrapper
    navWrapper:node(tbl)
    res:node(navWrapper)
    -- Render tracking categories
     renderTrackingCategories(res)
     renderTrackingCategories(res)