Skip to content
This repository
Browse code

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

…ddListener anymore.
  • Loading branch information...
commit d54312c577d49a3fc6efa5d5ba60e15ff49d92ee 1 parent 3b0388b
Arian Stolwijk arian authored

Showing 1 changed file with 9 additions and 16 deletions. Show diff stats Hide diff stats

  1. +9 16 Source/Element/Element.js
25 Source/Element/Element.js
@@ -898,13 +898,7 @@ Element.implement({
898 898 [Element, Window, Document].invoke('implement', {
899 899
900 900 addListener: function(type, fn){
901   - if (type == 'unload'){
902   - var old = fn, self = this;
903   - old.$ref = fn = function(){
904   - self.removeListener('unload', fn);
905   - old();
906   - };
907   - } else if (window.attachEvent && !window.addEventListener){
  901 + if (window.attachEvent && !window.addEventListener){
908 902 collected[Slick.uidOf(this)] = this;
909 903 }
910 904 if (this.addEventListener) this.addEventListener(type, fn, !!arguments[2]);
@@ -913,11 +907,6 @@ Element.implement({
913 907 },
914 908
915 909 removeListener: function(type, fn){
916   - if (type == 'unload' && fn.$ref){
917   - var old = fn;
918   - fn = fn.$ref;
919   - delete old.$ref;
920   - }
921 910 if (this.removeEventListener) this.removeEventListener(type, fn, !!arguments[2]);
922 911 else this.detachEvent('on' + type, fn);
923 912 return this;
@@ -944,10 +933,14 @@ Element.implement({
944 933 });
945 934
946 935 /*<ltIE9>*/
947   -if (window.attachEvent && !window.addEventListener) window.addListener('unload', function(){
948   - Object.each(collected, clean);
949   - if (window.CollectGarbage) CollectGarbage();
950   -});
  936 +if (window.attachEvent && !window.addEventListener){
  937 + var gc = function(){
  938 + Object.each(collected, clean);
  939 + if (window.CollectGarbage) CollectGarbage();
  940 + window.removeListener('unload', gc);
  941 + }
  942 + window.addListener('unload', gc);
  943 +}
951 944 /*</ltIE9>*/
952 945
953 946 Element.Properties = {};

0 comments on commit d54312c

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