|
|
@@ -1,11 +1,9 @@
|
|
|
from django import template
|
|
|
-from django.utils.safestring import mark_safe
|
|
|
|
|
|
from netbox.navigation.menu import MENUS
|
|
|
|
|
|
__all__ = (
|
|
|
'nav',
|
|
|
- 'htmx_boost',
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -43,30 +41,4 @@ def nav(context):
|
|
|
|
|
|
return {
|
|
|
'nav_items': nav_items,
|
|
|
- 'htmx_navigation': context['htmx_navigation']
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-@register.simple_tag(takes_context=True)
|
|
|
-def htmx_boost(context, target='#page-content', select='#page-content'):
|
|
|
- """
|
|
|
- Renders the HTML attributes needed to effect HTMX boosting within an element if
|
|
|
- HTMX navigation is enabled for the request. The target and select parameters are
|
|
|
- rendered as `hx-target` and `hx-select`, respectively. For example:
|
|
|
-
|
|
|
- <div id="page-content" {% htmx_boost %}>
|
|
|
-
|
|
|
- If HTMX navigation is not enabled, the tag renders no content.
|
|
|
- """
|
|
|
- if not context.get('htmx_navigation', False):
|
|
|
- return ''
|
|
|
- hx_params = {
|
|
|
- 'hx-boost': 'true',
|
|
|
- 'hx-target': target,
|
|
|
- 'hx-select': select,
|
|
|
- 'hx-swap': 'outerHTML show:window:top',
|
|
|
- }
|
|
|
- htmx_params = ' '.join([
|
|
|
- f'{k}="{v}"' for k, v in hx_params.items()
|
|
|
- ])
|
|
|
- return mark_safe(htmx_params)
|