From 88f3fe567cbb3401b27c3bb374457aff988be67b Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sat, 19 Oct 2013 15:06:23 +0200 Subject: [PATCH] try to fix focus --- src/js/controller/mail-list.js | 6 +++--- src/js/controller/write.js | 18 ++++++++++++++---- src/tpl/write.html | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/js/controller/mail-list.js b/src/js/controller/mail-list.js index 16e9bb1..e17b128 100644 --- a/src/js/controller/mail-list.js +++ b/src/js/controller/mail-list.js @@ -214,16 +214,16 @@ define(function(require) { // var ngModule = angular.module('mail-list', []); - ngModule.directive('ngIscroll', function() { + ngModule.directive('ngIscroll', function($timeout) { return { link: function(scope, elm) { - setTimeout(function() { + $timeout(function() { var myScroll; // activate iscroll myScroll = new IScroll(elm[0], { mouseWheel: true }); - }, 0); + }); } }; diff --git a/src/js/controller/write.js b/src/js/controller/write.js index fbd45f8..a47f37c 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -167,11 +167,21 @@ define(function(require) { }; }); - ngModule.directive('focusMe', function($timeout) { + ngModule.directive('focusMe', function($timeout, $parse) { return { - link: function(scope, element) { - $timeout(function() { - element[0].focus(); + //scope: true, // optionally create a child scope + link: function(scope, element, attrs) { + var model = $parse(attrs.focusMe); + scope.$watch(model, function(value) { + if (value === true) { + $timeout(function() { + element[0].focus(); + }); + } + }); + // set attribute value to 'false' on blur event: + element.bind('blur', function() { + scope.$apply(model.assign(scope, false)); }); } }; diff --git a/src/tpl/write.html b/src/tpl/write.html index 766aa95..333be95 100644 --- a/src/tpl/write.html +++ b/src/tpl/write.html @@ -9,7 +9,7 @@

To: - +

Cc: