Refactor page-leave-warning on unsaved edits

* removed usage of prototype
* extracted code into separate file