From 1d5a708cb4a735d0d6b107d1da93ec46e663af40 Mon Sep 17 00:00:00 2001 From: vonavi Date: Tue, 8 Jul 2014 17:59:44 +0300 Subject: [PATCH] Scroll the game text to the current move. --- assets/js/custom.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/js/custom.js b/assets/js/custom.js index f6d3d02..25426fb 100644 --- a/assets/js/custom.js +++ b/assets/js/custom.js @@ -30,17 +30,33 @@ $(function() { }); }) -/* Stylize pgn4web elements by Bootstrap */ function customFunctionOnPgnGameLoad() { + /* Stylize pgn4web elements by Bootstrap */ $('#GameSelSelect').addClass('form-control'); $('#autoplayButton').click(refreshButtonset); /* No titles for mouse wheel over the chess board */ $('#GameBoard .pieceImage').removeAttr('title'); } + function customFunctionOnMove() { refreshButtonset(); + + /* Scroll the game text to the current move */ + var $gameText = $('#GameText'); + var $moveOn = $gameText.find('.moveOn:first'); + var gtHeight = $gameText.height(); + if ($moveOn.length) { + var height = $moveOn.height(); + var y = $moveOn.position().top; + if (y < height * 5) { + $gameText.scrollTop($gameText.scrollTop() + y - height * 5); + } else if (y > (gtHeight - height * 6)) { + $gameText.scrollTop($gameText.scrollTop() + y + height * 6 - gtHeight); + } + } } + function refreshButtonset() { $('#GameButtons input').addClass('btn btn-default'); }