Skip to content

Execute handler functions with scope ControllerObject #22

Merged
merged 1 commit into from Feb 13, 2012

2 participants

@ivorbosloper

I would like handler functions to be executed in the ControllerObject scope (instead of the current no-scope). This allows you to use this in the ControllerObject/handler functions. Additionally, you could extend handlers with a scope keyword.

var router=new $.mobile.Router([
  { "#page": { handler: "page", events: "s" }},
  { "#test": { handler: "test", events: "s" }}],
  {
    sharedFunction: function(page) {
      // initialize footer on page
      $(page).append('<div>footer</div>');
    },
    page: function(eventType, matchObj, ui, page, evt) {
      this.sharedFunction(page);
      // other logic
    }
  }
]);
@ivorbosloper

I'm trying to learn git/github, so let me know if I did something wrong...

@azicchetti
Owner

Perfect, thanks for the patch.

I'll fix a small potential issue in a further commit, because the ControllerObject passed to the router is now just copied into an empty object {} [ cfr: $.extend(this.userHandlers,userHandlers||{}) ].
It's better to keep a reference to the original object, if provided by the user.

@azicchetti azicchetti merged commit 3661d34 into azicchetti:master Feb 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.