Module:Timeline of release years: Difference between revisions

Content deleted Content added
optimize to 1940
No further discussion, copied the better sandbox version here.
Line 3:
local p = {}
 
local function isYearReleaseditems(args, year)
local itemList = {}
if args[year] or args[year .. 'a'] then
return true
titleItem table.insert(builderitemList, args[year] or args[year .. 'a' ])
end
for asciiletter = 9798, 106 do -- 9798 == ab, 106 == j
if args[year .. string.char(asciiletter)] then
titleItem table.insert(builderitemList, args[year .. string.char(asciiletter)])
return true
end
end
return table.maxn(itemList), itemList
end
 
local function color(args, year, itemNum)
if args[year .. '_color'] then
Line 22 ⟶ 24:
for yearrange = 1, 5 do
if args['range' .. yearrange] and args['range' .. yearrange .. '_color'] then
local _, _, beginyear, endyear = string.find( args['range' .. yearrange], '^(%d%d%d%d).%D+(%d%d%d%d)$' )
local year = tonumber(year) or 9999 -- For year == 'TBA'
Line 30 ⟶ 32:
if year >= beginyear and year <= endyear then
local _, _, color1, color2 = string.find( args['range' .. yearrange .. '_color'], '^(%S*)%s*(%S*)$' )
color2 = (string.find(color2 ==, '^#?%w+$')) and color1color2 or color2color1
return isYearReleased(args,itemNum year> 0) and color1 or color2
end
end
end
return isYearReleased(args,itemNum year> 0) and '#0BDA51' or '#228B22'
end
 
local function titleItemleft(builder, contentargs, year, itemNum)
builder = builder:tag( 'td' )
if content ~= nil then
:cssattr('paddingscope', '5pxrow')
builder:tag( 'span' ):wikitext( content .. '<br />' )
:css( 'border', '1px solid blacknone' )
:css( 'padding', '5px' )
:css( 'backgroundborder-colorright', '20px solid ' .. color(args, year), itemNum))
:wikitext( year )
if itemNum > 1 then
builder = builder:attr('rowspan', itemNum)
end
end
 
local function leftright(builder, args, year, itemNum, itemList)
if isYearReleased(args, year)itemNum == nil0 then return end
builder:tag( 'td' )
:css('padding', '5px')
:wikitext( year )
end
 
local function center(builder, args, year)
builder:tag( 'td' )
:css( 'width', '10px' )
:css( 'border', '1px solid black' )
:css( 'background-color', color(args, year) )
:css( 'padding', '5px' )
end
 
local function right(builder, args, year)
if isYearReleased(args, year) == nil then return end
if contentitemNum ~== nil1 then
builder = builder:tag('td')
builder:csstag('padding','5pxtd')
:css( 'widthpadding', '10px5px' )
titleItem(builder, args[year] or args[year .. 'a' ])
:css('border', 'none')
 
:wikitext(itemList[1])
for asciiletter = 98, 106 do -- 98 == b, 106 == j
return true
titleItem(builder, args[year .. string.char(asciiletter)])
end
-- if itemNum >= 2
builder:tag( 'td' )
:css('border', 'none')
:css('padding','5px 5px 2px 5px')
:wikitext(itemList[1])
for key = 2, itemNum - 1 do
builder = builder:tag( 'tdtr' )
:tag('td')
:css('border', 'none')
:css('padding','2px 5px 2px 5px')
:wikitext(itemList[key])
end
builder = builder:tag('tr')
:tag('td')
:css('border', 'none')
:css('padding','2px 5px 5px 5px')
:wikitext(itemList[itemNum])
 
end
 
local function row(builder, args, year)
local itemNum, itemList = items(args, year)
builder = builder:tag('tr')
left(builder, args, year, itemNum)
centerright(builder, args, year, itemNum, itemList)
right(builder, args, year)
end
 
Line 88 ⟶ 104:
-- Main module code goes here.
local ret
local firstyear, lastyear, TBA
local TBA = isYearReleased(items(args, 'TBA')) > 0 and true or false
ret = mw.html.create( 'table' )
:addClass('wikitable')
:css('border', 'none')
:css('float', args.align or 'right')
:css('clear', args.align or 'right')
Line 96 ⟶ 114:
:css('font-size', '80%')
:css('line-height', '90%')
:css('border-collapse', 'collapseseparate')
:css('border-spacing', '0 1px')
:css('background-color', 'transparent')
ret:tag('caption')
:css('padding', '5px')
:wikitext(args.title and ('<b>' .. args.title .. '</b>') or '<b>Timeline of release years</b>')
:wikitext(args.subtitle and string.format('<br />'<span ..style="font-weight: normal;">%s</span>', args.subtitle), '')
 
if tonumber(args.first) then
Line 108 ⟶ 127:
else
for i = 1940, os.date('%Y') do
if isYearReleased(items(args, i)) > 0 then
firstyear = i
break
Line 119 ⟶ 138:
else
for i = os.date('%Y') + 3, TBA and os.date('%Y') or firstyear, -1 do
if isYearReleased(items(args, i)) > 0 then
lastyear = i
break