Last active
August 29, 2015 14:02
-
-
Save alisonmf/35c5ebfc9e00e57ddcb6 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
//Closes interceptor | |
// | |
$('.btn-close-interceptor').click( | |
function() | |
{ | |
$('#link-interceptor-container').bPopup().close(); | |
}); | |
//Intercepts all anchor clicks | |
// | |
$('a').click( | |
function(e) | |
{ | |
var href = this.href; | |
var temporaryDomainCheck = parseUri(href); | |
var domainWhiteList = [ | |
'domain.com' | |
]; | |
var index = href.indexOf("mailto:"); | |
var isEmailLink = href.indexOf("mailto:") > -1; | |
if(isEmailLink) | |
{ | |
console.log("This was an email link!"); | |
} | |
else | |
{ | |
console.log("This was a web link!"); | |
} | |
var showPopup = isEmailLink; | |
if(!showPopup) | |
{ | |
showPopup = (temporaryDomainCheck['host'] != '' && $.inArray(temporaryDomainCheck['host'],domainWhiteList) == -1); | |
} | |
if(showPopup) | |
{ | |
var templateName = 'tpl-intercepter'; | |
if(isEmailLink) | |
{ | |
templateName = 'tpl-interceptor-mail'; | |
} | |
//Get a nice template to work with | |
// | |
var intercetorTpl = GetTemplate(templateName); | |
//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; | |
} | |
} | |
); | |
function GetTemplate(id) | |
{ | |
var template = ''; | |
if(document.getElementById(id)) | |
{ | |
template = document.getElementById(id).text; | |
} | |
return template; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment