MCPcopy Create free account
hub / github.com/python-visualization/folium / JSCSSMixin

Class JSCSSMixin

folium/elements.py:24–67  ·  view source on GitHub ↗

Render links to external Javascript and CSS resources.

Source from the content-addressed store, hash-verified

22
23
24class JSCSSMixin(MacroElement):
25 """Render links to external Javascript and CSS resources."""
26
27 default_js: List[Tuple[str, str]] = []
28 default_css: List[Tuple[str, str]] = []
29
30 # Since this is typically used as a mixin, we cannot
31 # override the _template member variable here. It would
32 # be overwritten by any subclassing class that also has
33 # a _template variable.
34 def render(self, **kwargs):
35 figure = self.get_root()
36 assert isinstance(
37 figure, Figure
38 ), "You cannot render this Element if it is not in a Figure."
39
40 for name, url in self.default_js:
41 figure.header.add_child(JavascriptLink(url), name=name)
42
43 for name, url in self.default_css:
44 figure.header.add_child(CssLink(url), name=name)
45
46 super().render(**kwargs)
47
48 def add_css_link(self, name: str, url: str):
49 """Add or update css resource link."""
50 self._add_link(name, url, self.default_css)
51
52 def add_js_link(self, name: str, url: str):
53 """Add or update JS resource link."""
54 self._add_link(name, url, self.default_js)
55
56 def _add_link(self, name: str, url: str, default_list: List[Tuple[str, str]]):
57 """Modify a css or js link.
58
59 If `name` does not exist, the link will be appended
60 """
61
62 for i, pair in enumerate(default_list):
63 if pair[0] == name:
64 default_list[i] = (name, url)
65 break
66 else:
67 default_list.append((name, url))
68
69
70class EventHandler(MacroElement):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…