Created
June 3, 2014 14:16
-
-
Save alisonmf/1a0981c41a19ad1282e4 to your computer and use it in GitHub Desktop.
intercepts the link to create a "speed bump" popup, letting you know you are leaving the site. requires bPopup
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
//Closes interceptor | |
// | |
$('.btn-close-interceptor').click( | |
function() | |
{ | |
$('#link-interceptor-container').bPopup().close(); | |
}); | |
//Intercepts all anchor clicks | |
// | |
$('a').click( | |
function() | |
{ | |
var preservedLink = this.href; | |
var temporaryDomainCheck = parseUri(this.href); | |
//Add any domains that do not require a "road bump". If the domain is not listed here then its a pop! | |
// | |
var domainWhiteList = [ | |
'subdomain.domain-example.com' | |
] | |
//For each of the whitelisted domains | |
// | |
if(temporaryDomainCheck['host'] != '' && $.inArray(temporaryDomainCheck['host'],domainWhiteList) == -1) | |
{ | |
//Get a nice template to work with | |
// | |
var intercetorTpl = GetTemplate('tpl-interceptor'); | |
//Ensure that it is a string | |
// | |
intercetorTpl.toString(); | |
//Replace any tokens | |
// | |
intercetorTpl = intercetorTpl.replace('<!--LINK-->', preservedLink); | |
//Put the content into the popup content body | |
// | |
$('#link-interceptor-content').html(intercetorTpl); | |
//Pop it up! | |
// | |
$('#link-interceptor-container').bPopup(); | |
//Halt the native anchor click action and do your own thang above with the popup and thangs | |
// | |
return false; | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment