Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions static/canjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ var $articleContainer,
// Override link behavior
$(document.body).on("click", "a", function(ev) {
var noModifierKeys = !ev.altKey && !ev.ctrlKey && !ev.metaKey && !ev.shiftKey,
sameHostname = this.hostname === window.location.hostname,
sameProtocol = this.protocol === window.location.protocol;
sameHostname = (ev.target.hostname || this.hostname) === window.location.hostname,
sameProtocol = (ev.target.protocol || this.protocol) === window.location.protocol;

if (noModifierKeys && sameHostname && sameProtocol) {
ev.preventDefault();
var href = this.href;
navigate(href);
navigate(ev.target.href || this.href);
}
}).on('keyup', 'input[type="checkbox"]', function(e){
var $target = $(e.target);
Expand Down
11 changes: 11 additions & 0 deletions static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,17 @@ var Search = Control.extend({
}

return "/" + this.url;
},
addTargetToExternalURLs: function(html){
var $html = $('<div>').html(html);
$html.find('a').each(function(){
var $a = $(this);
var a = $a[0];
if(a.hostname !== location.hostname || a.protocol !== location.protocol){
$a.attr('target', '_blank');
}
});
return $html.contents();
}
});

Expand Down
2 changes: 1 addition & 1 deletion templates/search-results.stache
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

{{#if result.description}}
<div class="result-description" title="{{result.description}}">
{{{result.description}}}
{{{addTargetToExternalURLs(result.description)}}}
</div>
{{/if}}
</a>
Expand Down