From 46da85c8cf7dbd7ce7e6a19398d2c25bd0b9ebfc Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Tue, 9 Jan 2018 10:59:33 +0100 Subject: [PATCH] feat(services): bind enter key when scaling a service (#1560) --- app/directives/autofocus.js | 7 +++---- app/directives/onEnterKey.js | 18 ++++++++++++++++++ .../services-datatable/servicesDatatable.html | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 app/directives/onEnterKey.js diff --git a/app/directives/autofocus.js b/app/directives/autofocus.js index 0b9029c33..7843e8139 100644 --- a/app/directives/autofocus.js +++ b/app/directives/autofocus.js @@ -1,11 +1,10 @@ -angular -.module('portainer') +angular.module('portainer') .directive('autoFocus', ['$timeout', function porAutoFocus($timeout) { var directive = { restrict: 'A', - link: function($scope, $element) { + link: function(scope, element) { $timeout(function() { - $element[0].focus(); + element[0].focus(); }); } }; diff --git a/app/directives/onEnterKey.js b/app/directives/onEnterKey.js new file mode 100644 index 000000000..1d13e8d22 --- /dev/null +++ b/app/directives/onEnterKey.js @@ -0,0 +1,18 @@ +angular.module('portainer') +.directive('onEnterKey', [function porOnEnterKey() { + var directive = { + restrict: 'A', + link: function(scope, element, attrs) { + element.bind('keydown keypress', function (e) { + if ( e.which === 13 ) { + e.preventDefault(); + scope.$apply(function () { + scope.$eval(attrs.onEnterKey); + }); + } + }); + } + }; + + return directive; +}]); diff --git a/app/directives/ui/datatables/services-datatable/servicesDatatable.html b/app/directives/ui/datatables/services-datatable/servicesDatatable.html index 82b9c97d3..cf94c0f6a 100644 --- a/app/directives/ui/datatables/services-datatable/servicesDatatable.html +++ b/app/directives/ui/datatables/services-datatable/servicesDatatable.html @@ -108,7 +108,7 @@ - +