Allow submit of comments using shift+enter

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-10-08 21:35:17 +02:00
parent cb3c083d8b
commit 27f9707058
2 changed files with 17 additions and 7 deletions

View File

@@ -22,10 +22,13 @@
import app from '../app/App'; import app from '../app/App';
app.directive("ngContenteditable", function($compile) { app.directive('ngContenteditable', function($compile) {
return { return {
require: "ngModel", require: 'ngModel',
restrict: 'A', restrict: 'A',
scope: {
submit: '&ngSubmit'
},
link: function(scope, element, attrs, ngModel) { link: function(scope, element, attrs, ngModel) {
//read the text typed in the div (syncing model with the view) //read the text typed in the div (syncing model with the view)
@@ -37,13 +40,20 @@ app.directive("ngContenteditable", function($compile) {
//$render is invoked when the modelvalue differs from the viewvalue //$render is invoked when the modelvalue differs from the viewvalue
//see documentation: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController# //see documentation: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#
ngModel.$render = function() { ngModel.$render = function() {
element.html(ngModel.$viewValue || ""); element.html(ngModel.$viewValue || '');
}; };
//do this whenever someone starts typing //do this whenever someone starts typing
element.bind("blur keyup change", function() { element.bind('blur keyup change', function(event) {
scope.$apply(read); scope.$apply(read);
}); });
element.bind('keydown', function(event) {
if(event.which == '13' && event.shiftKey) {
scope.submit();
}
});
} }
}; };
}); });

View File

@@ -4,10 +4,10 @@
<div class="avatardiv" avatar ng-attr-user="{{ $ctrl.currentUser.uid }}" ng-attr-displayname="{{ $ctrl.currentUser.displayName }}" ng-attr-size="24"></div> <div class="avatardiv" avatar ng-attr-user="{{ $ctrl.currentUser.uid }}" ng-attr-displayname="{{ $ctrl.currentUser.displayName }}" ng-attr-size="24"></div>
<div class="author currentUser">{{ $ctrl.currentUser.displayName }}</div> <div class="author currentUser">{{ $ctrl.currentUser.displayName }}</div>
</div> </div>
<form class="newCommentForm"> <form class="newCommentForm" ng-submit="$ctrl.postComment()">
<div ng-contenteditable contenteditable="true" class="message" data-placeholder="{{ $ctrl.t('New comment …') }}" ng-model="$ctrl.$scope.newComment" ng-disabled="$ctrl.status.commentCreateLoading"></div> <div ng-contenteditable contenteditable="true" class="message" ng-submit="$ctrl.postComment()" data-placeholder="{{ $ctrl.t('New comment …') }}" ng-model="$ctrl.$scope.newComment" ng-disabled="$ctrl.status.commentCreateLoading"></div>
<input class="submit icon-confirm has-tooltip" type="submit" <input class="submit icon-confirm has-tooltip" type="submit"
value="" title="" data-original-title="Post" ng-click="$ctrl.postComment()" ng-if="!$ctrl.status.commentCreateLoading"> value="" title="" data-original-title="Post" ng-if="!$ctrl.status.commentCreateLoading">
<div class="submitLoading icon-loading-small" ng-if="$ctrl.status.commentCreateLoading"></div> <div class="submitLoading icon-loading-small" ng-if="$ctrl.status.commentCreateLoading"></div>
</form> </form>
</div> </div>