Module:Icon: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
Fixed black icons not being inverted to white
LVL (talk | contribs)
Added shorthand support. Can now use flags like "icon-only" or sizes like "40px" without typing "size=" or "=true". Old syntax still works..
Line 48: Line 48:
     local name = args[1] or ""
     local name = args[1] or ""
     local customText = args.l1 or ""
     local customText = args.l1 or ""
   
    -- 1. Set Defaults from named arguments
     local size = args.size or "20px"
     local size = args.size or "20px"
     local noLink = args["no-link"] == "true"
     local noLink = args["no-link"] == "true"
     local iconOnly = args["icon-only"] == "true"
     local iconOnly = args["icon-only"] == "true"


    -- 2. Scan unnamed parameters (2, 3, 4...) for flags and size
    -- This allows: {{HeroIcon|Name|icon-only|no-link}} or {{HeroIcon|Name|40px|icon-only}}
    for k, v in pairs(args) do
        if type(k) == "number" and k > 1 then
            local val = mw.text.trim(v) -- Clean up whitespace
           
            if val == "icon-only" then
                iconOnly = true
            elseif val == "no-link" then
                noLink = true
            elseif val:match("^%d+px$") then
                -- If it looks like "20px" or "40px", set the size
                size = val
            end
        end
    end
    -- 3. Proceed with standard logic...
     local iconData, err = getIconData(name)
     local iconData, err = getIconData(name)
     if not iconData then
     if not iconData then