hash-brown-router
Advanced tools
Comparing version 1.3.2 to 1.3.3
var EventEmitter = require('events').EventEmitter | ||
module.exports = function HashLocation() { | ||
module.exports = function HashLocation(window) { | ||
var emitter = new EventEmitter() | ||
var last = '' | ||
function onHashChange() { | ||
emitter.emit('hashchange') | ||
} | ||
window.addEventListener('hashchange', function() { | ||
if (last !== emitter.get()) { | ||
last = emitter.get() | ||
emitter.emit('hashchange') | ||
} | ||
}) | ||
window.addEventListener('hashchange', onHashChange) | ||
emitter.go = go.bind(null, window) | ||
emitter.replace = replace.bind(null, window) | ||
emitter.get = get.bind(null, window) | ||
emitter.go = go | ||
emitter.replace = replace | ||
emitter.get = get | ||
return emitter | ||
} | ||
function replace(newPath) { | ||
location.replace(location.origin + location.pathname + '#' + newPath) | ||
function replace(window, newPath) { | ||
window.location.replace(window.location.origin + window.location.pathname + '#' + newPath) | ||
} | ||
function go(newPath) { | ||
location.hash = newPath | ||
function go(window, newPath) { | ||
window.location.hash = newPath | ||
} | ||
function get() { | ||
return removeHashFromPath(location.hash) | ||
function get(window) { | ||
return removeHashFromPath(window.location.hash) | ||
} | ||
@@ -30,0 +32,0 @@ |
@@ -9,3 +9,3 @@ var pathToRegexp = require('path-to-regexp-with-reversible-keys') | ||
if (!hashLocation) { | ||
hashLocation = browserHashLocation() | ||
hashLocation = browserHashLocation(window) | ||
} | ||
@@ -12,0 +12,0 @@ |
{ | ||
"name": "hash-brown-router", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "A client-side router that only cares about the bits after the #", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,2 +36,8 @@ # hash-brown-router | ||
## `go(newPath)` - navigate to a new path | ||
router.go('/some-other/path') | ||
Changes the current location hash. | ||
## `replace(newPath)` - replace the current route in the browser history | ||
@@ -45,3 +51,3 @@ | ||
Convenience method for `location.replace(location.origin + location.pathname + '#' + newPath)`. | ||
Changes the current location hash, replacing the last location in the browser history, i.e. `location.replace(location.origin + location.pathname + '#' + newPath)`. | ||
@@ -48,0 +54,0 @@ ## `evaluateCurrent(defaultPath)` - evaluate the current url |
@@ -141,3 +141,3 @@ var router = require('../') | ||
tester.add('parmeters include values from querystring', function(t, locationHash, done) { | ||
tester.add('parameters include values from querystring', function(t, locationHash, done) { | ||
t.plan(4) | ||
@@ -144,0 +144,0 @@ |
@@ -37,3 +37,3 @@ var domready = require('domready') | ||
function start() { | ||
var hashLocation = browserHashLocation() | ||
var hashLocation = browserHashLocation(window) | ||
allTests.forEach(function(next) { | ||
@@ -40,0 +40,0 @@ test(next.description, function(t) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15082
363
73