Javascript API

Japano offers two features which normally require client-side javascript to work: Take a look at the sample webapplication for an example of both features. Note that if you can ignore the javascript API if you don't use javascript views or partial updates.


Using the Javascrip API

To use the japano javascript API you must include the "japano.js" file included in the japano distribution and instantiate a japano object by using the following code:
var japano=new Japano();
The Japano object offers the following methods:
japano.get(URL, fn, params, waitCursor)
Calls the given URL with the given associative parameter array params and feeds the evaluated JSON response to the function fn. If waitCursor is set to true, a wait cursor is set until a response is received.
japano.getText(URL, fn, params, waitCursor)
Calls the given URL with the given associative parameter array params and feeds the text response to the function fn. If waitCursor is set to true, a wait cursor is set until a response is received.
japano.getHTML(URL, fn, params, waitCursor)
Calls the given URL with the given associative parameter array params and feeds the received HTML element to the function fn. If waitCursor is set to true, a wait cursor is set until a response is received.
japano.getXML(URL, fn, params, waitCursor)
Calls the given URL with the given associative parameter array params and feeds the XML response to the function fn. If waitCursor is set to true, a wait cursor is set until a response is received.
japano.convertToURL(URI)
Converts the given URI to an URL.
japano.readParameter(formElement)
Reads the content of the given form element into an associative array.
japano.commit(id, fn)
Commits the form with the given id and reloads it via partial Update.
japano.isError(o)
Returns true if the given object is a japano Error object.
japano.dump(o, fn)
Dumps the given Object as HTML.
japano.forSpan( className, fn)

Calls the given function for every span tag whose className contains the given className. the function is called with two arguments:

function fn(element, data) :
element
the span DOM element.
data
data object embedded in the span.
This is best illustrated with an example:

The japano framework uses forSpan to create the buttons of <jpn:button> tags. The button tag inserts something like this into the page.

<span class="jpn_button" onclick="data={button:'Push me!',fn:'doStuff'};">non js code</span>
            
Japano calls forSpan() like this:
this.forSpan("jpn_button", 
  function(elem, data)
  {      
    if (data)
    {
      var code="var fn="+data.fn+";";
      eval(code);
      var button=document.createElement("BUTTON");      
      button.addEventListener("click", fn, false);
      while (elem.hasChildNodes())
        elem.removeChild(elem.firstChild);
      elem.appendChild(button);
      button.appendChild(document.createTextNode(data.button));
   }
  });
            
forSpan() searches the DOM for spans containing "jpn_button" in their class attributes. Then it calls the function with the span element and the evaluated data object. The function creates the button with the given text that calls the given function when pushed. Without javascript only an empty span is there. fallback code can be added in <noscript></noscript> after that.


japano.Error(code, response)
This Object is thrown by japano to indicate an error.