##// END OF EJS Templates
Change css dict to a list,...
Jonathan Frederic -
Show More
@@ -410,16 +410,16 b' function(WidgetManager, _, Backbone){'
410
410
411 var css = this.model.get('_css');
411 var css = this.model.get('_css');
412 if (css === undefined) {return;}
412 if (css === undefined) {return;}
413 var that = this;
413 for (var i = 0; i < css.length; i++) {
414 _.each(css, function(css_traits, selector){
415 // Apply the css traits to all elements that match the selector.
414 // Apply the css traits to all elements that match the selector.
416 var elements = that._get_selector_element(selector);
415 var selector = css[i][0];
416 var elements = this._get_selector_element(selector);
417 if (elements.length > 0) {
417 if (elements.length > 0) {
418 _.each(css_traits, function(css_value, css_key){
418 var trait_key = css[i][1];
419 elements.css(css_key, css_value);
419 var trait_value = css[i][2];
420 });
420 elements.css(trait_key ,trait_value);
421 }
421 }
422 });
422 }
423 },
423 },
424
424
425 _get_selector_element: function (selector) {
425 _get_selector_element: function (selector) {
@@ -341,7 +341,7 b' class Widget(LoggingConfigurable):'
341
341
342 class DOMWidget(Widget):
342 class DOMWidget(Widget):
343 visible = Bool(True, help="Whether the widget is visible.", sync=True)
343 visible = Bool(True, help="Whether the widget is visible.", sync=True)
344 _css = Dict(sync=True) # Internal CSS property dict
344 _css = List(sync=True) # Internal CSS property list: (selector, key, value)
345
345
346 def get_css(self, key, selector=""):
346 def get_css(self, key, selector=""):
347 """Get a CSS property of the widget.
347 """Get a CSS property of the widget.
@@ -384,18 +384,17 b' class DOMWidget(Widget):'
384 of the view that should be styled with common CSS (see
384 of the view that should be styled with common CSS (see
385 `$el_to_style` in the Javascript code).
385 `$el_to_style` in the Javascript code).
386 """
386 """
387 if not selector in self._css:
388 self._css[selector] = {}
389 my_css = self._css[selector]
390
391 if value is None:
387 if value is None:
392 css_dict = dict_or_key
388 css_dict = dict_or_key
393 else:
389 else:
394 css_dict = {dict_or_key: value}
390 css_dict = {dict_or_key: value}
395
391
396 for (key, value) in css_dict.items():
392 for (key, value) in css_dict.items():
397 if not (key in my_css and value == my_css[key]):
393 # First remove the selector/key pair from the css list if it exists.
398 my_css[key] = value
394 # Then add the selector/key pair and new value to the bottom of the
395 # list.
396 self._css = [x for x in self._css if not (x[0]==selector and x[1]==key)]
397 self._css += [(selector, key, value)]
399 self.send_state('_css')
398 self.send_state('_css')
400
399
401 def add_class(self, class_names, selector=""):
400 def add_class(self, class_names, selector=""):
General Comments 0
You need to be logged in to leave comments. Login now