מדיה ויקי:Gadget-pgnviewer.js: הבדלים בין גרסאות בדף

collapse and collapsible
גרסה מעודכנת
שורה 16: שורה 16:
pieceImageUrl = {},
pieceImageUrl = {},
boardImageUrl,
boardImageUrl,
flipImageUrl,
WHITE = 'l',
WHITE = 'l',
BLACK = 'd',
BLACK = 'd',
שורה 22: שורה 21:
moveBucket = [], // this is a scratch thing, but since we access it from different objects, it's convenient to have it global
moveBucket = [], // this is a scratch thing, but since we access it from different objects, it's convenient to have it global
anim = 1000,
anim = 1000,
maxDelay = 8000,  // max delay between moves for autoplay, in ms
sides = ['n', 'e', 's', 'w'], // used for legends
sides = ['n', 'e', 's', 'w'], // used for legends
defaultBlockSize = 45,
defaultBlockSize = 45,
שורה 56: שורה 56:
index = $this.data('index'),
index = $this.data('index'),
noAnim = $this.data('noAnim');
noAnim = $this.data('noAnim');
game.gs.clearTimer();
game.gs.stopAutoPlay();
game.showMoveTo(index, noAnim);
game.showMoveTo(index, noAnim);
}
}


function Gameset() { // set of functions and features that depend on blocksize, and currentGame.
function Gameset() { // set of functions and features that depend on blocksize, and currentGame.
שורה 69: שורה 70:
flip: false,
flip: false,
timer: null,
timer: null,
movesInMinute: 30,
isAutoplay: 0,
autoPlayRate: 0,
top: function(row, l) { return (((this.flip ? row : (7 - row)) + (l ? 0.3 : 0)) * this.blockSize + 20) + 'px'; },
top: function(row, l) { return (((this.flip ? row : (7 - row)) + (l ? 0.3 : 0)) * this.blockSize + 20) + 'px'; },
left: function(file, l) { return (((this.flip ? 7 - file : file) + (l ? 0.5 : 0)) * this.blockSize + 20) + 'px'; },
left: function(file, l) { return (((this.flip ? 7 - file : file) + (l ? 0.5 : 0)) * this.blockSize + 20) + 'px'; },
שורה 103: שורה 105:
this.fenDiv.text( boardToFen(board) );
this.fenDiv.text( boardToFen(board) );
},
},
drawIfNeedRefresh: function() {
drawIfNeedRefresh: function(again) {
this.refreshFEN();
this.refreshFEN();
if (this.needRefresh && this.currentGame)
if (this.needRefresh && this.currentGame)
שורה 132: שורה 134:
return this.flip;
return this.flip;
},
},
clearTimer: function() {
stopAutoPlay: function() {
clearInterval(this.timer);
clearTimeout(this.timer);
this.timer = null;
this.isAutoplay = false;
this.currentGame.tds.playButton.attr('value', '\u25BA');
this.currentGame.tds.playButton.attr('value', '\u25BA');
},
},
setAutoplayRate: function( rate, force ) {
sceduleAutoPlay: function() {
this.movesInMinute = rate;
clearTimeout( this.timer );
if ( this.timer || force ) {
if ( this.isAutoplay ) {
this.clearTimer();
var gs = this;
var cg = this.currentGame;
this.timer = setTimeout( function() { gs.autoPlayCallback(); }, this.autoPlayRate );
this.timer = setInterval(function() { cg.advance() }, (60000 / rate) );
cg.tds.playButton.attr('value', '\u275A\u275A');
}
}
},
},
play: function() {
autoPlayCallback: function() {
if (this.timer)
this.clearTimer();
else {
var cg = this.currentGame;
var cg = this.currentGame;
cg.wrapAround();
cg.wrapAround();
cg.advance();
cg.advance();
this.setAutoplayRate( this.movesInMinute, true );
},
}
toggleAutoPlay: function() {
if ( this.isAutoplay ^= 1 )
{
this.currentGame.tds.playButton.attr('value', '\u275A\u275A');
this.autoPlayCallback();
} else
this.stopAutoPlay();
}
}
});
});
שורה 175: שורה 178:
var gameSet = this.game.gs;
var gameSet = this.game.gs;
gameSet.refreshFEN();
gameSet.refreshFEN();
this.img.animate({top: gameSet.top(row), left: gameSet.left(file)}, anim, function() { gameSet.drawIfNeedRefresh(); });
this.img.animate( {top: gameSet.top(row), left: gameSet.left(file)},  
anim,  
'swing',
function() {  
gameSet.sceduleAutoPlay();
}
);
};
};
   
   
שורה 278: שורה 287:
   
   
// cleanup from previous game.
// cleanup from previous game.
this.gs.clearTimer();
this.gs.stopAutoPlay();
tds.descriptionsDiv.empty();
tds.descriptionsDiv.empty();
tds.pgnDiv.empty();
tds.pgnDiv.empty();
שורה 391: שורה 400:
}
}
if (this.index == this.moves.length - 1)
if (this.index == this.moves.length - 1)
this.gs.clearTimer();
this.gs.stopAutoPlay();
}
}
   
   
שורה 656: שורה 665:
   
   
function createFlipper( gameSet ) {
function createFlipper( gameSet ) {
return $( '<input>', { type: 'button', 'class': 'pgn-button' } )
return $( '<input>', { type: 'button', 'class': 'pgn-button', value: '\u262F' } ) // yin-yeng character
.append( $( '<img>', { src: flipImageUrl, 'class': 'pgn-button-image' } ) )
.click(function() { $(this).toggleClass( 'pgn-upside-down', gameSet.doFlip() ); } );
.click(function() { $(this).toggleClass( '', gameSet.doFlip() ); } );
}
}


