@@ -9,12 +9,18 @@ angular.module('ui.tinymce', [])
9
9
return {
10
10
require : 'ngModel' ,
11
11
link : function ( scope , elm , attrs , ngModel ) {
12
- var expression , options , tinyInstance ;
12
+ var expression , options , tinyInstance ,
13
+ updateView = function ( ) {
14
+ ngModel . $setViewValue ( elm . val ( ) ) ;
15
+ if ( ! scope . $$phase ) {
16
+ scope . $apply ( ) ;
17
+ }
18
+ } ;
13
19
// generate an ID if not present
14
20
if ( ! attrs . id ) {
15
21
attrs . $set ( 'id' , 'uiTinymce' + generatedIds ++ ) ;
16
22
}
17
-
23
+
18
24
if ( attrs . uiTinymce ) {
19
25
expression = scope . $eval ( attrs . uiTinymce ) ;
20
26
} else {
@@ -30,18 +36,17 @@ angular.module('ui.tinymce', [])
30
36
// Update model on button click
31
37
ed . on ( 'ExecCommand' , function ( e ) {
32
38
ed . save ( ) ;
33
- ngModel . $setViewValue ( elm . val ( ) ) ;
34
- if ( ! scope . $$phase ) {
35
- scope . $apply ( ) ;
36
- }
39
+ updateView ( ) ;
37
40
} ) ;
38
41
// Update model on keypress
39
42
ed . on ( 'KeyUp' , function ( e ) {
40
43
ed . save ( ) ;
41
- ngModel . $setViewValue ( elm . val ( ) ) ;
42
- if ( ! scope . $$phase ) {
43
- scope . $apply ( ) ;
44
- }
44
+ updateView ( ) ;
45
+ } ) ;
46
+ // Update model on change, i.e. copy/pasted text, plugins altering content
47
+ ed . on ( 'SetContent' , function ( e ) {
48
+ ed . save ( ) ;
49
+ updateView ( ) ;
45
50
} ) ;
46
51
if ( expression . setup ) {
47
52
scope . $eval ( expression . setup ) ;
0 commit comments