Skip to content

Commit 128bc40

Browse files
committed
Now waits for editor initialized event before sending commands. Avoids warnings given by editor.
1 parent ca535eb commit 128bc40

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
froala/*
3+
dist/*
34
bower_components/*
45
node_modules/*
56
npm-debug.log

src/angular-froala.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,21 @@ value('froalaConfig', {})
4141

4242
//Instruct ngModel how to update the froala editor
4343
ngModel.$render = function () {
44-
element.froalaEditor('html.set', ngModel.$viewValue || '', true);
45-
//This will reset the undo stack everytime the model changes externally. Can we fix this?
4644
if (ctrl.editorInitialized) {
45+
element.froalaEditor('html.set', ngModel.$viewValue || '', true);
46+
//This will reset the undo stack everytime the model changes externally. Can we fix this?
4747
element.froalaEditor('undo.reset');
4848
element.froalaEditor('undo.saveStep');
4949
}
5050
};
5151

5252
ngModel.$isEmpty = function (value) {
53-
if (!value) return true;
53+
if (!value) {
54+
return true;
55+
}
5456

55-
var isEmpty = element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
56-
return isEmpty;
57+
var isEmpty = element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
58+
return isEmpty;
5759
};
5860
};
5961

@@ -67,6 +69,11 @@ value('froalaConfig', {})
6769
ctrl.listeningEvents.push('keyup');
6870
}
6971

72+
ctrl.registerEventsWithCallbacks('froalaEditor.initialized', function() {
73+
ctrl.editorInitialized = true;
74+
ngModel.$render();
75+
});
76+
7077
// Register events provided in the options
7178
// Registering events before initializing the editor will bind the initialized event correctly.
7279
for (var eventName in ctrl.options.events) {
@@ -83,17 +90,7 @@ value('froalaConfig', {})
8390
if (scope.froalaOptions) {
8491
scope.froalaOptions.froalaEditor = ctrl.froalaEditor;
8592
}
86-
87-
if (ctrl.options.initOnClick) {
88-
ctrl.registerEventsWithCallbacks('froalaEditor.initialized', function() {
89-
ctrl.editorInitialized = true;
90-
});
91-
} else {
92-
ctrl.editorInitialized = ctrl.froalaEditor ? true : false;
93-
}
9493
}
95-
96-
9794
};
9895

9996
ctrl.initListeners = function () {

test/angular-froala.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ describe("froala", function () {
171171

172172
$rootScope.content = '<i>New Text</i>';
173173
$rootScope.$digest();
174+
element.trigger('froalaEditor.initialized');
174175

175176
expect(froalaEditorStub.getCall(1).args[0]).toEqual('html.set');
176177
expect(froalaEditorStub.getCall(1).args[1]).toEqual('<i>New Text</i>');
@@ -219,9 +220,11 @@ describe("froala", function () {
219220
createEditorInManualMode();
220221

221222
$rootScope.initControls.initialize();
223+
element.trigger('froalaEditor.initialized');
224+
222225
$rootScope.initControls.initialize();
223226

224-
expect(froalaEditorStub.callCount).toEqual(1);
227+
expect(froalaEditorStub.callCount).toEqual(4); // 1 for creating editor and 3 after initialized event
225228
});
226229

227230
it('Can re-initialize the editor after closing it', function () {

0 commit comments

Comments
 (0)