From 12147c3ff625df26e0d820c2a9134ae5108068a8 Mon Sep 17 00:00:00 2001
From: Henrik Danielsson <h.danielsson@gmail.com>
Date: Wed, 20 Apr 2011 11:21:33 +0200
Subject: [PATCH] Issue #1132142 by TwoD: Fixed nicEdit doesn't remove its submit handlers.

---
 editors/js/nicedit.js |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/editors/js/nicedit.js b/editors/js/nicedit.js
index ba8fc91..d6c584c 100644
--- a/editors/js/nicedit.js
+++ b/editors/js/nicedit.js
@@ -4,12 +4,32 @@
  * Attach this editor to a target element.
  */
 Drupal.wysiwyg.editor.attach.nicedit = function(context, params, settings) {
+  // Intercept submit handlers so we can unbind them later.
+  var oldAddEvent = bkLib.addEvent,
+  submitHandlers = [];
+  bkLib.addEvent = function(obj, type, fn) {
+   if (type == 'submit') {
+    submitHandlers.push({
+      'obj' : obj,
+      'fn' : fn
+    });
+   }
+   oldAddEvent(obj, type, fn);
+  }
   // Attach editor.
   var editor = new nicEditor(settings);
   editor.panelInstance(params.field);
   editor.addEvent('focus', function () {
     Drupal.wysiwyg.activeId = params.field;
   });
+  // Restore the helper function and register our unbinder.
+  bkLib.addEvent = oldAddEvent;
+  editor.addEvent('remove', function () {
+    var handlerInfo;
+    while (handlerInfo = submitHandlers.pop()) {
+      (handlerInfo.obj.removeEventListener ? handlerInfo.obj.removeEventListener('submit', handlerInfo.fn) : handlerInfo.obj.detachEvent('onsubmit', handlerInfo.fn));
+    }
+  });
 };
 
 /**
-- 
1.7.1

