add/remove_class now can accept a list of classes

This commit is contained in:
Jonathan Frederic 2014-01-07 11:58:24 +00:00
parent 2600913067
commit 696a6e4c28

View File

@ -393,35 +393,41 @@ class Widget(BaseWidget):
raise Exception('set_css only accepts 1-3 arguments') raise Exception('set_css only accepts 1-3 arguments')
def add_class(self, class_name, selector=""): def add_class(self, class_names, selector=""):
"""Add class[es] to a DOM element """Add class[es] to a DOM element
Parameters Parameters
---------- ----------
class_name: unicode class_names: unicode or list
Class name(s) to add to the DOM element(s). Multiple class names Class name(s) to add to the DOM element(s).
must be space separated.
selector: unicode (optional) selector: unicode (optional)
JQuery selector to select the DOM element(s) that the class(es) will JQuery selector to select the DOM element(s) that the class(es) will
be added to. be added to.
""" """
class_list = class_names
if isinstance(list, class_list):
class_list = ' '.join(class_list)
self.send({"msg_type": "add_class", self.send({"msg_type": "add_class",
"class_list": class_name, "class_list": class_list,
"selector": selector}) "selector": selector})
def remove_class(self, class_name, selector=""): def remove_class(self, class_names, selector=""):
"""Remove class[es] from a DOM element """Remove class[es] from a DOM element
Parameters Parameters
---------- ----------
class_name: unicode class_names: unicode or list
Class name(s) to remove from the DOM element(s). Multiple class Class name(s) to remove from the DOM element(s).
names must be space separated.
selector: unicode (optional) selector: unicode (optional)
JQuery selector to select the DOM element(s) that the class(es) will JQuery selector to select the DOM element(s) that the class(es) will
be removed from. be removed from.
""" """
class_list = class_names
if isinstance(list, class_list):
class_list = ' '.join(class_list)
self.send({"msg_type": "remove_class", self.send({"msg_type": "remove_class",
"class_list": class_name, "class_list": class_list,
"selector": selector}) "selector": selector})