Before, on and after events

Initial implementation of before, on and after events. Also moved dom
observers out into a new method api.observe.on_dom to clean up the
api.observe.on method which is already carrying extra code to support
backwards compatibility.