Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.cantaa.util.wicket.jquery;
  
  import java.util.List;
  
  
API for rendering several JQuery-function calls. Every function call is represented by a JQSnippet. Calls can be chained by just adding snippets to the JQuery-Instance

Usage:

    Component anim = new WebMarkupContainer("somediv");
    anim.setOutputMarkupId(true);
    JQuery jq = JQuery.$(clickArea).slideUp(300);
    String s = jq.render(); // => "$('#div12').slideUp(300);"
 

Author(s):
Hans Lesmeister
See also:
JQSnippet
JQueryBehavior
 
 public class JQuery implements JQRenderable {
 
     private final Component component;
     private final String tag;
 
     List<JQSnippetsnippets = new ArrayList<JQSnippet>();

    
Use JQuery.$(...) to instantiate JQuery

Parameters:
component The component on which the Instance will work, eg. its Markup-Id
 
     private JQuery(Component component) {
         super();
         Reject.ifNull(component"component is null");
         this. = component;
          = null;
     }

    
Use JQuery.$(...) to instantiate JQuery

Parameters:
tag The string on which the Instance will work, like 'div' or '.someClass'
 
     private JQuery(String tag) {
         super();
         Reject.ifTrue(Strings.isEmpty(tag), "tag is null or empty");
         this. = tag;
          = null;
     }

    
Factory-Method to create a JQuery-Instance

Parameters:
component
Returns:
Instance
 
     public static JQuery $(Component component) {
         return new JQuery(component);
     }

    
Factory-Method to create a JQuery-Instance

Parameters:
tag
Returns:
Instance
 
     public static JQuery $(String tag) {
         return new JQuery(tag);
     }
 
     public JQuery addSnippet(JQSnippet snippet) {
         .add(snippet);
         return this;
     }

    
Render the JQuery-Call to a string. Internall this calls render(true)
 
     public String render() {
         return render(true);
     }

    
Render the JQuery-Call to a string.

Parameters:
withClosingSemicolon if true (def.): add a semicolon (;) to the end of the call
 
     public String render(boolean withClosingSemicolon) {
         StringBuilder sb = new StringBuilder();
 
         sb.append("$('");
 
         if ( != null) {
             sb.append("#").append(.getMarkupId());
         } else if ( != null) {
             sb.append();
         }
        sb.append("')");
        for (JQSnippet snippet : ) {
            sb.append(".");
            sb.append(snippet.render());
        }
        if (withClosingSemicolon) {
            sb.append(";");
        }
        return sb.toString();
    }
    public JQuery click(JQFunction function) {
        addSnippet(new JQSnippet("click"function));
        return this;
    }
    public JQuery slideUp(int milliseconds) {
        addSnippet(new JQSnippet("slideUp"milliseconds));
        return this;
    }
    public JQuery slideDown(int milliseconds) {
        addSnippet(new JQSnippet("slideDown"milliseconds));
        return this;
    }

    
Convenient to slideUp or slideDown dependant on the passed boolean

Parameters:
doSlideUp true: slideUp is called, false: slideDown is called
milliseconds Passed on to one of the called functions
Returns:
this for chaining
    public JQuery slide(boolean doSlideUpint milliseconds) {
        if (doSlideUp) {
            return slideUp(milliseconds);
        } else {
            return slideDown(milliseconds);
        }
    }

    
Covenient do show or hide with the passed boolean

Parameters:
doShow true: show, false: hide
Returns:
this for chaining
    public JQuery showHide(boolean doShow) {
        if (doShow) {
            return show();
        } else {
            return hide();
        }
    }
    public JQuery hide() {
        addSnippet(new JQSnippet("hide"));
        return this;
    }
    public JQuery show() {
        addSnippet(new JQSnippet("show"));
        return this;
    }
    public JQuery attr(String attributeName) {
        addSnippet(new JQSnippet("attr"attributeName));
        return this;
    }
    public JQuery attr(String attributeNameString value) {
        addSnippet(new JQSnippet("attr"attributeNamevalue));
        return this;
    }
    public JQuery trigger(String trigger) {
        addSnippet(new JQSnippet("trigger"trigger));
        return this;
    }
    public JQuery enable() {
        addSnippet(new JQSnippet("prop""disabled"false));
        return this;
    }
    public JQuery disable() {
        addSnippet(new JQSnippet("prop""disabled"true));
        return this;
    }
    public JQuery focus() {
        addSnippet(new JQSnippet("focus"));
        return this;
    }
    public JQuery select() {
        addSnippet(new JQSnippet("select"));
        return this;
    }
    public JQuery scrollTop(int position) {
        addSnippet(new JQSnippet("scrollTop"position));
        return this;
    }
New to GrepCode? Check out our FAQ X