Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute handler functions with scope ControllerObject #22

Merged
merged 1 commit into from Feb 13, 2012
Merged

Execute handler functions with scope ControllerObject #22

merged 1 commit into from Feb 13, 2012

Conversation

ivorbosloper
Copy link
Contributor

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
Copy link
Contributor Author

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

@azicchetti
Copy link
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 added a commit that referenced this pull request Feb 13, 2012
Execute handler functions with scope ControllerObject
@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants