Skip to content

Commit

Permalink
added support for function values in .url
Browse files Browse the repository at this point in the history
  • Loading branch information
lmjabreu committed Jul 4, 2013
1 parent e8b9e27 commit 76410b9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backbone.basicauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
* @return {object} Reference to Backbone.sync for chaining
*/
Backbone.Collection.prototype.sync = Backbone.Model.prototype.sync = function backboneSyncOverride ( method, context, options ) {
// Handle both string and function urls
var remoteURL = ( _.isFunction( context.url ) ) ? context.url() : context.url ;
// Retrieve the auth credentials from the context url
var credentials = context.url.match( /\/\/(.*):(.*)@/ ),
var credentials = remoteURL.match( /\/\/(.*):(.*)@/ ),
token;
// Set the token if available
if ( credentials && credentials.length === 3 ) {
Expand Down

0 comments on commit 76410b9

Please sign in to comment.