diff --git a/assets/javascripts/lib/page.coffee b/assets/javascripts/lib/page.coffee index 7a5329f6a8..4ca8bc3413 100644 --- a/assets/javascripts/lib/page.coffee +++ b/assets/javascripts/lib/page.coffee @@ -178,16 +178,20 @@ onclick = (event) -> link = $.eventTarget(event) link = link.parentNode while link and link.tagName isnt 'A' - if link and not link.target and isSameOrigin(link.href) + if link and not link.target and isSameOrigin(link.href) and not isSameOriginDifferentDoc event.preventDefault() path = link.pathname + link.search + link.hash path = path.replace /^\/\/+/, '/' # IE11 bug page.show(path) + return isSameOrigin = (url) -> url.indexOf("#{location.protocol}//#{location.hostname}") is 0 +isSameOriginDifferentDoc = (url) -> + url.pathname == location.pathname + updateCanonicalLink = -> @canonicalLink ||= document.head.querySelector('link[rel="canonical"]') @canonicalLink.setAttribute('href', "https://#{location.host}#{location.pathname}") diff --git a/lib/docs/core/filter.rb b/lib/docs/core/filter.rb index 52b9cfca10..5be7788397 100644 --- a/lib/docs/core/filter.rb +++ b/lib/docs/core/filter.rb @@ -96,15 +96,5 @@ def clean_path(path) path = path.gsub %r{\+}, '_plus_' path end - - def path_to_root - if subpath == '' - return '../' - else - previous_dirs = subpath.scan(/\//) - return '../' * previous_dirs.length - end - end - end end diff --git a/lib/docs/filters/core/external_urls.rb b/lib/docs/filters/core/external_urls.rb index 47fbc2200a..cd4bd4c267 100644 --- a/lib/docs/filters/core/external_urls.rb +++ b/lib/docs/filters/core/external_urls.rb @@ -6,8 +6,6 @@ class ExternalUrlsFilter < Filter def call if context[:external_urls] - root = path_to_root - css('a').each do |node| next unless anchorUrl = node['href'] @@ -24,7 +22,7 @@ def call context[:external_urls].each do |host, name| if url.host.to_s.match?(host) - node['href'] = root + name + url.path.to_s + '#' + url.fragment.to_s + node['href'] = '/' + name + url.path.to_s + '#' + url.fragment.to_s end end