Module:NavboxMobile: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 16: | Line 16: | ||
local listnums = {} | local listnums = {} | ||
-- Function to | -- Analogous function to add_navbox_styles from Module:Navbox | ||
local | local function add_navbox_mobile_styles(hiding_templatestyles) | ||
return mw.html.create(' | local frame = mw.getCurrentFrame() | ||
: | |||
:wikitext( | -- Function to add user-defined templatestyles | ||
local function add_user_styles(templatestyles) | |||
if templatestyles and templatestyles ~= '' then | |||
return frame:extensionTag{ | |||
name = 'templatestyles', | |||
args = { src = templatestyles } | |||
} | |||
end | |||
return '' | |||
end | |||
-- Get base templatestyles from config | |||
local base_templatestyles = cfg.templatestyles | |||
local templatestyles = add_user_styles(args[cfg.arg.templatestyles]) | |||
local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles]) | |||
-- Combine all styles into a single <div> | |||
return mw.html.create('div') | |||
:addClass(cfg.class.navbox_styles) | |||
:wikitext( | |||
base_templatestyles .. | |||
templatestyles .. | |||
child_templatestyles .. | |||
table.concat(hiding_templatestyles) | |||
) | |||
:done() | :done() | ||
end | |||
-- Work around for style markers (similar to Navbox) | |||
local function move_hiding_templatestyles(args) | |||
local gfind = string.gmatch | |||
local gsub = string.gsub | |||
local templatestyles_markers = {} | |||
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)' | |||
for k, arg in pairs(args) do | |||
for marker in gfind(arg, strip_marker_pattern) do | |||
table.insert(templatestyles_markers, marker) | |||
end | |||
args[k] = gsub(arg, strip_marker_pattern, '') | |||
end | |||
return templatestyles_markers | |||
end | end | ||
Line 321: | Line 360: | ||
end | end | ||
function p._navboxMobile(navboxMobileArgs) | function p._navboxMobile(navboxMobileArgs) | ||
args = navboxMobileArgs | args = navboxMobileArgs | ||
Line 331: | Line 367: | ||
listnums = {} | 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 | ||
local listnum = | if type(k) == 'string' then | ||
local listnum = k:match('^list(%d+)$') | |||
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 | ||
Line 345: | Line 390: | ||
local res = mw.html.create() | local res = mw.html.create() | ||
-- Inject styles | -- Inject styles analogous to Module:Navbox | ||
res:node( | res:node(add_navbox_mobile_styles(hiding_templatestyles)) | ||
-- Handle wrapping based on border parameter | -- Handle wrapping based on border parameter | ||
Line 353: | Line 398: | ||
local navWrapper = mw.html.create('div') | local navWrapper = mw.html.create('div') | ||
:attr('role', 'navigation') | :attr('role', 'navigation') | ||
:attr('aria-label', cfg.aria_label) | :attr('aria-label', cfg.aria_label) | ||
:node(tbl) | :node(tbl) | ||
res:node(navWrapper) | res:node(navWrapper) | ||
elseif border == 'subgroup' or border == 'child' then | elseif border == 'subgroup' or border == 'child' then | ||
-- Assume this navboxMobile is | -- Assume this navboxMobile is inside a parent navboxMobile's list cell | ||
-- Insert closing and opening divs to manage padding | -- Insert closing and opening divs to manage padding | ||
res | res | ||
Line 368: | Line 413: | ||
:attr('role', 'navigation') | :attr('role', 'navigation') | ||
:addClass('navboxMobile') -- Add appropriate classes | :addClass('navboxMobile') -- Add appropriate classes | ||
:cssText(args.bodystyle) | :cssText(args.bodystyle) | ||
:cssText(args.style) | :cssText(args.style) | ||
:css('padding', '2px') -- Adjust padding as needed | |||
:node(tbl) | :node(tbl) | ||
res:node(navWrapper) | res:node(navWrapper) | ||
Line 381: | Line 426: | ||
end | end | ||
function p.navboxMobile(frame) | function p.navboxMobile(frame) | ||
if not getArgs then | if not getArgs then | ||
Line 391: | Line 433: | ||
-- Read the arguments in the order they'll be output in, to make references number in the right order. | -- Read the arguments in the order they'll be output in, to make references number in the right order. | ||
local _ | local _ | ||
_ = args.title | _ = args.title |