שורה 665: שורה 673:
allTheway
allTheway
? (forward ? '|\u25B7' : '\u25C1|')
? (forward ? '|\u25B7' : '\u25C1|')
: (forward ? '>' : '<')
: (forward ? '<' : '>')
return $('<input>', {'class': 'pgn-button', type: 'button', rel: 'f', value: legend})
return $('<input>', {'class': 'pgn-button', type: 'button', rel: 'f', value: legend})
.click(function() {
.click(function() {
gameSet.clearTimer();
gameSet.stopAutoPlay();
if (allTheway) {
if (allTheway) {
var links = gameSet.currentGame.linkOfIndex;
var links = gameSet.currentGame.linkOfIndex;
שורה 681: שורה 689:
function autoPlayButton(gameSet) {
function autoPlayButton(gameSet) {
return $('<input>', {type: 'button', 'class': 'pgn-button', value: '\u25BA'})
return $('<input>', {type: 'button', 'class': 'pgn-button', value: '\u25BA'})
.click(function() { gameSet.play(); });
.click(function() { gameSet.toggleAutoPlay(); });
}
}
   
   
שורה 713: שורה 721:
slider = $('<div>', {'class': 'pgn-slider'})
slider = $('<div>', {'class': 'pgn-slider'})
.slider({
.slider({
min: 1,
min: 0,
max: 60,
max: maxDelay,
orientation: 'horizontal',
orientation: 'horizontal',
value: 60,
value: maxDelay,
stop: function() { gameSet.setAutoplayRate( 0 + slider.slider('value') ); }
stop: function() { gameSet.autoPlayRate = maxDelay - slider.slider( 'value' ); }
}),
}),
collapsibleDiv = $( '<div>' ),
collapsibleDiv = $( '<div>' ),
שורה 735: שורה 743:
gameSetDiv = $('<div>', {'class': 'pgn-gameset-div'})
gameSetDiv = $('<div>', {'class': 'pgn-gameset-div'})
.css({width: 40 + 8 * gameSet.blockSize});
.css({width: 40 + 8 * gameSet.blockSize});
gameSet.fenDiv = $('<div>', { id: fenId } );  
gameSet.fenDiv = $('<div>', { id: fenId } )
.css( { 'word-wrap': 'break-word' } );  
tabberDiv = $( '<div>' )
tabberDiv = $( '<div>' )
.css( { margin: 'auto' } )
.css( { margin: 'auto' } )
שורה 838: שורה 847:
for (var t in types)
for (var t in types)
allPieces.push('File:Chess ' + types[t] + colors[c] + 't45.svg');
allPieces.push('File:Chess ' + types[t] + colors[c] + 't45.svg');
allPieces.push('File:Yin and Yang.svg');
allPieces.push('File:Chessboard480.png');
allPieces.push('File:Chessboard480.png');
var params = {titles: allPieces.join('|'), prop: 'imageinfo', iiprop: 'url'};
var params = {titles: allPieces.join('|'), prop: 'imageinfo', iiprop: 'url'};
שורה 851: שורה 859:
if (match)
if (match)
pieceImageUrl[match[1]] = url;
pieceImageUrl[match[1]] = url;
else if (/Yin/.test(url))
flipImageUrl = url;
else if (/Chessboard/.test(url))
else if (/Chessboard/.test(url))
boardImageUrl = url;
boardImageUrl = url;