You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GwtQuerySampleModule.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2011, The gwtquery team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package gwtquery.samples.client;
  17. import static com.google.gwt.query.client.GQuery.$;
  18. import static com.google.gwt.query.client.GQuery.document;
  19. import static com.google.gwt.query.client.GQuery.lazy;
  20. import com.google.gwt.core.client.EntryPoint;
  21. import com.google.gwt.core.client.GWT;
  22. import com.google.gwt.dom.client.Style.Cursor;
  23. import com.google.gwt.query.client.GQuery;
  24. import com.google.gwt.query.client.Selector;
  25. import com.google.gwt.query.client.Selectors;
  26. import com.google.gwt.query.client.css.CSS;
  27. import com.google.gwt.query.client.css.RGBColor;
  28. import com.google.gwt.user.client.Window;
  29. public class GwtQuerySampleModule implements EntryPoint {
  30. public interface Sample extends Selectors {
  31. @Selector(".note")
  32. GQuery allNotes();
  33. }
  34. public void onModuleLoad() {
  35. // Use compiled selectors
  36. Sample s = GWT.create(Sample.class);
  37. // Just a simple usage of dom manipulation, events, and lazy usage
  38. s.allNotes().text("Hello Google I/O").
  39. css(CSS.CURSOR.with(Cursor.POINTER)).
  40. toggle(
  41. lazy().css(CSS.COLOR.with(RGBColor.RED)).done(),
  42. lazy().css(CSS.COLOR.with(null)).done()
  43. );
  44. // Cascade effects
  45. $("<div id='id' style='font-size: 150%;'>Cascade Efects</div>").appendTo(document).hide().fadeIn(5000).fadeOut(3000);
  46. int gqw = $(".outer").width();
  47. String jqw = runJsCommand("$wnd.$('.outer').width()");
  48. int gqh = $(".outer").height();
  49. String jqh = runJsCommand("$wnd.$('.outer').height()");
  50. String msg = ".outer size: GQuery: " + gqw + "x" + gqh + " jQuery: " + jqw + "x" + jqh;
  51. Window.alert(msg);
  52. }
  53. private native String runJsCommand(String js) /*-{
  54. try {
  55. return "" + eval(js);
  56. } catch (e) {
  57. return "" + e;
  58. }
  59. }-*/;
  60. }