Permalink
Browse files

Multiple bugfix & cleanup, now works...

  • Loading branch information...
1 parent 50482ad commit cf78c6f1678a4c2f93657ee72fc632287af177e0 @ganmor committed Jun 26, 2012
Showing with 9 additions and 14 deletions.
  1. +9 −14 backbone_filters.js
View
@@ -5,38 +5,33 @@
if (_(filters).isEmpty())
return true;
- var def = new $.Defered();
- var beforeFiltersDefArray = new $.Deferred();
+ var def = new $.Deferred();
+ var beforeFiltersDefArray = [];
_(filters).each(function(func, filterRoute) {
if (!_.isRegExp(filterRoute)) {
filterRoute = new RegExp(filterRoute);
}
if (filterRoute.test(fragment)) {
- var result = (_.isFunction(func) ? func.apply(this, args) : this[func].apply(this, args));
- beforeFiltersDefArray.push( result );
+ var regexpResult = new RegExp( filterRoute ).exec( fragment );
+ var result = (_.isFunction(func) ? func.apply(this, [ args , regexpResult ]) : this[func].apply(this, [ args , regexpResult] ));
+ beforeFiltersDefArray.push( result );
}
}, this );
$.when.apply( null, beforeFiltersDefArray ).done( function(){
def.resolve();
});
- // TODO: If any of them failed, cancel this
return def;
},
-
- chritophe : function(){
-
- jkfdjdfj
- },
-
- route: function(route, name, callback) {
+
+ route: function( route , name , callback) {
var instance_ = this;
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);
- this._runFilters(this.before, fragment, args)).done(function(){
- callback.apply(instance_, args);
+ this._runFilters(this.before, fragment, args).done(function(){
+ callback && callback.apply(instance_, [ args , fragment ] );
instance_.trigger.apply(instance_, ['route:' + name].concat(args));
});
}, this));

0 comments on commit cf78c6f

Please sign in to comment.