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/
config.js

View file

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

View file

@ -118,6 +118,7 @@
<script src="/socket.io/socket.io.js"></script>
<script src="/js/lib/mustache.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/bootstrap.js"></script>
<script src="/js/chat.js"></script>

View file

@ -14,7 +14,7 @@ $(function() {
tpl[id] = tpl[id] || $(id).html();
if (!json) {
// If no data is supplied, return the template instead.
// Used when fetching partials.
// Handy when fetching partials.
return tpl[id];
}
return Mustache.render(
@ -123,11 +123,35 @@ $(function() {
sidebar.find("input[type=checkbox]").each(function() {
var input = $(this);
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() {
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(
"hide-" + value,
!input.prop("checked")
"show-" + value,
input.prop("checked")
);
});
});