From 7d36997b8370465aaf77fb0d26b2c56f882e040f Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 14 Jun 2014 23:21:09 +0200 Subject: [PATCH] Press tab to complete usernames --- client/js/chat.js | 24 +++++++++++++++--------- client/js/jquery.plugins.js | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client/js/chat.js b/client/js/chat.js index f043f518..326898d1 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -61,12 +61,12 @@ $(function() { chat.append(render("windows", {windows: [data.chan]})) .find(".window") .last() - .find(".chat") - .sticky() - .end() .find(".input") .tabcomplete(complete, {hint: false}) - .history(); + .history() + .end() + .find(".chat") + .sticky(); $("#network-" + data.id) .append(render("channels", {channels: [data.chan]})) @@ -97,12 +97,12 @@ $(function() { case "networks": var channels = $.map(data.networks, function(n) { return n.channels; }); chat.html(render("windows", {windows: channels})) - .find(".chat") - .sticky() - .end() .find(".input") .tabcomplete(complete, {hint: false}) - .history(); + .history() + .end() + .find(".chat") + .sticky(); var networks = $("#networks") .html(render("networks", {networks: data.networks})) @@ -291,8 +291,14 @@ $(function() { }); function complete(word) { + var words = commands; + var users = $(this).closest(".window") + .find(".users .user") + .each(function() { + words.push(this.getAttribute("href").slice(1)); + }); return $.grep( - commands, + words, function(cmd) { return !cmd.indexOf(word); } diff --git a/client/js/jquery.plugins.js b/client/js/jquery.plugins.js index dac8212e..25534ccb 100644 --- a/client/js/jquery.plugins.js +++ b/client/js/jquery.plugins.js @@ -175,7 +175,7 @@ if (typeof args === "function") { // If the user supplies a function, invoke it // and keep the result. - words = args(word); + words = args.call(self, word); } else { // Otherwise, call the .match() function. words = match(word, args, options.caseSensitive);