forked from ionparticle/angular-ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-ckeditor.min.js
More file actions
55 lines (55 loc) · 3.03 KB
/
Copy pathangular-ckeditor.min.js
File metadata and controls
55 lines (55 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
!function(a,b){
// AMD
"function"==typeof define&&define.amd?define(["angular"],b):b(angular)}(this,function(a){/**
* CKEditor directive.
*
* @example
* <div ckeditor="options" ng-model="content" ready="onReady()"></div>
*/
function b(a){return{restrict:"A",require:["ckeditor","ngModel"],controller:["$scope","$element","$attrs","$parse","$q",c],link:function(b,c,e,f){
// get needed controllers
var g=f[0],h=f[1];
// Initialize the editor content when it is ready.
g.ready().then(function(){
// Sync view on specific events.
["change","blur","saveSnapshot"].forEach(function(a){g.onCKEvent(a,function(){h.$setViewValue(g.instance.getData()||"")})});var c=!0;["dataReady"].forEach(function(a){g.onCKEvent(a,function(){
// First time only that we receive the dataReady event and the control is pristine it should remain so
c&=h.$pristine,c&&(h.$pristine=!1),h.$setViewValue(g.instance.getData()||""),h.$commitViewValue(),c&&(c=!1,h.$pristine=!0)})}),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)})}),
// Set editor data when view data change.
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),/**
* 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,f)}},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