Skip to content

Commit

Permalink
Merge pull request #71 from cjstewart88/cody/angular
Browse files Browse the repository at this point in the history
added say directive to allow a user to say commands via the input field
  • Loading branch information
John Ledbetter committed Dec 19, 2013
2 parents d1dfff6 + 86827d6 commit ef2f5a9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions public/javascripts/nirc.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/nirc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ angular.module('nirc')
/* -- public interface below -- */

say: function(text) {
this.socket.emit('command', text);
socket.emit('command', text);
},

connect: function() {
Expand Down
21 changes: 21 additions & 0 deletions public/javascripts/nirc/directives/say.js
Original file line number Diff line number Diff line change
@@ -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();
}
});
};

});
3 changes: 2 additions & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<script src='/javascripts/vendor/angular.min.js'></script>
<script src='/javascripts/vendor/lodash.min.js'></script>
<script src='/javascripts/nirc.js'></script>
<script src='/javascripts/nirc/directives/say.js'></script>
<script src='/javascripts/nirc/user.js'></script>
<script src='/javascripts/nirc/channel.js'></script>
<script src='/javascripts/nirc/chat_event.js'></script>
Expand Down Expand Up @@ -57,7 +58,7 @@
</div>

<div class="input-wrapper">
<input type="text" class="user-input">
<input type="text" class="user-input" say>
</div>
</body>
</html>

0 comments on commit ef2f5a9

Please sign in to comment.