declare const CKEDITOR: any; export class HashiEmailEditorViewController { public static NAME = "HashiEmailEditorViewController"; public static NAME_AS = `${HashiEmailEditorViewController.NAME} as hashiEmailEditorViewController`; public static $inject = ["$scope", "$log"]; private _editor: any; private EMAIL_BODY_KEY: string = "emailBody"; constructor(private $scope: ng.IScope, private $log: ng.ILogService) { this._editor = (CKEDITOR as any).replace("editorDivToReplace"); this.setupConfig(); this.setupEvents(); } private setupConfig(): void { this._editor.config.allowedContent = { $1: { elements: (CKEDITOR as any).dtd, attributes: true, styles: true, classes: true } }; this._editor.config.disallowedContent = 'script; *[on*]; *[ng-*]; *[data-*]'; this._editor.config.removeButtons = "NewPage,Preview,Print,Templates,Save,Cut,Copy,Paste,PasteText," + "PasteFromWord,Redo,Undo,Find,Replace,SelectAll,Scayt," + "HiddenField,ImageButton,Button,Select,Textarea,TextField,Radio,Checkbox,Form," + "Strike,Underline,Subscript,Superscript,BidiLtr,BidiRtl,Language,Flash,Iframe," + "About,PageBreak,Styles,Font,FontSize,BGColor"; this._editor.config.width = "100%"; this._editor.config.height = 500; this._editor.config.toolbarGroups = [ { name: 'styles', groups: ['styles'] }, { name: 'clipboard', groups: ['clipboard', 'undo'] }, { name: 'editing', groups: ['find', 'selection', 'spellchecker', 'editing'] }, { name: 'forms', groups: ['forms'] }, { name: 'basicstyles', groups: ['basicstyles', 'cleanup'] }, { name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph'] }, { name: 'links', groups: ['links'] }, { name: 'insert', groups: ['insert'] }, { name: 'colors', groups: ['colors'] }, { name: 'document', groups: ['mode', 'document', 'doctools'] }, { name: 'tools', groups: ['tools'] }, { name: 'others', groups: ['others'] } ]; } private setupEvents() { var self = this; self._editor.on("instanceReady", (eventInfo: any) => { self.$log.log("EmailEditorViewController: instanceReady"); self._editor.setData(this.$scope[this.EMAIL_BODY_KEY]); self._editor.on("dataReady", () => { self.changesWereMade() }); self._editor.on("change", () => { self.changesWereMade() }); self._editor.on("key", () => { self.changesWereMade() }); }); } private changesWereMade() { this.$scope.$apply((scope: ng.IScope) => { scope[this.EMAIL_BODY_KEY] = this._editor.getData(); }); } }