Permalink
Browse files

Merge pull request #2423 from kentaromiura/fixbug-2296

fixes #2296 - saving a ref in order to remove the unload method
  • Loading branch information...
2 parents e55422c + b0de803 commit 3b0388bce0fe2d03005c53fb72cb5cc440d104af @arian arian committed Sep 2, 2012
Showing with 15 additions and 1 deletion.
  1. +6 −1 Source/Element/Element.js
  2. +9 −0 Specs/1.4client/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 (type == 'unload' && 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;
@@ -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 = '<form action="s"><input id="action"></form>';

0 comments on commit 3b0388b

Please sign in to comment.