diff --git a/angular-ckeditor.js b/angular-ckeditor.js index 5b7af1e..6ba0413 100644 --- a/angular-ckeditor.js +++ b/angular-ckeditor.js @@ -125,7 +125,7 @@ // Return the deregistration function return function $off() { - instance.removeListener(event, applyListener); + instance.removeListener(event, asyncListener); }; }; diff --git a/angular-ckeditor.min.js b/angular-ckeditor.min.js index 22ca521..22caa31 100644 --- a/angular-ckeditor.min.js +++ b/angular-ckeditor.min.js @@ -17,14 +17,37 @@ g.ready().then(function(){ // completely ready and populated with data. d(function(){a(e.ready)(b)})}), // 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. */ function c(a,b,c,e,f){var g,h=e(c.ckeditor)(a)||{},i=b[0],j=f.defer();// a deferred to be resolved when the editor is ready // Create editor instance. -g=i.hasAttribute("contenteditable")&&"true"==i.getAttribute("contenteditable").toLowerCase()?this.instance=CKEDITOR.inline(i,h):this.instance=CKEDITOR.replace(i,h),this.onCKEvent=function(b,c){function e(){var a=arguments;d(function(){f.apply(null,a)})}function f(){var b=arguments;a.$apply(function(){c.apply(null,b)})}return g.on(b,e),function(){g.removeListener(b,f)}},this.onCKEvent("instanceReady",function(){j.resolve(!0)}),this.ready=function(){return j.promise},a.$on("$destroy",function(){j.promise.then(function(){g.destroy(!1)})})}a.module("ckeditor",[]).directive("ckeditor",["$parse",b]); +g=i.hasAttribute("contenteditable")&&"true"==i.getAttribute("contenteditable").toLowerCase()?this.instance=CKEDITOR.inline(i,h):this.instance=CKEDITOR.replace(i,h),/** + * Listen on events of a given type. + * This make all event asynchronous and wrapped in $scope.$apply. + * + * @param {String} event + * @param {Function} listener + * @returns {Function} Deregistration function for this listener. + */ +this.onCKEvent=function(b,c){function e(){var a=arguments;d(function(){f.apply(null,a)})}function f(){var b=arguments;a.$apply(function(){c.apply(null,b)})} +// Return the deregistration function +return g.on(b,e),function(){g.removeListener(b,e)}},this.onCKEvent("instanceReady",function(){j.resolve(!0)}),/** + * Check if the editor if ready. + * + * @returns {Promise} + */ +this.ready=function(){return j.promise}, +// Destroy editor when the scope is destroyed. +a.$on("$destroy",function(){ +// do not delete too fast or pending events will throw errors +j.promise.then(function(){g.destroy(!1)})})}a.module("ckeditor",[]).directive("ckeditor",["$parse",b]); // Polyfill setImmediate function. var d=window&&window.setImmediate?window.setImmediate:function(a){setTimeout(a,0)}}); //# sourceMappingURL=angular-ckeditor.min.js.map \ No newline at end of file diff --git a/angular-ckeditor.min.js.map b/angular-ckeditor.min.js.map index e8042f7..297b5c0 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;;;;;;AAkBhB,QAASE,GAAkBC,GACzB,OACEC,SAAU,IACVC,SAAU,WAAY,WACtBC,YACE,SACA,WACA,SACA,SAC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B,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","$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,gBAAgBC,QAAQ,SAAUC,GAChEX,EAAWY,UAAUD,EAAO,WAC1BJ,EAAkBM,cAAcb,EAAWc,SAASC,WAAa,QAIrEf,EAAWc,SAASE,cAAeX,EAAMY,UACzCZ,EAAMa,SAAS,WAAY,SAAUD,GACnCjB,EAAWc,SAASE,cAAeC;;;AAKrCE,EAAa,WACXtB,EAAOQ,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