mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
a few fixes and performance increases:
* username autocompletes on click now instead of showing undefined * an adjustable 'update interval' stops the huge performance hit by delaying events from firing until the user has stopped typing for a while * nested controllers can cause issues because of prototypal inheritance if the models are not defined correctly... with ChatCtrl._chatMessage, this was the case. Modified it to fit in better with "best practices". See blog post here: http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html
This commit is contained in:
@@ -79,7 +79,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
||||
}
|
||||
])
|
||||
|
||||
.controller('AutocompleteCtrl', ['$scope', 'Groups', 'User', 'InputCaret', function ($scope,Groups,User,InputCaret) {
|
||||
.controller('AutocompleteCtrl', ['$scope', '$timeout', 'Groups', 'User', 'InputCaret', function ($scope,$timeout,Groups,User,InputCaret) {
|
||||
$scope.clearUserlist = function() {
|
||||
$scope.response = [];
|
||||
$scope.usernames = [];
|
||||
@@ -87,6 +87,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
||||
|
||||
$scope.addNewUser = function(user) {
|
||||
if($.inArray(user.user,$scope.usernames) == -1) {
|
||||
user.username = user.user;
|
||||
$scope.usernames.push(user.user);
|
||||
$scope.response.push(user);
|
||||
}
|
||||
@@ -102,6 +103,8 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$watch('group.chat',$scope.chatChanged);
|
||||
|
||||
$scope.caretChanged = function(newCaretPos) {
|
||||
var relativeelement = $('.-options');
|
||||
var textarea = $('.chat-textarea');
|
||||
@@ -119,12 +122,20 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$watch('group.chat',$scope.chatChanged);
|
||||
$scope.$watch(function () { return $scope.caretPos; },$scope.caretChanged);
|
||||
$scope.updateTimer = false;
|
||||
|
||||
$scope.$watch(function () { return $scope.caretPos; },function(newCaretPos) {
|
||||
if($scope.updateTimer){
|
||||
$timeout.cancel($scope.updateTimer)
|
||||
}
|
||||
$scope.updateTimer = $timeout(function(){
|
||||
$scope.caretChanged(newCaretPos);
|
||||
},$scope.watchDelay)
|
||||
});
|
||||
}])
|
||||
|
||||
.controller('ChatCtrl', ['$scope', 'Groups', 'User', function($scope, Groups, User){
|
||||
$scope._chatMessage = '';
|
||||
$scope.message = {content:''};
|
||||
$scope._sending = false;
|
||||
|
||||
$scope.postChat = function(group, message){
|
||||
@@ -137,7 +148,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
||||
}else if(data.message){
|
||||
group.chat.unshift(data.message);
|
||||
}
|
||||
$scope._chatMessage = '';
|
||||
$scope.message.content = '';
|
||||
$scope._sending = false;
|
||||
}, function(err){
|
||||
$scope._sending = false;
|
||||
|
||||
Reference in New Issue
Block a user