Module:NavboxMobile: Difference between revisions

No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 150: Line 150:
         -- Applying nowrap to lines in a table does not make sense.
         -- Applying nowrap to lines in a table does not make sense.
         -- Add newlines to compensate for trim of x in |parm=x in a template.
         -- Add newlines to compensate for trim of x in |parm=x in a template.
        item = item:gsub('|%s*width%s*=%s*"[%d%w]+"', '| width="100%"')
         return '\n' .. item .. '\n'
         return '\n' .. item .. '\n'
     end
     end
     if nowrapitems == cfg.keyword.nowrapitems_yes then
     if nowrapitems == cfg.keyword.nowrapitems_yes or true then
         local lines = {}
         local lines = {}
         for line in (item .. '\n'):gmatch('([^\n]*)\n') do
         for line in (item .. '\n'):gmatch('([^\n]*)\n') do
Line 166: Line 167:
         return '\n' .. item .. '\n'
         return '\n' .. item .. '\n'
     end
     end
    -- Ensure no excessive whitespace
    item = mw.ustring.gsub(item, "%s+", " ")
     return item
     return item
end
end


-- Function to add a new table row with optional gutter
-- Function to add a new table row with optional gutter
Line 219: Line 223:
         :addClass(cfg.class.navbox_list)
         :addClass(cfg.class.navbox_list)
         :addClass(args[cfg.arg.titleclass])
         :addClass(args[cfg.arg.titleclass])
         :attr('data-level', 1) -- Level 1 for the main title
         :attr('data-level', 1)
         :attr('colspan', 2)
         :attr('colspan', 2)
         :cssText(args.basestyle)
         :cssText(args.basestyle)
         :cssText(args.titlestyle)
         :cssText(args.titlestyle)
        :css('position', 'relative')  -- Ensure relative positioning for absolute children


     -- Add the title content
     -- Add the title content, centered across the full width
     titleCell
     titleCell
         :tag('div')
         :tag('div')
             :css('font-size', '114%')
             :css('margin', '0 auto')
             :css('margin', '0')
             :css('text-align', 'center')
             :wikitext(addNewline(args.title))
             :wikitext(addNewline(args.title))
    -- Add the navbar, positioned absolutely in the top-right corner
    if has_navbar() then
        titleCell
            :tag('div')
                :addClass('navboxMobile-navbar')
                :css('position', 'absolute')
                :css('top', '0')
                :css('right', '0')
                :css('padding', '0.2em')  -- Optional: Adjust padding for alignment
                :wikitext(navbar{
                    args.name,
                    mini = 1,
                    fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;'
                })
    end
end
end


--
--
Line 257: Line 276:
                 :wikitext(addNewline(args.above))
                 :wikitext(addNewline(args.above))
end
end




Line 331: Line 349:
                         :addClass('navboxMobile-list-level' .. parentLevel) -- Correct level
                         :addClass('navboxMobile-list-level' .. parentLevel) -- Correct level
                         :addClass((i % 2 == 1) and 'navboxMobile-odd' or 'navboxMobile-even') -- Odd/even class
                         :addClass((i % 2 == 1) and 'navboxMobile-odd' or 'navboxMobile-even') -- Odd/even class
                         :addClass('hlist') -- Ensure `hlist` is applied for horizontal lists
                         :addClass(args.listclass or '') -- Apply `listclass` if defined in the template
                        :css('padding', '0.25em') -- Optional: Adjust padding for better spacing
                         :wikitext(processItem(args[listKey], args.nowrapitems))
                         :wikitext(processItem(args[listKey], args.nowrapitems))
                 end
                 end
Line 339: Line 356:
     end
     end
end
end




Line 408: Line 426:
         :addClass(cfg.class.navbox)
         :addClass(cfg.class.navbox)
         :addClass(args.bodyclass)
         :addClass(args.bodyclass)
        :addClass(args.listclass or '') -- Apply the `listclass` argument globally if applicable
         :cssText(args.bodystyle)
         :cssText(args.bodystyle)
         :cssText(args.style)
         :cssText(args.style)
Line 431: Line 450:
                 :addClass('navboxMobile-group-content')
                 :addClass('navboxMobile-group-content')
                 :addClass('navboxMobile-group-level1')
                 :addClass('navboxMobile-group-level1')
                :addClass(args.listclass or '') -- Apply `listclass` for group rows
                 :wikitext(processItem(args[groupKey]))
                 :wikitext(processItem(args[groupKey]))


Line 442: Line 462:
                     :addClass('navboxMobile-list-content')
                     :addClass('navboxMobile-list-content')
                     :addClass((listnum % 2 == 1) and 'navboxMobile-odd' or 'navboxMobile-even')
                     :addClass((listnum % 2 == 1) and 'navboxMobile-odd' or 'navboxMobile-even')
                    :addClass(args.listclass or '') -- Apply `listclass` to flat rows
                     :wikitext(processItem(args[listKey]))
                     :wikitext(processItem(args[listKey]))
             end
             end
Line 449: Line 470:
     -- Add the below row
     -- Add the below row
     renderBelowRow(tbl)
     renderBelowRow(tbl)
    -- Add the Navbar row last
    if has_navbar() then
        local navbarRow = tbl:tag('tr')
        navbarRow:tag('td')
            :attr('colspan', 2)
            :addClass('navboxMobile-navbar')
            :css('text-align', 'right')
            :wikitext(navbar{args.name, mini = 1})
    end


     return tbl
     return tbl