/* * author: Miller Augusto S. Martins * e-mail: miller.augusto@gmail.com * github: miamarti * */ !function(a,b){"use strict";angular.module("ng.ckeditor",["ng"]).directive("ngCkeditor",["$timeout",function(a){return CKEDITOR.on("instanceCreated",function(a){var b=a.editor,c=b.element;"simpleEditor"==c.getAttribute("class")&&b.on("configLoaded",function(){b.config.removePlugins="colorbutton,find,flash,font, forms,iframe,image,newpage,removeformat, smiley,specialchar,stylescombo,templates",b.removeButtons="About",b.config.toolbarGroups=[{name:"editing",groups:["basicstyles","links"]},{name:"undo"},{name:"clipboard",groups:["selection","clipboard"]}]})}),{restrict:"E",scope:{ngModel:"=ngModel",ngChange:"=ngChange",ngDisabled:"=ngDisabled",ngConfig:"=ngConfig"},link:function(b,c,d){c[0].innerHTML='
';var e=c[0].querySelectorAll(".ng-ckeditor"),f={removeButtons:void 0!=d.removeButtons?"About,"+d.removeButtons:"About",readOnly:b.ngDisabled?b.ngDisabled:!1};void 0!=d.removePlugins&&(f.removePlugins=d.removePlugins),void 0!=d.skin&&(f.skin=d.skin),void 0!=d.width&&(f.width=d.width),void 0!=d.height&&(f.height=d.height),void 0!=d.resizeEnabled&&(f.resize_enabled="false"==d.resizeEnabled?!1:!0);var g=CKEDITOR.appendTo(e[0],b.ngConfig?b.ngConfig:f,""),h=function(c){c.on("change",function(a){b.$apply(function(){b.ngModel=a.editor.getData()}),void 0!=d.msnCount&&(element[0].querySelector(".totalTypedCharacters").innerHTML=d.msnCount+" "+a.editor.getData().length),b.ngChange&&"function"==typeof b.ngChange&&b.ngChange(a.editor.getData())}),c.on("focus",function(a){c.setData(b.ngModel)}),c.on("key",function(c){a(function(){b.$apply(function(){b.ngModel=c.editor.getData()}),void 0!=d.msnCount&&(element[0].querySelector(".totalTypedCharacters").innerHTML=d.msnCount+" "+c.editor.getData().length),b.ngChange&&"function"==typeof b.ngChange&&b.ngChange(c.editor.getData())},0)})},i=void 0,j=function(a,b){i&&clearTimeout(i),i=setTimeout(function(){a&&b?b.setData(a):b&&b.setData("")},1e3)};h(g),b.$watch("ngModel",function(a){clearTimeout(i),a!==g.getData()&&j(a,g)}),b.$watch("ngDisabled",function(a){a?f.readOnly=!0:f.readOnly=!1,g.destroy(),g=CKEDITOR.appendTo(e[0],b.ngConfig?b.ngConfig:f,""),h(g),g.setData(b.ngModel)})}}}])}(window,document);