Module:NavboxMobile: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
--
-- This module implements {{navbox}} for MobileFrontend
-- This module implements {{navbox}} for MobileFrontend
--


local p = {}
local p = {}
Line 11: Line 9:
local inArray = require('Module:TableTools').inArray
local inArray = require('Module:TableTools').inArray
local format = string.format
local format = string.format


local args
local args
Line 313: Line 310:
             :cssText(args.bodystyle)
             :cssText(args.bodystyle)
             :cssText(args.style)
             :cssText(args.style)
     else -- regular navobx - bodystyle and style will be applied to the wrapper table
     else -- regular navbox - bodystyle and style will be applied to the wrapper table
         tbl
         tbl
             :addClass('navboxMobile-inner')
             :addClass('navboxMobile-inner')
Line 333: Line 330:
function p._navboxMobile(navboxMobileArgs)
function p._navboxMobile(navboxMobileArgs)
     args = navboxMobileArgs
     args = navboxMobileArgs
    -- Reset state variables to prevent state leakage between invocations
    tableRowAdded = false
    listnums = {}


     for k, v in pairs(args) do
     for k, v in pairs(args) do
Line 345: Line 346:
     local tbl = renderMainTable()
     local tbl = renderMainTable()


     -- render the appropriate wrapper around the navboxMobile, depending on the border param
     -- Create the final HTML with styles
     local res = mw.html.create()
     local res = mw.html.create()
        :node(addNavboxMobileStyles())
        :node(navWrapper)
        :node(tbl)


     local navWrapper = mw.html.create('div')
     -- Inject styles
        :attr('role', 'navigation')
    res:node(addNavboxMobileStyles())
        :attr('aria-label', cfg.aria_label) -- Ensure cfg.aria_label is defined appropriately
        :node(tbl)
   


    -- Handle wrapping based on border parameter
     if border == 'none' then
     if border == 'none' then
         res:node(tbl)
        -- Wrap the table within a navigation div with ARIA attributes
        local navWrapper = mw.html.create('div')
            :attr('role', 'navigation')
            :attr('aria-label', cfg.aria_label)
            :node(tbl)
         res:node(navWrapper)
     elseif border == 'subgroup' or border == 'child' then
     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
         -- Assume this navboxMobile is inside a parent navboxMobile's list cell
         -- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
         -- Insert closing and opening divs to manage padding
        -- padding being applied, and at the end add a <div> to balance out the parent's </div>
         res
         res
             :wikitext('</div>') -- XXX: hack due to lack of unclosed support in mw.html.
             :wikitext('</div>') -- Close parent div
             :node(tbl)
             :node(tbl)
             :wikitext('<div>') -- XXX: hack due to lack of unclosed support in mw.html.
             :wikitext('<div>') -- Reopen parent div
     else
     else
         res
         -- Wrap the table within a navigation div with additional classes and styles
             :tag('table')
        local navWrapper = mw.html.create('div')
                :addClass('navboxMobile')
             :attr('role', 'navigation')
                :css('border-spacing', 0)
            :addClass('navboxMobile') -- Add appropriate classes
                :cssText(args.bodystyle)
            :css('border-spacing', 0)
                :cssText(args.style)
            :cssText(args.bodystyle)
                :tag('tr')
            :cssText(args.style)
                    :tag('td')
            :tag('tr')
                        :css('padding', '2px')
                :tag('td')
                        :node(tbl)
                    :css('padding', '2px')
                    :node(tbl)
        res:node(navWrapper)
     end
     end


    -- Render tracking categories
     renderTrackingCategories(res)
     renderTrackingCategories(res)