Permalink
Browse files

Make compatible with Backbone 0.5.3

  • Loading branch information...
1 parent 806276c commit 4560c33168fc98958aa10a753ea37224ae2f28a6 @danharper danharper committed Jan 13, 2012
Showing with 34 additions and 34 deletions.
  1. +34 −34 backbone_filters.js
View
@@ -1,37 +1,37 @@
(function() {
- _.extend(Backbone.Controller.prototype, Backbone.Events, {
- before: {},
- after: {},
- _runFilters: function(filters, fragment, args) {
- if (_(filters).isEmpty()) {
- return true;
- }
- var failingFilter = _(filters).detect(function(func, filterRoute) {
- if (!_.isRegExp(filterRoute)) {
- filterRoute = this._routeToRegExp(filterRoute);
- }
- if (filterRoute.test(fragment)) {
- var result = (_.isFunction(func) ? func.apply(this, args) : this[func].apply(this, args));
- return _.isBoolean(result) && result === false;
- }
- return false;
- },
- this);
+ _.extend(Backbone.Router.prototype, Backbone.Events, {
+ before: {},
+ after: {},
+ _runFilters: function(filters, fragment, args) {
+ if (_(filters).isEmpty()) {
+ return true;
+ }
+ var failingFilter = _(filters).detect(function(func, filterRoute) {
+ if (!_.isRegExp(filterRoute)) {
+ // filterRoute = this._routeToRegExp(filterRoute);
+ filterRoute = new RegExp(filterRoute);
+ }
+ if (filterRoute.test(fragment)) {
+ var result = (_.isFunction(func) ? func.apply(this, args) : this[func].apply(this, args));
+ return _.isBoolean(result) && result === false;
+ }
+ return false;
+ },
+ this);
- return failingFilter ? false : true;
- },
- route: function(route, name, callback) {
- Backbone.history || (Backbone.history = new Backbone.History);
- if (!_.isRegExp(route)) route = this._routeToRegExp(route);
- Backbone.history.route(route, _.bind(function(fragment) {
- var args = this._extractParameters(route, fragment);
- if (this._runFilters(this.before, fragment, args)) {
- callback.apply(this, args);
- this._runFilters(this.after, fragment, args);
- this.trigger.apply(this, ['route:' + name].concat(args));
- }
- },
- this));
- }
- });
+ return failingFilter ? false : true;
+ },
+ route: function(route, name, callback) {
+ Backbone.history || (Backbone.history = new Backbone.History);
+ if (!_.isRegExp(route)) route = this._routeToRegExp(route);
+ Backbone.history.route(route, _.bind(function(fragment) {
+ var args = this._extractParameters(route, fragment);
+ if (this._runFilters(this.before, fragment, args)) {
+ callback.apply(this, args);
+ this._runFilters(this.after, fragment, args);
+ this.trigger.apply(this, ['route:' + name].concat(args));
+ }
+ }, this));
+ }
+ });
}).call(this);

0 comments on commit 4560c33

Please sign in to comment.