From 8ca9f9a469b5f967c8a46fb7810b179aa7189924 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 7 Apr 2014 22:20:30 +0000 Subject: [PATCH] Store internal reference to CKEDITOR instance, fixes Uncaught TypeError: Cannot read property 'on' of undefined --- etemplate/js/et2_widget_htmlarea.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/etemplate/js/et2_widget_htmlarea.js b/etemplate/js/et2_widget_htmlarea.js index 46a9362358..1036ab4502 100644 --- a/etemplate/js/et2_widget_htmlarea.js +++ b/etemplate/js/et2_widget_htmlarea.js @@ -86,6 +86,9 @@ var et2_htmlarea = et2_inputWidget.extend( // _super.apply is responsible for the actual setting of the params (some magic) this._super.apply(this, arguments); + // CK instance + this.ckeditor = null; + // Allow no child widgets this.supportedWidgetClasses = []; this.htmlNode = $j(document.createElement("textarea")) @@ -111,15 +114,13 @@ var et2_htmlarea = et2_inputWidget.extend( doLoadingFinished: function() { this._super.apply(this, arguments); - if(this.mode == 'ascii') return; + if(this.mode == 'ascii' || this.ckeditor != null) return; var self = this; - var ckeditor; try { - CKEDITOR.replace(this.dom_id,jQuery.extend({},this.options.config,this.options)); - ckeditor = CKEDITOR.instances[this.dom_id]; - ckeditor.setData(self.value); + this.ckeditor = CKEDITOR.replace(this.dom_id,jQuery.extend({},this.options.config,this.options)); + this.ckeditor.setData(self.value); delete self.value; } catch (e) @@ -130,9 +131,8 @@ var et2_htmlarea = et2_inputWidget.extend( } if(this.htmlNode.ckeditor) { - CKEDITOR.replace(this.dom_id,this.options.config); - ckeditor = CKEDITOR.instances[this.dom_id]; - ckeditor.setData(self.value); + this.ckeditor = CKEDITOR.replace(this.dom_id,this.options.config); + this.ckeditor.setData(self.value); delete self.value; } } @@ -142,8 +142,8 @@ var et2_htmlarea = et2_inputWidget.extend( try { //this.htmlNode.ckeditorGet().destroy(true); - var ckeditor = CKEDITOR.instances[this.dom_id]; - if (ckeditor) ckeditor.destroy(true); + if (this.ckeditor) this.ckeditor.destroy(true); + this.ckeditor = null; } catch (e) {