-
-
Save wololodev/e9ed539527396b77f340 to your computer and use it in GitHub Desktop.
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
// Only need this for pushState enabled browsers | |
if (Backbone.history && Backbone.history._hasPushState) { | |
var $document = $(window.document); | |
var openLinkInTab = false; | |
$document.keydown(function(e) { | |
if (e.ctrlKey || e.keyCode === 91) { | |
openLinkInTab = true; | |
} | |
}); | |
$document.keyup(function(e) { | |
openLinkInTab = false; | |
}); | |
$document.on("click", "a", function(e) { | |
var $this = $(this); | |
var href = $this.attr("href"); | |
var domain = $this.prop("hostname"); | |
// if the href is not equal to outpost.travel | |
var isCSRF = domain !== window.document.location.hostname; | |
var hasHashLink = href.indexOf("#") === -1; | |
// if it's been indicated that we don't want to open in a new tab | |
// and that the link is the same domain then preventDefault | |
// protection againts internal #div links | |
if (!openLinkInTab && !isCSRF && hasHashLink) { | |
e.preventDefault(); | |
Backbone.history.navigate(href, true); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this. YMMV but i needed to support using Backbone.history.root to deal with my app not being at the / root of the domain.
I also cleared up a couple things I found confusing and missing:
https://gist.github.com/shaneharter/c1458d8ddf504515c244