 Issue 5464830253203456:
  Refactored the abstraction layer to address prerendered pages on Safari caused by leaky abstraction  (Closed)
    
  
    Issue 5464830253203456:
  Refactored the abstraction layer to address prerendered pages on Safari caused by leaky abstraction  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 1 /* | 1 /* | 
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH | 
| 4 * | 4 * | 
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as | 
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. | 
| 8 * | 8 * | 
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, | 
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. | 
| 13 * | 13 * | 
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License | 
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| 16 */ | 16 */ | 
| 17 | 17 | 
| 18 | 18 | 
| 19 (function() | 19 (function() | 
| 20 { | 20 { | 
| 21 window.ext = {}; | 21 window.ext = {}; | 
| 22 | 22 | 
| 23 var EventTarget = ext._EventTarget = function(cancelable) | 23 var EventTarget = ext._EventTarget = function(cancelable) | 
| 24 { | 24 { | 
| 25 this._listeners = []; | 25 this._listeners = []; | 
| 26 this._cancelable = cancelable; | 26 this._cancelable = cancelable; | 
| 27 }; | 27 }; | 
| 28 EventTarget.prototype = { | 28 EventTarget.prototype = { | 
| 29 addListener: function(listener) | 29 addListener: function(listener) | 
| 30 { | 30 { | 
| 31 this._listeners.push(listener); | 31 if (this._listeners.indexOf(listener) == -1) | 
| 
Wladimir Palant
2014/04/04 14:00:35
Please check first whether this listener is alread
 
Sebastian Noack
2014/04/07 13:15:25
Done.
 | |
| 32 this._listeners.push(listener); | |
| 32 }, | 33 }, | 
| 33 removeListener: function(listener) | 34 removeListener: function(listener) | 
| 34 { | 35 { | 
| 35 var idx = this._listeners.indexOf(listener); | 36 var idx = this._listeners.indexOf(listener); | 
| 36 if (idx != -1) | 37 if (idx != -1) | 
| 37 this._listeners.splice(idx, 1); | 38 this._listeners.splice(idx, 1); | 
| 38 }, | 39 }, | 
| 39 _dispatch: function(cancelable, args) | 40 _dispatch: function(cancelable, args) | 
| 40 { | 41 { | 
| 41 for (var i = 0; i < this._listeners.length; i++) | 42 for (var i = 0; i < this._listeners.length; i++) | 
| 42 { | 43 { | 
| 43 var result = this._listeners[i].apply(null, arguments); | 44 var result = this._listeners[i].apply(null, arguments); | 
| 44 if (this._cancelable && result === false) | 45 if (this._cancelable && result === false) | 
| 45 return false; | 46 return false; | 
| 46 } | 47 } | 
| 47 return true; | 48 return true; | 
| 48 } | 49 } | 
| 49 }; | 50 }; | 
| 50 })(); | 51 })(); | 
| LEFT | RIGHT |