From a71e9f9ee383d6911b5b26fdeb679e5860eb37b4 Mon Sep 17 00:00:00 2001 From: Cristian Carlesso Date: Sun, 2 Sep 2012 18:58:37 +0200 Subject: [PATCH] saving a ref in order to remove the unload method saving a ref in order to remove the unload method add some test --- Source/Element/Element.js | 7 ++++++- Specs/1.4client/Element/Element.js | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Element/Element.js b/Source/Element/Element.js index db3821124..2a5942206 100644 --- a/Source/Element/Element.js +++ b/Source/Element/Element.js @@ -900,7 +900,7 @@ Element.implement({ addListener: function(type, fn){ if (type == 'unload'){ var old = fn, self = this; - fn = function(){ + old.$ref = fn = function(){ self.removeListener('unload', fn); old(); }; @@ -913,6 +913,11 @@ Element.implement({ }, removeListener: function(type, fn){ + if (fn.$ref){ + var old = fn; + fn = fn.$ref; + delete old.$ref; + } if (this.removeEventListener) this.removeEventListener(type, fn, !!arguments[2]); else this.detachEvent('on' + type, fn); return this; diff --git a/Specs/1.4client/Element/Element.js b/Specs/1.4client/Element/Element.js index e89ea38df..aa5f65533 100644 --- a/Specs/1.4client/Element/Element.js +++ b/Specs/1.4client/Element/Element.js @@ -10,6 +10,15 @@ describe('Element', function(){ describe('Element.getProperty', function(){ + it('should remove the onunload method', function(){ + var text; + var handler = function(){ text = 'nope'; }; + window.addEvent('unload', handler); + window.removeEvent('unload', handler); + window.fireEvent('unload'); + expect(text).toBe(undefined); + }); + it('should get the attrubte of a form when the form has an input with as ID the attribute name', function(){ var div = new Element('div'); div.innerHTML = '
';