Do not eval SCRIPT tags if parent element is not in the DOM

Closes #969
Cleanup checking whether node is inserted in the DOM