Skip to content
Browse files

Better fix for #2296 and #2423 - doesn't wrap onunload functions in a…

…ddListener anymore.
  • Loading branch information...
1 parent 3b0388b commit d54312c577d49a3fc6efa5d5ba60e15ff49d92ee @arian arian committed Sep 5, 2012
Showing with 9 additions and 16 deletions.
  1. +9 −16 Source/Element/Element.js
View
25 Source/Element/Element.js
@@ -898,13 +898,7 @@ Element.implement({
[Element, Window, Document].invoke('implement', {
addListener: function(type, fn){
- if (type == 'unload'){
- var old = fn, self = this;
- old.$ref = fn = function(){
- self.removeListener('unload', fn);
- old();
- };
- } else if (window.attachEvent && !window.addEventListener){
+ if (window.attachEvent && !window.addEventListener){
collected[Slick.uidOf(this)] = this;
}
if (this.addEventListener) this.addEventListener(type, fn, !!arguments[2]);
@@ -913,11 +907,6 @@ 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;
@@ -944,10 +933,14 @@ Element.implement({
});
/*<ltIE9>*/
-if (window.attachEvent && !window.addEventListener) window.addListener('unload', function(){
- Object.each(collected, clean);
- if (window.CollectGarbage) CollectGarbage();
-});
+if (window.attachEvent && !window.addEventListener){
+ var gc = function(){
+ Object.each(collected, clean);
+ if (window.CollectGarbage) CollectGarbage();
+ window.removeListener('unload', gc);
+ }
+ window.addListener('unload', gc);
+}
/*</ltIE9>*/
Element.Properties = {};

0 comments on commit d54312c

Please sign in to comment.
Something went wrong with that request. Please try again.