YouTube opens in same page
When you click a YouTube link, the YouTube page gets loaded within the same tab, taking you away from Diaspora. Please open the page in a new tab.
marking this one as a bug....
This is true will all off site links now with the simple markdown.
Since we use RedCarpet to do markdown, I don't see how we can easily do this. The target attribute that needs to be added to the anchor tag needs to happen in /lib/diaspora/markdownify.rb, which calls RedCarpet's auto_link.
But looking at https://github.com/tanoku/redcarpet/blob/master/ext/redcarpet/autolink.c I don't see where it handles the target attribute.
I suppose we can parse the HTML output of RedCarpet, then add the attribute, but I really don't like that.
What about adding the target with javascript? Instead of changing the markup of the text it self, we just add the functionality with js.
I've got some code lying around somewhere which does it.
Very basic example - on the site I used this, there are more checks and different titles get set, if it's files etc.
function create_external_links() {
var content = document.getElementById('content');
var hrefs = content.getElementsByTagName('a');
for (var i=0;i<hrefs.length;i++)
{
this_url = hrefs[i].getAttribute("href")
if (!/joindiaspora.com/i.test(this_url)) {
hrefs[i].target = "_blank";
hrefs[i].title = "Title on external links";
}
}
}
The following code works on adding the target attribute to the appropriate links, but I can't find where to wait for the ajax call to load the stream to invoke the code.
var links = $("#main_stream div.ltr a");
$.each(links, function(ignoreIndex, link) {
$(link).attr("target", "_blank");
});
think you want to make it live also so it updates as the websocket does.
firefly21's code is good, though I still think there should be a test for the whatever domain diaspora is running on, so internal links don't open in a new tab / window.
So something like this:
var links = $("#main_stream div.ltr a");
$.each(links, function(ignoreIndex, link) {
if (!/^[BASEHREF]/i.test($(link).attr('href')) {
$(link).attr("target", "_blank");
}
});
@firefly21 maybe on the "widget/ready" event handler in public/javascripts/widgets/stream.js file
in the previous commit i made it so that our autolink method always makes links in a new tab and added a test for it. it now makes it so that any link a user submits to us is opened in a new tab.
That looks good - probably better to do it serverside anyway.
BUT, what about checking the domain? I would say this is somewhat important?
Or - would you want all links opening in a new tab, so you could keep your own sacred stream?