Skip to content

Commit 35ffdcf

Browse files
author
Ilija Boshkov
committed
Merged pull requests lemonde#52, lemonde#49, lemonde#48
1 parent 086bb15 commit 35ffdcf

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ HTML:
3131
<script src="angular-ckeditor.js"></script>
3232

3333
<div ng-controller="CkeditorCtrl">
34-
<div ckeditor="options" ng-model="content" ready="onReady()"></div>
34+
<div ckeditor="options" ng-model="content" ready="onReady($instance)"></div>
3535
</div>
3636
```
3737

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

5151
// Called when the editor is completely ready.
52-
$scope.onReady = function () {
52+
$scope.onReady = function ($instance) {
5353
// ...
5454
};
5555
}]);
@@ -69,7 +69,10 @@ Angular-ckeditor uses `ng-model`. If you add an `ng-if` on the element to whom t
6969
## Advanced usage
7070

7171
### getting internal ckeditor instance
72-
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).
72+
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
73+
`CKEditor.instances`, be sure to give them a unique id="..." (Beware of re-usable directives).
74+
75+
You can use the injected $instance that is passed into your ready function or
7376

7477
In a directive on the same element, you can also use :
7578
```javascript

angular-ckeditor.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,28 @@
4141
// Initialize the editor content when it is ready.
4242
controller.ready().then(function initialize() {
4343
// Sync view on specific events.
44-
['dataReady', 'change', 'blur', 'saveSnapshot'].forEach(function (event) {
44+
['change', 'input', 'blur', 'saveSnapshot', 'key', 'paste', 'selectionChange'].forEach(function (event) {
4545
controller.onCKEvent(event, function syncView() {
4646
ngModelController.$setViewValue(controller.instance.getData() || '');
4747
});
4848
});
49+
var firstTime = true;
50+
['dataReady'].forEach(function (event) {
51+
controller.onCKEvent(event, function syncView() {
52+
// First time only that we receive the dataReady event and the control is pristine it should remain so
53+
firstTime &= ngModelController.$pristine;
54+
if (firstTime) {
55+
ngModelController.$pristine = false; // Prevent the model change setting the form dirty.
56+
}
57+
ngModelController.$setViewValue(controller.instance.getData() || '');
58+
ngModelController.$commitViewValue();
59+
if (firstTime) {
60+
firstTime = false;
61+
ngModelController.$pristine = true;
62+
}
63+
});
64+
});
65+
4966

5067
controller.instance.setReadOnly(!! attrs.readonly);
5168
attrs.$observe('readonly', function (readonly) {

angular-ckeditor.min.js

Lines changed: 29 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular-ckeditor.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/angular-ckeditor.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('CKEditor directive', function () {
1616

1717
createElement = function () {
1818
element = $compile(
19-
'<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
19+
'<div contenteditable="true" ckeditor ng-model="content" ready="onReady($instance)"></div>'
2020
)(scope);
2121
};
2222
}));
@@ -61,7 +61,10 @@ describe('CKEditor directive', function () {
6161

6262
it('should call the ready callback on start', function (done) {
6363
scope.content = 'Hello';
64-
scope.onReady = done;
64+
scope.onReady = function ($instance) {
65+
expect($instance).to.deep.equal(_.find(CKEDITOR.instances));
66+
done();
67+
};
6568

6669
createElement();
6770
});

0 commit comments

Comments
 (0)