From 30434e227768c47cdcf97b552cdbc4f12fad86da Mon Sep 17 00:00:00 2001 From: madflow Date: Fri, 7 Jul 2017 09:52:56 +0200 Subject: [PATCH] fix: unbind refresh event listener Stops memory leaks on orphan refresh event listeners. Fixes #339 Closes #272 --- package.json | 2 +- src/tinymce.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 312f298..3d5d4e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-ui-tinymce", - "version": "0.0.18", + "version": "0.0.19", "descriptin": "This directive allows you to add a tinymce to your form elements.", "author": "https://github.com/angular-ui/ui-tinymce/graphs/contributors", "license": "MIT", diff --git a/src/tinymce.js b/src/tinymce.js index c0291af..e51b7af 100644 --- a/src/tinymce.js +++ b/src/tinymce.js @@ -179,7 +179,7 @@ angular.module('ui.tinymce', []) // This block is because of TinyMCE not playing well with removal and // recreation of instances, requiring instances to have different // selectors in order to render new instances properly - scope.$on('$tinymce:refresh', function(e, id) { + var unbindEventListener = scope.$on('$tinymce:refresh', function(e, id) { var eid = attrs.id; if (angular.isUndefined(id) || id === eid) { var parentElement = element.parent(); @@ -189,6 +189,7 @@ angular.module('ui.tinymce', []) clonedElement.removeAttr('aria-hidden'); tinymce.execCommand('mceRemoveEditor', false, eid); parentElement.append($compile(clonedElement)(scope)); + unbindEventListener(); } });