@@ -46,33 +46,27 @@ angular.module('ui.tinymce', [])
46
46
options = {
47
47
// Update model when calling setContent (such as from the source editor popup)
48
48
setup : function ( ed ) {
49
- var args ;
50
- ed . on ( 'init' , function ( args ) {
49
+ ed . on ( 'init' , function ( ) {
51
50
ngModel . $render ( ) ;
52
51
ngModel . $setPristine ( ) ;
53
52
} ) ;
54
53
// Update model on button click
55
- ed . on ( 'ExecCommand' , function ( e ) {
54
+ ed . on ( 'ExecCommand' , function ( ) {
56
55
ed . save ( ) ;
57
56
updateView ( ed ) ;
58
57
} ) ;
59
- // Update model on keypress
60
- ed . on ( 'KeyUp' , function ( e ) {
61
- ed . save ( ) ;
62
- updateView ( ed ) ;
63
- } ) ;
64
- // Update model on change, i.e. copy/pasted text, plugins altering content
65
- ed . on ( 'SetContent' , function ( e ) {
66
- if ( ! e . initial && ngModel . $viewValue !== e . content ) {
58
+ // Update model on change
59
+ ed . on ( 'change' , function ( e ) {
60
+ if ( ! e . originalEvent ) {
67
61
ed . save ( ) ;
68
62
updateView ( ed ) ;
69
63
}
70
64
} ) ;
71
- ed . on ( 'blur' , function ( e ) {
65
+ ed . on ( 'blur' , function ( ) {
72
66
element [ 0 ] . blur ( ) ;
73
67
} ) ;
74
68
// Update model when an object has been resized (table, image)
75
- ed . on ( 'ObjectResized' , function ( e ) {
69
+ ed . on ( 'ObjectResized' , function ( ) {
76
70
ed . save ( ) ;
77
71
updateView ( ed ) ;
78
72
} ) ;
@@ -88,12 +82,16 @@ angular.module('ui.tinymce', [])
88
82
angular . extend ( options , uiTinymceConfig , expression ) ;
89
83
tinymce . init ( options ) ;
90
84
85
+ ngModel . $formatters . unshift ( function ( modelValue ) {
86
+ return modelValue || '' ;
87
+ } ) ;
88
+
91
89
ngModel . $render = function ( ) {
92
90
if ( ! tinyInstance ) {
93
91
tinyInstance = tinymce . get ( attrs . id ) ;
94
92
}
95
93
if ( tinyInstance ) {
96
- tinyInstance . setContent ( ngModel . $viewValue || '' ) ;
94
+ tinyInstance . setContent ( ngModel . $viewValue ) ;
97
95
}
98
96
} ;
99
97
0 commit comments