Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add textarea support #379

Merged
merged 1 commit into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 25 additions & 30 deletions client/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,11 @@ button {
border-radius: 2px;
bottom: 4px;
left: 220px;
overflow: hidden;
position: absolute;
right: 5px;
top: 4px;
display: flex;
flex-direction: column;
}

.signed-out #main {
Expand All @@ -520,10 +521,9 @@ button {
}

#windows {
bottom: 48px;
position: absolute;
top: 0;
width: 100%;
position: relative;
overflow: hidden;
flex: 1;
}

#windows label {
Expand Down Expand Up @@ -1172,32 +1172,23 @@ button {
#form {
background: #eee;
border-top: 1px solid #ddd;
bottom: 0;
height: 48px;
left: 0;
position: absolute;
right: 0;
}

#form .inner {
bottom: 7px;
left: 7px;
position: absolute;
right: 7px;
top: 6px;
min-height: 48px;
flex: 0 0 auto;
padding: 7px;
}

#form .input {
font: 12px Consolas, Menlo, Monaco, "Lucida Console", "DejaVu Sans Mono", "Courier New", monospace;
left: 0;
height: 34px;
position: relative;
border: 1px solid #ddd;
border-radius: 2px;
background: white;
display: flex;
align-items: flex-end;
}

#form #nick {
background: #f6f6f6;
color: #666;
position: absolute;
font: inherit;
font-size: 11px;
margin: 5px;
Expand All @@ -1210,6 +1201,7 @@ button {
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
flex: 0 0 auto;
}

#form #nick:empty {
Expand All @@ -1221,24 +1213,27 @@ button {
}

#form #input {
border: 1px solid #ddd;
background: transparent;
border: none;
font: inherit;
border-radius: 2px;
height: 100%;
height: 18px;
max-height: 90px;
line-height: 1.5;
outline: none;
padding: 0 34px 0 10px;
-webkit-appearance: none;
width: 100%;
margin: 5px;
padding: 0;
resize: none;
flex: 1 0 auto;
align-self: center;
}

#form #submit {
color: #9ca5b4;
height: 34px;
line-height: 34px;
position: absolute;
right: 0;
transition: opacity .3s;
width: 34px;
flex: 0 0 auto;
}

#form #submit:before {
Expand Down
10 changes: 4 additions & 6 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,10 @@ <h2>About The Lounge</h2>
</div>
</div>
<form id="form" method="post" action="">
<div class="inner">
<div class="input">
<label for="input" id="nick"></label>
<button id="submit" type="submit" title="Send" aria-label="Send message"></button>
<input id="input" class="mousetrap">
</div>
<div class="input">
<label for="input" id="nick"></label>
<textarea id="input" class="mousetrap"></textarea>
<button id="submit" type="submit" title="Send" aria-label="Send message"></button>
</div>
</form>
</div>
Expand Down
15 changes: 15 additions & 0 deletions client/js/libs/jquery/inputhistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
var key = e.which;
switch (key) {
case 13: // Enter
if (e.shiftKey) {
return; // multiline input
}

if (self.val() != "") {
i = history.length;
history[i - 1] = self.val();
Expand All @@ -53,6 +57,17 @@
if (e.ctrlKey || e.metaKey) {
break;
}

if (
this.value.indexOf("\n") >= 0
&&
(key === 38 && this.selectionStart > 0)
||
(key === 40 && this.selectionStart < this.value.length))
{
return; // don't prevent default
}

history[i] = self.val();
if (key == 38 && i != 0) {
i--;
Expand Down
18 changes: 14 additions & 4 deletions client/js/lounge.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,19 @@ $(function() {

var input = $("#input")
.history()
.on("input keyup", function() {
var style = window.getComputedStyle(this);
this.style.height = "0px";
this.offsetHeight; // force reflow
this.style.height = Math.min(
Math.round(window.innerHeight - 100), // prevent overflow
this.scrollHeight
+ Math.round(parseFloat(style.borderTopWidth) || 0)
+ Math.round(parseFloat(style.borderBottomWidth) || 0)
) + "px";

$("#chat .chan.active .chat").trigger("msg.sticky"); // fix growing
})
.tab(complete, {hint: false});

var form = $("#form");
Expand Down Expand Up @@ -1133,10 +1146,7 @@ $(function() {
}

function setNick(nick) {
var width = $("#nick")
.html(nick)
.outerWidth(true);
input.css("padding-left", width);
$("#nick").text(nick);
}

function move(array, old_index, new_index) {
Expand Down
2 changes: 1 addition & 1 deletion client/themes/morning.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ body {
border-color: #242a33;
}

#form #input {
#form .input {
background-color: #2e3642;
border-color: #242a33;
color: #ccc;
Expand Down
2 changes: 1 addition & 1 deletion client/themes/zenburn.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ body {
border-color: #101010;
}

#form #input {
#form .input {
background-color: #434443;
border-color: #101010;
color: #dcdccc;
Expand Down
8 changes: 8 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ Client.prototype.setPassword = function(hash, callback) {
};

Client.prototype.input = function(data) {
var client = this;
data.text.split("\n").forEach(function(line) {
data.text = line;
client.inputLine(data);
});
};

Client.prototype.inputLine = function(data) {
var client = this;
var text = data.text;
var target = client.find(data.target);
Expand Down