<?xml version="1.0" encoding="UTF-8"?>
<section>
  <sectioninfo>
    <keywordset>
      <keyword>rich:jQuery</keyword>
    </keywordset>
  </sectioninfo>

  <table>
    <title>Component identification parameters</title>

    <tgroup cols="2">
      <thead>
        <row>
          <entry>Name</entry>

          <entry>Value</entry>
        </row>
      </thead>

      <tbody>
        <row>
          <entry>component-type</entry>

          <entry>org.richfaces.JQuery</entry>
        </row>

        <row>
          <entry>component-class</entry>

          <entry>org.richfaces.component.html.HtmlJQuery</entry>
        </row>

        <row>
          <entry>component-family</entry>

          <entry>org.richfaces.JQuery</entry>
        </row>

        <row>
          <entry>renderer-type</entry>

          <entry>org.richfaces.JQueryRenderer</entry>
        </row>

        <row>
          <entry>tag-class</entry>

          <entry>org.richfaces.taglib.JQueryTag</entry>
        </row>
      </tbody>
    </tgroup>
  </table>

  <section>
    <title>Creating the Component with a Page Tag</title>

    <para>To create the simplest variant on a page, use the following syntax:</para>

    <para>
      <emphasis role="bold">Example:</emphasis>
    </para>
    <programlisting role="XML"><![CDATA[...
      <rich:jQuery selector="#customList tr:odd" timing="onload" query="addClass(odd)" />
...]]></programlisting>
  </section>

  <section>
    <title>Creating the Component Dynamically Using Java</title>

    <para>
      <emphasis role="bold">Example:</emphasis>
    </para>
    <programlisting role="JAVA"><![CDATA[import org.richfaces.component.html.HtmlJQuery; 	
...
HtmlJQuery myJQuery = new HtmlJQuery();
...
]]></programlisting>
  </section>

  <section>
    <title>Details of Usage</title>
    <para><emphasis role="bold">
        <property>&lt;rich:jQuery&gt;</property>
      </emphasis> can be used in two main modes:</para>
    <itemizedlist>
      <listitem><para>as a one-time query applied immediately or on a document ready event</para></listitem>
      <listitem><para>as a JavaScript function that can be invoked from the JavaScript code</para></listitem>
    </itemizedlist>
    <para>The mode is chosen with <emphasis>
        <property>&quot;timing&quot;</property>
      </emphasis> attribute that has the following options:</para>
    <itemizedlist>
      <listitem><para>&quot;immediate&quot; - applying a query immediately</para></listitem>
      <listitem><para>&quot;onload&quot; - applying a query when a document is loaded</para></listitem>
      <listitem><para>onJScall - applying a query by invoked JavaScript function defined with the <emphasis>
          <property>&quot;name&quot;</property>
        </emphasis> attribute</para></listitem>
    </itemizedlist>
    <para>Definition of the <emphasis>
        <property>&quot;name&quot;</property>
      </emphasis> attribute is mandatory when the value of <emphasis>
        <property>&quot;timing&quot;</property>
      </emphasis> attribute is &quot;onJScall&quot;. If the<emphasis>
        <property>&quot;name&quot;</property>
      </emphasis> attribute is defined when <emphasis>
        <property>&quot;timing&quot;</property>
      </emphasis> value equals to &quot;immediate&quot; or
        &quot;onload&quot;, the query is applied according to this
      value, but you still have an opportunity to invoke it by a function name.</para>
    <para>The <emphasis>
        <property>&quot;selector&quot;</property>
      </emphasis> attribute defines an object or a list of objects. The query is defined with the <emphasis>
        <property>&quot;query&quot;</property>
      </emphasis>attribute.</para>
    <para>Here is an example of how to highlight odd rows in a table:</para>
    <para>
      <emphasis role="bold">Example:</emphasis>
    </para>
    <programlisting role="CSS"><![CDATA[...
<style>
    .odd {
          background-color: #FFC;
    }
</style>
...]]></programlisting>
    
    <programlisting role="XML"><![CDATA[...
    <rich:table id="customList" ...>
        ...
    </rich:table>
    ...
    <rich:jQuery selector="#customList tr:odd" timing="onload" query="addClass(odd)" />
...]]></programlisting>
    <para>The <emphasis>
        <property>&quot;selector&quot;</property>
      </emphasis> attribute uses defined by w3c consortium syntax for CSS rule <ulink
        url="http://www.w3.org/TR/REC-CSS2/selector.html">selector</ulink> with some jQuery
      extensions </para>
    <para>Those are typical examples of using selector in the <emphasis role="bold">
        <property>&lt;rich:jQuery&gt;</property>
      </emphasis> component.</para>

    <table>
      <title>Examples of using selector</title>

      <tgroup cols="2">
        <thead>
          <row>
            <entry>Selector</entry>

            <entry>Comment</entry>
          </row>
        </thead>

        <tbody>

          <row>
            <entry>&quot;p[a]&quot;</entry>
            <entry>In a document all &quot;p&quot; tags with &quot;a&quot; tag
              inside are selected</entry>
          </row>

          <row>
            <entry>&quot;ul/li&quot;</entry>
            <entry>All &quot;li&quot; elements of unordered &quot;ul&quot; lists are selected
            </entry>
          </row>

          <row>
            <entry>&quot;p.foo[a]&quot;</entry>
            <entry>All &quot;p&quot; tags with &quot;foo&quot; class and inserted
              &quot;a&quot; tag are selected</entry>
          </row>

          <row>
            <entry>&quot;input[@name=bar]&quot;</entry>
            <entry>All &quot;input&quot; tags with &quot;name&quot; attribute which
              value is &quot;bar&quot; are selected</entry>
          </row>

          <row>
            <entry>&quot;input[@type=radio][@checked]&quot;</entry>
            <entry>All &quot;input&quot; tags with attribute
              &quot;type&quot;=&quot;radio&quot; and attribute value =
              &quot;chekced&quot; are selected</entry>
          </row>

          <row>
            <entry>&quot;p,span,td&quot;</entry>
            <entry>All tag elements &quot;p&quot; or&quot;span&quot; or
              &quot;td&quot; are selected</entry>
          </row>

          <row>
            <entry>&quot;p#secret&quot;</entry>
            <entry>&quot;p&quot; paragraph element with &quot;id&quot;
              identification = &quot;secret&quot; is selected</entry>
          </row>

          <row>
            <entry>&quot;p span&quot;</entry>
            <entry>&quot;span&quot; tag is a (direct or non-direct) child of
              &quot;p&quot; tag. If it&apos;s necessary, use &quot;p >
              span&quot; or &quot;p/span&quot; is selected</entry>
          </row>

          <row>
            <entry>&quot;p[@foo^=bar]&quot;</entry>
            <entry>&quot;p&quot; tag containing &quot;foo&quot; attribute with
              textual value beginning with &quot;bar&quot; word is selected</entry>
          </row>

          <row>
            <entry>&quot;p[@foo$=bar] &quot;</entry>
            <entry>&quot;p&quot; tag containing &quot;foo&quot; attribute with
              textual value ending with &quot;bar&quot; word is selected</entry>
          </row>

          <row>
            <entry>&quot;p[@foo*=bar] &quot;</entry>
            <entry>&quot;p&quot; tag with &quot;foo&quot; attribute containing
              substring &quot;bar&quot; in any place is selected</entry>
          </row>

          <row>
            <entry>&quot;p//span &quot;</entry>
            <entry>&quot;span&quot; tag that is a (direct or non-direct) child of
              &quot;p&quot; tag is selected</entry>
          </row>

          <row>
            <entry>&quot;p/../span &quot;</entry>
            <entry>&quot;span&quot; tag that is a grandchild of &quot;p&quot; tag is selected</entry>
          </row>

        </tbody>
      </tgroup>
    </table>

    <para>In addition, RichFaces allows using either a component id or client id if you apply the
      query to a JSF component. When you define a selector, RichFaces examines its content and
      tries to replace the defined in the selector id with a component id if it&apos;s found.</para>
    <para>For example, you have the following code:</para>

    <programlisting role="XML"><![CDATA[...
    <h:form id="form">
        ...
        <h:panelGrid id="menu">
            <h:graphicImage ... />
            <h:graphicImage ... />
            ...
        </h:panelGrid>
    </h:form>
...]]></programlisting>

    <para>The actual id of the <emphasis role="bold">
        <property>&lt;h:panelGrid&gt;</property>
      </emphasis> table in the browser DOM is <code>&quot;form:menu&quot;</code>. However, you still can
      reference to images inside this table using the following selector: </para>

    <programlisting role="XML"><![CDATA[...
    <rich:jQuery selector="#menu img" query="..." />
...]]></programlisting>

    <para>You can define the exact id in the selector if you want. The following code reference to
      the same set of a DOM object:</para>

    <programlisting role="XML"><![CDATA[...
    <rich:jQuery selector="#form\\:menu img" query="..." />
...]]></programlisting>

    <para>Pay attention to double slashes that escape a colon in the id.</para>

    <para>In case when the <emphasis>
        <property>&quot;name&quot;</property>
      </emphasis> attribute is defined, <emphasis role="bold">
        <property>&lt;rich:jQuery&gt;</property>
      </emphasis> generates a JavaScript function that might be used from any place of JavaScript
      code on a page.</para>

    <para>There is an example of how to enlarge the picture smoothly on a mouse over event and return
      back to the normal size on mouse out:</para>

    <programlisting role="XML"><![CDATA[...
    <h:graphicImage onmouseover="enlargePic(this)" width="50" value="/images/price.png"
                onmouseover="enlargePic(this, {pwidth:'60px'})" onmouseover="releasePic(this)"  />
    <h:graphicImage onmouseover="enlargePic(this)" width="50" value="/images/discount.png"
                onmouseover="enlargePic(this, {pwidth:'100px'})" onmouseover="releasePic(this)"  />
    ...
    <rich:jQuery name="enlargePic" timing="onJScall" query="animate({width:param.pwidth})" />
    <rich:jQuery name="releasePic" timing="onJScall" query="animate({width:'50px'})"/> 
...]]></programlisting>

    <para>The JavaScript could use two parameters. The first parameter is a replacement for the
      selector attribute. Thus, you can share the same query, applying it to the different DOM
      objects. You can use a literal value or a direct reference for an existing DOM object. The
      second parameter can be used to path the specific value inside the query. The JSON syntax is
      used for the second parameter. The &quot;param.&quot; namespace is used for
      referencing data inside the parameter value.</para>

    <para><emphasis role="bold">
        <property>&lt;rich:jQuery&gt;</property>
      </emphasis> adds styles and behavior to the DOM object dynamically. This means if you replace
      something on a page during an Ajax response, the applied artifacts  is overwritten. But you
      are allowed to apply them again after the Ajax response is complete.</para>
    <para>Usually, it could be done with reRendering the <emphasis role="bold">
        <property>&lt;rich:jQuery&gt;</property>
      </emphasis> components in the same Ajax interaction with the components these queries are
      applied to. Note, that queries with <emphasis>
        <property>&quot;timing&quot;</property>
      </emphasis> attribute set to &quot;onload&quot; are not
      invoked even if the query is reRendered, because a DOM document is not fully reloaded during
      the Ajax interaction. If you need to re-applies query with
        &quot;onload&quot; value of <emphasis>
        <property>&quot;timing&quot;</property>
      </emphasis> attribute, define the <emphasis>
        <property>&quot;name&quot;</property>
      </emphasis> attribute and invoke the query by name in the <emphasis>
        <property>&quot;oncomplete&quot;</property>
      </emphasis> attribute of the Ajax component.</para>

    <para>RichFaces includes jQuery JavaScript framework. You can use the futures of jQuery directly
      without defining the <emphasis role="bold">
        <property>&lt;rich:jQuery&gt;</property>
      </emphasis> component on a page if it is convenient for you. To start using the jQuery feature
      on the page, include the library into a page with the following code:</para>

    <programlisting role="XML"><![CDATA[...
    <a4j:loadScript src="resource://jquery.js"/>
...]]></programlisting>

    <para>Refer to the <ulink url="http://docs.jquery.com/">jQuery documentation</ulink> for the
      right syntax. Remember to use <code>jQuery()</code> function instead of <code>$()</code>, as soon as jQuery works
      without conflicts with <code>prototype.js</code>.</para>
  </section>
  
  <section>
    <title>Look-and-Feel Customization</title>
    
    <para><emphasis role="bold">
      <property>&lt;rich:jQuery&gt;</property>
    </emphasis> has no skin parameters and custom <property>style classes</property>, as the
      component isn&apos;t visual.</para>
  </section>
  
    <section>
      <title>Relevant Resources Links</title>
      <para>More information about jQuery framework and its features you can read <ulink
          url="http://jquery.com/">here</ulink>.</para>
      <para>How to use jQuery with other libraries see <ulink
          url="http://docs.jquery.com/Using_jQuery_with_Other_Libraries">here</ulink>.</para>

    <para>
	  Some additional information about usage of component can be found 
	  <ulink url="http://livedemo.exadel.com/richfaces-demo/richfaces/jQuery.jsf?c=jQuery">on its LiveDemo</ulink>.
    </para>
       
  </section>
</section>
