Module:NavboxMobile: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) 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 | 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() | ||
-- | -- Create the final HTML with styles | ||
local res = mw.html.create() | local res = mw.html.create() | ||
-- Inject styles | |||
res:node(addNavboxMobileStyles()) | |||
-- Handle wrapping based on border parameter | |||
if border == 'none' then | if border == 'none' then | ||
res:node( | -- 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 | ||
-- | -- Assume this navboxMobile is inside a parent navboxMobile's list cell | ||
-- | -- Insert closing and opening divs to manage padding | ||
res | res | ||
:wikitext('</div>') -- | :wikitext('</div>') -- Close parent div | ||
:node(tbl) | :node(tbl) | ||
:wikitext('<div>') -- | :wikitext('<div>') -- Reopen parent div | ||
else | else | ||
-- Wrap the table within a navigation div with additional classes and styles | |||
: | local navWrapper = mw.html.create('div') | ||
:attr('role', 'navigation') | |||
:addClass('navboxMobile') -- Add appropriate classes | |||
:css('border-spacing', 0) | |||
:cssText(args.bodystyle) | |||
:cssText(args.style) | |||
:tag('tr') | |||
:tag('td') | |||
:css('padding', '2px') | |||
:node(tbl) | |||
res:node(navWrapper) | |||
end | end | ||
-- Render tracking categories | |||
renderTrackingCategories(res) | renderTrackingCategories(res) | ||