-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use fork of catch-links to avoid its dependency on the url module whi…
…ch adds ~25kb of JS https://github.com/jackmoore/catch-links/blob/aedc104ae5b1031b325398997827c76bb08d9f4c/index.js
- Loading branch information
1 parent
cd0ae5f
commit 26bde96
Showing
3 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,6 @@ | |
], | ||
"author": "Kyle Mathews <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"catch-links": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module.exports = function(root, cb) { | ||
root.addEventListener(`click`, function(ev) { | ||
if ( | ||
ev.altKey || | ||
ev.ctrlKey || | ||
ev.metaKey || | ||
ev.shiftKey || | ||
ev.defaultPrevented | ||
) { | ||
return true | ||
} | ||
|
||
var anchor = null | ||
for (var n = ev.target; n.parentNode; n = n.parentNode) { | ||
if (n.nodeName === `A`) { | ||
anchor = n | ||
break | ||
} | ||
} | ||
if (!anchor) return true | ||
|
||
// IE clears the host value if the anchor href changed after creation, e.g. | ||
// in React. Creating a new anchor element to ensure host value is present | ||
var a1 = document.createElement(`a`) | ||
a1.href = anchor.href | ||
|
||
// In IE, the default port is included in the anchor host but excluded from | ||
// the location host. This affects the ability to directly compare | ||
// location host to anchor host. For example: http://example.com would | ||
// have a location.host of 'example.com' and an anchor.host of | ||
// 'example.com:80' Creating anchor from the location.href to normalize the | ||
// host value. | ||
var a2 = document.createElement(`a`) | ||
a2.href = location.href | ||
|
||
if (a1.host !== a2.host) return true | ||
|
||
ev.preventDefault() | ||
|
||
var base = location.protocol + `//` + location.host | ||
|
||
cb(anchor.getAttribute(`href`)) | ||
return false | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import catchLinks from "catch-links" | ||
import browserHistory from "react-router/lib/browserHistory" | ||
import catchLinks from "./catch-links" | ||
import createHistory from "history/createBrowserHistory" | ||
|
||
const history = createHistory() | ||
console.log(history) | ||
window.gatsby_history = history | ||
|
||
catchLinks(window, href => { | ||
console.log(href) | ||
browserHistory.push(href) | ||
// TODO figure out why this isn't working... | ||
history.push(href) | ||
}) |