@@ -94,6 +94,7 @@ angular.module('ui.tinymce', [])
9494 // re-rendering directive
9595 $timeout ( function ( ) {
9696 tinymce . init ( options ) ;
97+ toggleDisable ( scope . $eval ( attrs . ngDisabled ) ) ;
9798 } ) ;
9899
99100 ngModel . $formatters . unshift ( function ( modelValue ) {
@@ -116,25 +117,13 @@ angular.module('ui.tinymce', [])
116117 tinyInstance . getDoc ( )
117118 ) {
118119 tinyInstance . setContent ( viewValue ) ;
120+ // Triggering change event due to TinyMCE not firing event &
121+ // becoming out of sync for change callbacks
119122 tinyInstance . fire ( 'change' ) ;
120123 }
121124 } ;
122125
123- attrs . $observe ( 'disabled' , function ( disabled ) {
124- if ( disabled ) {
125- ensureInstance ( ) ;
126-
127- if ( tinyInstance ) {
128- tinyInstance . getBody ( ) . setAttribute ( 'contenteditable' , false ) ;
129- }
130- } else {
131- ensureInstance ( ) ;
132-
133- if ( tinyInstance ) {
134- tinyInstance . getBody ( ) . setAttribute ( 'contenteditable' , true ) ;
135- }
136- }
137- } ) ;
126+ attrs . $observe ( 'disabled' , toggleDisable ) ;
138127
139128 // This block is because of TinyMCE not playing well with removal and
140129 // recreation of instances, requiring instances to have different
@@ -166,6 +155,22 @@ angular.module('ui.tinymce', [])
166155 tinyInstance = tinymce . get ( attrs . id ) ;
167156 }
168157 }
158+
159+ function toggleDisable ( disabled ) {
160+ if ( disabled ) {
161+ ensureInstance ( ) ;
162+
163+ if ( tinyInstance ) {
164+ tinyInstance . getBody ( ) . setAttribute ( 'contenteditable' , false ) ;
165+ }
166+ } else {
167+ ensureInstance ( ) ;
168+
169+ if ( tinyInstance ) {
170+ tinyInstance . getBody ( ) . setAttribute ( 'contenteditable' , true ) ;
171+ }
172+ }
173+ }
169174 }
170175 } ;
171176 } ] ) ;
0 commit comments