Adjustments to context menu directive

Based on discussions with @fred I've made two adjustments to the context menu directive:

* It is recommended to provide a callback function to $apply instead of changing states and then call $apply. This is related to error handling in Angular.
* If a change:center event occurs before the popup gets displayed then the popup cannot be hidden anymore. This is now fixed by registering the change:center event right before displaying the popup.