Goktug Gokdogan has submitted this change and it was merged.
Change subject: Adds Element#toggleClassName.
......................................................................
Adds Element#toggleClassName.
Change-Id: I1b2a507d5ee8482a91aae28c9dc9a6b6826afb2f
---
M user/src/com/google/gwt/dom/client/Element.java
M user/test/com/google/gwt/dom/client/ElementTest.java
2 files changed, 46 insertions(+), 8 deletions(-)
Approvals:
Daniel Kurka: Looks good to me, approved
Manuel Carrasco Moñino: Looks good to me, but someone else must approve
Leeroy Jenkins: Verified
diff --git a/user/src/com/google/gwt/dom/client/Element.java
b/user/src/com/google/gwt/dom/client/Element.java
index c801f5d..6232db6 100644
--- a/user/src/com/google/gwt/dom/client/Element.java
+++ b/user/src/com/google/gwt/dom/client/Element.java
@@ -595,6 +595,18 @@
}
/**
+ * Add the class name if it doesn't exist or removes it if does.
+ *
+ * @param className the class name to be toggled
+ */
+ public final void toggleClassName(String className) {
+ boolean added = addClassName(className);
+ if (!added) {
+ removeClassName(className);
+ }
+ }
+
+ /**
* Replace one class name with another.
*
* @param oldClassName the class name to be replaced
diff --git a/user/test/com/google/gwt/dom/client/ElementTest.java
b/user/test/com/google/gwt/dom/client/ElementTest.java
index 911d788..c4a2acf 100644
--- a/user/test/com/google/gwt/dom/client/ElementTest.java
+++ b/user/test/com/google/gwt/dom/client/ElementTest.java
@@ -34,11 +34,9 @@
return "com.google.gwt.dom.DOMTest";
}
- public void testAddRemoveReplaceHasClassName() {
+ public void testAddClassName() {
DivElement div = Document.get().createDivElement();
-
div.setClassName("foo");
- assertEquals("foo", div.getClassName());
assertTrue(div.addClassName("bar"));
assertEquals("foo bar", div.getClassName());
@@ -48,12 +46,13 @@
assertFalse(div.addClassName("baz"));
assertEquals("foo bar baz", div.getClassName());
+ }
- div.replaceClassName("bar", "tintin");
- assertTrue(div.getClassName().contains("tintin"));
- assertFalse(div.getClassName().contains("bar"));
+ public void testRemoveClassName() {
+ DivElement div = Document.get().createDivElement();
+ div.setClassName("foo bar baz");
- assertTrue(div.removeClassName("tintin"));
+ assertTrue(div.removeClassName("bar"));
assertEquals("foo baz", div.getClassName());
assertFalse(div.removeClassName("bar"));
@@ -64,15 +63,42 @@
assertTrue(div.removeClassName("foo"));
assertEquals("", div.getClassName());
+ }
+ public void testHasClassName() {
+ DivElement div = Document.get().createDivElement();
div.setClassName("foo bar");
+
assertTrue(div.hasClassName("bar"));
assertTrue(div.hasClassName("foo"));
- div.removeClassName("foo");
+
+ div.setClassName("bar");
assertFalse(div.hasClassName("foo"));
assertTrue(div.hasClassName("bar"));
}
+ public void testToggleClassName() {
+ DivElement div = Document.get().createDivElement();
+ div.setClassName("foo bar baz");
+
+ div.toggleClassName("bar");
+ assertEquals("foo baz", div.getClassName());
+
+ div.toggleClassName("bar");
+ assertEquals("foo baz bar", div.getClassName());
+ }
+
+ public void testReplaceClassName() {
+ DivElement div = Document.get().createDivElement();
+ div.setClassName("foo bar baz");
+
+ div.replaceClassName("bar", "tintin");
+ assertEquals("foo baz tintin", div.getClassName());
+
+ div.replaceClassName("bar", "tintin2");
+ assertEquals("foo baz tintin tintin2", div.getClassName());
+ }
+
public void testIndexOfName() {
assertEquals(-1, Element.indexOfName("", "foo"));
--
To view, visit https://gwt-review.googlesource.com/3501
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1b2a507d5ee8482a91aae28c9dc9a6b6826afb2f
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Goktug Gokdogan <gok...@google.com>
Gerrit-Reviewer: Daniel Kurka <danku...@google.com>
Gerrit-Reviewer: Goktug Gokdogan <gok...@google.com>
Gerrit-Reviewer: Leeroy Jenkins <jenk...@gwtproject.org>
Gerrit-Reviewer: Manuel Carrasco Moñino <manuel.carrasc...@gmail.com>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.