mixdown-router
Advanced tools
Comparing version 3.0.5 to 3.0.7-final1
82
index.js
@@ -23,6 +23,6 @@ var _ = require('lodash'); | ||
/** | ||
* Attaches a router plugin to an application. | ||
* | ||
**/ | ||
this.attach = function (options) { | ||
* Attaches a router plugin to an application. | ||
* | ||
**/ | ||
this.attach = function(options) { | ||
var app = options.app; | ||
@@ -58,5 +58,5 @@ var handlers = options.handlers || instance; | ||
/** | ||
* Creates a new instance of router. | ||
* | ||
**/ | ||
* Creates a new instance of router. | ||
* | ||
**/ | ||
self.create = function() { | ||
@@ -68,8 +68,7 @@ var newRouter = new plRouter(); | ||
newRouter.timeout = 0; | ||
} | ||
else if (options.timeout) { | ||
} else if (options.timeout) { | ||
newRouter.timeout = options.timeout; | ||
} | ||
var addParam = function (param, key) { | ||
var addParam = function(param, key) { | ||
@@ -80,4 +79,3 @@ if (param && param.regex) { | ||
newRouter.param(key, new RegExp(param.regex)); | ||
} | ||
else if (param.kind.toLowerCase() === 'query') { | ||
} else if (param.kind.toLowerCase() === 'query') { | ||
newRouter.qparam(key, new RegExp(param.regex)); | ||
@@ -91,3 +89,3 @@ } | ||
// add routes | ||
_.each(self.routes, function (route, key) { | ||
_.each(self.routes, function(route, key) { | ||
// if a handler is specified, validate and bind it | ||
@@ -113,8 +111,8 @@ if (route.handler) { | ||
route.method, | ||
route.path, | ||
{ timeout: route.timeout }, | ||
route.path, { | ||
timeout: route.timeout | ||
}, | ||
_.bind(handlers.constructor.prototype._baseHandler, app, handler, route) | ||
); | ||
} | ||
else { | ||
} else { | ||
routesWithBadHandlers.push(route.name); | ||
@@ -125,3 +123,3 @@ } | ||
if(routesWithBadHandlers.length !== 0) { | ||
if (routesWithBadHandlers.length !== 0) { | ||
throw new Error('the following routes have invalid handlers: ' + routesWithBadHandlers.join(' ')); | ||
@@ -134,9 +132,14 @@ } | ||
self.listen = function(callback) { | ||
self._hasPushState = !!(window.history && window.history.pushState); | ||
self._hasPushState = !! (window.history && window.history.pushState); | ||
self.root = window.location.pathname; | ||
self.checkRoot = _.isBoolean(options.checkRoot) ? options.checkRoot : true; | ||
// Build a URL string for navigating w/o hash or additional search params | ||
var getUrlString = function() { | ||
var loc = window.location; | ||
return loc.protocol + '//' + loc.host + self.root + ((loc.hash) ? loc.hash.replace(routeStripper, '') : loc.search); | ||
if (self.checkRoot) { | ||
var loc = window.location; | ||
return loc.protocol + '//' + loc.host + self.root + ((loc.hash) ? loc.hash.replace(routeStripper, '') : loc.search); | ||
} else { | ||
return window.location.href; | ||
} | ||
}; | ||
@@ -177,12 +180,11 @@ | ||
if (arguments.length === 2) { | ||
var arg1 = arguments[1]; | ||
var arg1 = arguments[1]; | ||
if (typeof(arg1) === 'function') { | ||
if (typeof(arg1) === 'function') { | ||
callback = arg1; | ||
params = null; | ||
} | ||
else { | ||
} else { | ||
callback = null; | ||
params = arg1; | ||
} | ||
} | ||
} | ||
@@ -202,4 +204,3 @@ | ||
newUrl = app.plugins.router.url(route, params); | ||
} | ||
else { | ||
} else { | ||
var newUrl = url.parse(route); | ||
@@ -211,5 +212,5 @@ } | ||
if (self.initialized && | ||
newUrl.pathname === loc.pathname && | ||
newUrl.search == loc.search && | ||
newUrl.hash == loc.hash | ||
newUrl.pathname === loc.pathname && | ||
newUrl.search == loc.search && | ||
newUrl.hash == loc.hash | ||
) { | ||
@@ -227,3 +228,5 @@ return null; | ||
var req = new MockRequest({ url: url.format(newUrl) }); | ||
var req = new MockRequest({ | ||
url: url.format(newUrl) | ||
}); | ||
var res = new MockResponse(); | ||
@@ -239,6 +242,6 @@ | ||
// html5-history-api should be used to support pushState with hashbangs | ||
if(self._hasPushState) { | ||
if (self._hasPushState) { | ||
window.history.pushState({}, document.title, httpContext.url.href); | ||
// if html5-history-api not loaded, then do an old school href assign. | ||
// if html5-history-api not loaded, then do an old school href assign. | ||
} else { | ||
@@ -254,3 +257,3 @@ window.location.href = httpContext.url.href; | ||
self.emit('page_loaded', routerData); | ||
}); | ||
@@ -288,6 +291,5 @@ | ||
var self = this[namespace]; | ||
try{ | ||
try { | ||
var attempt = self.create(); | ||
} | ||
catch(err){ | ||
} catch (err) { | ||
done(err); | ||
@@ -297,3 +299,3 @@ return; | ||
done(null,self); | ||
done(null, self); | ||
}; | ||
@@ -313,2 +315,2 @@ }; | ||
module.exports = Router; | ||
module.exports = Router; |
{ | ||
"name": "mixdown-router", | ||
"version": "3.0.5", | ||
"version": "3.0.7-final1", | ||
"description": "Router for mixdown.js", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"lodash": "~2.4.1", | ||
"pipeline-router": "~1.2.4", | ||
"pipeline-router": "~1.2.5", | ||
"hammock": "~0.1.5", | ||
@@ -79,2 +79,2 @@ "substr-polyfill": "*" | ||
} | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
34443
656
2
Updatedpipeline-router@~1.2.5