Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Editor to specify whether Event links should open in in blank tab #368

Open
2 tasks
brylie opened this issue Mar 16, 2022 · 3 comments
Open
2 tasks
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@brylie
Copy link
Member

brylie commented Mar 16, 2022

Currently, Event website links open in a blank tab. However, the Editor may want to selectively open some links in a new tab, such as external links, while others would open in the same tab (e.g., internal links).

ℹ️ see a possible solution in a comment below: #368 (comment)

The Wagtail RichText editor doesn't allow users to specify a target when adding URLs but may support that feature at a later point: wagtail/wagtail#8150
wagtail/wagtail#1167

Task

  • determine the priority of supporting the target attribute for Event-related links
  • decide on a possible solution, such as adding a repeating field group for Event website(s) and a target attribute
@brylie brylie added this to the Post-MVP milestone Mar 16, 2022
@brylie
Copy link
Member Author

brylie commented Mar 23, 2022

We might use a bit of JavaScript to scan all links on a page when it renders and set the target link to blank for external links.

// Work-in-progress based on
// https://github.com/wagtail/wagtail/issues/1167#issuecomment-1072345927
$(document).ready(function(){
    $('a[href^="http://westernfriend.org"]').attr('target', '_blank');
    $('a[href^="http://"]').attr('rel', 'nofollow noopener');
    $('a[href^="https://"]').attr('target', '_blank');
    $('a[href^="https://"]').attr('rel', 'nofollow noopener');
    });

@brylie
Copy link
Member Author

brylie commented Dec 27, 2022

There is a solution to this issue that was suggested in the Wagtail GitHub issue: wagtail/wagtail#1167 (comment)

from django.utils.html import escape
from wagtail.core import hooks

def external_link_handler(attrs):
    href = attrs["href"]
    return '<a href="%s" target="_blank" rel="noopener nofollower">' % escape(href)

@hooks.register('register_rich_text_features')
def register_external_link(features):
    features.register_link_type('external', external_link_handler)

@brylie brylie self-assigned this Dec 27, 2022
@brylie brylie modified the milestones: Post-MVP, MVP Feb 27, 2023
@brylie brylie added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Feb 27, 2023
@brylie brylie modified the milestones: MVP, Post-MVP Mar 8, 2023
@brylie brylie removed their assignment May 6, 2023
@marycklein
Copy link
Member

I think this flexibility is something I would like to have site-wide, not just for "events."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
Status: Up next
Development

No branches or pull requests

2 participants