Add MOTD toggle

This commit is contained in:
Mattias Erming 2014-06-20 02:26:48 +02:00
parent 5e8ae7686e
commit afda79db4b
4 changed files with 76 additions and 15 deletions

View File

@ -339,7 +339,7 @@ button {
}
#chat .row {
display: table-row;
word-break: break-word;
word-break: break-all;
word-wrap: break-word;
}
#chat .row span {
@ -396,6 +396,39 @@ button {
text-align: right;
width: 46px;
}
#chat .motd {
opacity: 0;
position: absolute;
}
#chat .motd-toggle .motd {
opacity: 1;
position: inherit;
}
#chat .toggle {
background: #f9f9f9;
border: 1px solid #eee;
border-radius: 2px;
color: #999;
float: left;
font-size: 14px;
line-height: 0px;
margin: 2px 9px 0 0;
overflow: hidden;
}
#chat .toggle:hover {
border-color: #ddd;
}
#chat .toggle .tri {
border: 3px solid transparent;
border-top-color: #666;
float: left;
margin: 5px 4px 1px;
}
#chat .toggle.open .tri {
border-top-color: transparent;
border-bottom-color: #666;
margin: 1px 4px 5px;
}
#chat .sidebar {
bottom: 0;
display: none;

View File

@ -143,11 +143,14 @@
<a href="#{{from}}" class="user">{{from}}</a>
</span>
<span class="text">
{{#if type}}
{{#contains type "toggle"}}
<button class="toggle" data-type="{{type}}">
<i class="tri"></i>
</button>
{{/contains}}
<em class="type">
{{type}}
</em>
{{/if}}
{{{uri text}}}
</span>
</div>

View File

@ -168,7 +168,7 @@ $(function() {
setTimeout(function() {
// Enable transitions.
$("body").removeClass("preload");
//$("body").removeClass("preload");
}, 500);
var pop = new Audio();
@ -341,6 +341,14 @@ $(function() {
});
});
chat.on("click", ".toggle", function() {
var chat = $(this)
.toggleClass("open")
.closest(".chat")
.toggleClass($(this).data("type"))
.end();
});
var toggle = "click";
if (touchDevice) {
toggle = "touchstart";
@ -390,17 +398,7 @@ $(function() {
return e[c];
});
}
Handlebars.registerHelper(
"equal", function(a, b, opt) {
a = parseInt(a);
b = parseInt(b);
if (a == b) {
return opt.fn(this);
}
}
);
Handlebars.registerHelper(
"uri", function(text) {
var urls = [];
@ -425,4 +423,22 @@ $(function() {
return new Handlebars.SafeString(render(id, this));
}
);
Handlebars.registerHelper(
"equal", function(a, b, opt) {
a = a.toString();
b = b.toString();
if (a == b) {
return opt.fn(this);
}
}
);
Handlebars.registerHelper(
"contains", function(a, b, opt) {
if (a.indexOf(b) !== -1) {
return opt.fn(this);
}
}
);
});

View File

@ -6,6 +6,15 @@ module.exports = function(client, sockets) {
client.on("motd", function(data) {
var rows = data.motd;
var chan = network.channels[0];
var msg = new Msg({
type: "motd-toggle",
from: "-!-"
});
chan.addMsg(msg);
sockets.in("chat").emit("msg", {
id: chan.id,
msg: msg,
});
rows.forEach(function(text) {
var msg = new Msg({
type: "motd",