Add load callback and page:before-partial-replace event

@kristianpd can you give this a detailed review? I couldn't apply the patch verbatim since there were upstream changes, and I took the chance to improve it a bit as well.

@nsimmons @kmcphillips