sheet-router
Advanced tools
Comparing version 4.0.0-0 to 4.0.1
@@ -21,5 +21,5 @@ const document = require('global/document') | ||
search: document.location.search, | ||
hash: document.location.hash | ||
hash: document.location.hash, | ||
href: document.location.href | ||
} | ||
newLocation.href = createHref(newLocation) | ||
return newLocation | ||
@@ -30,3 +30,2 @@ } else { | ||
const newLocation = parseUrl(patch) | ||
newLocation.href = createHref(newLocation) | ||
return newLocation | ||
@@ -36,3 +35,2 @@ } else { | ||
const newLocation = xtend(state, patch) | ||
newLocation.href = createHref(newLocation) | ||
return newLocation | ||
@@ -42,11 +40,2 @@ } | ||
// compute a href similar to node's href | ||
// (obj) -> str | ||
function createHref (location) { | ||
var ret = location.pathname | ||
if (location.hash) ret += (location.hash) | ||
if (location.search) ret += (location.search) | ||
return ret | ||
} | ||
// parse a URL into a kv object inside the browser | ||
@@ -59,3 +48,4 @@ // str -> obj | ||
return { | ||
href: a.pathname, | ||
href: a.href, | ||
pathname: a.pathname, | ||
search: a.search, | ||
@@ -62,0 +52,0 @@ hash: a.hash |
@@ -11,4 +11,4 @@ const window = require('global/window') | ||
// trailing '#' so empty links work as expected. | ||
// fn(str) -> null | ||
function href (cb) { | ||
// (fn(str), obj?) -> undefined | ||
function href (cb, root) { | ||
assert.equal(typeof cb, 'function', 'sheet-router/href: cb must be a function') | ||
@@ -20,3 +20,3 @@ | ||
const node = (function traverse (node) { | ||
if (!node) return | ||
if (!node || node === root) return | ||
if (node.localName !== 'a') return traverse(node.parentNode) | ||
@@ -23,0 +23,0 @@ if (node.href === undefined) return traverse(node.parentNode) |
{ | ||
"name": "sheet-router", | ||
"version": "4.0.0-0", | ||
"version": "4.0.1", | ||
"description": "Fast, modular client router", | ||
@@ -34,2 +34,3 @@ "main": "index.js", | ||
"noop2": "^2.0.0", | ||
"sinon": "^1.17.5", | ||
"standard": "^5.4.1", | ||
@@ -36,0 +37,0 @@ "tape": "^4.4.0", |
@@ -92,2 +92,11 @@ # sheet-router [![stability][0]][1] | ||
Also, if you pass an optional `root` node reference as a second argument to `href`, it will never intercept clicks outside that node. This is useful when your app is confined to a widget in a larger document. | ||
```js | ||
href(function (href) { | ||
router(href) | ||
console.log('link was clicked: ' + href) | ||
}, document.getElementById("app-root")) | ||
``` | ||
### qs | ||
@@ -94,0 +103,0 @@ Sometimes [query strings][mdn-qs] must be decoded. In order to do this, the |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26458
16
505
1
287
0
8