@@ -24,9 +24,7 @@ angular.module('ui.tinymce', [])
2424 var expression , options , tinyInstance ,
2525 updateView = function ( editor ) {
2626 var content = editor . getContent ( { format : options . format } ) . trim ( ) ;
27- if ( options . trusted ) {
28- content = $sce . trustAsHtml ( content ) ;
29- }
27+ content = $sce . trustAsHtml ( content ) ;
3028
3129 ngModel . $setViewValue ( content ) ;
3230 if ( ! $rootScope . $$phase ) {
@@ -42,7 +40,8 @@ angular.module('ui.tinymce', [])
4240 angular . extend ( expression , scope . $eval ( attrs . uiTinymce ) ) ;
4341
4442 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)
4645 setup : function ( ed ) {
4746 ed . on ( 'init' , function ( ) {
4847 ngModel . $render ( ) ;
@@ -60,10 +59,8 @@ angular.module('ui.tinymce', [])
6059
6160 // Update model on change
6261 ed . on ( 'change' , function ( e ) {
63- if ( ! e . originalEvent ) {
64- ed . save ( ) ;
65- updateView ( ed ) ;
66- }
62+ ed . save ( ) ;
63+ updateView ( ed ) ;
6764 } ) ;
6865
6966 ed . on ( 'blur' , function ( ) {
@@ -89,7 +86,8 @@ angular.module('ui.tinymce', [])
8986 format : 'raw' ,
9087 selector : '#' + attrs . id
9188 } ;
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
9391 angular . extend ( options , uiTinymceConfig , expression ) ;
9492 // Wrapped in $timeout due to $tinymce:refresh implementation, requires
9593 // element to be present in DOM before instantiating editor when
@@ -99,22 +97,26 @@ angular.module('ui.tinymce', [])
9997 } ) ;
10098
10199 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 ) : '' ;
103105 } ) ;
104106
105107 ngModel . $render = function ( ) {
106108 ensureInstance ( ) ;
107109
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
111115 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 ( )
116117 ) {
117- tinyInstance . setContent ( ngModel . $viewValue ) ;
118+ tinyInstance . setContent ( viewValue ) ;
119+ tinyInstance . fire ( 'change' ) ;
118120 }
119121 } ;
120122
0 commit comments