main.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. if(window.location.hostname == 'gamenchat.pleasantprogrammer.com' && window.location.port != 8000) {
  2. window.location = 'http://gamenchat.pleasantprogrammer.com:8000';
  3. }
  4. angular.module('taboo', ['chatServices', 'tabooServices'])
  5. function partial(template) {
  6. return jsRoutes.controllers.Assets.at('partials/'+template+'.html').url;
  7. }
  8. function ViewCtrl($scope, $location, Connection) {
  9. $scope.service = Connection;
  10. $scope.partial = partial;
  11. $scope.view = 'about';
  12. if($location.path()) {
  13. $scope.view = 'chatRoom';
  14. }
  15. $scope.nav = [
  16. {partial: 'about', name: 'About'},
  17. {partial: 'chatRoom', name: 'Chat'},
  18. {partial: 'contribute', name: 'Contribute'}
  19. ];
  20. $scope.setView = function(p) {
  21. $scope.view = p;
  22. }
  23. $scope.$on('ws:connected', function() {
  24. $scope.view = 'chatRoom';
  25. });
  26. }
  27. function LoginCtrl($scope, Connection) {
  28. $scope.service = Connection;
  29. }
  30. function ChatCtrl($scope, Chat, Connection) {
  31. $scope.service = Connection;
  32. $scope.chat = Chat;
  33. $scope.onType = function(event) {
  34. if(event.keyCode == 13) {
  35. Chat.send($scope.text);
  36. $scope.text = '';
  37. event.originalEvent.preventDefault();
  38. }
  39. }
  40. }
  41. function GameCtrl($scope, Taboo) {
  42. $scope.game = Taboo;
  43. }
  44. function ContributeCtrl($scope, $http, $timeout) {
  45. $scope.submitting = false;
  46. function init() {
  47. $scope.card = {
  48. word: '',
  49. taboos: []
  50. };
  51. }
  52. $scope.submit = function() {
  53. if($scope.submitting) return;
  54. $scope.submitting = true;
  55. $http.post(jsRoutes.controllers.Cards.add().url, $scope.card)
  56. .then(function() {
  57. $scope.submitting = false;
  58. $scope.thanks = true;
  59. $timeout(function() {
  60. $scope.thanks = false;
  61. }, 3000);
  62. init();
  63. $('#inputWord').focus();
  64. });
  65. }
  66. init();
  67. }