-- This module implements and .
local HTMLcolor = mw.loadData('Module:Color contrast/colors')
---------------------------------------------------------------------------------- EpisodeTable class-- The main class.--------------------------------------------------------------------------------
local contrast_ratio = require('Module:Color contrast')._ratiolocal EpisodeTable =
function EpisodeTable.cell(background, width, text, reference, textColor) local cell = mw.html.create('th') -- Width local cell_width if width
function EpisodeTable.reference(reference, background) local link1_cr = contrast_ratio local link2_cr = contrast_ratio 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
function EpisodeTable.abbr(text,title) local abbr = mw.html.create('abbr') :attr('title',title) :wikitext(text) return tostring(abbr)end
function EpisodeTable.part(frame,args) local row = mw.html.create('tr') local black_cr = contrast_ratio local white_cr = contrast_ratio local partTypes = 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) :css('color', black_cr > white_cr and 'black' or 'white') :wikitext("" .. displaytext .. "" .. (args.r and " " .. EpisodeTable.reference(args.r, args.c) or )) return tostring(row)end
function EpisodeTable.new(frame,args) args = args or local categories = local background = (args.background and args.background ~= and args.background ~= '#') and args.background or nil -- Add # to background if necessary if background ~= nil and HTMLcolor[background]
'auto' or args.total_width
0 and (args.background and args.background ~= and args.background ~= '#') and black_cr < 7 and white_cr < 7 then categories = categories .. '' end -- Main row local textColor = background and (black_cr > white_cr and 'black' or 'white') or 'black' local mainRow = root:tag('tr') mainRow :css('color', textColor) :css('text-align', 'center') -- Cells do local used_season = false local country = args.country ~= and args.country ~= nil local viewers = (country and args.country or ) .. ' ' .. (country and 'v' or 'V') .. 'iewers' .. ((not args.viewers_type or args.viewers_type ~= ) and '
(' .. (args.viewers_type or 'millions') .. ')' or ) local cellNames = for k,v in pairs(cellNames) do local thisCell = args[v[1]] or args[v[2]] if thisCell and (v[1] ~= 'series' or (v[1]
false)) then if v[1]
) then thisCell = '5' end if (thisCell
local templateStyles = mw.getCurrentFrame:extensionTag return (args.dontclose and mw.ustring.gsub(tostring(root), "", "") or tostring(root)) .. categories .. templateStylesend
---------------------------------------------------------------------------------- Exports--------------------------------------------------------------------------------
local p =
function p.main(frame) local args = require('Module:Arguments').getArgs(frame,) return EpisodeTable.new(frame,args)end
function p.part(frame) local args = require('Module:Arguments').getArgs(frame,) return EpisodeTable.part(frame,args)end
function p.ref(frame) local args = require('Module:Arguments').getArgs(frame,) return EpisodeTable.reference(args.r,args.b)end
return p