Show More
@@ -108,13 +108,7 b' define(["components/underscore/underscore-min",' | |||||
108 |
|
108 | |||
109 | // Handle when a widget is closed. |
|
109 | // Handle when a widget is closed. | |
110 | _handle_comm_closed: function (msg) { |
|
110 | _handle_comm_closed: function (msg) { | |
111 | for (var cell in this.views) { |
|
111 | this._execute_views_method('remove'); | |
112 | var views = this.views[cell]; |
|
|||
113 | for (var view_index in views) { |
|
|||
114 | var view = views[view_index]; |
|
|||
115 | view.remove(); |
|
|||
116 | } |
|
|||
117 | } |
|
|||
118 | delete this.comm.model; // Delete ref so GC will collect widget model. |
|
112 | delete this.comm.model; // Delete ref so GC will collect widget model. | |
119 | }, |
|
113 | }, | |
120 |
|
114 | |||
@@ -139,6 +133,12 b' define(["components/underscore/underscore-min",' | |||||
139 | case 'update': |
|
133 | case 'update': | |
140 | this._handle_update(msg.content.data.state); |
|
134 | this._handle_update(msg.content.data.state); | |
141 | break; |
|
135 | break; | |
|
136 | case 'add_class': | |||
|
137 | case 'remove_class': | |||
|
138 | var selector = msg.content.data.selector; | |||
|
139 | var class_list = msg.content.data.class_list; | |||
|
140 | this._execute_views_method(method, selector, class_list); | |||
|
141 | break; | |||
142 | case 'custom': |
|
142 | case 'custom': | |
143 | this._handle_custom_msg(msg.content.data.custom_content); |
|
143 | this._handle_custom_msg(msg.content.data.custom_content); | |
144 | break; |
|
144 | break; | |
@@ -262,6 +262,28 b' define(["components/underscore/underscore-min",' | |||||
262 | }, |
|
262 | }, | |
263 |
|
263 | |||
264 |
|
264 | |||
|
265 | _execute_views_method: function (/* method_name, [argument0], [argument1], [...] */) { | |||
|
266 | var method_name = arguments[0]; | |||
|
267 | var args = null; | |||
|
268 | if (arguments.length > 1) { | |||
|
269 | args = [].splice.call(arguments,1); | |||
|
270 | } | |||
|
271 | ||||
|
272 | for (var cell in this.views) { | |||
|
273 | var views = this.views[cell]; | |||
|
274 | for (var view_index in views) { | |||
|
275 | var view = views[view_index]; | |||
|
276 | var method = view[method_name]; | |||
|
277 | if (args === null) { | |||
|
278 | method.apply(view); | |||
|
279 | } else { | |||
|
280 | method.apply(view, args); | |||
|
281 | } | |||
|
282 | } | |||
|
283 | } | |||
|
284 | }, | |||
|
285 | ||||
|
286 | ||||
265 | // Create view that represents the model. |
|
287 | // Create view that represents the model. | |
266 | _display_view: function (view_name, parent_comm_id, cell) { |
|
288 | _display_view: function (view_name, parent_comm_id, cell) { | |
267 | var new_views = []; |
|
289 | var new_views = []; | |
@@ -428,10 +450,22 b' define(["components/underscore/underscore-min",' | |||||
428 | initialize: function() { |
|
450 | initialize: function() { | |
429 | this.visible = true; |
|
451 | this.visible = true; | |
430 | this.model.on('change',this.update,this); |
|
452 | this.model.on('change',this.update,this); | |
431 | this._add_class_calls = this.model.get('_add_class')[0]; |
|
|||
432 | this._remove_class_calls = this.model.get('_remove_class')[0]; |
|
|||
433 | }, |
|
453 | }, | |
434 |
|
454 | |||
|
455 | add_class: function(selector, class_list){ | |||
|
456 | var elements = this._get_selector_element(selector); | |||
|
457 | if (elements.length > 0) { | |||
|
458 | elements.addClass(class_list); | |||
|
459 | } | |||
|
460 | }, | |||
|
461 | ||||
|
462 | remove_class: function(selector, class_list){ | |||
|
463 | var elements = this._get_selector_element(selector); | |||
|
464 | if (elements.length > 0) { | |||
|
465 | elements.removeClass(class_list); | |||
|
466 | } | |||
|
467 | }, | |||
|
468 | ||||
435 | update: function() { |
|
469 | update: function() { | |
436 | if (this.model.get('visible') != undefined) { |
|
470 | if (this.model.get('visible') != undefined) { | |
437 | if (this.visible != this.model.get('visible')) { |
|
471 | if (this.visible != this.model.get('visible')) { | |
@@ -461,30 +495,6 b' define(["components/underscore/underscore-min",' | |||||
461 | } |
|
495 | } | |
462 | } |
|
496 | } | |
463 | } |
|
497 | } | |
464 |
|
||||
465 | var add_class = this.model.get('_add_class'); |
|
|||
466 | if (add_class != undefined){ |
|
|||
467 | var add_class_calls = add_class[0]; |
|
|||
468 | if (add_class_calls > this._add_class_calls) { |
|
|||
469 | this._add_class_calls = add_class_calls; |
|
|||
470 | var elements = this._get_selector_element(add_class[1]); |
|
|||
471 | if (elements.length > 0) { |
|
|||
472 | elements.addClass(add_class[2]); |
|
|||
473 | } |
|
|||
474 | } |
|
|||
475 | } |
|
|||
476 |
|
||||
477 | var remove_class = this.model.get('_remove_class'); |
|
|||
478 | if (remove_class != undefined){ |
|
|||
479 | var remove_class_calls = remove_class[0]; |
|
|||
480 | if (remove_class_calls > this._remove_class_calls) { |
|
|||
481 | this._remove_class_calls = remove_class_calls; |
|
|||
482 | var elements = this._get_selector_element(remove_class[1]); |
|
|||
483 | if (elements.length > 0) { |
|
|||
484 | elements.removeClass(remove_class[2]); |
|
|||
485 | } |
|
|||
486 | } |
|
|||
487 | } |
|
|||
488 | }, |
|
498 | }, | |
489 |
|
499 | |||
490 | _get_selector_element: function(selector) { |
|
500 | _get_selector_element: function(selector) { | |
@@ -493,7 +503,7 b' define(["components/underscore/underscore-min",' | |||||
493 | // the $el_to_style element is not defined, use apply the |
|
503 | // the $el_to_style element is not defined, use apply the | |
494 | // style to the view's element. |
|
504 | // style to the view's element. | |
495 | var elements = this.$el.find(selector); |
|
505 | var elements = this.$el.find(selector); | |
496 | if (selector=='') { |
|
506 | if (selector===undefined || selector===null || selector=='') { | |
497 | if (this.$el_to_style == undefined) { |
|
507 | if (this.$el_to_style == undefined) { | |
498 | elements = this.$el; |
|
508 | elements = this.$el; | |
499 | } else { |
|
509 | } else { |
@@ -60,8 +60,6 b' class Widget(LoggingConfigurable):' | |||||
60 | # Private/protected declarations |
|
60 | # Private/protected declarations | |
61 | _property_lock = (None, None) # Last updated (key, value) from the front-end. Prevents echo. |
|
61 | _property_lock = (None, None) # Last updated (key, value) from the front-end. Prevents echo. | |
62 | _css = Dict() # Internal CSS property dict |
|
62 | _css = Dict() # Internal CSS property dict | |
63 | _add_class = List() # Used to add a js class to a DOM element (call#, selector, class_name) |
|
|||
64 | _remove_class = List() # Used to remove a js class from a DOM element (call#, selector, class_name) |
|
|||
65 | _displayed = False |
|
63 | _displayed = False | |
66 | _comm = None |
|
64 | _comm = None | |
67 |
|
65 | |||
@@ -80,8 +78,6 b' class Widget(LoggingConfigurable):' | |||||
80 | via the default_view_name property. |
|
78 | via the default_view_name property. | |
81 | """ |
|
79 | """ | |
82 | self._children = [] |
|
80 | self._children = [] | |
83 | self._add_class = [0] |
|
|||
84 | self._remove_class = [0] |
|
|||
85 | self._display_callbacks = [] |
|
81 | self._display_callbacks = [] | |
86 | self._msg_callbacks = [] |
|
82 | self._msg_callbacks = [] | |
87 | super(Widget, self).__init__(**kwargs) |
|
83 | super(Widget, self).__init__(**kwargs) | |
@@ -108,7 +104,7 b' class Widget(LoggingConfigurable):' | |||||
108 |
|
104 | |||
109 | # Properties |
|
105 | # Properties | |
110 | def _get_keys(self): |
|
106 | def _get_keys(self): | |
111 |
keys = ['visible', '_css' |
|
107 | keys = ['visible', '_css'] | |
112 | keys.extend(self._keys) |
|
108 | keys.extend(self._keys) | |
113 | return keys |
|
109 | return keys | |
114 | keys = property(_get_keys) |
|
110 | keys = property(_get_keys) | |
@@ -309,8 +305,9 b' class Widget(LoggingConfigurable):' | |||||
309 | JQuery selector to select the DOM element(s) that the class(es) will |
|
305 | JQuery selector to select the DOM element(s) that the class(es) will | |
310 | be added to. |
|
306 | be added to. | |
311 | """ |
|
307 | """ | |
312 | self._add_class = [self._add_class[0] + 1, selector, class_name] |
|
308 | self._comm.send({"method": "add_class", | |
313 | self.send_state(key='_add_class') |
|
309 | "class_list": class_name, | |
|
310 | "selector": selector}) | |||
314 |
|
311 | |||
315 |
|
312 | |||
316 | def remove_class(self, class_name, selector=""): |
|
313 | def remove_class(self, class_name, selector=""): | |
@@ -325,8 +322,9 b' class Widget(LoggingConfigurable):' | |||||
325 | JQuery selector to select the DOM element(s) that the class(es) will |
|
322 | JQuery selector to select the DOM element(s) that the class(es) will | |
326 | be removed from. |
|
323 | be removed from. | |
327 | """ |
|
324 | """ | |
328 | self._remove_class = [self._remove_class[0] + 1, selector, class_name] |
|
325 | self._comm.send({"method": "remove_class", | |
329 | self.send_state(key='_remove_class') |
|
326 | "class_list": class_name, | |
|
327 | "selector": selector}) | |||
330 |
|
328 | |||
331 |
|
329 | |||
332 | def send(self, content): |
|
330 | def send(self, content): |
General Comments 0
You need to be logged in to leave comments.
Login now