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 { #chat .row {
display: table-row; display: table-row;
word-break: break-word; word-break: break-all;
word-wrap: break-word; word-wrap: break-word;
} }
#chat .row span { #chat .row span {
@ -396,6 +396,39 @@ button {
text-align: right; text-align: right;
width: 46px; 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 { #chat .sidebar {
bottom: 0; bottom: 0;
display: none; display: none;

View File

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

View File

@ -168,7 +168,7 @@ $(function() {
setTimeout(function() { setTimeout(function() {
// Enable transitions. // Enable transitions.
$("body").removeClass("preload"); //$("body").removeClass("preload");
}, 500); }, 500);
var pop = new Audio(); 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"; var toggle = "click";
if (touchDevice) { if (touchDevice) {
toggle = "touchstart"; toggle = "touchstart";
@ -390,17 +398,7 @@ $(function() {
return e[c]; 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( Handlebars.registerHelper(
"uri", function(text) { "uri", function(text) {
var urls = []; var urls = [];
@ -425,4 +423,22 @@ $(function() {
return new Handlebars.SafeString(render(id, this)); 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) { client.on("motd", function(data) {
var rows = data.motd; var rows = data.motd;
var chan = network.channels[0]; 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) { rows.forEach(function(text) {
var msg = new Msg({ var msg = new Msg({
type: "motd", type: "motd",