Module:NavboxUpgraded: Difference between revisions

No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
local format = string.format
local format = string.format


-- Load the stylesheet using the configuration's templatestyles
mw.getCurrentFrame():extensionTag(cfg.templatestyles)




Line 47: Line 45:
                     container:wikitext(nestedSubgroup)
                     container:wikitext(nestedSubgroup)
                 else
                 else
                     container:tag('ul')
                     -- Process the list into proper <li> elements
                    local listHtml = mw.html.create('ul')
                         :addClass('navbox-list')
                         :addClass('navbox-list')
                         :css('padding-left', '1.5em')
                         :css('padding-left', '1.5em')
                         :css('list-style', 'disc')
                         :css('list-style', 'disc')
                         :wikitext(sublist)
 
                    for item in sublist:gmatch("[^\n]+") do
                         -- Remove leading '*' or similar list markers
                        local cleanItem = item:gsub("^%s*[%*#]+%s*", "")
                        if cleanItem ~= '' then
                            listHtml:tag('li')
                                :wikitext(cleanItem)
                        end
                    end
 
                    container:node(listHtml)
                 end
                 end
             end
             end
Line 59: Line 68:
     return tostring(html)
     return tostring(html)
end
end


-- Function to generate the desktop navbox
-- Function to generate the desktop navbox
Line 246: Line 256:


local function add_navbox_styles()
local function add_navbox_styles()
     return mw.html.create('style')
     local html = mw.html.create()
        :wikitext(cfg.templatestyles .. cfg.hlist_templatestyles .. cfg.plainlist_templatestyles)
   
         :done()
    -- Helper function to add a stylesheet link
    local function add_stylesheet(path)
        html:tag('link')
            :attr('rel', 'stylesheet')
            :attr('href', path)
            :attr('type', 'text/css')
    end
 
    -- Assuming cfg.templatestyles contains space-separated CSS file paths
    if type(cfg.templatestyles) == 'string' and cfg.templatestyles ~= '' then
        for stylePath in cfg.templatestyles:gmatch("[^%s]+") do
            add_stylesheet(stylePath)
        end
    end
 
    if type(cfg.hlist_templatestyles) == 'string' and cfg.hlist_templatestyles ~= '' then
        for stylePath in cfg.hlist_templatestyles:gmatch("[^%s]+") do
            add_stylesheet(stylePath)
        end
    end
 
    if type(cfg.plainlist_templatestyles) == 'string' and cfg.plainlist_templatestyles ~= '' then
        for stylePath in cfg.plainlist_templatestyles:gmatch("[^%s]+") do
            add_stylesheet(stylePath)
         end
    end
 
    return html:done()
end
end




Line 260: Line 299:
     local desktopNavbox = p._navboxDesktop(args)
     local desktopNavbox = p._navboxDesktop(args)
     local mobileNavbox = p._navboxMobile(args)
     local mobileNavbox = p._navboxMobile(args)
   
 
     local res = mw.html.create('div')
     local res = mw.html.create('div')
     res:node(add_navbox_styles()) -- Add styles at the beginning of the div
     res:node(add_navbox_styles()) -- Add styles at the beginning of the div
     res
     res
         :tag('div')
         :tag('div')
             :addClass('nomobile')
             :addClass('nomobile')
             :wikitext(add_navbox_styles() .. desktopNavbox)
             :wikitext(desktopNavbox) -- Do not include `add_navbox_styles()` here
             :done()
             :done()
         :tag('div')
         :tag('div')
             :addClass('onlymobile')
             :addClass('onlymobile')
             :wikitext(add_navbox_styles() .. mobileNavbox)
             :wikitext(mobileNavbox) -- Do not include `add_navbox_styles()` here
             :done()
             :done()


     return tostring(res)
     return tostring(res)
end
end


return p
return p