From 453c00b891c393250431bda14392eb4a20c73d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Coll?= Date: Mon, 21 Dec 2015 14:31:22 -0300 Subject: [PATCH] Fixes #1000: message box not focused on a computer with touch enabled. Also introduces a "shouldFocusOnInteraction" configuration value to make it easier to understand what the code does and also allow easier changes to this behavior in the future. --- app/js/directives.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/js/directives.js b/app/js/directives.js index cc1991be..ac113b64 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -12,6 +12,8 @@ angular.module('myApp.directives', ['myApp.filters']) + .constant('shouldFocusOnInteraction', !Config.Navigator.mobile) + .directive('myHead', function() { return { restrict: 'AE', @@ -1427,8 +1429,7 @@ angular.module('myApp.directives', ['myApp.filters']) }) - .directive('mySendForm', function (_, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService) { - + .directive('mySendForm', function (_, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService, shouldFocusOnInteraction) { return { link: link, scope: { @@ -1570,7 +1571,7 @@ angular.module('myApp.directives', ['myApp.filters']) if (composerEmojiPanel) { composerEmojiPanel.update(); } - }, Config.Navigator.touch ? 100 : 0); + }, shouldFocusOnInteraction ? 0 : 100); return cancelEvent(e); } @@ -1601,7 +1602,7 @@ angular.module('myApp.directives', ['myApp.filters']) $('body').on('dragenter dragleave dragover drop', onDragDropEvent); $(document).on('paste', onPasteEvent); - if (!Config.Navigator.touch) { + if (shouldFocusOnInteraction) { $scope.$on('ui_peer_change', focusField); $scope.$on('ui_history_focus', focusField); $scope.$on('ui_history_change', focusField); @@ -1621,7 +1622,7 @@ angular.module('myApp.directives', ['myApp.filters']) composer.setValue($scope.draftMessage.text || ''); updateHeight(); } - if (!Config.Navigator.touch || options && options.focus) { + if (shouldFocusOnInteraction || options && options.focus) { composer.focus(); } } @@ -1635,7 +1636,7 @@ angular.module('myApp.directives', ['myApp.filters']) $scope.$on('ui_peer_reply', function () { onContentLoaded(function () { $scope.$emit('ui_editor_resize'); - if (!Config.Navigator.touch) { + if (shouldFocusOnInteraction) { composer.focus(); } }) @@ -1649,7 +1650,7 @@ angular.module('myApp.directives', ['myApp.filters']) updateValue(); }); $scope.$on('ui_message_send', function () { - if (!Config.Navigator.touch) { + if (shouldFocusOnInteraction) { focusField(); } }); @@ -1740,7 +1741,7 @@ angular.module('myApp.directives', ['myApp.filters']) fileSelects.off('change'); }); - if (!Config.Navigator.touch) { + if (shouldFocusOnInteraction) { focusField(); } @@ -2275,10 +2276,10 @@ angular.module('myApp.directives', ['myApp.filters']) } }) - .directive('myFocused', function(){ + .directive('myFocused', function(shouldFocusOnInteraction) { return { link: function($scope, element, attrs) { - if (Config.Navigator.touch) { + if (!shouldFocusOnInteraction) { return false; } setTimeout(function () { @@ -2288,11 +2289,11 @@ angular.module('myApp.directives', ['myApp.filters']) }; }) - .directive('myFocusOn', function(){ + .directive('myFocusOn', function(shouldFocusOnInteraction) { return { link: function($scope, element, attrs) { $scope.$on(attrs.myFocusOn, function () { - if (Config.Navigator.touch) { + if (!shouldFocusOnInteraction) { return false; } onContentLoaded(function () {