From ab80aedb63a5d7962c163c3808e402dfa99ad34b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 4 Jan 2023 00:09:35 -0600 Subject: [PATCH] Allow xref buttons to have "internal" links still assume external (open in new tab) by default --- tailbone/views/master.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 98355ec3..735755f0 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -2644,17 +2644,33 @@ class MasterView(View): return normal def make_xref_button(self, **kwargs): + """ + Make and return a HTML ```` literal, for display in + the cross-reference helper panel. + :param url: URL for the link. + :param text: Label for the button. + :param internal: Boolean indicating if the link is internal to + the site. This is false by default, meaning the link is + assumed to be external, which affects the icon and causes + button click to open link in a new tab. + """ # nb. unfortunately HTML.tag() calls its first arg 'tag' and # so we can't pass a kwarg with that name...so instead we # patch that into place manually - button = HTML.tag('b-button', type='is-primary', - href=kwargs['url'], target='_blank', - icon_pack='fas', icon_left='external-link-alt', - c=kwargs['text']) + btn_kw = dict(type='is-primary', + href=kwargs['url'], + icon_pack='fas', + c=kwargs['text']) + if kwargs.get('internal'): + btn_kw['icon_left'] = 'eye' + else: + btn_kw['icon_left'] = 'external-link-alt' + btn_kw['target'] = '_blank' + button = HTML.tag('b-button', **btn_kw) button = six.text_type(button) - button = button.replace('target="_blank"', - 'target="_blank" tag="a"') + button = button.replace('