Debounce $scope updates when typing in chat. (#8485)

Fixes #6462, by saving a bunch of time per frame. See the issue for evidence of
the win.
This commit is contained in:
Matt Handley
2017-02-27 12:19:42 -06:00
committed by Keith Holliday
parent 6d0df78441
commit 705a78e835
5 changed files with 80 additions and 11 deletions

View File

@@ -0,0 +1,25 @@
'use strict';
(function(){
angular
.module('habitrpg')
.directive('submitOnMetaEnter', submitOnMetaEnter);
function submitOnMetaEnter() {
return {
restrict: 'A',
link: function($scope, element, attrs) {
element.on('keydown', function(event) {
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
// Note that we use the normal browser way to invoke the submit
// event, because jquery's triggerHandler executes events in a
// strange order!
var event = new Event('submit');
element[0].form.dispatchEvent(event);
}
});
}
}
}
}());