Issue #222 attachDocumentListener

Hi David,

Please review.  Or merge if happy.

Thanks
Adam