-- This module implements {{Media table section}}.
local MediaTable = {}
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )
local contrast_ratio = require('Module:Color contrast')._ratio
function MediaTable.part(args)
local row = mw.html.create('tr')
if (args.c == 'header-blue' or args.c == nil or args.c == '') then args.c = '#CCCCFF' end
if (args.c == 'header-grey' or args.c == 'header-gray') then args.c = '#EAECF0' end
-- Add # to color if necessary
if args.c ~= nil and HTMLcolor[args.c] == nil then
args.c = '#'..(mw.ustring.match(args.c, '^[%s#]*([a-fA-F0-9]*)[%s]*$') or '')
end
local black_cr = contrast_ratio{args.c or '#CCCCFF', 'black', ['error'] = 0}
local white_cr = contrast_ratio{'white', args.c or '#CCCCFF', ['error'] = 0}
local partTypes = {
{'act','Act'},
{'chapter','Chapter'},
{'part','Part'},
{'volume','Volume'},
{'week','Week'},
}
local displaytext = ''
local isAnyPartSet = false
for k,v in pairs(partTypes) do
if args[v[1]] then
isAnyPartSet = true
displaytext = v[2] .. ' ' .. args[v[1]]
end
end
if args.subtitle then
displaytext = displaytext .. ((isAnyPartSet and ': ' or '') .. args.subtitle)
end
local plainText = require('Module:Plain text')._main
local displayTextAnchor = plainText(displaytext)
row:tag('td')
:attr('colspan', 13)
:attr('id', args.id or displayTextAnchor)
:css('text-align', 'center')
:css('background-color', args.c or '#CCCCFF')
:css('color', black_cr > white_cr and 'black' or 'white')
:wikitext((args.nobold and displaytext or "'''" .. displaytext .. "'''") .. (args.r and " " .. MediaTable.reference(args.r, args.c) or ''))
return tostring(row)
end
function MediaTable.reference(reference, background)
local link1_cr = contrast_ratio{'#0645AD', background or '#CCCCFF', ['error'] = 0}
local link2_cr = contrast_ratio{'#0B0080', background or '#CCCCFF', ['error'] = 0}
local refspan = mw.html.create('span')
:wikitext(reference)
if link1_cr < 7 or link2_cr < 7 then
refspan
:css('color','black')
:css('background-color','white')
:css('padding','1px')
:css('display','inline-block')
:css('line-height','50%')
end
return tostring(refspan)
end
--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------
local p = {}
function p.part(frame)
local args = require('Module:Arguments').getArgs(frame, {
removeBlanks = false,
wrappers = 'Template:Media table section'
})
return MediaTable.part(args)
end
return p