From 2822775fb89c3123d7a705073fe9e5ea70c26a15 Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Fri, 22 Nov 2024 15:01:32 +0100 Subject: [PATCH] [ADD] `js_type` parameter to allow JS modules to be loaded --- allianceauth/theme/hooks.py | 25 +++++++++++++------ .../templates/theme/theme_imports_js.html | 6 ++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/allianceauth/theme/hooks.py b/allianceauth/theme/hooks.py index dde11493..6156e96f 100644 --- a/allianceauth/theme/hooks.py +++ b/allianceauth/theme/hooks.py @@ -8,14 +8,16 @@ class ThemeHook: """ def __init__(self, - name: str, - description: str, - css: List[dict], - js: List[dict], - css_template: Optional[str] = None, - js_template: Optional[str] = None, - html_tags: Optional[Union[dict, str]] = None, - header_padding: Optional[str] = "4em"): + name: str, + description: str, + css: List[dict], + js: List[dict], + css_template: Optional[str] = None, + js_template: Optional[str] = None, + js_type: Optional[str] = None, + html_tags: Optional[Union[dict, str]] = None, + header_padding: Optional[str] = "4em" + ): """ :param name: Theme python name :type name: str @@ -29,11 +31,14 @@ class ThemeHook: :type css_template: Optional[str], optional :param js_template: _description_, defaults to None :type js_template: Optional[str], optional + :param js_type: The type of the JS (e.g.: 'module'), defaults to None + :type js_type: Optional[str], optional :param html_tags: Attributes added to the `` tag, defaults to None :type html_tags: Optional[dict|str], optional :param header_padding: Top padding, defaults to "4em" :type header_padding: Optional[str], optional """ + self.name = name self.description = description @@ -45,11 +50,15 @@ class ThemeHook: self.css_template = css_template self.js_template = js_template + # Define the JS type (e.g.: 'module') + self.js_type = js_type + self.html_tags = ( " ".join([f"{key}={value}" for key, value in html_tags.items()]) if isinstance(html_tags, dict) else html_tags ) self.header_padding = header_padding + def get_name(self): return f"{self.__class__.__module__}.{self.__class__.__name__}" diff --git a/allianceauth/theme/templates/theme/theme_imports_js.html b/allianceauth/theme/templates/theme/theme_imports_js.html index ad19fdf1..0821ba98 100644 --- a/allianceauth/theme/templates/theme/theme_imports_js.html +++ b/allianceauth/theme/templates/theme/theme_imports_js.html @@ -4,7 +4,11 @@ {% include theme.js_template %} {% else %} {% for x in theme.js %} - + {% if x.js_type %} + + {% else %} + + {% endif %} {% endfor %} {% endif %}