plone/mockup — pull request #178 by dextermilo (2013-09-18 22:09:08+00:00)
Title: Router for pattern callbacks on hash changes along with redirects

@garbas please review this pull which references #110

This adds a new Backbone.Router for matching patterns in the hash and calling a callback function. It also adds a basic method for registering actions to be performed on hash changes along with redirects from paths in the URL to a hash.

Basic functionality has also been added to the modal pattern to show a modal when the hash matches a provided id.

Refer to line 438 of modal.js for an example:

```JavaScript
Router.addRoute('modal', self.options.routerOptions.id, function() {
this.show();
}, self, self.options.routerOptions.pathExp);
```

If self.options.routerOptions.id = 'edit', this will match hashes with containing 'modal:edit' and call the callback.

Simple redirects from path to hash can also be added:

```JavaScript
Router.addRedirect(pathExp, destination);
```

Where pathExp should be a regular expression friendly string, usually something like "/edit$" which will be used to match a path segment in the URL. The matching segment will be removed and the hash will be set to '#!/'+destination.

An example has been added in toolbar.js for redirecting on /edit and launching the edit form modal.