org.odlabs.wiquery.core.javascript
Class JsStatement

java.lang.Object
  extended by org.odlabs.wiquery.core.javascript.JsStatement
All Implemented Interfaces:
Serializable

public class JsStatement
extends Object
implements Serializable

$Id$

A JsStatement defines a whole executable JavaScript statement. The generator eases "jQuery oriented" code, but you can still use another JavaScript coding style with the append(CharSequence) method.

To get a valid instance and to ease JavaScript and Wicket integration, you should use the JsQuery class (example below). This class will initialize a JsStatement and contribute to a WebPage.

The JavaScript generating by a JsStatement is jQuery oriented. Example of generated string:

$(".aClassName").each(function() {alert('foo');});

To generate the script above, you can write this:

new JsQuery().$().each(JsScope.quickScope("alert('foo')"));

Any JsStatement should be returned by a JsQuery within the $ methods.

Since:
0.7
Author:
Lionel Armanet
See Also:
JsQuery, JsScope, Serialized Form

Constructor Summary
JsStatement()
          Creates a new JsStatement.
 
Method Summary
 JsStatement $()
          Appends the jQuery's $ function to the current JsStatement.
 JsStatement $(org.apache.wicket.Component context)
          Same method as $(Component, String) with an empty selector.
 JsStatement $(org.apache.wicket.Component context, String selector)
          Appends the jQuery's $ function to the current JsStatement.
 JsStatement addClass(String className)
          Binds the addClass statement.
 JsStatement after(CharSequence html)
          Binds the after statement.
 JsStatement append(CharSequence charSequence)
          Appends the given CharSequence to this statement.
 JsStatement attr(String key, JsScope computedValue)
          Binds the attr statement.
 JsStatement attr(String key, String value)
          Binds the attr statement.
 JsStatement before(CharSequence html)
          Binds the before statement.
 JsStatement chain(ChainableStatement chainableStatement)
          Chains a function call to this JsStatement.
 JsStatement chain(CharSequence statementLabel, CharSequence... statementArgs)
          Chains a function call to this JsStatement.
 JsStatement css(Options options)
          Binds the css statement.
 JsStatement css(String name, String value)
          Binds the css statement.
 JsStatement document()
          Appends $(document) to the statement.
 JsStatement each(JsScope scope)
          Appends the each jQuery statement.
 StringBuilder getStatement()
           
 JsStatement html(CharSequence htmlContents)
          Binds the html statement.
 JsStatement insertAfter(String expression)
          Binds the insertAfter statement.
 JsStatement insertBefore(String expression)
          Binds the insertBefore statement.
 JsStatement ready(JsScope scope)
          Appends the ready jQuery statement.
 JsStatement removeAttr(String key)
          Binds the removeAttr statement.
 JsStatement removeClass(String className)
          Binds the removeClass statement.
 CharSequence render()
          Renders this statement.
 CharSequence render(boolean semicolon)
          Renders this statement.
 JsStatement self()
          Appends the this keyword to this statement.
 JsStatement toggleClass(String className)
          Binds the toggleClass statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsStatement

public JsStatement()
Creates a new JsStatement.

Method Detail

$

public JsStatement $()
Appends the jQuery's $ function to the current JsStatement. So, we can call some special jquery fonction, like $.browser ...

Returns:
JsStatement this instance.

$

public JsStatement $(org.apache.wicket.Component context)
Same method as $(Component, String) with an empty selector.

Returns:
JsStatement this instance.

$

public JsStatement $(org.apache.wicket.Component context,
                     String selector)
Appends the jQuery's $ function to the current JsStatement. If context is not null, the generated JavaScript code will be:

$("#component.getMarkupId selector")

If context is null, the generated JavaScript code will be:

$("selector")

Returns:
JsStatement this instance.

addClass

public JsStatement addClass(String className)
Binds the addClass statement.


after

public JsStatement after(CharSequence html)
Binds the after statement.


append

public JsStatement append(CharSequence charSequence)
Appends the given CharSequence to this statement.

Returns:
JsStatement this instance.

attr

public JsStatement attr(String key,
                        JsScope computedValue)
Binds the attr statement.


attr

public JsStatement attr(String key,
                        String value)
Binds the attr statement.


before

public JsStatement before(CharSequence html)
Binds the before statement.


chain

public JsStatement chain(ChainableStatement chainableStatement)
Chains a function call to this JsStatement. The function call is wrapped in a ChainableStatement. (eases JavaScript integration).

Returns:
JsStatement this instance.
See Also:
chain(CharSequence, CharSequence...).

chain

public JsStatement chain(CharSequence statementLabel,
                         CharSequence... statementArgs)
Chains a function call to this JsStatement. This will append statementLabel(statementArgs) to this JsStatement.

Parameters:
statementLabel - the statement label to append.
statementArgs - the statement args.
Returns:
JsStatement this instance.

css

public JsStatement css(Options options)
Binds the css statement.


css

public JsStatement css(String name,
                       String value)
Binds the css statement.


document

public JsStatement document()
Appends $(document) to the statement.

Returns:
JsStatement this instance.

each

public JsStatement each(JsScope scope)
Appends the each jQuery statement.

Parameters:
scope - the JsScope to execute within every matched element.

getStatement

public StringBuilder getStatement()
Returns:
the statement of the JsStatement

html

public JsStatement html(CharSequence htmlContents)
Binds the html statement.


insertAfter

public JsStatement insertAfter(String expression)
Binds the insertAfter statement.


insertBefore

public JsStatement insertBefore(String expression)
Binds the insertBefore statement.


ready

public JsStatement ready(JsScope scope)
Appends the ready jQuery statement.

Parameters:
scope - the JsScope to execute when jQuery is ready.
Returns:

removeAttr

public JsStatement removeAttr(String key)
Binds the removeAttr statement.


removeClass

public JsStatement removeClass(String className)
Binds the removeClass statement.


render

public CharSequence render()
Renders this statement.

Returns:
the renderable JavaScript statement as a CharSequence.

render

public CharSequence render(boolean semicolon)
Renders this statement.

Parameters:
semicolon - If true, a semicolon is automatically added
Returns:
the renderable JavaScript statement as a CharSequence.

self

public JsStatement self()
Appends the this keyword to this statement.

Returns:
JsStatement this instance.

toggleClass

public JsStatement toggleClass(String className)
Binds the toggleClass statement.



Copyright © 2012. All Rights Reserved.