diff options
author | Tommy Chen <tommy351@gmail.com> | 2012-06-02 12:20:09 +0200 |
---|---|---|
committer | Tommy Chen <tommy351@gmail.com> | 2012-06-02 12:28:16 +0200 |
commit | 5ba7052e5f584b5859ae3d9b00b1847391989ca1 (patch) | |
tree | a6f18139d421cea44ce3f808f7e2006cddf0f5eb /source | |
parent | 75f5e4ea0a93103cc1997aa69fc5f31fa052f8ef (diff) | |
download | octopress-theme-jeyzu-5ba7052e5f584b5859ae3d9b00b1847391989ca1.zip octopress-theme-jeyzu-5ba7052e5f584b5859ae3d9b00b1847391989ca1.tar.gz |
rewrite external.js
Diffstat (limited to 'source')
-rw-r--r-- | source/javascripts/external.js | 13 | ||||
-rw-r--r-- | source/javascripts/slash.js | 24 |
2 files changed, 14 insertions, 23 deletions
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 = '<option>Menu</option>'; @@ -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 |