avoid calling $scope.$apply twice in the same digest cycle if anything is listening on blur() or focus()

fix-space-nbsp 0.3.3
Dmitri Akatov 11 years ago
parent ccdece14ae
commit ba76a3749d

@ -1,5 +1,5 @@
angular.module('contenteditable', []) angular.module('contenteditable', [])
.directive('contenteditable', function() { return { .directive('contenteditable', ['$timeout', function($timeout) { return {
require: 'ngModel', require: 'ngModel',
link: function($scope, $element, attrs, ngModel) { link: function($scope, $element, attrs, ngModel) {
var old_render var old_render
@ -26,8 +26,10 @@ angular.module('contenteditable', [])
if (html === '') { if (html === '') {
// the cursor disappears if the contents is empty // the cursor disappears if the contents is empty
// so we need to refocus // so we need to refocus
$element.blur() $timeout(function(){
$element.focus() $element.blur()
$element.focus()
})
} }
}) })
}) })
@ -68,5 +70,4 @@ angular.module('contenteditable', [])
}) })
} }
} }
}}) }}])

@ -1,6 +1,6 @@
{ {
"name": "angular-contenteditable", "name": "angular-contenteditable",
"version": "0.3.2", "version": "0.3.3",
"main": "angular-contenteditable.js", "main": "angular-contenteditable.js",
"ignore": [ "ignore": [
".*", ".*",

@ -1,6 +1,6 @@
{ {
"name": "angular-contenteditable", "name": "angular-contenteditable",
"version": "0.3.2", "version": "0.3.3",
"description": "angular extensions", "description": "angular extensions",
"main": "angular-contenteditable.js", "main": "angular-contenteditable.js",
"directories": { "directories": {