Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from naiky/master
Migration
- Loading branch information
Showing
16 changed files
with
750 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
/** app level module which depends on services and controllers */ | ||
angular.module('liveChat', ['liveChat.controllers', 'ui.bootstrap']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
'use strict'; | ||
|
||
/** Controllers */ | ||
angular.module('liveChat.controllers', []). | ||
controller('ChatCtrl', function ($scope, $dialog, $http) { | ||
$scope.messages = []; | ||
$scope.inputText = ""; | ||
$scope.users = []; | ||
$scope.currentMessage = ""; | ||
$scope.currentUser =""; | ||
$scope.title= "toute l'actualité IT au Luxembourg"; | ||
|
||
|
||
$scope.connect = function (username) { | ||
var WS = window['MozWebSocket'] ? MozWebSocket : WebSocket; | ||
// $scope.chatSocket = new WS("ws://localhost:9000/room/chat/" + username); | ||
|
||
var url = jsRoutes.controllers.Application.chat(username).absoluteURL().replace("http://","ws://") | ||
$scope.chatSocket = new WS(url); | ||
$scope.chatSocket.onmessage = $scope.receiveEvent; | ||
|
||
$http.get('/username/' + username).success(function(data, status, headers, config) { | ||
$scope.currentUser = data; | ||
}); | ||
}; | ||
|
||
$scope.sendText = function (textMsg) { | ||
$scope.chatSocket.send(JSON.stringify( | ||
{text: textMsg} | ||
)) | ||
} | ||
|
||
$scope.receiveEvent = function (event) { | ||
var data = JSON.parse(event.data) | ||
|
||
// Handle errors | ||
if (data.error) { | ||
chatSocket.close() | ||
$("#onError span").text(data.error) | ||
$("#onError").show(); | ||
return | ||
} else { | ||
$("#onChat").show(); | ||
} | ||
|
||
var now = new Date(); | ||
var min = now.getMinutes() + ""; | ||
if (min.length == 1) { | ||
min = "0" + min; | ||
} | ||
data.time = now.getHours() + ':' + min; | ||
$scope.messages.push(data); | ||
$scope.users = data.members; | ||
$scope.$apply(); | ||
} | ||
|
||
|
||
var alreadyExist = function (user) { | ||
var resp = false | ||
$($scope.users).each(function () { | ||
if (this == user) | ||
resp = true | ||
}) | ||
return resp | ||
} | ||
|
||
$scope.changeUsername = function (username) { | ||
if (username.indexOf("<") != -1) { | ||
showErrorMsg("Si tu veux programmer en HTML, aide nous plutôt à faire évoluer le chat") | ||
} else if (username.indexOf("@@") != -1) { | ||
showErrorMsg("Le caractère @@ est réservé pour les comptes twitters") | ||
} else if (alreadyExist(username)) { | ||
showErrorMsg("Utilisateur déjà existant") | ||
} else if (username.trim() == "") { | ||
showErrorMsg("Merci de saisir un nom d'utilisateur") | ||
} else { | ||
myname = username | ||
$scope.sendText("nickname:" + username) | ||
$scope.currentUser = username; | ||
} | ||
} | ||
|
||
$scope.setUserStyle = function(username) { | ||
if (username == $scope.currentUser) { | ||
return "{color : 'blue';}"; | ||
} else { | ||
return "{}"; | ||
} | ||
} | ||
|
||
$scope.openChangeUsernameDlg = function () { | ||
var dialogOptions = { | ||
modal: true, | ||
fade: true, | ||
backdrop: true, | ||
keyboard: true, | ||
backdropClick: true, | ||
templateUrl: '/changeuser', | ||
controller: 'ChangeNameDlgCtrl' | ||
}; | ||
|
||
var d = $dialog.dialog(dialogOptions); | ||
d.open().then(function (username) { | ||
if (username) { | ||
$scope.changeUsername(username); | ||
} | ||
}); | ||
} | ||
|
||
var myname = ''; | ||
|
||
|
||
}); | ||
|
||
|
||
function ChangeNameDlgCtrl($scope, dialog) { | ||
$scope.close = function(result) { | ||
dialog.close(result); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
function fakeNgModel(initValue){ | ||
return { | ||
$setViewValue: function(value){ | ||
this.$viewValue = value; | ||
}, | ||
$viewValue: initValue | ||
}; | ||
} | ||
|
||
|
||
angular.module('liveChat').directive('ngEnter', function () { | ||
return function (scope, element, attrs) { | ||
element.bind("keydown keypress", function (event) { | ||
if (event.which === 13) { | ||
scope.$apply(function () { | ||
scope.$eval(attrs.ngEnter); | ||
}); | ||
|
||
event.preventDefault(); | ||
element.val(''); | ||
} | ||
}); | ||
}; | ||
}); | ||
|
||
|
||
angular.module('liveChat').directive('scrollGlue', function () { | ||
return { | ||
priority: 1, | ||
require: ['?ngModel'], | ||
restrict: 'A', | ||
link: function (scope, $el, attrs, ctrls) { | ||
var el = $el[0], | ||
ngModel = ctrls[0] || fakeNgModel(true); | ||
|
||
function scrollToBottom() { | ||
el.scrollTop = el.scrollHeight; | ||
} | ||
|
||
function shouldActivateAutoScroll() { | ||
return el.scrollTop + el.clientHeight == el.scrollHeight; | ||
} | ||
|
||
scope.$watch(function () { | ||
if (ngModel.$viewValue) { | ||
scrollToBottom(); | ||
} | ||
}); | ||
|
||
/* $el.bind('scroll', function () { | ||
scope.$apply(ngModel.$setViewValue.bind(ngModel, shouldActivateAutoScroll())); | ||
}); */ | ||
} | ||
}; | ||
}); |
Oops, something went wrong.