Show More
@@ -108,13 +108,7 b' define(["components/underscore/underscore-min",' | |||
|
108 | 108 | |
|
109 | 109 | // Handle when a widget is closed. |
|
110 | 110 | _handle_comm_closed: function (msg) { |
|
111 | for (var cell in this.views) { | |
|
112 | var views = this.views[cell]; | |
|
113 | for (var view_index in views) { | |
|
114 | var view = views[view_index]; | |
|
115 | view.remove(); | |
|
116 | } | |
|
117 | } | |
|
111 | this._execute_views_method('remove'); | |
|
118 | 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 | 133 | case 'update': |
|
140 | 134 | this._handle_update(msg.content.data.state); |
|
141 | 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 | 142 | case 'custom': |
|
143 | 143 | this._handle_custom_msg(msg.content.data.custom_content); |
|
144 | 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 | 287 | // Create view that represents the model. |
|
266 | 288 | _display_view: function (view_name, parent_comm_id, cell) { |
|
267 | 289 | var new_views = []; |
@@ -428,10 +450,22 b' define(["components/underscore/underscore-min",' | |||
|
428 | 450 | initialize: function() { |
|
429 | 451 | this.visible = true; |
|
430 | 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 | 469 | update: function() { |
|
436 | 470 | if (this.model.get('visible') != undefined) { |
|
437 | 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 | 500 | _get_selector_element: function(selector) { |
@@ -493,7 +503,7 b' define(["components/underscore/underscore-min",' | |||
|
493 | 503 | // the $el_to_style element is not defined, use apply the |
|
494 | 504 | // style to the view's element. |
|
495 | 505 | var elements = this.$el.find(selector); |
|
496 | if (selector=='') { | |
|
506 | if (selector===undefined || selector===null || selector=='') { | |
|
497 | 507 | if (this.$el_to_style == undefined) { |
|
498 | 508 | elements = this.$el; |
|
499 | 509 | } else { |
@@ -60,8 +60,6 b' class Widget(LoggingConfigurable):' | |||
|
60 | 60 | # Private/protected declarations |
|
61 | 61 | _property_lock = (None, None) # Last updated (key, value) from the front-end. Prevents echo. |
|
62 | 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 | 63 | _displayed = False |
|
66 | 64 | _comm = None |
|
67 | 65 | |
@@ -80,8 +78,6 b' class Widget(LoggingConfigurable):' | |||
|
80 | 78 | via the default_view_name property. |
|
81 | 79 | """ |
|
82 | 80 | self._children = [] |
|
83 | self._add_class = [0] | |
|
84 | self._remove_class = [0] | |
|
85 | 81 | self._display_callbacks = [] |
|
86 | 82 | self._msg_callbacks = [] |
|
87 | 83 | super(Widget, self).__init__(**kwargs) |
@@ -108,7 +104,7 b' class Widget(LoggingConfigurable):' | |||
|
108 | 104 | |
|
109 | 105 | # Properties |
|
110 | 106 | def _get_keys(self): |
|
111 |
keys = ['visible', '_css' |
|
|
107 | keys = ['visible', '_css'] | |
|
112 | 108 | keys.extend(self._keys) |
|
113 | 109 | return keys |
|
114 | 110 | keys = property(_get_keys) |
@@ -309,8 +305,9 b' class Widget(LoggingConfigurable):' | |||
|
309 | 305 | JQuery selector to select the DOM element(s) that the class(es) will |
|
310 | 306 | be added to. |
|
311 | 307 | """ |
|
312 | self._add_class = [self._add_class[0] + 1, selector, class_name] | |
|
313 | self.send_state(key='_add_class') | |
|
308 | self._comm.send({"method": "add_class", | |
|
309 | "class_list": class_name, | |
|
310 | "selector": selector}) | |
|
314 | 311 | |
|
315 | 312 | |
|
316 | 313 | def remove_class(self, class_name, selector=""): |
@@ -325,8 +322,9 b' class Widget(LoggingConfigurable):' | |||
|
325 | 322 | JQuery selector to select the DOM element(s) that the class(es) will |
|
326 | 323 | be removed from. |
|
327 | 324 | """ |
|
328 | self._remove_class = [self._remove_class[0] + 1, selector, class_name] | |
|
329 | self.send_state(key='_remove_class') | |
|
325 | self._comm.send({"method": "remove_class", | |
|
326 | "class_list": class_name, | |
|
327 | "selector": selector}) | |
|
330 | 328 | |
|
331 | 329 | |
|
332 | 330 | def send(self, content): |
General Comments 0
You need to be logged in to leave comments.
Login now