diff --git a/README.md b/README.md
index 880f2da..e420fe8 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ HTML:
```
@@ -49,7 +49,7 @@ angular.module('controllers.ckeditor', ['ckeditor'])
};
// Called when the editor is completely ready.
- $scope.onReady = function () {
+ $scope.onReady = function ($instance) {
// ...
};
}]);
@@ -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) {
diff --git a/angular-ckeditor.js b/angular-ckeditor.js
index 5b7af1e..b7081bc 100644
--- a/angular-ckeditor.js
+++ b/angular-ckeditor.js
@@ -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) {
controller.onCKEvent(event, function syncView() {
ngModelController.$setViewValue(controller.instance.getData() || '');
});
@@ -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});
});
});
diff --git a/angular-ckeditor.min.js b/angular-ckeditor.min.js
index 22ca521..fa8c587 100644
--- a/angular-ckeditor.min.js
+++ b/angular-ckeditor.min.js
@@ -12,13 +12,17 @@ var g=f[0],h=f[1];
// Initialize the editor content when it is ready.
g.ready().then(function(){
// Sync view on specific events.
-["dataReady","change","blur","saveSnapshot"].forEach(function(a){g.onCKEvent(a,function(){h.$setViewValue(g.instance.getData()||"")})}),g.instance.setReadOnly(!!e.readonly),e.$observe("readonly",function(a){g.instance.setReadOnly(!!a)}),
+["dataReady","change","blur","saveSnapshot","selectionChange","paste"].forEach(function(a){g.onCKEvent(a,function(){h.$setViewValue(g.instance.getData()||"")})}),g.instance.setReadOnly(!!e.readonly),e.$observe("readonly",function(a){g.instance.setReadOnly(!!a)}),
// Defer the ready handler calling to ensure that the editor is
// completely ready and populated with data.
-d(function(){a(e.ready)(b)})}),
+d(function(){a(e.ready)(b,{$instance:g.instance})})}),
// Set editor data when view data change.
-h.$render=function(){g.ready().then(function(){g.instance.setData(h.$viewValue||"",{noSnapshot:!0,callback:function(){
-//Amends the top of the undo stack with the current DOM changes
+h.$render=function(){g.ready().then(function(){
+// "noSnapshot" prevent recording an undo snapshot
+g.instance.setData(h.$viewValue||"",{noSnapshot:!0,callback:function(){
+// Amends the top of the undo stack with the current DOM changes
+// ie: merge snapshot with the first empty one
+// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-updateSnapshot
g.instance.fire("updateSnapshot")}})})}}}}/**
* CKEditor controller.
*/
diff --git a/angular-ckeditor.min.js.map b/angular-ckeditor.min.js.map
index e8042f7..8e446d4 100644
--- a/angular-ckeditor.min.js.map
+++ b/angular-ckeditor.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["angular-ckeditor.js"],"names":["root","factory","define","amd","angular","this","ckeditorDirective","$parse","restrict","require","controller","ckeditorController","link","scope","element","attrs","ctrls","ngModelController","ready","then","forEach","event","onCKEvent","$setViewValue","instance","getData","setReadOnly","readonly","$observe","setImmediate","$render","setData","$viewValue","noSnapshot","callback","fire","$scope","$element","$attrs","$q","config","ckeditor","editorElement","readyDeferred","defer","hasAttribute","getAttribute","toLowerCase","CKEDITOR","inline","replace","listener","asyncListener","args","arguments","applyListener","apply","$apply","on","removeListener","resolve","promise","$on","destroy","module","directive","window","fn","setTimeout"],"mappings":"CAAC,SAAUA,EAAMC;;AAEO,kBAAXC,SAAyBA,OAAOC,IAAKD,QAAQ,WAAYD,GAE/DA,EAAQG,UACbC,KAAM,SAAUD;;;;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,KAInClD,KAAKiB,UAAU,gBAAiB,WAC9BqB,EAAciB,SAAQ,KAQxBvD,KAAKa,MAAQ,WACX,MAAOyB,GAAckB,SAIvBzB,EAAO0B,IAAI,WAAY,WAErBnB,EAAckB,QAAQ1C,KAAK,WACzBK,EAASuC,SAAQ,OA1IvB3D,EACC4D,OAAO,eACPC,UAAU,YAAa,SAAU3D;;AAGlC,GAAIuB,GAAeqC,QAAUA,OAAOrC,aAAeqC,OAAOrC,aAAe,SAAUsC,GACjFC,WAAWD,EAAI","file":"angular-ckeditor.min.js"}
\ No newline at end of file
+{"version":3,"sources":["angular-ckeditor.js"],"names":["root","factory","define","amd","angular","this","ckeditorDirective","$parse","restrict","require","controller","ckeditorController","link","scope","element","attrs","ctrls","ngModelController","ready","then","forEach","event","onCKEvent","$setViewValue","instance","getData","setReadOnly","readonly","$observe","setImmediate","$instance","$render","setData","$viewValue","noSnapshot","callback","fire","$scope","$element","$attrs","$q","config","ckeditor","editorElement","readyDeferred","defer","hasAttribute","getAttribute","toLowerCase","CKEDITOR","inline","replace","listener","asyncListener","args","arguments","applyListener","apply","$apply","on","removeListener","resolve","promise","$on","destroy","module","directive","window","fn","setTimeout"],"mappings":"CAAC,SAAUA,EAAMC;;AAEO,kBAAXC,SAAyBA,OAAOC,IAAKD,QAAQ,WAAYD,GAE/DA,EAAQG,UACbC,KAAM,SAAUD;;;;;;AAkBhB,QAASE,GAAkBC,GACzB,OACEC,SAAU,IACVC,SAAU,WAAY,WACtBC,YACE,SACA,WACA,SACA,SACA,KACAC,GAEFC,KAAM,SAAUC,EAAOC,EAASC,EAAOC;;AAErC,GAAIN,GAAaM,EAAM,GACnBC,EAAoBD,EAAM;;AAG9BN,EAAWQ,QAAQC,KAAK;;CAErB,YAAa,SAAU,OAAQ,eAAgB,kBAAmB,SAASC,QAAQ,SAAUC,GAC5FX,EAAWY,UAAUD,EAAO,WAC1BJ,EAAkBM,cAAcb,EAAWc,SAASC,WAAa,QAIrEf,EAAWc,SAASE,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-ckeditor.min.js"}
\ No newline at end of file
diff --git a/test/angular-ckeditor.js b/test/angular-ckeditor.js
index e93ff6d..72f1f33 100644
--- a/test/angular-ckeditor.js
+++ b/test/angular-ckeditor.js
@@ -16,7 +16,7 @@ describe('CKEditor directive', function () {
createElement = function () {
element = $compile(
- ''
+ ''
)(scope);
};
}));
@@ -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();
});