mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
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:
committed by
Keith Holliday
parent
6d0df78441
commit
705a78e835
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user