8282 else {
8383 if ( ctrl . editorInitialized ) {
8484 // Set HTML.
85- element . froalaEditor ( 'html.set' , ngModel . $viewValue || '' , true ) ;
86-
85+ element . froalaEditor . html . set ( ngModel . $viewValue || '' )
8786 //This will reset the undo stack everytime the model changes externally. Can we fix this?
88- element . froalaEditor ( ' undo.reset' ) ;
89- element . froalaEditor ( ' undo.saveStep' ) ;
87+ element . froalaEditor . undo . reset ( ) ;
88+ element . froalaEditor . undo . saveStep ( ) ;
9089 }
9190 }
9291 } ;
9796 }
9897
9998 if ( ctrl . editorInitialized ) {
100- return element . froalaEditor ( ' node.isEmpty' , jQuery ( '<div>' + value + '</div>' ) . get ( 0 ) ) ;
99+ return element . froalaEditor . node . isEmpty ( jQuery ( '<div>' + value + '</div>' ) ) . get ( 0 ) ;
101100 }
102101
103102 return true ;
110109 froalaInitOptions = ( froalaInitOptions || { } ) ;
111110 ctrl . options = angular . extend ( { } , defaultConfig , froalaConfig , scope . froalaOptions , froalaInitOptions ) ;
112111
113- ctrl . registerEventsWithCallbacks ( 'froalaEditor. initializationDelayed' , function ( ) {
112+ ctrl . registerEventsWithCallbacks ( 'initializationDelayed' , function ( ) {
114113 ngModel . $render ( )
115114 } ) ;
116115
117- ctrl . registerEventsWithCallbacks ( 'froalaEditor. initialized' , function ( ) {
116+ ctrl . registerEventsWithCallbacks ( 'initialized' , function ( ) {
118117 ctrl . editorInitialized = true ;
119118 ngModel . $render ( )
120119 } )
127126 }
128127 }
129128
130- element . innerHTML =
131- ctrl . froalaElement = element . froalaEditor ( ctrl . options ) . data ( 'froala.editor' ) . $el ;
132- ctrl . froalaEditor = angular . bind ( element , element . froalaEditor ) ;
133- ctrl . initListeners ( ) ;
129+ ctrl . froalaEditor = element . froalaEditor = new FroalaEditor ( '#' + element . attr ( 'id' ) , ctrl . options ) ;
130+ element . innerHTML = ctrl . froalaElement = ctrl . froalaEditor . $el [ 0 ] ;
131+ ctrl . initListeners ( ) ;
134132
135133 //assign the froala instance to the options object to make methods available in parent scope
136134 if ( scope . froalaOptions ) {
141139
142140 ctrl . initListeners = function ( ) {
143141 if ( ctrl . options . immediateAngularModelUpdate ) {
144- ctrl . froalaElement . on ( 'froalaEditor. keyup', function ( ) {
142+ ctrl . registerEventsWithCallbacks ( ' keyup', function ( ) {
145143 scope . $evalAsync ( ctrl . updateModelView ) ;
146144 } ) ;
147145 }
148146
149- element . on ( 'froalaEditor. contentChanged', function ( ) {
147+ ctrl . registerEventsWithCallbacks ( ' contentChanged', function ( ) {
150148 scope . $evalAsync ( ctrl . updateModelView ) ;
151149 } ) ;
152150
153151 element . bind ( '$destroy' , function ( ) {
154152 if ( element ) {
155- element . froalaEditor ( ' destroy' ) ;
153+ element . froalaEditor . destroy ( ) ;
156154 element = null ;
157155 }
158156 } ) ;
159157 } ;
160158
161159 ctrl . updateModelView = function ( ) {
160+ if ( ! element ) {
161+ return ;
162+ }
162163
163164 var modelContent = null ;
164165
178179 }
179180 modelContent = attrs ;
180181 } else {
181- var returnedHtml = element . froalaEditor ( ' html.get' ) ;
182+ var returnedHtml = element . froalaEditor . html . get ( ) ;
182183 if ( angular . isString ( returnedHtml ) ) {
183184 modelContent = returnedHtml ;
184185 }
193194 ctrl . registerEventsWithCallbacks = function ( eventName , callback ) {
194195 if ( eventName && callback ) {
195196 ctrl . listeningEvents . push ( eventName ) ;
196- element . on ( eventName , callback ) ;
197+ if ( ! ctrl . options . events ) {
198+ ctrl . options . events = { } ;
199+ }
200+ ctrl . options . events [ eventName ] = callback ;
197201 }
198202 } ;
199203
203207 initialize : ctrl . createEditor ,
204208 destroy : function ( ) {
205209 if ( _ctrl . froalaEditor ) {
206- _ctrl . froalaEditor ( ' destroy' ) ;
210+ _ctrl . froalaEditor . destroy ( ) ;
207211 _ctrl . editorInitialized = false ;
208212 }
209213 } ,
234238 }
235239 } ;
236240 } ] ) ;
237- } ) ( window , window . angular , window . jQuery ) ;
241+ } ) ( window , window . angular , window . jQuery ) ;
0 commit comments