Skip to content

Commit a7ca071

Browse files
Angular Changes to make it work with Non Jquery froala v.3
1 parent 4c2fbab commit a7ca071

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/angular-froala.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@
7777
else {
7878
if (ctrl.editorInitialized) {
7979
// Set HTML.
80-
element.froalaEditor('html.set', ngModel.$viewValue || '', true);
81-
80+
element.froalaEditor.html.set(ngModel.$viewValue || '')
8281
//This will reset the undo stack everytime the model changes externally. Can we fix this?
83-
element.froalaEditor('undo.reset');
84-
element.froalaEditor('undo.saveStep');
82+
element.froalaEditor.undo.reset();
83+
element.froalaEditor.undo.saveStep();
8584
}
8685
}
8786
};
@@ -92,7 +91,7 @@
9291
}
9392

9493
if (ctrl.editorInitialized) {
95-
return element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
94+
return element.froalaEditor.node.isEmpty(jQuery('<div>' + value + '</div>')).get(0);
9695
}
9796

9897
return true;
@@ -105,11 +104,11 @@
105104
froalaInitOptions = (froalaInitOptions || {});
106105
ctrl.options = angular.extend({}, defaultConfig, froalaConfig, scope.froalaOptions, froalaInitOptions);
107106

108-
ctrl.registerEventsWithCallbacks('froalaEditor.initializationDelayed', function() {
107+
ctrl.registerEventsWithCallbacks('initializationDelayed', function() {
109108
ngModel.$render()
110109
});
111110

112-
ctrl.registerEventsWithCallbacks('froalaEditor.initialized', function () {
111+
ctrl.registerEventsWithCallbacks('initialized', function () {
113112
ctrl.editorInitialized = true;
114113
ngModel.$render()
115114
})
@@ -122,10 +121,9 @@
122121
}
123122
}
124123

125-
element.innerHTML =
126-
ctrl.froalaElement = element.froalaEditor(ctrl.options).data('froala.editor').$el;
127-
ctrl.froalaEditor = angular.bind(element, element.froalaEditor);
128-
ctrl.initListeners();
124+
ctrl.froalaEditor = element.froalaEditor = new FroalaEditor('#'+element.attr('id'),ctrl.options);
125+
element.innerHTML = ctrl.froalaElement = ctrl.froalaEditor.$el[0];
126+
ctrl.initListeners();
129127

130128
//assign the froala instance to the options object to make methods available in parent scope
131129
if (scope.froalaOptions) {
@@ -136,18 +134,18 @@
136134

137135
ctrl.initListeners = function() {
138136
if (ctrl.options.immediateAngularModelUpdate) {
139-
ctrl.froalaElement.on('froalaEditor.keyup', function() {
137+
ctrl.registerEventsWithCallbacks('keyup', function() {
140138
scope.$evalAsync(ctrl.updateModelView);
141139
});
142140
}
143141

144-
element.on('froalaEditor.contentChanged', function() {
142+
ctrl.registerEventsWithCallbacks('contentChanged', function() {
145143
scope.$evalAsync(ctrl.updateModelView);
146144
});
147145

148146
element.bind('$destroy', function() {
149147
if (element) {
150-
element.froalaEditor('destroy');
148+
element.froalaEditor.destroy();
151149
element = null;
152150
}
153151
});
@@ -176,7 +174,7 @@
176174
}
177175
modelContent = attrs;
178176
} else {
179-
var returnedHtml = element.froalaEditor('html.get');
177+
var returnedHtml = element.froalaEditor.html.get();
180178
if (angular.isString(returnedHtml)) {
181179
modelContent = returnedHtml;
182180
}
@@ -191,7 +189,10 @@
191189
ctrl.registerEventsWithCallbacks = function(eventName, callback) {
192190
if (eventName && callback) {
193191
ctrl.listeningEvents.push(eventName);
194-
element.on(eventName, callback);
192+
if(!ctrl.options.events){
193+
ctrl.options.events = {};
194+
}
195+
ctrl.options.events[eventName] = callback;
195196
}
196197
};
197198

@@ -201,7 +202,7 @@
201202
initialize: ctrl.createEditor,
202203
destroy: function() {
203204
if (_ctrl.froalaEditor) {
204-
_ctrl.froalaEditor('destroy');
205+
_ctrl.froalaEditor.destroy();
205206
_ctrl.editorInitialized = false;
206207
}
207208
},

0 commit comments

Comments
 (0)