Added auto-closing

Hi! It's my first pull request, please be gentle with me... :-)
You could simplify this by just inlining it. Probably not worth having an extra method. So just `#{"this.closeDoc();" if close}`