Module:Infobox/Widget/Header: Difference between revisions

From TwogPedia
No edit summary
No edit summary
Line 28: Line 28:
      
      
if roster then
if roster then
    local rosterDiv = mw.html.create('div')
    local rosterDiv = mw.html.create('div')
        :addClass('roster')
        :addClass('roster')
        :css('color', '#C1C1CD')
        :css('color', 'red') -- cor forte para testar
        :wikitext('Roster: ' .. roster)
        :wikitext('Roster: ' .. roster)
    infoRowDiv:node(rosterDiv)
    infoRowDiv:node(rosterDiv)
else
    infoRowDiv:node(mw.html.create('div'):wikitext('Roster: [nil]'))
end
end
Line 38: Line 40:
    local regionDiv = mw.html.create('div')
    local regionDiv = mw.html.create('div')
        :addClass('region')
        :addClass('region')
        :css('color', '#C1C1CD')
        :css('color', 'red')
        :wikitext('Region: ' .. region)
        :wikitext('Region: ' .. region)
    infoRowDiv:node(regionDiv)
    infoRowDiv:node(regionDiv)
else
    infoRowDiv:node(mw.html.create('div'):wikitext('Region: [nil]'))
end
end
      
      
     if nationality then
     if nationality then

Revision as of 22:38, 5 June 2025

Documentation for this module may be created at Module:Infobox/Widget/Header/doc

local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
local Header = {}

local function formatDate(dateStr)
    local year, month, day = dateStr:match("(%d+)%-(%d+)%-(%d+)")
    if year and month and day then
        return day .. "." .. month .. "." .. year
    else
        return dateStr
    end
end

function Header.make(title, logoLight, logoDark, logoAll, nationality, romanized, team, country, city, startDate, endDate, roster, region)
    local container = mw.html.create('div'):addClass('info-image')
    local imageURL = logoAll or logoLight or logoDark or 'Team placeholder light.png'
    local imageDiv = mw.html.create('div')
        :addClass('ib-image')
        :addClass('relative')
        :wikitext('[[File:' .. imageURL .. '|250px]]')
    container:node(imageDiv)
    
    local textOverlayDiv = mw.html.create('div'):addClass('text-overlay')
    local titleDiv = mw.html.create('div'):addClass('ib-title'):wikitext(title)
    textOverlayDiv:node(titleDiv)
    
    local infoRowDiv = mw.html.create('div'):addClass('info-row')
    
	if roster then
    local rosterDiv = mw.html.create('div')
        :addClass('roster')
        :css('color', 'red')  -- cor forte para testar
        :wikitext('Roster: ' .. roster)
    infoRowDiv:node(rosterDiv)
	else
	    infoRowDiv:node(mw.html.create('div'):wikitext('Roster: [nil]'))
	end
	
	if region then
	    local regionDiv = mw.html.create('div')
	        :addClass('region')
	        :css('color', 'red')
	        :wikitext('Region: ' .. region)
	    infoRowDiv:node(regionDiv)
	else
	    infoRowDiv:node(mw.html.create('div'):wikitext('Region: [nil]'))
	end

    
    if nationality then
        local category = team and mw.text.split(team, '/')[1] .. '/Players' or 'Players'
        local nationalityText = tostring(LocationWidget.make(nationality, nil, category))
        local nationalityDiv = mw.html.create('div'):addClass('nationality'):wikitext(nationalityText)
        infoRowDiv:node(nationalityDiv)
    end
  
	if country then
	    local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
	    local gameName = currentTitleSplit[1] or ""
	    gameName = gameName:gsub("Dota2", "Dota 2")
	    local locationContent = LocationWidget.make(country, city, currentTitleSplit[1] .. '/Tournaments')
	    
	    local rowDiv = mw.html.create('div')
	        :addClass('ib-row')
	        :css('display', 'flex')
	        :css('justify-content', 'space-between')
	        :css('align-items', 'center')
	        :css('width', '100%')
	        :css('flex-wrap', 'nowrap')
	    
	    local leftGroup = mw.html.create('div')
	        :css('display', 'flex')
	        :css('align-items', 'center')
	        :css('white-space', 'nowrap')
	    
	    local locationSpan = mw.html.create('span')
	        :css('color', '#C1C1CD')
	        :css('white-space', 'nowrap')
	        :node(locationContent)
	    leftGroup:node(locationSpan)
	    
	    if gameName:lower() == "dota 2" then
	        local gameIcon = mw.html.create('span')
	            :css('margin-left', '8px')
	            :wikitext('[[File:Mini-icon-dota2.png|18px]]')
	        leftGroup:node(gameIcon)
	        local gameNameSpan = mw.html.create('span')
	            :css('color', 'red')
	            -- :css('font-size', '15px')
	            :css('margin-left', '4px')
	            :css('white-space', 'nowrap')
	            :wikitext(gameName)
	        leftGroup:node(gameNameSpan)
	    end
	    
	    rowDiv:node(leftGroup)
	    
	    local rightGroup = mw.html.create('div')
	        :css('display', 'flex')
	        :css('align-items', 'center')
	        :css('white-space', 'nowrap')
	    
	    if startDate then
	        local formattedStart = formatDate(startDate)
	        local formattedEnd = endDate and formatDate(endDate) or ""
	        local dateText = formattedStart
	        if formattedEnd ~= "" then
	            dateText = dateText .. " - " .. formattedEnd
	        end
	        local dateSpan = mw.html.create('span')
	            :css('color', '#C1C1CD')
	            -- :css('font-size', '15px')
	            :css('white-space', 'nowrap')
	            :wikitext(dateText)
	        rightGroup:node(dateSpan)
	    end
	    
	    rowDiv:node(rightGroup)
	    infoRowDiv:node(rowDiv)
	end

    if romanized then
        local romanizedDiv = mw.html.create('div'):addClass('romanized-name'):wikitext(romanized)
        infoRowDiv:node(romanizedDiv)
    end
    
    textOverlayDiv:node(infoRowDiv)
    container:node(textOverlayDiv)
    
    if logoDark and not logoAll then
        imageDiv:addClass('light')
        local imageDivDark = mw.html.create('div')
            :addClass('ib-image dark')
            :wikitext('[[File:' .. logoDark .. '|250px]]')
        container:node(imageDivDark)
    end
    
    return container
end

return Header