Files
habitica/website/client-old/js/directives/submit-form-on-enter.directive.js
Matt Handley 705a78e835 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.
2017-02-27 11:19:42 -07:00

26 lines
681 B
JavaScript

'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);
}
});
}
}
}
}());