Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.
Open
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ HTML:
<script src="angular-ckeditor.js"></script>

<div ng-controller="CkeditorCtrl">
<div ckeditor="options" ng-model="content" ready="onReady()"></div>
<div ckeditor="options" ng-model="content" ready="onReady($instance)"></div>
</div>
```

Expand All @@ -49,7 +49,7 @@ angular.module('controllers.ckeditor', ['ckeditor'])
};

// Called when the editor is completely ready.
$scope.onReady = function () {
$scope.onReady = function ($instance) {
// ...
};
}]);
Expand All @@ -71,6 +71,8 @@ Angular-ckeditor uses `ng-model`. If you add an `ng-if` on the element to whom t
### getting internal ckeditor instance
Internally, CKEditor gives a name to its instances, either **the id of the element it's on** or automatic name (editor1, editor2...). If you plan to look for your instances programmatically via `CKEditor.istances`, be sure to give them a unique id="..." (Beware of re-usable directives).

You can use the injected $instance that is passed into your ready function or

In a directive on the same element, you can also use :
```javascript
link: function (scope, element) {
Expand Down
4 changes: 2 additions & 2 deletions angular-ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// Initialize the editor content when it is ready.
controller.ready().then(function initialize() {
// Sync view on specific events.
['dataReady', 'change', 'blur', 'saveSnapshot'].forEach(function (event) {
['dataReady', 'change', 'blur', 'saveSnapshot', 'selectionChange', 'paste'].forEach(function (event) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why model should be sync on selectionChange event ?

controller.onCKEvent(event, function syncView() {
ngModelController.$setViewValue(controller.instance.getData() || '');
});
Expand All @@ -55,7 +55,7 @@
// Defer the ready handler calling to ensure that the editor is
// completely ready and populated with data.
setImmediate(function () {
$parse(attrs.ready)(scope);
$parse(attrs.ready)(scope, {$instance: controller.instance});
});
});

Expand Down
12 changes: 8 additions & 4 deletions angular-ckeditor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion angular-ckeditor.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions test/angular-ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('CKEditor directive', function () {

createElement = function () {
element = $compile(
'<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
'<div contenteditable="true" ckeditor ng-model="content" ready="onReady($instance)"></div>'
)(scope);
};
}));
Expand Down Expand Up @@ -61,8 +61,10 @@ describe('CKEditor directive', function () {

it('should call the ready callback on start', function (done) {
scope.content = 'Hello';
scope.onReady = done;

scope.onReady = function ($instance) {
expect($instance).to.deep.equal(_.find(CKEDITOR.instances));
done();
};
createElement();
});

Expand Down