Browse Source

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.
master
Martín Coll 9 years ago
parent
commit
453c00b891
  1. 25
      app/js/directives.js

25
app/js/directives.js

@ -12,6 +12,8 @@
angular.module('myApp.directives', ['myApp.filters']) angular.module('myApp.directives', ['myApp.filters'])
.constant('shouldFocusOnInteraction', !Config.Navigator.mobile)
.directive('myHead', function() { .directive('myHead', function() {
return { return {
restrict: 'AE', 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 { return {
link: link, link: link,
scope: { scope: {
@ -1570,7 +1571,7 @@ angular.module('myApp.directives', ['myApp.filters'])
if (composerEmojiPanel) { if (composerEmojiPanel) {
composerEmojiPanel.update(); composerEmojiPanel.update();
} }
}, Config.Navigator.touch ? 100 : 0); }, shouldFocusOnInteraction ? 0 : 100);
return cancelEvent(e); return cancelEvent(e);
} }
@ -1601,7 +1602,7 @@ angular.module('myApp.directives', ['myApp.filters'])
$('body').on('dragenter dragleave dragover drop', onDragDropEvent); $('body').on('dragenter dragleave dragover drop', onDragDropEvent);
$(document).on('paste', onPasteEvent); $(document).on('paste', onPasteEvent);
if (!Config.Navigator.touch) { if (shouldFocusOnInteraction) {
$scope.$on('ui_peer_change', focusField); $scope.$on('ui_peer_change', focusField);
$scope.$on('ui_history_focus', focusField); $scope.$on('ui_history_focus', focusField);
$scope.$on('ui_history_change', focusField); $scope.$on('ui_history_change', focusField);
@ -1621,7 +1622,7 @@ angular.module('myApp.directives', ['myApp.filters'])
composer.setValue($scope.draftMessage.text || ''); composer.setValue($scope.draftMessage.text || '');
updateHeight(); updateHeight();
} }
if (!Config.Navigator.touch || options && options.focus) { if (shouldFocusOnInteraction || options && options.focus) {
composer.focus(); composer.focus();
} }
} }
@ -1635,7 +1636,7 @@ angular.module('myApp.directives', ['myApp.filters'])
$scope.$on('ui_peer_reply', function () { $scope.$on('ui_peer_reply', function () {
onContentLoaded(function () { onContentLoaded(function () {
$scope.$emit('ui_editor_resize'); $scope.$emit('ui_editor_resize');
if (!Config.Navigator.touch) { if (shouldFocusOnInteraction) {
composer.focus(); composer.focus();
} }
}) })
@ -1649,7 +1650,7 @@ angular.module('myApp.directives', ['myApp.filters'])
updateValue(); updateValue();
}); });
$scope.$on('ui_message_send', function () { $scope.$on('ui_message_send', function () {
if (!Config.Navigator.touch) { if (shouldFocusOnInteraction) {
focusField(); focusField();
} }
}); });
@ -1740,7 +1741,7 @@ angular.module('myApp.directives', ['myApp.filters'])
fileSelects.off('change'); fileSelects.off('change');
}); });
if (!Config.Navigator.touch) { if (shouldFocusOnInteraction) {
focusField(); focusField();
} }
@ -2275,10 +2276,10 @@ angular.module('myApp.directives', ['myApp.filters'])
} }
}) })
.directive('myFocused', function(){ .directive('myFocused', function(shouldFocusOnInteraction) {
return { return {
link: function($scope, element, attrs) { link: function($scope, element, attrs) {
if (Config.Navigator.touch) { if (!shouldFocusOnInteraction) {
return false; return false;
} }
setTimeout(function () { setTimeout(function () {
@ -2288,11 +2289,11 @@ angular.module('myApp.directives', ['myApp.filters'])
}; };
}) })
.directive('myFocusOn', function(){ .directive('myFocusOn', function(shouldFocusOnInteraction) {
return { return {
link: function($scope, element, attrs) { link: function($scope, element, attrs) {
$scope.$on(attrs.myFocusOn, function () { $scope.$on(attrs.myFocusOn, function () {
if (Config.Navigator.touch) { if (!shouldFocusOnInteraction) {
return false; return false;
} }
onContentLoaded(function () { onContentLoaded(function () {

Loading…
Cancel
Save