Skip to content

Commit

Permalink
saving a ref in order to remove the unload method
Browse files Browse the repository at this point in the history
saving a ref in order to remove the unload method
add some test
  • Loading branch information
Cristian Carlesso authored and Cristian Carlesso committed Sep 2, 2012
1 parent e55422c commit a71e9f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Source/Element/Element.js
Expand Up @@ -900,7 +900,7 @@ Element.implement({
addListener: function(type, fn){ addListener: function(type, fn){
if (type == 'unload'){ if (type == 'unload'){
var old = fn, self = this; var old = fn, self = this;
fn = function(){ old.$ref = fn = function(){
self.removeListener('unload', fn); self.removeListener('unload', fn);
old(); old();
}; };
Expand All @@ -913,6 +913,11 @@ Element.implement({
}, },


removeListener: function(type, fn){ 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]); if (this.removeEventListener) this.removeEventListener(type, fn, !!arguments[2]);
else this.detachEvent('on' + type, fn); else this.detachEvent('on' + type, fn);
return this; return this;
Expand Down
9 changes: 9 additions & 0 deletions Specs/1.4client/Element/Element.js
Expand Up @@ -10,6 +10,15 @@ describe('Element', function(){


describe('Element.getProperty', 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(){ 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'); var div = new Element('div');
div.innerHTML = '<form action="s"><input id="action"></form>'; div.innerHTML = '<form action="s"><input id="action"></form>';
Expand Down

0 comments on commit a71e9f9

Please sign in to comment.