Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:StaffCard: Difference between revisions

From Vault Hunters Official Wiki
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 13: Line 13:
     local joined = args.joined or ''
     local joined = args.joined or ''
     local discord = args.discord or ''
     local discord = args.discord or ''
    local youtube = args.youtube or ''
    local github = args.github or ''
     local pronouns = args.pronouns or ''
     local pronouns = args.pronouns or ''
     local twitch = args.twitch or ''
     local twitch = args.twitch or ''
Line 88: Line 90:
      
      
     -- Footer section (only show if we have details to display)
     -- Footer section (only show if we have details to display)
     if status ~= '' or joined ~= '' or discord ~= '' or twitch ~= '' then
     if status ~= '' or joined ~= '' or discord ~= '' or twitch ~= '' or youtube ~= '' or github ~= '' then
         local footer = html:tag('div'):addClass('staff-card-footer')
         local footer = html:tag('div'):addClass('staff-card-footer')
          
          
Line 103: Line 105:
          
          
         -- Additional details
         -- Additional details
         if joined ~= '' or discord ~= '' or twitch ~= '' then
         if joined ~= '' then
             local details = footer:tag('div'):addClass('staff-card-details')
             local details = footer:tag('div'):addClass('staff-card-details')
              
              
Line 109: Line 111:
                 details:tag('span'):wikitext('Joined: '):tag('strong'):wikitext(joined)
                 details:tag('span'):wikitext('Joined: '):tag('strong'):wikitext(joined)
             end
             end
      end
      if discord ~= '' or twitch ~= '' or youtube ~= '' or github ~= '' then
          local socialDiv = footer:tag('div'):addClass('staff-card-social-icons')
              
              
             if discord ~= '' then
             if discord ~= '' then
                details:tag('span'):wikitext('Discord: '):tag('strong'):wikitext(discord)
              local discordWikitext = '[https://discord.com/users/' .. discord .. ' [[File:Discord-Symbol-White.svg|20px|alt=Discord|link=]]]'
              socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(discordWikitext)
             end
             end
              
              
             if twitch ~= '' then
             if twitch ~= '' then
                local twitchSpan = details:tag('span'):wikitext('Twitch: ')
              local twitchWikitext = '[https://twitch.tv/' .. twitch .. ' [[File:Twitch-icon.svg|20px|alt=Twitch|link=]]]'
                local socialDiv = twitchSpan:tag('span'):addClass('staff-card-social')
              socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(twitchWikitext)
                local twitchLink = socialDiv:tag('a')
            end
                    :attr('href', 'https://twitch.tv/' .. twitch)
         
                    :attr('target', '_blank')
            if youtube ~= '' then
                    :attr('rel', 'noopener')
                local youtubeWikitext = '[https://youtube.com/@' .. youtube .. ' [[File:Youtube.svg|20px|alt=YouTube|link=]]]'
                    :attr('title', twitch .. ' on Twitch')
                 socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(youtubeWikitext)
                  
            end
                -- Add Twitch icon SVG
            if github ~= '' then
                twitchLink:tag('svg')
                local githubWikitext = '[https://github.com/' .. github .. ' [[File:Github-mark-white.svg|20px|alt=YouTube|link=]]]'
                    :addClass('staff-card-twitch-icon')
                socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(githubWikitext)
                    :attr('viewBox', '0 0 24 24')
                    :attr('xmlns', 'http://www.w3.org/2000/svg')
                    :tag('path')
                    :attr('d', 'M11.571 4.714h1.715v5.143H11.57zm4.715 0H18v5.143h-1.714zM6 0L1.714 4.286v15.428h5.143V24l4.286-4.286h3.428L22.286 12V0zm14.571 11.143l-3.428 3.428h-3.429l-3 3v-3H6.857V1.714h13.714Z')
             end
             end
         end
         end

Latest revision as of 23:35, 7 July 2025

