angular-froala-wysiwyg 4.0.18 → 4.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FroalaEditorDirective","el","zone","this","_opts","immediateAngularModelUpdate","angularIgnoreAttrs","SPECIAL_TAGS","INNER_HTML_ATTR","_hasSpecialTag","_editorInitialized","_oldModel","onChange","_","onTouched","froalaModelChange","EventEmitter","froalaInit","element","nativeElement","indexOf","tagName","toLowerCase","_element","prototype","writeValue","content","updateEditor","registerOnChange","fn","registerOnTouched","Object","defineProperty","opts","clone","assign","item","result","me","Number","String","Boolean","forEach","type","toString","call","child","index","array","nodeType","cloneNode","Date","i","JSON","stringify","_model","setContent","_editor","html","set","innerHTML","updateModel","_this","run","modelContent","attributeNodes","attributes","attrs","length","attrName","name","value","returnedHtml","get","emit","registerEvent","eventName","callback","events","initListeners","self","on","setTimeout","createEditor","runOutsideAngular","initialized","existingInitCallback","overridden","FroalaEditor","setHtml","undo","reset","saveStep","firstTime","tags","attr","hasOwnProperty","setAttribute","destroyEditor","destroy","getEditor","generateManualController","controls","initialize","bind","ngAfterViewInit","observers","ngOnDestroy","setDisabledState","isDisabled","Directive","args","selector","exportAs","providers","provide","NG_VALUE_ACCESSOR","useExisting","forwardRef","multi","ElementRef","NgZone","Input","Output","FroalaEditorModule","forRoot","ngModule","NgModule","declarations","exports","FroalaViewDirective","renderer","addClass","Renderer2","FroalaViewModule","imports"],"sources":["../../projects/library/src/editor/editor.directive.ts","../../projects/library/src/editor/editor.module.ts","../../projects/library/src/view/view.directive.ts","../../projects/library/src/view/view.module.ts","../../projects/library/src/fe-root.module.ts"],"sourcesContent":["import { ControlValueAccessor, NG_VALUE_ACCESSOR } from \"@angular/forms\";\nimport { Directive, ElementRef, EventEmitter, forwardRef, Input, NgZone, Output } from '@angular/core';\n\nimport FroalaEditor from 'froala-editor';\n\n@Directive({\n selector: '[froalaEditor]',\n exportAs: 'froalaEditor',\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => FroalaEditorDirective),\n multi: true\n }\n ]\n})\nexport class FroalaEditorDirective implements ControlValueAccessor {\n\n // editor options\n private _opts: any = {\n immediateAngularModelUpdate: false,\n angularIgnoreAttrs: null\n };\n\n private _element: any;\n\n private SPECIAL_TAGS: string[] = ['img', 'button', 'input', 'a'];\n private INNER_HTML_ATTR: string = 'innerHTML';\n private _hasSpecialTag: boolean = false;\n\n // editor element\n private _editor: any;\n\n // initial editor content\n private _model: string;\n\n private _editorInitialized: boolean = false;\n\n private _oldModel: string = null;\n\n constructor(el: ElementRef, private zone: NgZone) {\n\n let element: any = el.nativeElement;\n\n // check if the element is a special tag\n if (this.SPECIAL_TAGS.indexOf(element.tagName.toLowerCase()) != -1) {\n this._hasSpecialTag = true;\n }\n this._element = element;\n\n this.zone = zone;\n }\n\n // Begin ControlValueAccesor methods.\n onChange = (_) => {\n };\n onTouched = () => {\n };\n\n // Form model content changed.\n writeValue(content: any): void {\n this.updateEditor(content);\n }\n\n registerOnChange(fn: (_: any) => void): void {\n this.onChange = fn;\n }\n\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n // End ControlValueAccesor methods.\n\n // froalaEditor directive as input: store the editor options\n @Input() set froalaEditor(opts: any) {\n this._opts = this.clone( opts || this._opts);\n this._opts = {...this._opts};\n }\n\n // TODO: replace clone method with better possible alternate \n private clone(item) {\n \tconst me = this; \n if (!item) { return item; } // null, undefined values check\n\n let types = [ Number, String, Boolean ], \n result;\n\n // normalizing primitives if someone did new String('aaa'), or new Number('444');\n types.forEach(function(type) {\n if (item instanceof type) {\n result = type( item );\n }\n });\n\n if (typeof result == \"undefined\") {\n if (Object.prototype.toString.call( item ) === \"[object Array]\") {\n result = [];\n item.forEach(function(child, index, array) { \n result[index] = me.clone( child );\n });\n } else if (typeof item == \"object\") {\n // testing that this is DOM\n if (item.nodeType && typeof item.cloneNode == \"function\") {\n result = item.cloneNode( true ); \n } else if (!item.prototype) { // check that this is a literal\n if (item instanceof Date) {\n result = new Date(item);\n } else {\n // it is an object literal\n result = {};\n for (var i in item) {\n result[i] = me.clone( item[i] );\n }\n }\n } else {\n if (false && item.constructor) {\n result = new item.constructor();\n } else {\n result = item;\n }\n }\n } else {\n result = item;\n }\n }\n return result;\n }\n // froalaModel directive as input: store initial editor content\n @Input() set froalaModel(content: any) {\n this.updateEditor(content);\n }\n\n // Update editor with model contents.\n private updateEditor(content: any) {\n if (JSON.stringify(this._oldModel) == JSON.stringify(content)) {\n return;\n }\n\n if (!this._hasSpecialTag) {\n this._oldModel = content;\n } else {\n this._model = content;\n }\n\n if (this._editorInitialized) {\n if (!this._hasSpecialTag) {\n this._editor.html.set(content);\n } else {\n this.setContent();\n }\n } else {\n if (!this._hasSpecialTag) {\n this._element.innerHTML = content || '';\n } else {\n this.setContent();\n }\n }\n }\n\n // froalaModel directive as output: update model if editor contentChanged\n @Output() froalaModelChange: EventEmitter<any> = new EventEmitter<any>();\n\n // froalaInit directive as output: send manual editor initialization\n @Output() froalaInit: EventEmitter<Object> = new EventEmitter<Object>();\n\n // update model if editor contentChanged\n private updateModel() {\n this.zone.run(() => {\n\n let modelContent: any = null;\n\n if (this._hasSpecialTag) {\n\n let attributeNodes = this._element.attributes;\n let attrs = {};\n\n for (let i = 0; i < attributeNodes.length; i++) {\n\n let attrName = attributeNodes[i].name;\n if (this._opts.angularIgnoreAttrs && this._opts.angularIgnoreAttrs.indexOf(attrName) != -1) {\n continue;\n }\n\n attrs[attrName] = attributeNodes[i].value;\n }\n\n if (this._element.innerHTML) {\n attrs[this.INNER_HTML_ATTR] = this._element.innerHTML;\n }\n\n modelContent = attrs;\n } else {\n\n let returnedHtml: any = this._editor.html.get();\n if (typeof returnedHtml === 'string') {\n modelContent = returnedHtml;\n }\n }\n if (this._oldModel !== modelContent) {\n this._oldModel = modelContent;\n\n // Update froalaModel.\n this.froalaModelChange.emit(modelContent);\n\n // Update form model.\n this.onChange(modelContent);\n }\n\n })\n }\n\n private registerEvent(eventName, callback) {\n if (!eventName || !callback) {\n return;\n }\n\n if (!this._opts.events) {\n this._opts.events = {};\n }\n\n this._opts.events[eventName] = callback;\n }\n\n private initListeners() {\n let self = this;\n // Check if we have events on the editor.\n if (this._editor.events) {\n // bind contentChange and keyup event to froalaModel\n this._editor.events.on('contentChanged', function () {\n self.updateModel();\n });\n this._editor.events.on('mousedown', function () {\n setTimeout(function () {\n self.onTouched();\n }, 0);\n });\n\n if (this._opts.immediateAngularModelUpdate) {\n this._editor.events.on('keyup', function () {\n setTimeout(function () {\n self.updateModel();\n }, 0);\n });\n }\n }\n\n this._editorInitialized = true;\n }\n\n private createEditor() {\n if (this._editorInitialized) {\n return;\n }\n\n this.setContent(true);\n\n // init editor\n this.zone.runOutsideAngular(() => {\n // Add listeners on initialized event.\n if (!this._opts.events) this._opts.events = {};\n\n // Register initialized event.\n this.registerEvent('initialized', this._opts.events && this._opts.events.initialized);\n const existingInitCallback = this._opts.events.initialized;\n // Default initialized event.\n if (!this._opts.events.initialized || !this._opts.events.initialized.overridden) {\n this._opts.events.initialized = () => {\n this.initListeners();\n existingInitCallback && existingInitCallback.call(this._editor, this);\n };\n this._opts.events.initialized.overridden = true;\n }\n\n // Initialize the Froala Editor.\n this._editor = new FroalaEditor(\n this._element,\n this._opts\n );\n });\n }\n\n private setHtml() {\n this._editor.html.set(this._model || \"\");\n\n // This will reset the undo stack everytime the model changes externally. Can we fix this?\n this._editor.undo.reset();\n this._editor.undo.saveStep();\n }\n\n private setContent(firstTime = false) {\n let self = this;\n\n // Set initial content\n if (this._model || this._model == '') {\n this._oldModel = this._model;\n if (this._hasSpecialTag) {\n\n let tags: Object = this._model;\n\n // add tags on element\n if (tags) {\n\n for (let attr in tags) {\n if (tags.hasOwnProperty(attr) && attr != this.INNER_HTML_ATTR) {\n this._element.setAttribute(attr, tags[attr]);\n }\n }\n\n if (tags.hasOwnProperty(this.INNER_HTML_ATTR)) {\n this._element.innerHTML = tags[this.INNER_HTML_ATTR];\n }\n }\n } else {\n if (firstTime) {\n this.registerEvent('initialized', function () {\n self.setHtml();\n });\n } else {\n self.setHtml();\n }\n }\n }\n }\n\n private destroyEditor() {\n if (this._editorInitialized) {\n this._editor.destroy();\n this._editorInitialized = false;\n }\n }\n\n private getEditor() {\n if (this._element) {\n return this._editor;\n }\n\n return null;\n }\n\n // send manual editor initialization\n private generateManualController() {\n let controls = {\n initialize: this.createEditor.bind(this),\n destroy: this.destroyEditor.bind(this),\n getEditor: this.getEditor.bind(this),\n };\n this.froalaInit.emit(controls);\n }\n\n // TODO not sure if ngOnInit is executed after @inputs\n ngAfterViewInit() {\n // check if output froalaInit is present. Maybe observers is private and should not be used?? TODO how to better test that an output directive is present.\n if (!this.froalaInit.observers.length) {\n this.createEditor();\n } else {\n this.generateManualController();\n }\n }\n\n ngOnDestroy() {\n this.destroyEditor();\n }\n\n setDisabledState(isDisabled: boolean): void {\n }\n}\n","import { NgModule, ModuleWithProviders } from '@angular/core';\n\nimport { FroalaEditorDirective } from './editor.directive';\n\n@NgModule({\n declarations: [FroalaEditorDirective],\n exports: [FroalaEditorDirective]\n})\n\nexport class FroalaEditorModule {\n public static forRoot(): ModuleWithProviders<FroalaEditorModule> {\n return {ngModule: FroalaEditorModule, providers: []};\n }\n}\n","import { Directive, ElementRef, Renderer2, Input } from '@angular/core';\n\n@Directive({\n selector: '[froalaView]'\n})\nexport class FroalaViewDirective {\n\n private _element: HTMLElement;\n\n constructor(private renderer: Renderer2, element: ElementRef) {\n this._element = element.nativeElement;\n }\n\n // update content model as it comes\n @Input() set froalaView(content: string) {\n this._element.innerHTML = content;\n }\n\n ngAfterViewInit() {\n this.renderer.addClass(this._element, \"fr-view\");\n }\n}\n","import { NgModule, ModuleWithProviders } from '@angular/core';\n\nimport { FroalaViewDirective } from './view.directive';\n\n@NgModule({\n declarations: [FroalaViewDirective],\n exports: [FroalaViewDirective]\n})\nexport class FroalaViewModule {\n public static forRoot(): ModuleWithProviders<FroalaViewModule> {\n return {ngModule: FroalaViewModule, providers: []};\n }\n}\n","import { NgModule } from '@angular/core';\nimport { FroalaEditorModule } from './editor/editor.module';\nimport { FroalaViewModule } from './view/view.module';\n\n@NgModule({\n imports: [\n FroalaEditorModule.forRoot(),\n FroalaViewModule.forRoot()\n ],\n exports: [\n FroalaEditorModule,\n FroalaViewModule\n ]\n})\nexport class FERootModule {\n\n}\n"],"mappings":"iiBAwCE,SAAAA,EAAYC,EAAwBC,GAAAC,KAAAD,OArB5BC,KAAAC,MAAa,CACnBC,6BAA6B,EAC7BC,mBAAoB,MAKdH,KAAAI,aAAyB,CAAC,MAAO,SAAU,QAAS,KACpDJ,KAAAK,gBAA0B,YAC1BL,KAAAM,gBAA0B,EAQ1BN,KAAAO,oBAA8B,EAE9BP,KAAAQ,UAAoB,KAgB5BR,KAAAS,SAAW,SAACC,G,EAEZV,KAAAW,UAAY,W,EAyGFX,KAAAY,kBAAuC,IAAIC,eAG3Cb,KAAAc,WAAmC,IAAID,eA1H/C,IAAIE,EAAejB,EAAGkB,eAG2C,GAA7DhB,KAAKI,aAAaa,QAAQF,EAAQG,QAAQC,iBAC5CnB,KAAKM,gBAAiB,GAExBN,KAAKoB,SAAWL,EAEhBf,KAAKD,KAAOA,C,QAUdF,EAAAwB,UAAAC,WAAA,SAAWC,GACTvB,KAAKwB,aAAaD,E,EAGpB1B,EAAAwB,UAAAI,iBAAA,SAAiBC,GACf1B,KAAKS,SAAWiB,C,EAGlB7B,EAAAwB,UAAAM,kBAAA,SAAkBD,GAChB1B,KAAKW,UAAYe,C,EAMnBE,OAAAC,eAAahC,EAAAwB,UAAA,eAAY,C,IAAzB,SAA0BS,GACxB9B,KAAKC,MAAQD,KAAK+B,MAAQD,GAAQ9B,KAAKC,OACvCD,KAAKC,MAAK2B,OAAAI,OAAA,GAAQhC,KAAKC,M,kCAIjBJ,EAAAwB,UAAAU,MAAA,SAAME,GACb,IAIOC,EAJDC,EAAK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,WAEnBI,QAAS,CACPL,EACAU,O"}
|
|
1
|
+
{"version":3,"sources":["../../projects/library/src/editor/editor.directive.ts","../../projects/library/src/editor/editor.module.ts","../../projects/library/src/view/view.directive.ts","../../projects/library/src/view/view.module.ts","../../projects/library/src/fe-root.module.ts"],"names":["FroalaEditorDirective","el","zone","this","_opts","immediateAngularModelUpdate","angularIgnoreAttrs","SPECIAL_TAGS","INNER_HTML_ATTR","_hasSpecialTag","_editorInitialized","_oldModel","onChange","_","onTouched","froalaModelChange","EventEmitter","froalaInit","element","nativeElement","indexOf","tagName","toLowerCase","_element","prototype","writeValue","content","updateEditor","registerOnChange","fn","registerOnTouched","Object","defineProperty","opts","clone","assign","item","result","me","Number","String","Boolean","forEach","type","toString","call","child","index","array","nodeType","cloneNode","Date","i","JSON","stringify","_model","setContent","_editor","html","set","innerHTML","updateModel","_this","run","modelContent","attributeNodes","attributes","attrs","length","attrName","name","value","returnedHtml","get","emit","registerEvent","eventName","callback","events","initListeners","self","on","setTimeout","createEditor","runOutsideAngular","initialized","existingInitCallback","overridden","FroalaEditor","setHtml","undo","reset","saveStep","firstTime","tags","attr","hasOwnProperty","setAttribute","destroyEditor","destroy","getEditor","generateManualController","controls","initialize","bind","ngAfterViewInit","observers","ngOnDestroy","setDisabledState","isDisabled","Directive","args","selector","exportAs","providers","provide","NG_VALUE_ACCESSOR","useExisting","forwardRef","multi","ElementRef","NgZone","Input","Output","FroalaEditorModule","forRoot","ngModule","NgModule","declarations","exports","FroalaViewDirective","renderer","addClass","Renderer2","FroalaViewModule","imports"],"mappings":"iiBAwCE,SAAAA,EAAYC,EAAwBC,GAAAC,KAAAD,KAAAA,EArB5BC,KAAAC,MAAa,CACnBC,6BAA6B,EAC7BC,mBAAoB,MAKdH,KAAAI,aAAyB,CAAC,MAAO,SAAU,QAAS,KACpDJ,KAAAK,gBAA0B,YAC1BL,KAAAM,gBAA0B,EAQ1BN,KAAAO,oBAA8B,EAE9BP,KAAAQ,UAAoB,KAgB5BR,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P,WACL,MAAO,CAACC,SAAUF,EAAoBV,UAAW,8BAPpDa,EAAAA,SAAQhB,KAAA,CAAC,CACRiB,aAAc,CAAChI,GACfiI,QAAS,CAACjI,wBCGV,SAAAkI,EAAoBC,EAAqBjH,GAArBf,KAAAgI,SAAAA,EAClBhI,KAAKoB,SAAWL,EAAQC,qBAI1BY,OAAAC,eAAakG,EAAA1G,UAAA,aAAU,KAAvB,SAAwBE,GACtBvB,KAAKoB,SAASqC,UAAYlC,mCAG5BwG,EAAA1G,UAAAiF,gBAAA,WACEtG,KAAKgI,SAASC,SAASjI,KAAKoB,SAAU,qCAjBzCuF,EAAAA,UAASC,KAAA,CAAC,CACTC,SAAU,4DAHoBqB,EAAAA,iBAAZb,EAAAA,kDAcjBE,EAAAA,0BCNH,SAAAY,YACgBA,EAAAT,QAAP,WACL,MAAO,CAACC,SAAUQ,EAAkBpB,UAAW,8BANlDa,EAAAA,SAAQhB,KAAA,CAAC,CACRiB,aAAc,CAACE,GACfD,QAAS,CAACC,aCQZ,iCAVCH,EAAAA,SAAQhB,KAAA,CAAC,CACRwB,QAAS,CACPX,EAAmBC,UACnBS,EAAiBT,WAEnBI,QAAS,CACPL,EACAU","sourcesContent":["import { ControlValueAccessor, NG_VALUE_ACCESSOR } from \"@angular/forms\";\nimport { Directive, ElementRef, EventEmitter, forwardRef, Input, NgZone, Output } from '@angular/core';\n\nimport FroalaEditor from 'froala-editor';\n\n@Directive({\n selector: '[froalaEditor]',\n exportAs: 'froalaEditor',\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => FroalaEditorDirective),\n multi: true\n }\n ]\n})\nexport class FroalaEditorDirective implements ControlValueAccessor {\n\n // editor options\n private _opts: any = {\n immediateAngularModelUpdate: false,\n angularIgnoreAttrs: null\n };\n\n private _element: any;\n\n private SPECIAL_TAGS: string[] = ['img', 'button', 'input', 'a'];\n private INNER_HTML_ATTR: string = 'innerHTML';\n private _hasSpecialTag: boolean = false;\n\n // editor element\n private _editor: any;\n\n // initial editor content\n private _model: string;\n\n private _editorInitialized: boolean = false;\n\n private _oldModel: string = null;\n\n constructor(el: ElementRef, private zone: NgZone) {\n\n let element: any = el.nativeElement;\n\n // check if the element is a special tag\n if (this.SPECIAL_TAGS.indexOf(element.tagName.toLowerCase()) != -1) {\n this._hasSpecialTag = true;\n }\n this._element = element;\n\n this.zone = zone;\n }\n\n // Begin ControlValueAccesor methods.\n onChange = (_) => {\n };\n onTouched = () => {\n };\n\n // Form model content changed.\n writeValue(content: any): void {\n this.updateEditor(content);\n }\n\n registerOnChange(fn: (_: any) => void): void {\n this.onChange = fn;\n }\n\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n // End ControlValueAccesor methods.\n\n // froalaEditor directive as input: store the editor options\n @Input() set froalaEditor(opts: any) {\n this._opts = this.clone( opts || this._opts);\n this._opts = {...this._opts};\n }\n\n // TODO: replace clone method with better possible alternate \n private clone(item) {\n \tconst me = this; \n if (!item) { return item; } // null, undefined values check\n\n let types = [ Number, String, Boolean ], \n result;\n\n // normalizing primitives if someone did new String('aaa'), or new Number('444');\n types.forEach(function(type) {\n if (item instanceof type) {\n result = type( item );\n }\n });\n\n if (typeof result == \"undefined\") {\n if (Object.prototype.toString.call( item ) === \"[object Array]\") {\n result = [];\n item.forEach(function(child, index, array) { \n result[index] = me.clone( child );\n });\n } else if (typeof item == \"object\") {\n // testing that this is DOM\n if (item.nodeType && typeof item.cloneNode == \"function\") {\n result = item.cloneNode( true ); \n } else if (!item.prototype) { // check that this is a literal\n if (item instanceof Date) {\n result = new Date(item);\n } else {\n // it is an object literal\n result = {};\n for (var i in item) {\n result[i] = me.clone( item[i] );\n }\n }\n } else {\n if (false && item.constructor) {\n result = new item.constructor();\n } else {\n result = item;\n }\n }\n } else {\n result = item;\n }\n }\n return result;\n }\n // froalaModel directive as input: store initial editor content\n @Input() set froalaModel(content: any) {\n this.updateEditor(content);\n }\n\n // Update editor with model contents.\n private updateEditor(content: any) {\n if (JSON.stringify(this._oldModel) == JSON.stringify(content)) {\n return;\n }\n\n if (!this._hasSpecialTag) {\n this._oldModel = content;\n } else {\n this._model = content;\n }\n\n if (this._editorInitialized) {\n if (!this._hasSpecialTag) {\n this._editor.html.set(content);\n } else {\n this.setContent();\n }\n } else {\n if (!this._hasSpecialTag) {\n this._element.innerHTML = content || '';\n } else {\n this.setContent();\n }\n }\n }\n\n // froalaModel directive as output: update model if editor contentChanged\n @Output() froalaModelChange: EventEmitter<any> = new EventEmitter<any>();\n\n // froalaInit directive as output: send manual editor initialization\n @Output() froalaInit: EventEmitter<Object> = new EventEmitter<Object>();\n\n // update model if editor contentChanged\n private updateModel() {\n this.zone.run(() => {\n\n let modelContent: any = null;\n\n if (this._hasSpecialTag) {\n\n let attributeNodes = this._element.attributes;\n let attrs = {};\n\n for (let i = 0; i < attributeNodes.length; i++) {\n\n let attrName = attributeNodes[i].name;\n if (this._opts.angularIgnoreAttrs && this._opts.angularIgnoreAttrs.indexOf(attrName) != -1) {\n continue;\n }\n\n attrs[attrName] = attributeNodes[i].value;\n }\n\n if (this._element.innerHTML) {\n attrs[this.INNER_HTML_ATTR] = this._element.innerHTML;\n }\n\n modelContent = attrs;\n } else {\n\n let returnedHtml: any = this._editor.html.get();\n if (typeof returnedHtml === 'string') {\n modelContent = returnedHtml;\n }\n }\n if (this._oldModel !== modelContent) {\n this._oldModel = modelContent;\n\n // Update froalaModel.\n this.froalaModelChange.emit(modelContent);\n\n // Update form model.\n this.onChange(modelContent);\n }\n\n })\n }\n\n private registerEvent(eventName, callback) {\n if (!eventName || !callback) {\n return;\n }\n\n if (!this._opts.events) {\n this._opts.events = {};\n }\n\n this._opts.events[eventName] = callback;\n }\n\n private initListeners() {\n let self = this;\n // Check if we have events on the editor.\n if (this._editor.events) {\n // bind contentChange and keyup event to froalaModel\n this._editor.events.on('contentChanged', function () {\n self.updateModel();\n });\n this._editor.events.on('mousedown', function () {\n setTimeout(function () {\n self.onTouched();\n }, 0);\n });\n\n if (this._opts.immediateAngularModelUpdate) {\n this._editor.events.on('keyup', function () {\n setTimeout(function () {\n self.updateModel();\n }, 0);\n });\n }\n }\n\n this._editorInitialized = true;\n }\n\n private createEditor() {\n if (this._editorInitialized) {\n return;\n }\n\n this.setContent(true);\n\n // init editor\n this.zone.runOutsideAngular(() => {\n // Add listeners on initialized event.\n if (!this._opts.events) this._opts.events = {};\n\n // Register initialized event.\n this.registerEvent('initialized', this._opts.events && this._opts.events.initialized);\n const existingInitCallback = this._opts.events.initialized;\n // Default initialized event.\n if (!this._opts.events.initialized || !this._opts.events.initialized.overridden) {\n this._opts.events.initialized = () => {\n this.initListeners();\n existingInitCallback && existingInitCallback.call(this._editor, this);\n };\n this._opts.events.initialized.overridden = true;\n }\n\n // Initialize the Froala Editor.\n this._editor = new FroalaEditor(\n this._element,\n this._opts\n );\n });\n }\n\n private setHtml() {\n this._editor.html.set(this._model || \"\");\n\n // This will reset the undo stack everytime the model changes externally. Can we fix this?\n this._editor.undo.reset();\n this._editor.undo.saveStep();\n }\n\n private setContent(firstTime = false) {\n let self = this;\n\n // Set initial content\n if (this._model || this._model == '') {\n this._oldModel = this._model;\n if (this._hasSpecialTag) {\n\n let tags: Object = this._model;\n\n // add tags on element\n if (tags) {\n\n for (let attr in tags) {\n if (tags.hasOwnProperty(attr) && attr != this.INNER_HTML_ATTR) {\n this._element.setAttribute(attr, tags[attr]);\n }\n }\n\n if (tags.hasOwnProperty(this.INNER_HTML_ATTR)) {\n this._element.innerHTML = tags[this.INNER_HTML_ATTR];\n }\n }\n } else {\n if (firstTime) {\n this.registerEvent('initialized', function () {\n self.setHtml();\n });\n } else {\n self.setHtml();\n }\n }\n }\n }\n\n private destroyEditor() {\n if (this._editorInitialized) {\n this._editor.destroy();\n this._editorInitialized = false;\n }\n }\n\n private getEditor() {\n if (this._element) {\n return this._editor;\n }\n\n return null;\n }\n\n // send manual editor initialization\n private generateManualController() {\n let controls = {\n initialize: this.createEditor.bind(this),\n destroy: this.destroyEditor.bind(this),\n getEditor: this.getEditor.bind(this),\n };\n this.froalaInit.emit(controls);\n }\n\n // TODO not sure if ngOnInit is executed after @inputs\n ngAfterViewInit() {\n // check if output froalaInit is present. Maybe observers is private and should not be used?? TODO how to better test that an output directive is present.\n if (!this.froalaInit.observers.length) {\n this.createEditor();\n } else {\n this.generateManualController();\n }\n }\n\n ngOnDestroy() {\n this.destroyEditor();\n }\n\n setDisabledState(isDisabled: boolean): void {\n }\n}\n","import { NgModule, ModuleWithProviders } from '@angular/core';\n\nimport { FroalaEditorDirective } from './editor.directive';\n\n@NgModule({\n declarations: [FroalaEditorDirective],\n exports: [FroalaEditorDirective]\n})\n\nexport class FroalaEditorModule {\n public static forRoot(): ModuleWithProviders<FroalaEditorModule> {\n return {ngModule: FroalaEditorModule, providers: []};\n }\n}\n","import { Directive, ElementRef, Renderer2, Input } from '@angular/core';\n\n@Directive({\n selector: '[froalaView]'\n})\nexport class FroalaViewDirective {\n\n private _element: HTMLElement;\n\n constructor(private renderer: Renderer2, element: ElementRef) {\n this._element = element.nativeElement;\n }\n\n // update content model as it comes\n @Input() set froalaView(content: string) {\n this._element.innerHTML = content;\n }\n\n ngAfterViewInit() {\n this.renderer.addClass(this._element, \"fr-view\");\n }\n}\n","import { NgModule, ModuleWithProviders } from '@angular/core';\n\nimport { FroalaViewDirective } from './view.directive';\n\n@NgModule({\n declarations: [FroalaViewDirective],\n exports: [FroalaViewDirective]\n})\nexport class FroalaViewModule {\n public static forRoot(): ModuleWithProviders<FroalaViewModule> {\n return {ngModule: FroalaViewModule, providers: []};\n }\n}\n","import { NgModule } from '@angular/core';\nimport { FroalaEditorModule } from './editor/editor.module';\nimport { FroalaViewModule } from './view/view.module';\n\n@NgModule({\n imports: [\n FroalaEditorModule.forRoot(),\n FroalaViewModule.forRoot()\n ],\n exports: [\n FroalaEditorModule,\n FroalaViewModule\n ]\n})\nexport class FERootModule {\n\n}\n"]}
|
package/package.json
CHANGED