complete zoom migration

This commit is contained in:
Thibault Duplessis 2017-03-09 22:38:28 +01:00
parent 462d7ba9dc
commit 01fbee459b
3 changed files with 26 additions and 14 deletions

View file

@ -15,8 +15,7 @@ openGraph: Option[lila.app.ui.OpenGraph] = None,
atom: Option[Html] = None, atom: Option[Html] = None,
chessground: Boolean = true, chessground: Boolean = true,
withLangAnnotations: Boolean = true, withLangAnnotations: Boolean = true,
withGtm: Boolean = false, withGtm: Boolean = false)(body: Html)(implicit ctx: Context)
zoomable: Boolean = true)(body: Html)(implicit ctx: Context)
<!doctype html> <!doctype html>
<html lang="@lang.language"> <html lang="@lang.language">
<head> <head>
@ -31,7 +30,10 @@ zoomable: Boolean = true)(body: Html)(implicit ctx: Context)
} }
@cssTag("common.css") @cssTag("common.css")
@cssTag("board.css") @cssTag("board.css")
@ctx.zoom.ifTrue(zoomable).map { z => @zoomStyle(z / 100f) } @if(!chessground) {
@ctx.zoom.map { z =>
@zoomStyle(z / 100f) }
}
@if(ctx.is3d) { @cssTag("board-3d.css") } @if(ctx.is3d) { @cssTag("board-3d.css") }
@if(ctx.pref.coords == 1) { @cssTag("board.coords.inner.css") } @if(ctx.pref.coords == 1) { @cssTag("board.coords.inner.css") }
@moreCss @moreCss
@ -70,7 +72,8 @@ zoomable: Boolean = true)(body: Html)(implicit ctx: Context)
data-bg="@ctx.currentBg" data-bg="@ctx.currentBg"
data-asset-url="@assetBaseUrl" data-asset-url="@assetBaseUrl"
data-asset-version="@ctx.pageData.assetVersion" data-asset-version="@ctx.pageData.assetVersion"
data-accept-languages="@acceptLanguages.mkString(",")"> data-accept-languages="@acceptLanguages.mkString(",")"
data-zoom="@ctx.zoomOrDefault">
<form id="blind_mode" action="@routes.Main.toggleBlindMode" method="POST"> <form id="blind_mode" action="@routes.Main.toggleBlindMode" method="POST">
<input type="hidden" name="enable" value="@ctx.blindMode.fold(0,1)" /> <input type="hidden" name="enable" value="@ctx.blindMode.fold(0,1)" />
<input type="hidden" name="redirect" value="@ctx.req.path" /> <input type="hidden" name="redirect" value="@ctx.req.path" />

View file

@ -72,6 +72,8 @@ sealed trait Context extends lila.user.UserContextWrapper {
def zoom: Option[Int] = req.session get "zoom" flatMap parseIntOption filter (100<) def zoom: Option[Int] = req.session get "zoom" flatMap parseIntOption filter (100<)
def zoomOrDefault = zoom | 100
private def ctxPref(name: String): Option[String] = private def ctxPref(name: String): Option[String] =
req.session get name orElse { pref get name } req.session get name orElse { pref get name }

View file

@ -1,4 +1,4 @@
// var start = new Date(); var millis = 2000; while (new Date() - millis < start) {} // var start = new Date(); var millis = 500; while (new Date() - millis < start) {}
lichess.challengeApp = (function() { lichess.challengeApp = (function() {
var instance, booted; var instance, booted;
@ -557,7 +557,7 @@ lichess.notifyApp = (function() {
$('link[href*="board.css"]').clone().each(function() { $('link[href*="board.css"]').clone().each(function() {
$(this).attr('href', $(this).attr('href').replace(/board\.css/, 'board-3d.css')).appendTo('head'); $(this).attr('href', $(this).attr('href').replace(/board\.css/, 'board-3d.css')).appendTo('head');
}); });
setZoom(getZoom()); setZoom(currentZoom);
}; };
$themepicker.find('.background a').click(function() { $themepicker.find('.background a').click(function() {
background = $(this).data('bg'); background = $(this).data('bg');
@ -593,7 +593,7 @@ lichess.notifyApp = (function() {
max: 2, max: 2,
range: 'min', range: 'min',
step: 0.01, step: 0.01,
value: getZoom(), value: currentZoom,
slide: function(e, ui) { slide: function(e, ui) {
manuallySetZoom(ui.value); manuallySetZoom(ui.value);
} }
@ -612,11 +612,11 @@ lichess.notifyApp = (function() {
}); });
// Zoom // Zoom
var getZoom = function() { var currentZoom = lichess.isTrident ? 1 : $('body').data('zoom') / 100;
return lichess.isTrident ? 1 : (lichess.storage.get('zoom') || 1);
};
var setZoom = function(zoom) { var setZoom = function(zoom) {
lichess.storage.set('zoom', zoom);
currentZoom = zoom;
var $lichessGame = $('.lichess_game, .board_and_ground'); var $lichessGame = $('.lichess_game, .board_and_ground');
var $boardWrap = $lichessGame.find('.cg-board-wrap').not('.mini_board .cg-board-wrap'); var $boardWrap = $lichessGame.find('.cg-board-wrap').not('.mini_board .cg-board-wrap');
@ -662,20 +662,27 @@ lichess.notifyApp = (function() {
}; };
var saveZoom = lichess.fp.debounce(function() { var saveZoom = lichess.fp.debounce(function() {
console.log(currentZoom);
$.ajax({ $.ajax({
method: 'post', method: 'post',
url: '/pref/zoom?v=' + Math.round(getZoom() * 100) url: '/pref/zoom?v=' + Math.round(currentZoom * 100)
}); });
}, 500); }, 500);
var manuallySetZoom = lichess.fp.debounce(function(z) { var manuallySetZoom = lichess.fp.debounce(function(z) {
setZoom(z); setZoom(z);
saveZoom(); saveZoom();
}, 10); }, 10);
if (getZoom() > 1) setZoom(getZoom()); // Instantiate the page's zoom
lichess.pubsub.on('reset_zoom', function() { lichess.pubsub.on('reset_zoom', function() {
if (getZoom() > 1) setZoom(getZoom()); if (currentZoom > 1) setZoom(currentZoom);
}); });
// migrate from storage to cookie DELETE ME - 09/03/17
var oldZoom = lichess.storage.get('zoom');
if (oldZoom) {
manuallySetZoom(oldZoom);
lichess.storage.remove('zoom');
}
function translateTexts() { function translateTexts() {
$('.trans_me').each(function() { $('.trans_me').each(function() {
var t = $(this).removeClass('trans_me'); var t = $(this).removeClass('trans_me');