Browse Source

custom: move js library dependencies into python component

Falko Schindler 4 years ago
parent
commit
b0051de4fb
3 changed files with 7 additions and 8 deletions
  1. 3 2
      nicegui/elements/joystick.py
  2. 4 2
      nicegui/elements/three.py
  3. 0 4
      nicegui/static/templates/quasar.html

+ 3 - 2
nicegui/elements/joystick.py

@@ -17,9 +17,10 @@ class JoystickView(jp.JustpyBaseComponent):
         self.allowed_events = ['onMove']
         self.initialize(temp=False, onMove=self.handle_move)
 
-    def add_to_page(self, wp: jp.WebPage):
+    def add_page(self, wp: jp.WebPage):
 
-        wp.add_component(self)
+        wp.head_html += '<script src="https://cdn.jsdelivr.net/npm/nipplejs@0.9.0/dist/nipplejs.min.js"></script>'
+        super().add_page(wp)
 
     def react(self, _):
 

+ 4 - 2
nicegui/elements/three.py

@@ -17,9 +17,11 @@ class ThreeView(jp.JustpyBaseComponent):
         self.allowed_events = ['onClick']
         self.initialize(temp=False, onClick=self.handle_click)
 
-    def add_to_page(self, wp: jp.WebPage):
+    def add_page(self, wp: jp.WebPage):
 
-        wp.add_component(self)
+        wp.head_html += '<script src="https://cdn.jsdelivr.net/npm/three@0.129.0/build/three.min.js"></script>'
+        wp.head_html += '<script src="https://cdn.jsdelivr.net/npm/three@0.129.0/examples/js/controls/OrbitControls.js"></script>'
+        super().add_page(wp)
 
     def react(self, _):
 

+ 0 - 4
nicegui/static/templates/quasar.html

@@ -67,10 +67,6 @@
         {% endif %}
     {% endif %}
 
-    <script src="https://cdn.jsdelivr.net/npm/nipplejs@0.9.0/dist/nipplejs.min.js"></script>
-    <script src="https://cdn.jsdelivr.net/npm/three@0.129.0/build/three.min.js"></script>
-    <script src="https://cdn.jsdelivr.net/npm/three@0.129.0/examples/js/controls/OrbitControls.js"></script>
-
 </head>