From 5ba7052e5f584b5859ae3d9b00b1847391989ca1 Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Sat, 2 Jun 2012 18:20:09 +0800 Subject: rewrite external.js --- source/javascripts/external.js | 13 ------------- source/javascripts/slash.js | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 source/javascripts/external.js diff --git a/source/javascripts/external.js b/source/javascripts/external.js deleted file mode 100644 index 2501d9b..0000000 --- a/source/javascripts/external.js +++ /dev/null @@ -1,13 +0,0 @@ -(function($){ - var host = location.host; - - $('a').on('click', function(e){ - var href = $(this).attr('href'), - link = href.replace(/(https?:\/\/)(.*)\/(.*)/, '$2'); - - if (href.match('https?') && link != host){ - window.open(href); - e.preventDefault(); - } - }); -})(jQuery); \ No newline at end of file diff --git a/source/javascripts/slash.js b/source/javascripts/slash.js index c23a4a2..270f39c 100644 --- a/source/javascripts/slash.js +++ b/source/javascripts/slash.js @@ -1,16 +1,19 @@ (function($){ - /* external.js */ - var host = location.host; + // Open external links in new window + var externalLinks = function(){ + var host = location.host; - $('a').on('click', function(e){ - var href = $(this).attr('href'), - link = href.replace(/(https?:\/\/)(.*)\/(.*)/, '$2'); + $('body').on('click', 'a', function(e){ + var href = this.href, + link = href.replace(/https?:\/\/([^\/]+)(.*)/, '$1'); + + if (link != host){ + window.open(href); + e.preventDefault(); + } + }); + }; - if (href.match('https?') && link != host){ - window.open(href); - e.preventDefault(); - } - }); /* navigation.js */ var appends = ''; @@ -42,4 +45,5 @@ }); }); $('.fancybox').fancybox(); + externalLinks(); // Delete or comment this line to disable opening external links in new window })(jQuery); \ No newline at end of file -- cgit v1.1-2-g2b99