diff --git a/lib/CKEditor.js b/lib/CKEditor.js index a6ad0f3..bd6bcea 100644 --- a/lib/CKEditor.js +++ b/lib/CKEditor.js @@ -110,10 +110,14 @@ var CKEditor = exports.CKEditor = (_dec = (0, _core.Component)({ * On component destroy */ value: function ngOnDestroy() { + var _this = this; + if (this.instance) { - this.instance.removeAllListeners(); - this.instance.destroy(); - this.instance = null; + setTimeout(function () { + _this.instance.removeAllListeners(); + _this.instance.destroy(); + _this.instance = null; + }); } } @@ -136,15 +140,15 @@ var CKEditor = exports.CKEditor = (_dec = (0, _core.Component)({ }, { key: 'updateValue', value: function updateValue(value) { - var _this = this; + var _this2 = this; this.zone.run(function () { - _this.value = value; + _this2.value = value; - _this.onChange(value); + _this2.onChange(value); - _this.onTouched(); - _this.change.emit(value); + _this2.onTouched(); + _this2.change.emit(value); }); } @@ -155,7 +159,7 @@ var CKEditor = exports.CKEditor = (_dec = (0, _core.Component)({ }, { key: 'ckeditorInit', value: function ckeditorInit(config) { - var _this2 = this; + var _this3 = this; if (!CKEDITOR) { console.error('Please include CKEditor in your page'); @@ -171,25 +175,25 @@ var CKEditor = exports.CKEditor = (_dec = (0, _core.Component)({ // listen for instanceReady event this.instance.on('instanceReady', function (evt) { // send the evt to the EventEmitter - _this2.ready.emit(evt); + _this3.ready.emit(evt); }); // CKEditor change event this.instance.on('change', function () { - _this2.onTouched(); - var value = _this2.instance.getData(); + _this3.onTouched(); + var value = _this3.instance.getData(); // Debounce update - if (_this2.debounce) { - if (_this2.debounceTimeout) clearTimeout(_this2.debounceTimeout); - _this2.debounceTimeout = setTimeout(function () { - _this2.updateValue(value); - _this2.debounceTimeout = null; - }, parseInt(_this2.debounce)); + if (_this3.debounce) { + if (_this3.debounceTimeout) clearTimeout(_this3.debounceTimeout); + _this3.debounceTimeout = setTimeout(function () { + _this3.updateValue(value); + _this3.debounceTimeout = null; + }, parseInt(_this3.debounce)); // Live update } else { - _this2.updateValue(value); + _this3.updateValue(value); } }); } diff --git a/lib/CKEditor.js.map b/lib/CKEditor.js.map index ed91aad..0106f1a 100644 --- a/lib/CKEditor.js.map +++ b/lib/CKEditor.js.map @@ -1 +1 @@ -{"version":3,"sources":["CKEditor.es6"],"names":[],"mappings":";;;;;;;;;yJAAA;;;AACA;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA,IAAM,kCAAkC,6CAEtC;AACE,eAAa,sBAAW;AAAA,WAAM,QAAN;AAAA,GAAX,CADf;AAEE,SAAO;AAFT,CAFsC,CAAxC;;AAQA;;;;;IAUa,Q,WAAA,Q,WALZ,qBAAU;AACT,YAAU,UADD;AAET,aAAW,CAAC,+BAAD,CAFF;AAGT;AAHS,CAAV,C,UAOE,kB,UACA,kB,UAEA,mB,UACA,mB,UACA,qBAAU,MAAV,C,UAeA,kB;;AARD;;;AAGA,oBAAY,IAAZ,EAAwB;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,SARxB,MAQwB,GARf,EAQe;AAAA,SAPxB,QAOwB,QAPxB,QAOwB;AAAA,SANxB,eAMwB,QANxB,eAMwB;AAAA,SALxB,IAKwB,QALxB,IAKwB;;AACtB,SAAK,IAAL,GAAY,IAAZ;AACD;;;;;;AAUD;;;kCAGa;AACX,UAAI,KAAK,QAAT,EAAmB;AACjB,aAAK,QAAL,CAAc,kBAAd;AACA,aAAK,QAAL,CAAc,OAAd;AACA,aAAK,QAAL,GAAgB,IAAhB;AACD;AACF;;AAED;;;;;;sCAGiB;AACf;AACA,UAAI,SAAS,KAAK,MAAL,IAAe,EAA5B;AACA,WAAK,YAAL,CAAkB,MAAlB;AACD;;AAED;;;;;;gCAGY,K,EAAM;AAAA;;AAChB,WAAK,IAAL,CAAU,GAAV,CAAc,YAAM;AAClB,cAAK,KAAL,GAAa,KAAb;;AAEA,cAAK,QAAL,CAAc,KAAd;;AAEA,cAAK,SAAL;AACA,cAAK,MAAL,CAAY,IAAZ,CAAiB,KAAjB;AACD,OAPD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EAAuB;AACrB,aAAK,MAAL,GAAc,CAAd;AACA,aAAK,QAAL,CAAc,CAAd;AACD;AACF;;;;;;;gBAzBQ,M;;;;;gBACA,Q;;;;;WAEU,wB;;;;;WACD,wB;;;;;gBACC,I;;;4DAPR,Q","file":"CKEditor.js","sourcesContent":["// Imports\nimport {\n Component,\n Input,\n Output,\n ElementRef,\n ViewChild,\n Optional,\n EventEmitter,\n NgZone,\n Provider,\n forwardRef,\n Renderer\n} from '@angular/core';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\n\n// Control Value accessor provider\nconst CKEDITOR_CONTROL_VALUE_ACCESSOR = new Provider(\n NG_VALUE_ACCESSOR,\n {\n useExisting: forwardRef(() => CKEditor),\n multi: true\n }\n);\n\n/**\n * CKEditor component\n * Usage :\n * \n */\n@Component({\n selector: 'ckeditor',\n providers: [CKEDITOR_CONTROL_VALUE_ACCESSOR],\n template: ``,\n})\nexport class CKEditor {\n\n @Input() config;\n @Input() debounce;\n\n @Output() change = new EventEmitter();\n @Output() ready = new EventEmitter();\n @ViewChild('host') host;\n\n _value = '';\n instance;\n debounceTimeout;\n zone;\n\n /**\n * Constructor\n */\n constructor(zone:NgZone){\n this.zone = zone;\n }\n\n get value(): any { return this._value; };\n @Input() set value(v) {\n if (v !== this._value) {\n this._value = v;\n this.onChange(v);\n }\n }\n\n /**\n * On component destroy\n */\n ngOnDestroy(){\n if (this.instance) {\n this.instance.removeAllListeners();\n this.instance.destroy();\n this.instance = null;\n }\n }\n\n /**\n * On component view init\n */\n ngAfterViewInit(){\n // Configuration\n var config = this.config || {};\n this.ckeditorInit(config);\n }\n\n /**\n * Value update process\n */\n updateValue(value){\n this.zone.run(() => {\n this.value = value;\n\n this.onChange(value);\n\n this.onTouched();\n this.change.emit(value);\n });\n }\n\n /**\n * CKEditor init\n */\n ckeditorInit(config){\n if (!CKEDITOR) {\n console.error('Please include CKEditor in your page');\n return;\n }\n\n // CKEditor replace textarea\n this.instance = CKEDITOR.replace(this.host.nativeElement, config);\n\n // Set initial value\n this.instance.setData(this.value);\n\n // listen for instanceReady event\n this.instance.on('instanceReady', (evt) => {\n // send the evt to the EventEmitter\n this.ready.emit(evt);\n });\n\n // CKEditor change event\n this.instance.on('change', () => {\n this.onTouched();\n let value = this.instance.getData();\n\n // Debounce update\n if (this.debounce) {\n if(this.debounceTimeout) clearTimeout(this.debounceTimeout);\n this.debounceTimeout = setTimeout(() => {\n this.updateValue(value);\n this.debounceTimeout = null;\n }, parseInt(this.debounce));\n\n // Live update\n }else{\n this.updateValue(value);\n }\n });\n }\n\n /**\n * Implements ControlValueAccessor\n */\n writeValue(value){\n this._value = value;\n if (this.instance)\n this.instance.setData(value);\n }\n onChange(_){}\n onTouched(){}\n registerOnChange(fn){this.onChange = fn;}\n registerOnTouched(fn){this.onTouched = fn;}\n}\n"]} \ No newline at end of file +{"version":3,"sources":["CKEditor.es6"],"names":[],"mappings":";;;;;;;;;yJAAA;;;AACA;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA,IAAM,kCAAkC,6CAEtC;AACE,eAAa,sBAAW;AAAA,WAAM,QAAN;AAAA,GAAX,CADf;AAEE,SAAO;AAFT,CAFsC,CAAxC;;AAQA;;;;;IAUa,Q,WAAA,Q,WALZ,qBAAU;AACT,YAAU,UADD;AAET,aAAW,CAAC,+BAAD,CAFF;AAGT;AAHS,CAAV,C,UAOE,kB,UACA,kB,UAEA,mB,UACA,mB,UACA,qBAAU,MAAV,C,UAeA,kB;;AARD;;;AAGA,oBAAY,IAAZ,EAAwB;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,SARxB,MAQwB,GARf,EAQe;AAAA,SAPxB,QAOwB,QAPxB,QAOwB;AAAA,SANxB,eAMwB,QANxB,eAMwB;AAAA,SALxB,IAKwB,QALxB,IAKwB;;AACtB,SAAK,IAAL,GAAY,IAAZ;AACD;;;;;;AAUD;;;kCAGa;AAAA;;AACX,UAAI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Ad,CAHoB,CAAvB;;AAKF;AACC,SARD,MAQK;AACH,iBAAK,WAAL,CAAiB,KAAjB;AACD;AACF,OAhBD;AAiBD;;AAED;;;;;;+BAGW,K,EAAM;AACf,WAAK,MAAL,GAAc,KAAd;AACA,UAAI,KAAK,QAAT,EACE,KAAK,QAAL,CAAc,OAAd,CAAsB,KAAtB;AACH;;;6BACQ,C,EAAE,CAAE;;;gCACF,CAAE;;;qCACI,E,EAAG;AAAC,WAAK,QAAL,GAAgB,EAAhB;AAAoB;;;sCACvB,E,EAAG;AAAC,WAAK,SAAL,GAAiB,EAAjB;AAAqB;;;wBAhG1B;AAAE,aAAO,KAAK,MAAZ;AAAqB,K;sBACrB,C,EAAG;AACpB,UAAI,MAAM,KAAK,MAAf,EAAuB;AACrB,aAAK,MAAL,GAAc,CAAd;AACA,aAAK,QAAL,CAAc,CAAd;AACD;AACF;;;;;;;gBAzBQ,M;;;;;gBACA,Q;;;;;WAEU,wB;;;;;WACD,wB;;;;;gBACC,I;;;4DAPR,Q","file":"CKEditor.js","sourcesContent":["// Imports\nimport {\n Component,\n Input,\n Output,\n ElementRef,\n ViewChild,\n Optional,\n EventEmitter,\n NgZone,\n Provider,\n forwardRef,\n Renderer\n} from '@angular/core';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\n\n// Control Value accessor provider\nconst CKEDITOR_CONTROL_VALUE_ACCESSOR = new Provider(\n NG_VALUE_ACCESSOR,\n {\n useExisting: forwardRef(() => CKEditor),\n multi: true\n }\n);\n\n/**\n * CKEditor component\n * Usage :\n * \n */\n@Component({\n selector: 'ckeditor',\n providers: [CKEDITOR_CONTROL_VALUE_ACCESSOR],\n template: ``,\n})\nexport class CKEditor {\n\n @Input() config;\n @Input() debounce;\n\n @Output() change = new EventEmitter();\n @Output() ready = new EventEmitter();\n @ViewChild('host') host;\n\n _value = '';\n instance;\n debounceTimeout;\n zone;\n\n /**\n * Constructor\n */\n constructor(zone:NgZone){\n this.zone = zone;\n }\n\n get value(): any { return this._value; };\n @Input() set value(v) {\n if (v !== this._value) {\n this._value = v;\n this.onChange(v);\n }\n }\n\n /**\n * On component destroy\n */\n ngOnDestroy(){\n if (this.instance) {\n setTimeout(() => {\n this.instance.removeAllListeners();\n this.instance.destroy();\n this.instance = null;\n });\n }\n }\n\n /**\n * On component view init\n */\n ngAfterViewInit(){\n // Configuration\n var config = this.config || {};\n this.ckeditorInit(config);\n }\n\n /**\n * Value update process\n */\n updateValue(value){\n this.zone.run(() => {\n this.value = value;\n\n this.onChange(value);\n\n this.onTouched();\n this.change.emit(value);\n });\n }\n\n /**\n * CKEditor init\n */\n ckeditorInit(config){\n if (!CKEDITOR) {\n console.error('Please include CKEditor in your page');\n return;\n }\n\n // CKEditor replace textarea\n this.instance = CKEDITOR.replace(this.host.nativeElement, config);\n\n // Set initial value\n this.instance.setData(this.value);\n\n // listen for instanceReady event\n this.instance.on('instanceReady', (evt) => {\n // send the evt to the EventEmitter\n this.ready.emit(evt);\n });\n\n // CKEditor change event\n this.instance.on('change', () => {\n this.onTouched();\n let value = this.instance.getData();\n\n // Debounce update\n if (this.debounce) {\n if(this.debounceTimeout) clearTimeout(this.debounceTimeout);\n this.debounceTimeout = setTimeout(() => {\n this.updateValue(value);\n this.debounceTimeout = null;\n }, parseInt(this.debounce));\n\n // Live update\n }else{\n this.updateValue(value);\n }\n });\n }\n\n /**\n * Implements ControlValueAccessor\n */\n writeValue(value){\n this._value = value;\n if (this.instance)\n this.instance.setData(value);\n }\n onChange(_){}\n onTouched(){}\n registerOnChange(fn){this.onChange = fn;}\n registerOnTouched(fn){this.onTouched = fn;}\n}\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 1342040..7844b13 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-ckeditor", - "version": "1.0.5", + "version": "1.0.6", "description": "Angular2 CKEditor component", "main": "lib/CKEditor.js", "typings": "./CKEditor.d.ts", diff --git a/src/CKEditor.es6 b/src/CKEditor.es6 index 27345b8..b942231 100644 --- a/src/CKEditor.es6 +++ b/src/CKEditor.es6 @@ -67,9 +67,11 @@ export class CKEditor { */ ngOnDestroy(){ if (this.instance) { - this.instance.removeAllListeners(); - this.instance.destroy(); - this.instance = null; + setTimeout(() => { + this.instance.removeAllListeners(); + this.instance.destroy(); + this.instance = null; + }); } }