Allow xref buttons to have "internal" links
still assume external (open in new tab) by default
This commit is contained in:
parent
c7537e7994
commit
ab80aedb63
|
@ -2644,17 +2644,33 @@ class MasterView(View):
|
|||
return normal
|
||||
|
||||
def make_xref_button(self, **kwargs):
|
||||
"""
|
||||
Make and return a HTML ``<b-button>`` 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',
|
||||
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('<b-button ',
|
||||
'<b-button tag="a"')
|
||||
button = HTML.literal(button)
|
||||
return button
|
||||
|
||||
|
|
Loading…
Reference in a new issue