##// END OF EJS Templates
Changed js loading,...
Jonathan Frederic -
Show More
@@ -1,4 +1,4 b''
1 from base import Widget
1 from base import Widget, init_widget_js
2
2
3 from container import ContainerWidget
3 from container import ContainerWidget
4 from float_range import FloatRangeWidget
4 from float_range import FloatRangeWidget
@@ -11,13 +11,21 b' from IPython.utils.traitlets import Unicode, Dict, List'
11 from IPython.display import Javascript, display
11 from IPython.display import Javascript, display
12 from IPython.utils.py3compat import string_types
12 from IPython.utils.py3compat import string_types
13
13
14 def init_widget_js():
15 path = os.path.split(os.path.abspath( __file__ ))[0]
16 for filepath in glob(os.path.join(path, "*.py")):
17 filename = os.path.split(filepath)[1]
18 name = filename.rsplit('.', 1)[0]
19 if not (name == 'base' or name == '__init__'):
20 js_path = 'static/notebook/js/widgets/%s.js' % name
21 display(Javascript(data='$.getScript("%s");' % js_path))
22
14
23
15 class Widget(LoggingConfigurable):
24 class Widget(LoggingConfigurable):
16
25
17 ### Public declarations
26 ### Public declarations
18 target_name = Unicode('widget')
27 target_name = Unicode('widget')
19 default_view_name = Unicode()
28 default_view_name = Unicode()
20 js_requirements = List()
21
29
22
30
23 ### Private/protected declarations
31 ### Private/protected declarations
@@ -122,11 +130,6 b' class Widget(LoggingConfigurable):'
122 if not view_name:
130 if not view_name:
123 view_name = self.default_view_name
131 view_name = self.default_view_name
124
132
125 # Require traitlet specified widget js
126 self._require_js('static/notebook/js/widget.js')
127 for requirement in self.js_requirements:
128 self._require_js(requirement)
129
130 # Create a comm.
133 # Create a comm.
131 if self.comm is None:
134 if self.comm is None:
132 self.comm = Comm(target_name=self.target_name)
135 self.comm = Comm(target_name=self.target_name)
@@ -159,10 +162,3 b' class Widget(LoggingConfigurable):'
159 pass # Eat errors, nom nom nom
162 pass # Eat errors, nom nom nom
160 self.comm.send({"method": "update",
163 self.comm.send({"method": "update",
161 "state": state})
164 "state": state})
162
163 ### Private methods
164
165 def _require_js(self, js_path):
166 # Since we are loading requirements that must be loaded before this call
167 # returns, preform async js load.
168 display(Javascript(data='$.ajax({url: "%s", async: false, dataType: "script", timeout: 1000});' % js_path))
General Comments 0
You need to be logged in to leave comments. Login now