gwtsizzle - CSS selectors for GWT dom

86 views
Skip to first unread message

Sebastián Gurin

unread,
Dec 31, 2012, 4:55:50 PM12/31/12
to google-we...@googlegroups.com
I needed a lightweight solution for CSS selectors in com.google.gwt.dom.client.Element so I made a GWT port of the JavaScript library sizzlejs.com/

GWTSIZZLE : http://code.google.com/p/gwtsizzle/

Since it has a very simple JavaScript API it only took me 1 hour to author this project. It is much more lighter than using gquery (about 19kb). Any feedback is most appreciated.

Usage example:

// ala JavaScript
JsArray<Element> result = Sizzle.sizzleArray("div p");
for (int i = 0; i < result.length(); i++)
    System.out.println(result.get(i).getTagName());

// ala Java
for (Element e : Sizzle.sizzleCol("div p"))
    System.out.println(e.getTagName());

Thomas Broyer

unread,
Dec 31, 2012, 6:58:44 PM12/31/12
to google-we...@googlegroups.com


On Monday, December 31, 2012 10:55:50 PM UTC+1, Sebastián Gurin wrote:
I needed a lightweight solution for CSS selectors in com.google.gwt.dom.client.Element so I made a GWT port of the JavaScript library sizzlejs.com/

Ah, this is not a port, it's a wrapper.
Also note that the <script src=""> in the gwt.xml won't work with the xsiframe linker (and the xsiframe linker is the future)

Sebastián Gurin

unread,
Jan 1, 2013, 12:13:32 AM1/1/13
to google-we...@googlegroups.com
Thank you Thomas for the clarification and for taking a look to the project. Didn't know about the new xsiframe. I'm reading some documentation and fixing my projects.

about wrapper/port thing, I thought a wrapper was when you put the JSO as a "pure" java class attribute. Then you delegate all methods to the JSO. You have a little (x2) overhead because of the second call but you gain in language because you work with "pure" java so you can do new MyClass() and inheritance.

In my case I use JSOs for talking directly to JS objects from java, so I didn't called "wrapper" but perhaps you are right, i don't know... iIm pretty confused about terminology here.... you are right it is not a port... I would call it "(direct) Java API for sizzlejs ".

Happy new year and thanks again!

Chris Price

unread,
Jan 1, 2013, 5:24:51 AM1/1/13
to google-we...@googlegroups.com

Not sure which browsers you are targeting or the selectors you require, but querySelector might be an alternative without requiring the extra library.
http://caniuse.com/#feat=queryselector

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/RjoowyRiuDEJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Thomas Broyer

unread,
Jan 1, 2013, 5:28:15 AM1/1/13
to google-we...@googlegroups.com


On Tuesday, January 1, 2013 6:13:32 AM UTC+1, Sebastián Gurin wrote:
Thank you Thomas for the clarification and for taking a look to the project. Didn't know about the new xsiframe. I'm reading some documentation and fixing my projects.

about wrapper/port thing, I thought a wrapper was when you put the JSO as a "pure" java class attribute. Then you delegate all methods to the JSO. You have a little (x2) overhead because of the second call but you gain in language because you work with "pure" java so you can do new MyClass() and inheritance.

I would say there are two "levels" of wrapping: providing a GWT API for a JS lib, and then providing a more Java-like/bean-like API on top of it.
 
In my case I use JSOs for talking directly to JS objects from java, so I didn't called "wrapper" but perhaps you are right, i don't know... iIm pretty confused about terminology here.... you are right it is not a port... I would call it "(direct) Java API for sizzlejs ".

Let's call it a "bridge" then. 

Sebastián Gurin

unread,
Jan 1, 2013, 10:25:37 AM1/1/13
to google-we...@googlegroups.com
Yes, I know, sizzle will use querySelector when available and it has an implementation for old browsers. Regards
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

Sebastián Gurin

unread,
Jan 1, 2013, 10:29:37 AM1/1/13
to google-we...@googlegroups.com
Oh another term :( I think I will call it wrapper as you suggested before. I like the first level wrapper vs second level wrapper idea for discriminate between them. Thank you again for all the help!

Reply all
Reply to author
Forward
0 new messages