Financial-Times/ftdomdelegate

Waiting for window load event in README examples

callumlocke opened this issue · 2 comments

function handleImageFail() {
  this.style.display = 'none';
}

window.addEventListener('load', function() {
  var delegate = new Delegate(document.body);
  delegate.on('error', 'img', handleImageFail);
}, false);

Is there a reason to wait for the window load event here? Doesn't it mean that any image errors (from img's in the HTML) will have already been dispatched and missed before the delegate starts listening for them?

I think the reason that the example does that is that there needs to be a document.body for domdelegate to even be able to start listening, and that might not be available before the load event.

I believe @callumlocke is correct, we updated this to wait on DOMContentLoaded in PR #83. Closing issue please reopen if you have any further comments.