@@ -17,21 +17,24 @@ angular.module('ui.tinymce', [])
17
17
if ( ! $window . tinymce ) {
18
18
return ;
19
19
}
20
-
21
20
var ngModel = ctrls [ 0 ] ,
22
21
form = ctrls [ 1 ] || null ;
23
22
23
+ var lastSeenContent = null ;
24
24
var expression , options = {
25
25
debounce : true
26
26
} , tinyInstance ,
27
27
updateView = function ( editor ) {
28
+ // don't jump into any digest if the content is the same
28
29
var content = editor . getContent ( { format : options . format } ) . trim ( ) ;
29
- content = $sce . trustAsHtml ( content ) ;
30
-
31
- ngModel . $setViewValue ( content ) ;
32
- if ( ! $rootScope . $$phase ) {
33
- scope . $digest ( ) ;
30
+ if ( lastSeenContent === content ) {
31
+ return ;
34
32
}
33
+ lastSeenContent = content ;
34
+ content = $sce . trustAsHtml ( content ) ;
35
+ scope . $evalAsync ( function ( ) {
36
+ ngModel . $setViewValue ( content ) ;
37
+ } ) ;
35
38
} ;
36
39
37
40
function toggleDisable ( disabled ) {
@@ -64,10 +67,10 @@ angular.module('ui.tinymce', [])
64
67
return function ( ed ) {
65
68
$timeout . cancel ( debouncedUpdateTimer ) ;
66
69
debouncedUpdateTimer = $timeout ( function ( ) {
67
- return ( function ( ed ) {
68
- if ( ed . isDirty ( ) ) {
69
- ed . save ( ) ;
70
- updateView ( ed ) ;
70
+ return ( function ( debouncedEditor ) {
71
+ if ( debouncedEditor . isDirty ( ) ) {
72
+ debouncedEditor . save ( ) ;
73
+ updateView ( debouncedEditor ) ;
71
74
}
72
75
} ) ( ed ) ;
73
76
} , debouncedUpdateDelay ) ;
@@ -102,11 +105,10 @@ angular.module('ui.tinymce', [])
102
105
} ) ;
103
106
104
107
ed . on ( 'blur' , function ( ) {
105
- element [ 0 ] . blur ( ) ;
106
- ngModel . $setTouched ( ) ;
107
- if ( ! $rootScope . $$phase ) {
108
- scope . $digest ( ) ;
109
- }
108
+ scope . $evalAsync ( function ( ) {
109
+ element [ 0 ] . blur ( ) ;
110
+ ngModel . $setTouched ( ) ;
111
+ } ) ;
110
112
} ) ;
111
113
112
114
ed . on ( 'remove' , function ( ) {
0 commit comments