浏览代码

custom: move js library dependencies into python component

Falko Schindler 4 年之前
父节点
当前提交
b0051de4fb
共有 3 个文件被更改,包括 7 次插入8 次删除
  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.allowed_events = ['onMove']
         self.initialize(temp=False, onMove=self.handle_move)
         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, _):
     def react(self, _):
 
 

+ 4 - 2
nicegui/elements/three.py

@@ -17,9 +17,11 @@ class ThreeView(jp.JustpyBaseComponent):
         self.allowed_events = ['onClick']
         self.allowed_events = ['onClick']
         self.initialize(temp=False, onClick=self.handle_click)
         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, _):
     def react(self, _):
 
 

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

@@ -67,10 +67,6 @@
         {% endif %}
         {% endif %}
     {% 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>
 </head>