Module:Infobox/Widget/Header: Difference between revisions

From TwogPedia
mNo edit summary
No edit summary
Line 1: Line 1:
local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
local Header = {}
local Header = {}


function Header.make(title, logoLight, logoDark, logoAll)
local function formatDate(dateStr)
local container = mw.html.create('div')
    local year, month, day = dateStr:match("(%d+)%-(%d+)%-(%d+)")
local title = mw.html.create('div')
    if year and month and day then
:addClass('ib-title')
        return day .. "." .. month .. "." .. year
:wikitext(title)
    else
local imageURL = logoAll or logoLight or logoDark or 'Team placeholder light.png'
        return dateStr
    end
end


local imageDiv = mw.html.create('div')
function Header.make(title, logoLight, logoDark, logoAll, nationality, romanized, team, country, city, startDate, endDate)
:addClass('ib-image')
    local container = mw.html.create('div'):addClass('info-image')
:wikitext('[[File:'.. imageURL .. '|250px|link=]]')
    local imageURL = logoAll or logoLight or logoDark or 'Team placeholder light.png'
    local imageDiv = mw.html.create('div')
container:node(title):node(imageDiv)
        :addClass('ib-image')
        :addClass('relative')
if logoDark and logoAll == nil then
        :wikitext('[[File:' .. imageURL .. '|250px]]')
imageDiv:addClass('light')
    container:node(imageDiv)
local imageDivDark = mw.html.create('div')
   
:addClass('ib-image dark')
    local textOverlayDiv = mw.html.create('div'):addClass('text-overlay')
:wikitext('[[File:'.. logoDark .. '|250px|link=]]')
    local titleDiv = mw.html.create('div'):addClass('ib-title'):wikitext(title)
container:node(imageDivDark)
    textOverlayDiv:node(titleDiv)
   
    local infoRowDiv = mw.html.create('div'):addClass('info-row')
    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
end
 
return container
    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
end


return Header
return Header

Revision as of 03:11, 25 April 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)
    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 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