diff options
author | Manolo Carrasco <manolo@apache.org> | 2011-08-29 18:29:38 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2011-08-29 18:29:38 +0000 |
commit | 9b9a0a54a21cbb79fc2729bf2a34442ff44122f6 (patch) | |
tree | b77c72000cddd8fed419f8131dff6271617077a9 /gwtquery-core | |
parent | a5cbeed9ca1f085f989628825d4655e4fec943d3 (diff) | |
download | gwtquery-9b9a0a54a21cbb79fc2729bf2a34442ff44122f6.tar.gz gwtquery-9b9a0a54a21cbb79fc2729bf2a34442ff44122f6.zip |
When setting attributes they should be hyphenized. Move Hyphenize and Camelize methods to JsUtils
Diffstat (limited to 'gwtquery-core')
3 files changed, 52 insertions, 51 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 0df60ea7..0208b69f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -34,6 +34,7 @@ import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.SelectElement;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.HasCssName;
+import com.google.gwt.dom.client.StyleInjector.StyleInjectorImpl;
import com.google.gwt.dom.client.TextAreaElement;
import com.google.gwt.query.client.css.HasCssValue;
import com.google.gwt.query.client.css.TakesCssValue;
@@ -886,7 +887,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { public GQuery attr(Properties properties) {
for (Element e : elements) {
for (String name : properties.keys()) {
- e.setAttribute(name, properties.getStr(name));
+ e.setAttribute(JsUtils.hyphenize(name), properties.getStr(name));
}
}
return this;
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index 730026b2..d24eeb41 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -27,23 +27,6 @@ import com.google.gwt.user.client.Window; * A helper class to get computed CSS styles for elements. */ public class DocumentStyleImpl { - - /** - * Camelize style property names. for instance: font-name -> fontName - */ - public static native String camelize(String s)/*-{ - return s.replace(/\-(\w)/g, function(all, letter) { - return letter.toUpperCase(); - }); - }-*/; - - /** - * Hyphenize style property names. for instance: fontName -> font-name - */ - public static native String hyphenize(String name) /*-{ - return name.replace(/([A-Z])/g, "-$1" ).toLowerCase(); - }-*/; - /** * Returns the numeric value of a css property. * @@ -113,7 +96,7 @@ public class DocumentStyleImpl { if (!force) { return ret == null ? "" : ret; } else { - return getComputedStyle(elem, hyphenize(name), name, null); + return getComputedStyle(elem, JsUtils.hyphenize(name), name, null); } } @@ -126,7 +109,7 @@ public class DocumentStyleImpl { } else if ("for".equalsIgnoreCase(name)) { return "htmlFor"; } - return camelize(name); + return JsUtils.camelize(name); } public int getHeight(Element e) { @@ -174,7 +157,7 @@ public class DocumentStyleImpl { if (prop.matches("^[A-Z]+$")) { prop = prop.toLowerCase(); } - prop = camelize(prop); + prop = JsUtils.camelize(prop); if (val == null || val.trim().length() == 0) { removeStyleProperty(e, prop); } else { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index c3c5de92..e315aad2 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -31,6 +31,40 @@ import com.google.gwt.user.client.DOM; public class JsUtils { /** + * Camelize style property names. for instance: font-name -> fontName + */ + public static native String camelize(String s)/*-{ + return s.replace(/\-(\w)/g, function(all, letter) { + return letter.toUpperCase(); + }); + }-*/; + + /** + * Merge the oldNodes list into the newNodes one. + * If oldNodes is null, a new list will be created and returned. + * If oldNodes is not null, a new list will be created depending on + * the create flag. + */ + public static NodeList<Element> copyNodeList(NodeList<Element> oldNodes, NodeList<Element> newNodes, boolean create) { + NodeList<Element> ret = oldNodes == null || create ? JsNodeArray.create() : oldNodes; + JsCache idlist = JsCache.create(); + for (int i = 0; oldNodes != null && i < oldNodes.getLength(); i++) { + Element e = oldNodes.getItem(i); + idlist.put(e.hashCode(), 1); + if (create) { + ret.<JsNodeArray>cast().addNode(e, i); + } + } + for (int i = 0, l = newNodes.getLength(), j = ret.getLength(); i < l; i++) { + Element e = newNodes.getItem(i); + if (!idlist.exists(e.hashCode())) { + ret.<JsNodeArray>cast().addNode(newNodes.getItem(i), j++); + } + } + return ret; + } + + /** * Use the method in the gquery class $(elem).cur(prop, force); */ @Deprecated @@ -44,7 +78,7 @@ public class JsUtils { public static native boolean eq(double s1, double s2) /*-{ return s1 == s2; }-*/; - + /** * Compare two objects using javascript equality. */ @@ -53,6 +87,13 @@ public class JsUtils { }-*/; /** + * Hyphenize style property names. for instance: fontName -> font-name + */ + public static native String hyphenize(String name) /*-{ + return name.replace(/([A-Z])/g, "-$1" ).toLowerCase(); + }-*/; + + /** * Load an external javascript library. * The inserted script replaces the element with the * given id in the document. @@ -66,27 +107,28 @@ public class JsUtils { GQuery.$("#" + id).remove(); gp.append(gs.attr("src", url).attr("type", "text/javascript").attr("id", id)); } - + /** * Return the element which is truth in the double scope. */ public static native double or(double s1, double s2) /*-{ return s1 || s2; }-*/; - + /** * Return the element which is truth in the javascript scope. */ public static native <T> T or(T s1, T s2) /*-{ return s1 || s2; }-*/; - + /** * Check if a number is true in the javascript scope. */ public static native boolean truth(double a) /*-{ return a ? true : false; }-*/; + /** * Check if an object is true in the javascript scope. @@ -94,7 +136,7 @@ public class JsUtils { public static native boolean truth(Object a) /*-{ return a ? true : false; }-*/; - + /** * Remove duplicates from an elements array */ @@ -111,29 +153,4 @@ public class JsUtils { } return ret; } - - /** - * Merge the oldNodes list into the newNodes one. - * If oldNodes is null, a new list will be created and returned. - * If oldNodes is not null, a new list will be created depending on - * the create flag. - */ - public static NodeList<Element> copyNodeList(NodeList<Element> oldNodes, NodeList<Element> newNodes, boolean create) { - NodeList<Element> ret = oldNodes == null || create ? JsNodeArray.create() : oldNodes; - JsCache idlist = JsCache.create(); - for (int i = 0; oldNodes != null && i < oldNodes.getLength(); i++) { - Element e = oldNodes.getItem(i); - idlist.put(e.hashCode(), 1); - if (create) { - ret.<JsNodeArray>cast().addNode(e, i); - } - } - for (int i = 0, l = newNodes.getLength(), j = ret.getLength(); i < l; i++) { - Element e = newNodes.getItem(i); - if (!idlist.exists(e.hashCode())) { - ret.<JsNodeArray>cast().addNode(newNodes.getItem(i), j++); - } - } - return ret; - } } |