SpringAll icon indicating copy to clipboard operation
SpringAll copied to clipboard

YouTube opens in same page

Open Nygu opened this issue 15 years ago • 12 comments

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.

Nygu avatar Sep 15 '11 15:09 Nygu

marking this one as a bug....

danielgrippi avatar Sep 15 '11 16:09 danielgrippi

This is true will all off site links now with the simple markdown.

dmorley avatar Sep 17 '11 12:09 dmorley

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.

firefly21 avatar Oct 02 '11 03:10 firefly21

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.

halfd avatar Oct 02 '11 10:10 halfd

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"; 
        }
    }
}

halfd avatar Oct 02 '11 10:10 halfd

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");
});

firefly21 avatar Oct 02 '11 19:10 firefly21

think you want to make it live also so it updates as the websocket does.

dmorley avatar Oct 02 '11 19:10 dmorley

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.

halfd avatar Oct 02 '11 19:10 halfd

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");
    }
});

halfd avatar Oct 02 '11 19:10 halfd

@firefly21 maybe on the "widget/ready" event handler in public/javascripts/widgets/stream.js file

grzuy avatar Oct 03 '11 02:10 grzuy

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.

ohaibbq avatar Oct 03 '11 03:10 ohaibbq

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?

halfd avatar Oct 03 '11 14:10 halfd