Elements in shadow dom erroneously considered that they were detached from document. This patch starts using `Element.isConnected` instead of `document.contains()` call. Fixes #1061.