diff --git a/src/app/@theme/components/tiny-mce/tiny-mce.component.ts b/src/app/@theme/components/tiny-mce/tiny-mce.component.ts new file mode 100644 index 00000000..fc7e2c02 --- /dev/null +++ b/src/app/@theme/components/tiny-mce/tiny-mce.component.ts @@ -0,0 +1,37 @@ +import { Component, OnDestroy, AfterViewInit, Output, EventEmitter, ElementRef } from '@angular/core'; +import { LocationStrategy } from '@angular/common'; + +@Component({ + selector: 'ngx-tiny-mce', + template: '', +}) +export class TinyMCEComponent implements OnDestroy, AfterViewInit { + + @Output() editorKeyup = new EventEmitter(); + + editor: any; + + constructor( + private host: ElementRef, + private locationStrategy: LocationStrategy, + ) { } + + ngAfterViewInit() { + tinymce.init({ + target: this.host.nativeElement, + plugins: ['link', 'paste', 'table'], + skin_url: `${this.locationStrategy.getBaseHref()}assets/skins/lightgray`, + setup: editor => { + this.editor = editor; + editor.on('keyup', () => { + this.editorKeyup.emit(editor.getContent()); + }); + }, + height: '320', + }); + } + + ngOnDestroy() { + tinymce.remove(this.editor); + } +}