Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
froala/*
dist/*
bower_components/*
node_modules/*
npm-debug.log
27 changes: 12 additions & 15 deletions src/angular-froala.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ value('froalaConfig', {})

//Instruct ngModel how to update the froala editor
ngModel.$render = function () {
element.froalaEditor('html.set', ngModel.$viewValue || '', true);
//This will reset the undo stack everytime the model changes externally. Can we fix this?
if (ctrl.editorInitialized) {
element.froalaEditor('html.set', ngModel.$viewValue || '', true);
//This will reset the undo stack everytime the model changes externally. Can we fix this?
element.froalaEditor('undo.reset');
element.froalaEditor('undo.saveStep');
}
};

ngModel.$isEmpty = function (value) {
if (!value) return true;
if (!value) {
return true;
}

var isEmpty = element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
return isEmpty;
var isEmpty = element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
return isEmpty;
};
};

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

ctrl.registerEventsWithCallbacks('froalaEditor.initialized', function() {
ctrl.editorInitialized = true;
ngModel.$render();
});

// Register events provided in the options
// Registering events before initializing the editor will bind the initialized event correctly.
for (var eventName in ctrl.options.events) {
Expand All @@ -83,17 +90,7 @@ value('froalaConfig', {})
if (scope.froalaOptions) {
scope.froalaOptions.froalaEditor = ctrl.froalaEditor;
}

if (ctrl.options.initOnClick) {
ctrl.registerEventsWithCallbacks('froalaEditor.initialized', function() {
ctrl.editorInitialized = true;
});
} else {
ctrl.editorInitialized = ctrl.froalaEditor ? true : false;
}
}


};

ctrl.initListeners = function () {
Expand Down
5 changes: 4 additions & 1 deletion test/angular-froala.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ describe("froala", function () {

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

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

$rootScope.initControls.initialize();
element.trigger('froalaEditor.initialized');

$rootScope.initControls.initialize();

expect(froalaEditorStub.callCount).toEqual(1);
expect(froalaEditorStub.callCount).toEqual(4); // 1 for creating editor and 3 after initialized event
});

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