Use Mutation Observers to observe captcha changes instead of Mutation Listeners when possible.

This commit is contained in:
Nicolas Stepien 2013-02-24 18:49:35 +01:00
parent 43530b0302
commit 1246df80af
2 changed files with 18 additions and 5 deletions

View File

@ -6276,7 +6276,7 @@
}), this.ready.bind(this));
},
ready: function() {
var imgContainer, inputContainer;
var MutationObserver, imgContainer, inputContainer, observer;
imgContainer = $.el('div', {
className: 'captchaimg',
title: 'Reload',
@ -6293,9 +6293,16 @@
img: imgContainer.firstChild,
input: inputContainer.firstChild
};
if (MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.OMutationObserver) {
observer = new MutationObserver(this.load.bind(this));
observer.observe(this.nodes.challenge, {
childList: true
});
} else {
$.on(this.nodes.challenge, 'DOMNodeInserted', this.load.bind(this));
}
$.on(imgContainer, 'click', this.reload.bind(this));
$.on(this.nodes.input, 'keydown', this.keydown.bind(this));
$.on(this.nodes.challenge, 'DOMNodeInserted', this.load.bind(this));
$.sync('captchas', this.count.bind(this));
this.count($.get('captchas', []));
this.reload();

View File

@ -522,9 +522,15 @@ QR =
img: imgContainer.firstChild
input: inputContainer.firstChild
$.on imgContainer, 'click', @reload.bind @
$.on @nodes.input, 'keydown', @keydown.bind @
$.on @nodes.challenge, 'DOMNodeInserted', @load.bind @
if MutationObserver = window.MutationObserver or window.WebKitMutationObserver or window.OMutationObserver
observer = new MutationObserver @load.bind @
observer.observe @nodes.challenge,
childList: true
else
$.on @nodes.challenge, 'DOMNodeInserted', @load.bind @
$.on imgContainer, 'click', @reload.bind @
$.on @nodes.input, 'keydown', @keydown.bind @
$.sync 'captchas', @count.bind @
@count $.get 'captchas', []
# start with an uncached captcha