Skip to content

Commit

Permalink
Merged pull requests lemonde#52, lemonde#49, lemonde#48
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilija Boshkov committed Oct 17, 2016
1 parent 086bb15 commit 35ffdcf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
9 changes: 6 additions & 3 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 @@ -69,7 +69,10 @@ Angular-ckeditor uses `ng-model`. If you add an `ng-if` on the element to whom t
## Advanced usage

### 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).
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.instances`, 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
Expand Down
19 changes: 18 additions & 1 deletion angular-ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,28 @@
// 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) {
['change', 'input', 'blur', 'saveSnapshot', 'key', 'paste', 'selectionChange'].forEach(function (event) {
controller.onCKEvent(event, function syncView() {
ngModelController.$setViewValue(controller.instance.getData() || '');
});
});
var firstTime = true;
['dataReady'].forEach(function (event) {
controller.onCKEvent(event, function syncView() {
// First time only that we receive the dataReady event and the control is pristine it should remain so
firstTime &= ngModelController.$pristine;
if (firstTime) {
ngModelController.$pristine = false; // Prevent the model change setting the form dirty.
}
ngModelController.$setViewValue(controller.instance.getData() || '');
ngModelController.$commitViewValue();
if (firstTime) {
firstTime = false;
ngModelController.$pristine = true;
}
});
});


controller.instance.setReadOnly(!! attrs.readonly);
attrs.$observe('readonly', function (readonly) {
Expand Down
33 changes: 29 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.

7 changes: 5 additions & 2 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,7 +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

0 comments on commit 35ffdcf

Please sign in to comment.