Skip to content

Commit f65969f

Browse files
committed
Merge branch 'master' of github.com:froala/angular-froala
2 parents 06f4464 + 89932b4 commit f65969f

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-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: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,39 @@ 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?
46-
element.froalaEditor('undo.reset');
47-
element.froalaEditor('undo.saveStep');
44+
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?
47+
element.froalaEditor('undo.reset');
48+
element.froalaEditor('undo.saveStep');
49+
}
4850
};
4951

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

53-
var isEmpty = element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
54-
return isEmpty;
57+
var isEmpty = element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
58+
return isEmpty;
5559
};
5660
};
5761

58-
ctrl.createEditor = function () {
62+
ctrl.createEditor = function (froalaInitOptions) {
5963
ctrl.listeningEvents = ['froalaEditor'];
6064
if (!ctrl.editorInitialized) {
61-
ctrl.options = angular.extend({}, defaultConfig, froalaConfig, scope.froalaOptions);
65+
froalaInitOptions = (froalaInitOptions || {});
66+
ctrl.options = angular.extend({}, defaultConfig, froalaConfig, scope.froalaOptions,froalaInitOptions);
6267

6368
if (ctrl.options.immediateAngularModelUpdate) {
6469
ctrl.listeningEvents.push('keyup');
6570
}
6671

72+
ctrl.registerEventsWithCallbacks('froalaEditor.initialized', function() {
73+
ctrl.editorInitialized = true;
74+
ngModel.$render();
75+
});
76+
6777
// Register events provided in the options
6878
// Registering events before initializing the editor will bind the initialized event correctly.
6979
for (var eventName in ctrl.options.events) {
@@ -80,8 +90,6 @@ value('froalaConfig', {})
8090
if (scope.froalaOptions) {
8191
scope.froalaOptions.froalaEditor = ctrl.froalaEditor;
8292
}
83-
84-
ctrl.editorInitialized = ctrl.froalaEditor ? true : false;
8593
}
8694
};
8795

@@ -106,6 +114,9 @@ value('froalaConfig', {})
106114
var returnedHtml = element.froalaEditor('html.get');
107115
if (angular.isString(returnedHtml)) {
108116
ngModel.$setViewValue(returnedHtml);
117+
if (!scope.$root.$$phase) {
118+
scope.$apply();
119+
}
109120
}
110121
};
111122

test/angular-froala.spec.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("froala", function () {
5656
if (scope.froalaOptions === undefined) {
5757
scope.froalaOptions = {};
5858
}
59-
scope.froalaOptions.initOnClick = true;
59+
scope.froalaOptions.disableRightClick = true;
6060
scope.content = '';
6161
};
6262

@@ -88,7 +88,7 @@ describe("froala", function () {
8888
compileElement();
8989

9090
expect(froalaEditorStub.args[0][0].placeholderText).toEqual('Placeholder');
91-
expect(froalaEditorStub.args[0][0].initOnClick).toBeTruthy();
91+
expect(froalaEditorStub.args[0][0].disableRightClick).toBeTruthy();
9292
});
9393

9494
it('Uses default option values when no options are provided', function () {
@@ -150,6 +150,7 @@ describe("froala", function () {
150150
});
151151

152152
froalaEditorOnStub.callArgOn(1);
153+
$rootScope.$digest();
153154

154155
expect($rootScope.content).toEqual('My String');
155156
});
@@ -160,6 +161,7 @@ describe("froala", function () {
160161
});
161162

162163
element.trigger('froalaEditor.contentChanged');
164+
$rootScope.$digest();
163165

164166
expect($rootScope.content).toEqual('My String');
165167
});
@@ -169,6 +171,7 @@ describe("froala", function () {
169171

170172
$rootScope.content = '<i>New Text</i>';
171173
$rootScope.$digest();
174+
element.trigger('froalaEditor.initialized');
172175

173176
expect(froalaEditorStub.getCall(1).args[0]).toEqual('html.set');
174177
expect(froalaEditorStub.getCall(1).args[1]).toEqual('<i>New Text</i>');
@@ -217,9 +220,11 @@ describe("froala", function () {
217220
createEditorInManualMode();
218221

219222
$rootScope.initControls.initialize();
223+
element.trigger('froalaEditor.initialized');
224+
220225
$rootScope.initControls.initialize();
221226

222-
expect(froalaEditorStub.callCount).toEqual(1);
227+
expect(froalaEditorStub.callCount).toEqual(4); // 1 for creating editor and 3 after initialized event
223228
});
224229

225230
it('Can re-initialize the editor after closing it', function () {
@@ -297,12 +302,21 @@ describe("froala", function () {
297302

298303
});
299304

300-
it('Sets the view to the value of the model', function () {
305+
it('Sets the view to the value of the model', function () {
301306
$rootScope.content = '<i>New Text</i>';
302307

303308
compileViewElement();
304309
$rootScope.$digest();
305310

306311
expect(view.html()).toEqual("<i>New Text</i>");
307-
});
312+
});
313+
314+
it('Sets options when the editor is instantiated manually', function () {
315+
createEditorInManualMode();
316+
317+
$rootScope.initControls.initialize({initOnClick: false});
318+
319+
expect(froalaEditorStub.called).toBeTruthy();
320+
expect(froalaEditorStub.args[0][0].initOnClick).toBeFalsy();
321+
});
308322
});

0 commit comments

Comments
 (0)