Content deleted Content added
sync and make one adjustment, will look at tstyles in a minute |
rename class "chess-board" to "chess-pieces", since the div contains only the pieces, and to avoid confusion with the new top-level "chessboard" class |
||
(43 intermediate revisions by 7 users not shown) | |||
Line 1:
local p = {}
local cfg, nrows, ncols
local function innerboard(args, size, rev)
pattern = cfg.pattern or '%w%w'
local root = mw.html.create('div')
root:addClass('chess-
:css('position', 'relative')
:wikitext(cfg.image_board(size))
for trow = 1,
local row = rev and trow or (
for tcol = 1,
local col = rev and (
local piece = args[
if piece:match(
local img = cfg.image_square(piece:match(
root:tag('div')
:css('top', tostring(( trow - 1 ) * size) .. 'px')
:css('left', tostring(( tcol - 1 ) * size) .. 'px')
:wikitext(img)
end
Line 101 ⟶ 30:
function chessboard(args, size, rev, letters, numbers, header, footer, align, clear)
function letters_row( rev, num_lt, num_rt )
local letters =
local root = mw.html.create('')
if num_lt then
root:tag('td')
end
for k = 1,
root:tag('td')
:css('height', '18px')
:css('width', size .. 'px')
:wikitext(rev and letters[
end
if num_rt then
root:tag('td')
end
return tostring(root)
Line 129 ⟶ 51:
local numbers_lt = numbers:match( 'both' ) or numbers:match( 'left' )
local numbers_rt = numbers:match( 'both' ) or numbers:match( 'right' )
local width =
if ( numbers_lt ) then width = width + 18 end
if ( numbers_rt ) then width = width + 18 end
local root = mw.html.create('div')
:addClass('chessboard')
:addClass('thumb')
:addClass('noviewer')
:addClass(align)
if( header and header ~= '' ) then
root:tag('div')
:addClass('center') :css('line-height', '130%') :css('margin', '0 auto') :css('max-width', (width + :wikitext(header) end
local div = root:tag('div')
Line 145 ⟶ 74:
:attr('cellpadding', '0')
:attr('cellspacing', '0')
if ( letters_tp ) then
b:tag('tr')
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
local tablerow = b:tag('tr
if ( numbers_lt ) then
tablerow:tag('td')
:css('width', '18px')
:css('height', size .. 'px')
:wikitext(rev and 1 or
end
local td = tablerow:tag('td')
:attr('colspan',
:attr('rowspan',
:wikitext(innerboard(args, size, rev))
if ( numbers_rt ) then
tablerow:tag('td')
:css('width', '18px')
:css('height', size .. 'px')
:wikitext(rev and 1 or
end
if ( numbers_lt or numbers_rt ) then
for trow = 2,
local idx = rev and trow or (
tablerow = b:tag('tr')
if ( numbers_lt ) then
tablerow:tag('td')
:css('height', size .. 'px')
:wikitext(idx)
Line 197 ⟶ 108:
if ( numbers_rt ) then
tablerow:tag('td')
:css('height', size .. 'px')
:wikitext(idx)
Line 207 ⟶ 115:
if ( letters_bt ) then
b:tag('tr')
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
if
div:tag('div')
:addClass('thumbcaption')
Line 217 ⟶ 124:
end
return tostring(root) ..
mw.getCurrentFrame():extensionTag( 'templatestyles', '', { src = 'Module:Chessboard/styles.css' } )
end
Line 263 ⟶ 171:
local args = frame.args
local pargs = frame:getParent().args
local style = args.style or pargs.style or 'Chess'
cfg = require('Module:Chessboard/' .. style)
nrows, ncols = cfg.dims()
local size = args.size or pargs.size or '26'
local reverse = ( args.reverse or pargs.reverse or '' ):lower() == "true"
Line 268 ⟶ 180:
local numbers = ( args.numbers or pargs.numbers or 'both' ):lower()
local header = args[2] or pargs[2] or ''
local footer = args[
local align = ( args[1] or pargs[1] or 'tright' ):lower()
local clear = args.clear or pargs.clear or ( align:match('tright') and 'right' ) or 'none'
local fen = args.fen or pargs.fen
local pgn = args.pgn or pargs.pgn
size = mw.ustring.match( size, '[%d]+' ) or '26' -- remove px from size
if (pgn) then
local pgnModule = require('Module:Pgn')
metadata, moves = pgnModule.main(pgn)
fen = moves[#moves]
end
if (fen) then
align = args.align or pargs.align or 'tright'
Line 286 ⟶ 204:
return chessboard(pargs, size, reverse, letters, numbers, header, footer, align, clear)
end
end
|