sheet-router
Advanced tools
Comparing version 2.0.4 to 2.0.5
19
href.js
const window = require('global/window') | ||
const assert = require('assert') | ||
module.exports = history | ||
module.exports = href | ||
@@ -10,11 +10,18 @@ // handle a click if is anchor tag with an href | ||
// fn(str) -> null | ||
function history (cb) { | ||
function href (cb) { | ||
assert.equal(typeof cb, 'function', 'cb must be a function') | ||
window.onclick = function (e) { | ||
if (e.target.localName !== 'a') return | ||
if (e.target.href === undefined) return | ||
if (window.location.host !== e.target.host) return | ||
const href = e.target.href.replace(/#$/, '') | ||
const node = (function traverse (node) { | ||
if (!node) return | ||
if (node.localName !== 'a') return traverse(node.parentNode) | ||
if (node.href === undefined) return traverse(node.parentNode) | ||
if (window.location.host !== node.host) return traverse(node.parentNode) | ||
return node | ||
})(e.target) | ||
if (!node) return | ||
e.preventDefault() | ||
const href = node.href.replace(/#$/, '') | ||
cb(href) | ||
@@ -21,0 +28,0 @@ window.history.pushState({}, null, href) |
{ | ||
"name": "sheet-router", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Fast, modular client router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
16275
275