*/\r
package com.google.gwt.query.client;\r
\r
-import java.util.ArrayList;\r
-\r
import com.google.gwt.core.client.JavaScriptObject;\r
-import com.google.gwt.core.client.JsArrayString;\r
+import com.google.gwt.query.client.js.JsCache;\r
+import com.google.gwt.regexp.shared.MatchResult;\r
+import com.google.gwt.regexp.shared.RegExp;\r
\r
/**\r
* JSO for accessing Javascript objective literals used by GwtQuery functions.\r
}-*/;\r
\r
public static String wrapPropertiesString(String s) {\r
- String ret = "({"\r
- + s.replaceFirst("^[({]+", "").replaceFirst("[})]+$", "")\r
- .replaceAll("\\s*/\\*[\\s\\S]*?\\*/\\s*", "")\r
- .replaceAll(":\\s*[\"']?([^;,]+)([,;]|$)[\"']?\\s*", ":'$1',")\r
- .replaceFirst("[;,]$", "").replaceAll("\\s*[']+\\s*", "'")\r
+ String ret = "({" + s //\r
+ .replaceAll("\\s*/\\*[\\s\\S]*?\\*/\\s*", "") //\r
+ .replaceAll("([:\\)\\(,;}{'\"])\\s+" , "$1") //\r
+ .replaceAll("\\s+([:\\)\\(,;}{'\"])" , "$1") //\r
+ .replaceFirst("^[{\\(]+(.+[^}\\)])[}\\)]+$", "$1") //\r
+ .replaceAll("\\('([^\\)]+)'\\)" , "($1)") //\r
+ .replaceAll(",([\\w-]+:+)" , ";$1") //\r
+ .replaceAll(":\\s*[\"']?([^;]+)([;]|$)[\"']?\\s*", ":'$1',") //\r
+ .replaceFirst("[;,]$", "") //\r
+ .replaceAll("\\s*[']+\\s*", "'") //\r
+ "})";\r
return ret;\r
}\r
}-*/;\r
\r
public final String[] keys() {\r
- JsArrayString a = keysImpl();\r
- ArrayList<String> list = new ArrayList<String>();\r
- for (int i = 0; i < a.length(); i++) {\r
- String key = a.get(i).toString();\r
- // Chrome in DevMode injects a property to JS objects\r
- if (!"__gwt_ObjectId".equals(key)) {\r
- list.add(key);\r
- }\r
- }\r
- return list.toArray(new String[list.size()]);\r
+ return this.<JsCache>cast().keys();\r
}\r
\r
- public final native JsArrayString keysImpl() /*-{\r
- var key, keys=[];\r
- for(key in this) {\r
- keys.push("" + key); \r
- }\r
- return keys;\r
- }-*/;\r
-\r
public final native void set(String key, Object val) /*-{\r
this[key]=val;\r
}-*/;\r
package com.google.gwt.query.client.js;
+import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
}-*/;
public final native int length() /*-{
- if (this.length) return this.length;
- var key, ret = 0;
- for (key in this) ret ++;
+ if (typeof(this.length) == 'number')
+ return this.length;
+
+ var key, ret = 0;
+ // Chrome in DevMode injects a property to JS objects
+ for (key in this) if (key != "__gwt_ObjectId") ret ++;
return ret;
}-*/;
JsArrayString a = keysImpl();
String[] ret = new String[a.length()];
for (int i = 0; i < a.length(); i++) {
- ret[i] = a.get(i);
+ ret[i] = a.get(i);
}
return ret;
}
private final native JsArrayString keysImpl() /*-{
var key, keys=[];
- for(key in this) keys.push(String(key));
+ // Chrome in DevMode injects a property to JS objects
+ for(key in this) if (key != '__gwt_ObjectId') keys.push(String(key));
return keys;
}-*/;
}
*/
package com.google.gwt.query.client;
+import static com.google.gwt.query.client.GQuery.$;
+
import com.google.gwt.dom.client.Element;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.query.client.js.JsCache;
+import com.google.gwt.query.client.js.JsNodeArray;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
assertEquals(6, c.length());
assertEquals("N", c.get(-1));
}
+
+ public void testChrome__gwt_ObjectId() {
+ JsCache a = JsCache.create();
+ assertEquals(0, a.length());
+ assertEquals(0, a.keys().length);
+ assertEquals(0, a.elements().length);
+
+ a.put("obj", new Long(21));
+ assertEquals(1, a.length());
+ assertEquals(1, a.keys().length);
+ assertEquals(1, a.elements().length);
+
+ JsNodeArray n = JsNodeArray.create();
+ assertEquals(0, n.getLength());
+ assertEquals(0, n.<JsCache>cast().keys().length);
+ assertEquals(0, n.elements().length);
+
+ n.addNode($("<hr/>").get(0));
+ assertEquals(1, n.getLength());
+ assertEquals(1, n.<JsCache>cast().keys().length);
+ assertEquals(1, n.elements().length);
+ }
}
.wrapPropertiesString("{(border:'1px solid black')}"));
assertEquals("({border:'1px solid black'})", Properties
.wrapPropertiesString("({border:'1px solid black'})"));
- assertEquals("({b:'a',c:'1',d:'url('adfafa')'})", Properties
- .wrapPropertiesString("b: 'a'; c: 1, /*gg: aadf*/d: url('adfafa');"));
+ assertEquals("({b:'a',c:'1',d:'url(https://test.com)'})", Properties
+ .wrapPropertiesString("b: 'a'; c: 1, /*gg: aadf*/d: url('https://test.com');"));
+ assertEquals("({color:'rgb(0,0,139)',background:'red'})", Properties
+ .wrapPropertiesString("color: 'rgb(0, 0,139)', background: red"));
}
}