From 86827d649cbf91633f8ef79a1ddbd14c767c5d88 Mon Sep 17 00:00:00 2001 From: Cody Stewart Date: Thu, 19 Dec 2013 12:40:45 -0500 Subject: [PATCH] added say directive to allow a user to say commands via the input field --- public/javascripts/nirc.js | 6 ++++++ public/javascripts/nirc/client.js | 2 +- public/javascripts/nirc/directives/say.js | 21 +++++++++++++++++++++ views/index.html | 3 ++- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 public/javascripts/nirc/directives/say.js diff --git a/public/javascripts/nirc.js b/public/javascripts/nirc.js index 331c2db..2e61e77 100644 --- a/public/javascripts/nirc.js +++ b/public/javascripts/nirc.js @@ -1,7 +1,13 @@ angular.module('nirc', []) .controller('MainCtrl', function($scope, Client) { + $scope.client = Client; + + $scope.say = function(command) { + $scope.client.say(command); + }; + }) .controller('TabCtrl', function($scope) { diff --git a/public/javascripts/nirc/client.js b/public/javascripts/nirc/client.js index 7c71b2d..96dbb1a 100644 --- a/public/javascripts/nirc/client.js +++ b/public/javascripts/nirc/client.js @@ -25,7 +25,7 @@ angular.module('nirc') /* -- public interface below -- */ say: function(text) { - this.socket.emit('command', text); + socket.emit('command', text); }, connect: function() { diff --git a/public/javascripts/nirc/directives/say.js b/public/javascripts/nirc/directives/say.js new file mode 100644 index 0000000..23f8c7d --- /dev/null +++ b/public/javascripts/nirc/directives/say.js @@ -0,0 +1,21 @@ +angular.module('nirc') + + .directive('say', function() { + + return function (scope, element, attrs) { + element.bind("keydown keypress", function (event) { + if (event.which === 13) { + var command = element.val(); + + if (command.charAt(0) != '/') { + command = "/msg " + scope.client.activeChannel.name + ' ' + command; + } + + scope.say(command); + element.val(''); + event.preventDefault(); + } + }); + }; + + }); \ No newline at end of file diff --git a/views/index.html b/views/index.html index 16d384c..39237b2 100644 --- a/views/index.html +++ b/views/index.html @@ -7,6 +7,7 @@ + @@ -100,7 +101,7 @@
- +