From ba76a3749de5bcc70e910c5ad3dd705a65319a8f Mon Sep 17 00:00:00 2001 From: Dmitri Akatov Date: Tue, 30 Jul 2013 20:47:02 -0700 Subject: [PATCH] avoid calling $scope.$apply twice in the same digest cycle if anything is listening on blur() or focus() --- angular-contenteditable.js | 11 ++++++----- bower.json | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/angular-contenteditable.js b/angular-contenteditable.js index 20ab9d6..6f315f5 100644 --- a/angular-contenteditable.js +++ b/angular-contenteditable.js @@ -1,5 +1,5 @@ angular.module('contenteditable', []) - .directive('contenteditable', function() { return { + .directive('contenteditable', ['$timeout', function($timeout) { return { require: 'ngModel', link: function($scope, $element, attrs, ngModel) { var old_render @@ -26,8 +26,10 @@ angular.module('contenteditable', []) if (html === '') { // the cursor disappears if the contents is empty // so we need to refocus - $element.blur() - $element.focus() + $timeout(function(){ + $element.blur() + $element.focus() + }) } }) }) @@ -68,5 +70,4 @@ angular.module('contenteditable', []) }) } } - }}) - + }}]) diff --git a/bower.json b/bower.json index 4a7f653..d10ae2b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-contenteditable", - "version": "0.3.2", + "version": "0.3.3", "main": "angular-contenteditable.js", "ignore": [ ".*", diff --git a/package.json b/package.json index ce647fe..65a16e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-contenteditable", - "version": "0.3.2", + "version": "0.3.3", "description": "angular extensions", "main": "angular-contenteditable.js", "directories": {