htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java
branchemul
changeset 100 029e6eed60e9
parent 28 81ad7a739fed
child 106 346633cd13d6
     1.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Tue Sep 25 09:55:34 2012 +0200
     1.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Thu Oct 11 06:15:22 2012 -0700
     1.3 @@ -17,6 +17,8 @@
     1.4   */
     1.5  package org.apidesign.bck2brwsr.htmlpage.api;
     1.6  
     1.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
     1.8 +
     1.9  /** Represents a generic HTML element.
    1.10   *
    1.11   * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.12 @@ -30,14 +32,33 @@
    1.13      
    1.14      abstract void dontSubclass();
    1.15      
    1.16 +    @JavaScriptBody(
    1.17 +        args={"el", "property", "value"},
    1.18 +        body="var e = window.document.getElementById(el.id);\n"
    1.19 +           + "e[property] = value;\n"
    1.20 +    )
    1.21      static void setAttribute(Element el, String property, Object value) {
    1.22          throw new UnsupportedOperationException("Needs JavaScript!");
    1.23      }
    1.24 +
    1.25 +    @JavaScriptBody(
    1.26 +        args={"el", "property"},
    1.27 +        body="var e = window.document.getElementById(el.id);\n"
    1.28 +           + "return e[property];\n"
    1.29 +    )
    1.30 +    static Object getAttribute(Element el, String property) {
    1.31 +        throw new UnsupportedOperationException("Needs JavaScript!");
    1.32 +    }
    1.33      
    1.34      /** Executes given runnable when user performs a "click" on the given
    1.35       * element.
    1.36       * @param r the runnable to execute, never null
    1.37       */
    1.38 +    @JavaScriptBody(
    1.39 +        args={"el", "r"},
    1.40 +        body="var e = window.document.getElementById(el.id);\n"
    1.41 +           + "e.onclick = function() { r.runV(); };\n"
    1.42 +    )
    1.43      public final void addOnClick(Runnable r) {
    1.44          throw new UnsupportedOperationException("Needs JavaScript!");
    1.45      }