@@ -24,9 +24,7 @@ angular.module('ui.tinymce', [])
24
24
var expression , options , tinyInstance ,
25
25
updateView = function ( editor ) {
26
26
var content = editor . getContent ( { format : options . format } ) . trim ( ) ;
27
- if ( options . trusted ) {
28
- content = $sce . trustAsHtml ( content ) ;
29
- }
27
+ content = $sce . trustAsHtml ( content ) ;
30
28
31
29
ngModel . $setViewValue ( content ) ;
32
30
if ( ! $rootScope . $$phase ) {
@@ -42,7 +40,8 @@ angular.module('ui.tinymce', [])
42
40
angular . extend ( expression , scope . $eval ( attrs . uiTinymce ) ) ;
43
41
44
42
options = {
45
- // Update model when calling setContent (such as from the source editor popup)
43
+ // Update model when calling setContent
44
+ // (such as from the source editor popup)
46
45
setup : function ( ed ) {
47
46
ed . on ( 'init' , function ( ) {
48
47
ngModel . $render ( ) ;
@@ -60,10 +59,8 @@ angular.module('ui.tinymce', [])
60
59
61
60
// Update model on change
62
61
ed . on ( 'change' , function ( e ) {
63
- if ( ! e . originalEvent ) {
64
- ed . save ( ) ;
65
- updateView ( ed ) ;
66
- }
62
+ ed . save ( ) ;
63
+ updateView ( ed ) ;
67
64
} ) ;
68
65
69
66
ed . on ( 'blur' , function ( ) {
@@ -89,7 +86,8 @@ angular.module('ui.tinymce', [])
89
86
format : 'raw' ,
90
87
selector : '#' + attrs . id
91
88
} ;
92
- // extend options with initial uiTinymceConfig and options from directive attribute value
89
+ // extend options with initial uiTinymceConfig and
90
+ // options from directive attribute value
93
91
angular . extend ( options , uiTinymceConfig , expression ) ;
94
92
// Wrapped in $timeout due to $tinymce:refresh implementation, requires
95
93
// element to be present in DOM before instantiating editor when
@@ -99,22 +97,26 @@ angular.module('ui.tinymce', [])
99
97
} ) ;
100
98
101
99
ngModel . $formatters . unshift ( function ( modelValue ) {
102
- return modelValue || '' ;
100
+ return modelValue ? $sce . trustAsHtml ( modelValue ) : '' ;
101
+ } ) ;
102
+
103
+ ngModel . $parsers . unshift ( function ( viewValue ) {
104
+ return viewValue ? $sce . getTrustedHtml ( viewValue ) : '' ;
103
105
} ) ;
104
106
105
107
ngModel . $render = function ( ) {
106
108
ensureInstance ( ) ;
107
109
108
- // tinymce replaces '\r\n' to '\n', so we have to do the same on model value
109
- // instance.getDoc() check is a guard against null value when destruction &
110
- // recreation of instances happen
110
+ var viewValue = ngModel . $viewValue ?
111
+ $sce . getTrustedHtml ( ngModel . $viewValue ) : '' ;
112
+
113
+ // instance.getDoc() check is a guard against null value
114
+ // when destruction & recreation of instances happen
111
115
if ( tinyInstance &&
112
- tinyInstance . getDoc ( ) &&
113
- ( tinyInstance . getContent ( { format : options . format } ) . trim ( ) !== ngModel . $viewValue . replace ( / \r \n / g, '\n' ) ||
114
- ! ngModel . $viewValue ||
115
- ! ngModel . $viewValue . replace ( / \r \n / g, '\n' ) )
116
+ tinyInstance . getDoc ( )
116
117
) {
117
- tinyInstance . setContent ( ngModel . $viewValue ) ;
118
+ tinyInstance . setContent ( viewValue ) ;
119
+ tinyInstance . fire ( 'change' ) ;
118
120
}
119
121
} ;
120
122
0 commit comments