Show More
@@ -309,6 +309,8 b' define(["components/underscore/underscore-min",' | |||||
309 | initialize: function() { |
|
309 | initialize: function() { | |
310 | this.visible = true; |
|
310 | this.visible = true; | |
311 | this.model.on('change',this.update,this); |
|
311 | this.model.on('change',this.update,this); | |
|
312 | this._add_class_calls = this.model.get('_add_class')[0]; | |||
|
313 | this._remove_class_calls = this.model.get('_remove_class')[0]; | |||
312 | }, |
|
314 | }, | |
313 |
|
315 | |||
314 | update: function() { |
|
316 | update: function() { | |
@@ -322,25 +324,14 b' define(["components/underscore/underscore-min",' | |||||
322 | } |
|
324 | } | |
323 | } |
|
325 | } | |
324 | } |
|
326 | } | |
|
327 | ||||
325 | if (this.model.css != undefined) { |
|
328 | if (this.model.css != undefined) { | |
326 | for (var selector in this.model.css) { |
|
329 | for (var selector in this.model.css) { | |
327 | if (this.model.css.hasOwnProperty(selector)) { |
|
330 | if (this.model.css.hasOwnProperty(selector)) { | |
328 |
|
331 | |||
329 | // Get the elements via the css selector. If the selector is |
|
|||
330 | // blank, apply the style to the $el_to_style element. If |
|
|||
331 | // the $el_to_style element is not defined, use apply the |
|
|||
332 | // style to the view's element. |
|
|||
333 | var elements = this.$el.find(selector); |
|
|||
334 | if (selector=='') { |
|
|||
335 | if (this.$el_to_style == undefined) { |
|
|||
336 | elements = this.$el; |
|
|||
337 | } else { |
|
|||
338 | elements = this.$el_to_style; |
|
|||
339 | } |
|
|||
340 | } |
|
|||
341 |
|
||||
342 | // Apply the css traits to all elements that match the selector. |
|
332 | // Apply the css traits to all elements that match the selector. | |
343 |
|
|
333 | var elements = this.get_selector_element(selector); | |
|
334 | if (elements.length > 0) { | |||
344 | var css_traits = this.model.css[selector]; |
|
335 | var css_traits = this.model.css[selector]; | |
345 | for (var css_key in css_traits) { |
|
336 | for (var css_key in css_traits) { | |
346 | if (css_traits.hasOwnProperty(css_key)) { |
|
337 | if (css_traits.hasOwnProperty(css_key)) { | |
@@ -351,6 +342,46 b' define(["components/underscore/underscore-min",' | |||||
351 | } |
|
342 | } | |
352 | } |
|
343 | } | |
353 | } |
|
344 | } | |
|
345 | ||||
|
346 | var add_class = this.model.get('_add_class'); | |||
|
347 | if (add_class != undefined){ | |||
|
348 | var add_class_calls = add_class[0]; | |||
|
349 | if (add_class_calls > this._add_class_calls) { | |||
|
350 | this._add_class_calls = add_class_calls; | |||
|
351 | var elements = this.get_selector_element(add_class[1]); | |||
|
352 | if (elements.length > 0) { | |||
|
353 | elements.addClass(add_class[2]); | |||
|
354 | } | |||
|
355 | } | |||
|
356 | } | |||
|
357 | ||||
|
358 | var remove_class = this.model.get('_remove_class'); | |||
|
359 | if (remove_class != undefined){ | |||
|
360 | var remove_class_calls = remove_class[0]; | |||
|
361 | if (remove_class_calls > this._remove_class_calls) { | |||
|
362 | this._remove_class_calls = remove_class_calls; | |||
|
363 | var elements = this.get_selector_element(remove_class[1]); | |||
|
364 | if (elements.length > 0) { | |||
|
365 | elements.removeClass(remove_class[2]); | |||
|
366 | } | |||
|
367 | } | |||
|
368 | } | |||
|
369 | }, | |||
|
370 | ||||
|
371 | get_selector_element: function(selector) { | |||
|
372 | // Get the elements via the css selector. If the selector is | |||
|
373 | // blank, apply the style to the $el_to_style element. If | |||
|
374 | // the $el_to_style element is not defined, use apply the | |||
|
375 | // style to the view's element. | |||
|
376 | var elements = this.$el.find(selector); | |||
|
377 | if (selector=='') { | |||
|
378 | if (this.$el_to_style == undefined) { | |||
|
379 | elements = this.$el; | |||
|
380 | } else { | |||
|
381 | elements = this.$el_to_style; | |||
|
382 | } | |||
|
383 | } | |||
|
384 | return elements; | |||
354 | }, |
|
385 | }, | |
355 | }); |
|
386 | }); | |
356 |
|
387 |
@@ -44,6 +44,9 b' def init_widget_js():' | |||||
44 | #----------------------------------------------------------------------------- |
|
44 | #----------------------------------------------------------------------------- | |
45 | class Widget(LoggingConfigurable): |
|
45 | class Widget(LoggingConfigurable): | |
46 |
|
46 | |||
|
47 | # Shared declarations | |||
|
48 | _keys = [] | |||
|
49 | ||||
47 | # Public declarations |
|
50 | # Public declarations | |
48 | target_name = Unicode('widget', help="""Name of the backbone model |
|
51 | target_name = Unicode('widget', help="""Name of the backbone model | |
49 | registered in the frontend to create and sync this widget with.""") |
|
52 | registered in the frontend to create and sync this widget with.""") | |
@@ -64,11 +67,12 b' class Widget(LoggingConfigurable):' | |||||
64 | new._children.append(self) |
|
67 | new._children.append(self) | |
65 | if old is not None and self in old._children: |
|
68 | if old is not None and self in old._children: | |
66 | old._children.remove(self) |
|
69 | old._children.remove(self) | |
67 |
|
70 | |||
68 | # Private/protected declarations |
|
71 | # Private/protected declarations | |
69 | _keys = [] |
|
|||
70 | _property_lock = False |
|
72 | _property_lock = False | |
71 | _css = Dict() |
|
73 | _css = Dict() # Internal CSS property dict | |
|
74 | _add_class = List() # Used to add a js class to a DOM element (call#, selector, class_name) | |||
|
75 | _remove_class = List() # Used to remove a js class from a DOM element (call#, selector, class_name) | |||
72 | _displayed = False |
|
76 | _displayed = False | |
73 | _comm = None |
|
77 | _comm = None | |
74 |
|
78 | |||
@@ -87,6 +91,8 b' class Widget(LoggingConfigurable):' | |||||
87 | via the default_view_name property. |
|
91 | via the default_view_name property. | |
88 | """ |
|
92 | """ | |
89 | self._children = [] |
|
93 | self._children = [] | |
|
94 | self._add_class = [0] | |||
|
95 | self._remove_class = [0] | |||
90 | super(Widget, self).__init__(**kwargs) |
|
96 | super(Widget, self).__init__(**kwargs) | |
91 |
|
97 | |||
92 | # Register after init to allow default values to be specified |
|
98 | # Register after init to allow default values to be specified | |
@@ -108,7 +114,7 b' class Widget(LoggingConfigurable):' | |||||
108 |
|
114 | |||
109 | # Properties |
|
115 | # Properties | |
110 | def _get_keys(self): |
|
116 | def _get_keys(self): | |
111 | keys = ['_css', 'visible'] |
|
117 | keys = ['visible', '_css', '_add_class', '_remove_class'] | |
112 | keys.extend(self._keys) |
|
118 | keys.extend(self._keys) | |
113 | return keys |
|
119 | return keys | |
114 | keys = property(_get_keys) |
|
120 | keys = property(_get_keys) | |
@@ -212,7 +218,39 b' class Widget(LoggingConfigurable):' | |||||
212 | # Only update the property if it has changed. |
|
218 | # Only update the property if it has changed. | |
213 | if not (key in self._css[selector] and value in self._css[selector][key]): |
|
219 | if not (key in self._css[selector] and value in self._css[selector][key]): | |
214 | self._css[selector][key] = value |
|
220 | self._css[selector][key] = value | |
215 | self.send_state() # Send new state to client. |
|
221 | self.send_state('_css') # Send new state to client. | |
|
222 | ||||
|
223 | ||||
|
224 | def add_class(self, class_name, selector=""): | |||
|
225 | """Add class[es] to a DOM element | |||
|
226 | ||||
|
227 | Parameters | |||
|
228 | ---------- | |||
|
229 | class_name: unicode | |||
|
230 | Class name(s) to add to the DOM element(s). Multiple class names | |||
|
231 | must be space separated. | |||
|
232 | selector: unicode (optional) | |||
|
233 | JQuery selector to select the DOM element(s) that the class(es) will | |||
|
234 | be added to. | |||
|
235 | """ | |||
|
236 | self._add_class = [self._add_class[0] + 1, selector, class_name] | |||
|
237 | self.send_state(key='_add_class') | |||
|
238 | ||||
|
239 | ||||
|
240 | def remove_class(self, class_name, selector=""): | |||
|
241 | """Remove class[es] from a DOM element | |||
|
242 | ||||
|
243 | Parameters | |||
|
244 | ---------- | |||
|
245 | class_name: unicode | |||
|
246 | Class name(s) to remove from the DOM element(s). Multiple class | |||
|
247 | names must be space separated. | |||
|
248 | selector: unicode (optional) | |||
|
249 | JQuery selector to select the DOM element(s) that the class(es) will | |||
|
250 | be removed from. | |||
|
251 | """ | |||
|
252 | self._remove_class = [self._remove_class[0] + 1, selector, class_name] | |||
|
253 | self.send_state(key='_remove_class') | |||
216 |
|
254 | |||
217 |
|
255 | |||
218 | # Support methods |
|
256 | # Support methods |
General Comments 0
You need to be logged in to leave comments.
Login now