Save settings in a cookie

This commit is contained in:
Mattias Erming 2014-03-22 20:23:48 +01:00
parent fb85b38e7c
commit dcd72b2345
4 changed files with 40 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
node_modules/ node_modules/
config.js

View File

@ -99,12 +99,19 @@ h2 {
padding: 0 10px; padding: 0 10px;
width: 100%; width: 100%;
} }
#chat.hide-join .join, #chat .join,
#chat.hide-part .part, #chat .part,
#chat.hide-nick .nick, #chat .nick,
#chat.hide-quit .quit { #chat .quit {
/* Hidden by default */
display: none; display: none;
} }
#chat.show-join .join,
#chat.show-part .part,
#chat.show-nick .nick,
#chat.show-quit .quit {
display: block;
}
#chat .window { #chat .window {
background: #fff; background: #fff;
display: none; display: none;

View File

@ -118,6 +118,7 @@
<script src="/socket.io/socket.io.js"></script> <script src="/socket.io/socket.io.js"></script>
<script src="/js/lib/mustache.js"></script> <script src="/js/lib/mustache.js"></script>
<script src="/js/lib/jquery.js"></script> <script src="/js/lib/jquery.js"></script>
<script src="/js/lib/jquery.cookie.js"></script>
<script src="/js/lib/jquery.scrollGlue.js"></script> <script src="/js/lib/jquery.scrollGlue.js"></script>
<script src="/js/lib/bootstrap.js"></script> <script src="/js/lib/bootstrap.js"></script>
<script src="/js/chat.js"></script> <script src="/js/chat.js"></script>

View File

@ -14,7 +14,7 @@ $(function() {
tpl[id] = tpl[id] || $(id).html(); tpl[id] = tpl[id] || $(id).html();
if (!json) { if (!json) {
// If no data is supplied, return the template instead. // If no data is supplied, return the template instead.
// Used when fetching partials. // Handy when fetching partials.
return tpl[id]; return tpl[id];
} }
return Mustache.render( return Mustache.render(
@ -123,11 +123,35 @@ $(function() {
sidebar.find("input[type=checkbox]").each(function() { sidebar.find("input[type=checkbox]").each(function() {
var input = $(this); var input = $(this);
var value = input.val(); var value = input.val();
input.prop("checked", true).wrap("<label>").parent().append(value);
var checked = true;
if (($.cookie("hidden") || []).indexOf(value) !== -1) {
checked = false;
}
input.prop("checked", checked)
.wrap("<label>")
.parent()
.append(value);
if (checked) {
chat.addClass("show-" + value);
}
input.on("change", function() { input.on("change", function() {
var hidden = $.cookie("hidden") || "";
if (input.prop("checked")) {
hidden = hidden.replace(value, "");
} else {
hidden += value;
}
// Save the cookie with the new values.
$.cookie("hidden", hidden);
chat.toggleClass( chat.toggleClass(
"hide-" + value, "show-" + value,
!input.prop("checked") input.prop("checked")
); );
}); });
}); });