store sound settings in js local storage

pull/83/head
Thibault Duplessis 2013-06-11 12:41:21 +02:00
parent 673fa96422
commit 3d4f024ebd
8 changed files with 11 additions and 24 deletions

View File

@ -24,17 +24,12 @@ object Setting extends LilaController {
private lazy val setters = Map(
"theme" -> setTheme,
"sound" -> setSound,
"bg" -> setBg)
private lazy val setTheme: Setter = forms.theme -> {
(setting, v) setting.theme(v)
}
private lazy val setSound: Setter = forms.sound -> {
(setting, v) setting.sound(v)
}
private lazy val setBg: Setter = forms.bg -> {
(setting, v) setting.bg(v)
}

View File

@ -9,8 +9,5 @@ trait SettingHelper {
def setting(implicit ctx: Context) = new Setting(ctx)
def soundString(implicit ctx: Context) =
setting(ctx).sound.fold("sound_state_on", "")
def themeList = Theme.list
}

View File

@ -35,7 +35,7 @@ themepicker: Boolean = false)(body: Html)(implicit ctx: Context)
data-accept-languages="@acceptLanguages">
<div id="site_description">@trans.freeOnlineChessGamePlayChessNowInACleanInterfaceNoRegistrationNoAdsNoPluginRequiredPlayChessWithComputerFriendsOrRandomOpponents()</div>
<div id="top" class="clearfix">
<a href="@routes.Setting.set("sound")" title="@trans.toggleSound()" id="sound_state" class="available @soundString">
<a title="@trans.toggleSound()" id="sound_state" class="available">
<span></span>
</a>
<div class="lichess_language">

View File

@ -0,0 +1,4 @@
db.user2.update({},{$unset:{
'settings.chat':1,
'settings.sound':1
}}, {multi:1});

View File

@ -9,14 +9,6 @@ object DataForm {
"bio" -> text(maxLength = 400)
))
val chat = Form(single(
"chat" -> jsBoolean
))
val sound = Form(single(
"sound" -> jsBoolean
))
val theme = Form(single(
"theme" -> nonEmptyText.verifying(Theme contains _)
))
@ -31,6 +23,7 @@ object DataForm {
newPasswd2: String) {
def samePasswords = newPasswd1 == newPasswd2
}
val passwd = Form(mapping(
"oldPasswd" -> nonEmptyText,
"newPasswd1" -> nonEmptyText(minLength = 2),

View File

@ -9,9 +9,6 @@ final class Setting(ctx: Context) {
def theme = Theme(get("theme"))
def theme(value: String) = set("theme", Theme(value).toString)
def sound = get("sound", "false").parseBoolean | false
def sound(value: String) = set("sound", value)
def bg = get("bg", "light")
def bg(value: String) = set("bg", value)

View File

@ -657,7 +657,7 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
var elem = document.createElement('audio');
var canPlayAudio = !! elem.canPlayType && elem.canPlayType('audio/ogg; codecs="vorbis"');
var $soundToggle = $('#sound_state');
var $soundToggle = $('#sound_state').toggleClass('sound_state_on', localStorage.getItem('sound') == 1);
function soundEnabled() {
return $soundToggle.hasClass("sound_state_on");
@ -680,9 +680,7 @@ var lichess_sri = Math.random().toString(36).substring(5); // 8 chars
var enabled = !soundEnabled();
$soundToggle.toggleClass('sound_state_on', enabled);
$.playSound();
$.post($soundToggle.attr('href'), {
sound: enabled
});
localStorage.setItem('sound', enabled ? 1 : null);
return false;
});
$game && $game.trigger('lichess.audio_ready');

3
todo
View File

@ -71,4 +71,7 @@ disable unused websocket hijack protection
---
PRE DEPLOY
mongo lichess bin/mongodb/clean-settings.js
hope for https://github.com/zenexity/ReactiveMongo/issues/72