Documentation for this module may be created at Module:StaffCard/doc

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    
    -- Get parameters
    local handle = args.handle or args[1] or ''
    local ign = args.ign or args[2] or ''
    local roles = args.roles or args[3] or ''
    local bio = args.bio or args[4] or ''
    local avatar = args.avatar or ''
    local status = args.status or 'active'
    local joined = args.joined or ''
    local discord = args.discord or ''
    local youtube = args.youtube or ''
    local github = args.github or ''
    local pronouns = args.pronouns or ''
    local twitch = args.twitch or ''
    
    -- Check if we're being called from the template page itself (no parameters)
    -- This prevents errors when viewing the template page directly
    local hasAnyArgs = false
    for k, v in pairs(args) do
        if v and v ~= '' then
            hasAnyArgs = true
            break
        end
    end
    
    -- If no arguments provided (viewing template page), return empty string
    if not hasAnyArgs then
        return ''
    end
    
    -- Validate required fields for actual usage
    if handle == '' then
        return '<div class="error">Error: Handle is required for staff card</div>'
    end
    
    -- Build the card HTML
    local html = mw.html.create('div')
        :addClass('staff-card')
        :attr('data-handle', handle)
    
    -- Header section
    local header = html:tag('div'):addClass('staff-card-header')
    
    -- Avatar
    local avatarDiv = header:tag('div'):addClass('staff-card-avatar')
    if avatar ~= '' then
        -- Use custom avatar if provided
        avatarDiv:tag('img'):attr('src', avatar):attr('alt', handle .. ' avatar')
    elseif ign ~= '' then
        -- Use PlayerHead template if IGN is provided but no custom avatar
        local playerHeadWikitext = frame:preprocess('{{PlayerHead|' .. ign .. '|60px}}')
        avatarDiv:wikitext(playerHeadWikitext)
    else
        -- Use first letter of handle as fallback
        avatarDiv:wikitext(mw.ustring.sub(handle, 1, 1))
    end
    
    -- Info section
    local info = header:tag('div'):addClass('staff-card-info')
    info:tag('h3'):wikitext(handle)
    
    if ign ~= '' then
        info:tag('div'):addClass('staff-card-ign'):wikitext('IGN: ' .. ign)
    end
    
    if pronouns ~= '' then
        info:tag('div'):addClass('staff-card-pronouns'):wikitext('(' .. pronouns .. ')')
    end
    
    -- Roles section
    if roles ~= '' then
        local rolesDiv = html:tag('div'):addClass('staff-card-roles')
        local roleList = mw.text.split(roles, ',')
        for _, role in ipairs(roleList) do
            role = mw.text.trim(role)
            if role ~= '' then
                rolesDiv:tag('span'):addClass('staff-card-role'):wikitext(role)
            end
        end
    end
    
    -- Bio section
    if bio ~= '' then
        html:tag('div'):addClass('staff-card-bio'):wikitext(bio)
    end
    
    -- Footer section (only show if we have details to display)
    if status ~= '' or joined ~= '' or discord ~= '' or twitch ~= '' or youtube ~= '' or github ~= '' then
        local footer = html:tag('div'):addClass('staff-card-footer')
        
        -- Status and meta info
        local meta = footer:tag('div'):addClass('staff-card-meta')
        
        -- Status indicator
        if status ~= '' then
            local statusSpan = meta:tag('span')
                :addClass('staff-card-status')
                :addClass(status:lower())
                :wikitext(status)
        end
        
        -- Additional details
        if joined ~= '' then
            local details = footer:tag('div'):addClass('staff-card-details')
            
            if joined ~= '' then
                details:tag('span'):wikitext('Joined: '):tag('strong'):wikitext(joined)
            end
       end

       if discord ~= '' or twitch ~= '' or youtube ~= '' or github ~= '' then
           local socialDiv = footer:tag('div'):addClass('staff-card-social-icons')
            
            if discord ~= '' then
               local discordWikitext = '[https://discord.com/users/' .. discord .. ' [[File:Discord-Symbol-White.svg|20px|alt=Discord|link=]]]'
               socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(discordWikitext)
            end
            
            if twitch ~= '' then
               local twitchWikitext = '[https://twitch.tv/' .. twitch .. ' [[File:Twitch-icon.svg|20px|alt=Twitch|link=]]]'
               socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(twitchWikitext)
            end
           
            if youtube ~= '' then
                local youtubeWikitext = '[https://youtube.com/@' .. youtube .. ' [[File:Youtube.svg|20px|alt=YouTube|link=]]]'
                socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(youtubeWikitext)
            end
            if github ~= '' then
                local githubWikitext = '[https://github.com/' .. github .. ' [[File:Github-mark-white.svg|20px|alt=YouTube|link=]]]'
                socialDiv:tag('span'):addClass('social-icon-wrapper'):wikitext(githubWikitext)
            end
        end
    end
    
    return tostring(html)
end

return p