From 669e52a1f3ac28ac81535f20319198db87327ad6 Mon Sep 17 00:00:00 2001 From: Manuel Schweigert Date: Mon, 26 Sep 2016 16:44:22 +0200 Subject: [PATCH 1/2] Check for editor.destroyed before getting data Tinymce sends a last "nodechange" event when the DOM node has been removed, which will then result in an exception in `editor.getContent()` because the body is null. Insert this check to prevent this. --- knockout-tinymce.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/knockout-tinymce.coffee b/knockout-tinymce.coffee index b034131..4f3e8ce 100644 --- a/knockout-tinymce.coffee +++ b/knockout-tinymce.coffee @@ -86,6 +86,7 @@ editor.on "change keyup nodechange", (e) -> setTimeout (-> + return if editor.destroyed value = editor.getContent() cache = value cacheInstance = editor From 35318eab8ad33992d2cf303f968f74add09a6fcb Mon Sep 17 00:00:00 2001 From: Manuel-S Date: Mon, 26 Sep 2016 16:55:39 +0200 Subject: [PATCH 2/2] generated files --- knockout-tinymce.js | 3 +++ knockout-tinymce.min.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/knockout-tinymce.js b/knockout-tinymce.js index f911403..8043ad4 100644 --- a/knockout-tinymce.js +++ b/knockout-tinymce.js @@ -83,6 +83,9 @@ editor.on("change keyup nodechange", function(e) { return setTimeout((function() { var name, value; + if (editor.destroyed) { + return; + } value = editor.getContent(); cache = value; cacheInstance = editor; diff --git a/knockout-tinymce.min.js b/knockout-tinymce.min.js index ea79006..4eb8dd7 100644 --- a/knockout-tinymce.min.js +++ b/knockout-tinymce.min.js @@ -1 +1 @@ -(function(){!function(a,b){var c,d,e,f,g;d="",e=null,c={after:["attr","value"],defaults:{},extensions:{},init:function(d,g,h,i,j){var k,l,m,n;return k=a(d),m=h.has("tinymceConfig")?h.get("tinymceConfig"):null,l=h.has("tinymceExtensions")?h.get("tinymceExtensions"):[],n=f(c.defaults,l,m,arguments),k[k.is("input, textarea")?"text":"html"](b.unwrap(g())),setTimeout(function(){k.tinymce(n)},0),b.utils.domNodeDisposal.addDisposeCallback(d,function(){var b;b=a(d).tinymce(),b&&b.remove(),b===e&&(e=null)}),{controlsDescendantBindings:!0}},update:function(c,f,g,h,i){var j,k;j=a(c).tinymce(),k=b.unwrap(f()),null===k&&(k=""),!j||e===j&&d===k||(e=j,d=k,j.getContent()!==k&&j.setContent(k))}},g=function(a,c,d,e,f){var g;if(a&&b.isObservable(a)){if(b.isWriteableObservable(a)&&(!f||a.peek()!==e))return a(e)}else if(g=c.get("_ko_property_writers"),g&&g[d])return g[d](e)},f=function(f,h,i,j){var k,l,m;return l=a.extend(!0,{},f),i&&(b.utils.objectForEach(i,function(a){"[object Array]"===Object.prototype.toString.call(i[a])&&(l[a]||(l[a]=[]),i[a]=b.utils.arrayGetDistinctValues(l[a].concat(i[a])))}),a.extend(!0,l,i)),l.plugins?-1===a.inArray("paste",l.plugins)&&l.plugins.push("paste"):l.plugins=["paste"],k=function(a){a.on("change keyup nodechange",function(b){return setTimeout(function(){var f,i;i=a.getContent(),d=i,e=a,g(j[1](),j[2],"tinymce",i);for(f in h)h.hasOwnProperty(f)&&c.extensions[h[f]](a,b,j[2],j[4])},0)})},"function"==typeof l.setup?(m=l.setup,l.setup=function(a){m(a),k(a)}):l.setup=k,l},b.bindingHandlers.tinymce=c,b.expressionRewriting._twoWayBindings.tinymce=!0}(jQuery,ko)}).call(this); \ No newline at end of file +(function(){!function(a,b){var c,d,e,f,g;d="",e=null,c={after:["attr","value"],defaults:{},extensions:{},init:function(d,g,h,i,j){var k,l,m,n;return k=a(d),m=h.has("tinymceConfig")?h.get("tinymceConfig"):null,l=h.has("tinymceExtensions")?h.get("tinymceExtensions"):[],n=f(c.defaults,l,m,arguments),k[k.is("input, textarea")?"text":"html"](b.unwrap(g())),setTimeout(function(){k.tinymce(n)},0),b.utils.domNodeDisposal.addDisposeCallback(d,function(){var b;b=a(d).tinymce(),b&&b.remove(),b===e&&(e=null)}),{controlsDescendantBindings:!0}},update:function(c,f,g,h,i){var j,k;j=a(c).tinymce(),k=b.unwrap(f()),null===k&&(k=""),!j||e===j&&d===k||(e=j,d=k,j.getContent()!==k&&j.setContent(k))}},g=function(a,c,d,e,f){var g;if(a&&b.isObservable(a)){if(b.isWriteableObservable(a)&&(!f||a.peek()!==e))return a(e)}else if(g=c.get("_ko_property_writers"),g&&g[d])return g[d](e)},f=function(f,h,i,j){var k,l,m;return l=a.extend(!0,{},f),i&&(b.utils.objectForEach(i,function(a){"[object Array]"===Object.prototype.toString.call(i[a])&&(l[a]||(l[a]=[]),i[a]=b.utils.arrayGetDistinctValues(l[a].concat(i[a])))}),a.extend(!0,l,i)),l.plugins?a.inArray("paste",l.plugins)===-1&&l.plugins.push("paste"):l.plugins=["paste"],k=function(a){a.on("change keyup nodechange",function(b){return setTimeout(function(){var f,i;if(!a.destroyed){i=a.getContent(),d=i,e=a,g(j[1](),j[2],"tinymce",i);for(f in h)h.hasOwnProperty(f)&&c.extensions[h[f]](a,b,j[2],j[4])}},0)})},"function"==typeof l.setup?(m=l.setup,l.setup=function(a){m(a),k(a)}):l.setup=k,l},b.bindingHandlers.tinymce=c,b.expressionRewriting._twoWayBindings.tinymce=!0}(jQuery,ko)}).call(this); \ No newline at end of file