1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 11:22:38 +01:00

Merge branch 'master' of github.com:gorhill/uBlock into fix-433

This commit is contained in:
gorhill 2015-01-04 10:04:59 -05:00
commit 81e035589b

View File

@ -20,7 +20,6 @@
*/ */
/* exported uDom */ /* exported uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/
@ -32,6 +31,8 @@
var uDom = (function() { var uDom = (function() {
'use strict';
/******************************************************************************/ /******************************************************************************/
var DOMList = function() { var DOMList = function() {
@ -639,6 +640,24 @@ DOMList.prototype.toggleClasses = function(classNames, targetState) {
/******************************************************************************/ /******************************************************************************/
var listenerEntries = [];
var ListenerEntry = function(target, type, capture, callback) {
this.target = target;
this.type = type;
this.capture = capture;
this.callback = callback;
target.addEventListener(type, callback, capture);
};
ListenerEntry.prototype.dispose = function() {
this.target.removeEventListener(this.type, this.callback, this.capture);
this.target = null;
this.callback = null;
};
/******************************************************************************/
var makeEventHandler = function(selector, callback) { var makeEventHandler = function(selector, callback) {
return function(event) { return function(event) {
var dispatcher = event.currentTarget; var dispatcher = event.currentTarget;
@ -662,7 +681,7 @@ DOMList.prototype.on = function(etype, selector, callback) {
var i = this.nodes.length; var i = this.nodes.length;
while ( i-- ) { while ( i-- ) {
this.nodes[i].addEventListener(etype, callback, selector !== undefined); listenerEntries.push(new ListenerEntry(this.nodes[i], etype, selector !== undefined, callback));
} }
return this; return this;
}; };
@ -693,6 +712,20 @@ DOMList.prototype.trigger = function(etype) {
/******************************************************************************/ /******************************************************************************/
// Cleanup
var onBeforeUnload = function() {
var entry;
while ( entry = listenerEntries.pop() ) {
entry.dispose();
}
window.removeEventListener('beforeunload', onBeforeUnload);
};
window.addEventListener('beforeunload', onBeforeUnload);
/******************************************************************************/
return DOMListFactory; return DOMListFactory;
})(); })();