You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1021 B

  1. // Works like jQuery's $(document).ready.
  2. // Supports IE8+. Courtesy of http://youmightnotneedjquery.com/
  3. function ready(fn) {
  4. if (document.readyState != 'loading') {
  5. fn();
  6. } else if (document.addEventListener) {
  7. document.addEventListener('DOMContentLoaded', fn);
  8. } else {
  9. document.attachEvent('onreadystatechange', function() {
  10. if (document.readyState != 'loading')
  11. fn();
  12. });
  13. }
  14. }
  15. ready(function() {
  16. var website = window.location.hostname;
  17. var internalLinkRegex = new RegExp('^((((http:\\/\\/|https:\\/\\/)(www\\.)?)?'
  18. + website
  19. + ')|(localhost:\\d{4})|(\\/.*))(\\/.*)?$', '');
  20. var anchorEls = document.querySelectorAll('a');
  21. var anchorElsLength = anchorEls.length;
  22. for (var i = 0; i < anchorElsLength; i++) {
  23. var anchorEl = anchorEls[i];
  24. var href = anchorEl.getAttribute('href');
  25. if (!internalLinkRegex.test(href)) {
  26. anchorEl.setAttribute('target', '_blank');
  27. }
  28. }
  29. });