|
JuiceDoc
Package juice.rpcAjax(Since 0.1.1) Performs asynchronous get/post requests and handles response. Constructorvar ajax = new juice.rpc.Ajax(url, response, error); Parameters:
Methods
Response wrapperThe ajax object will pass to the handler a wrapper object that encapsulates the response object. This wrapper is created by the ajax object.
DescriptionThe ajax object will handle all assynchrounous, sending the request using get or post, and calling the appropriate response handler when needed. The object will pass to the handler a wrapper object that encapsulates the response object. The code above show an example: var ajax = new juice.rpc.Ajax("my_test_url", response_handler);
function response_handler(req){
sb = new juice.text.StringBuffer();
sb.append("OK:");
sb.append("txt::"+req.text());
sb.append("xml::"+req.xml());
sb.append("json::"+req.json());
sb.append("status::"+req.statusText());
sb.append("status code::"+req.statusCode());
sb.append("obj::"+req.responseObject());
alert(sb.concat('\n'));
}AjaxScheduler(Since 0.1.2) Performs asynchronous get/post requests at regular intervals and handles response. Constructorvar sched = new juice.rpc.AjaxScheduler(url, params); Parameters:
Methods
DescriptionThe AjaxScheduler object perform asynchronous requests, calling the appropriate response handler when needed. As with the Ajax object, the scheduler will pass to the handler a wrapper object that encapsulates the response object. The code above show an example: Example 1: var sched = new juice.rpc.AjaxScheduler("url",
{response: response_handler,
delay: 7000});
function response_handler(req){
sb = new juice.text.StringBuffer();
sb.append("OK:");
sb.append("txt::"+req.text());
sb.append("xml::"+req.xml());
sb.append("json::"+req.json());
sb.append("status::"+req.statusText());
sb.append("status code::"+req.statusCode());
sb.append("obj::"+req.responseObject());
alert(sb.concat('\n'));
}Example 2: var sched = new juice.rpc.AjaxScheduler("url",
{response: function(){alert("OK");},
request: function(){return "id=2";},
delay: 7000,
method: "GET"});Example 3: var sched = new juice.rpc.AjaxScheduler("url",
{response: function(){alert("OK");},
error: function(){alert("ERROR");},
request: "id=2",
delay: 7000});get(url, params, response, error)(Since 0.2) Function that wraps ans Ajax GET request. Parameters:
post(url, params, response, error)(Since 0.2) Function that wraps ans Ajax POST request. Parameters:
send(url, params)(Since 0.2) Function that sends an Ajax POST request without waiting for a response. Parameters:
Package juice.htmlbuildRequestString(dict)(Since 0.1.2) Builds a request string based on data stored in an associative array. Example: juice.html.buildRequestString({"id":2, "name":"ajax"}) returns "id=2&name=ajax".
Package juice.datadictKeys(dict)(Since 0.1.1) Returns an array containing all the keys stored in an associative array. Example: juice.data.dictKeys({"a":1,"b":2,"c":3}) returns ["a","b","c"]. dictValue(dict)(Since 0.1.1) Returns an array containing all the values stored in an associative array. Example: juice.data.dictKeys({"a":1,"b":2,"c":3}) returns [1,2,3]. Array functions(Since 0.1.1) Juice Lib adds some useful functions to the native javascript array object.
Package juice.textStringBuffer(Since 0.1.1) juice.text.StringBuffer offers a buffer to build strings. Very useful if you need to concatenate small pieces of text to build a sentence. Some comparison tests showed that the use of string buffer is much more efficient than using str = str1 + str2. Constructor: var buffer = new juice.text.StringBuffer() Methods:
String functions(Since 0.1.1) Juice lib adds some functions to the native javascript String, that can be used in any string. Example: "Hello World ".rstrip() returns "Hello World".
Package juice.events(Since 0.1.1) juice.events.onload(Since 0.1.1) Provides some facilites to create on load events. add(func)(Since 0.1.1) Registers a function to be executed after document loading. Parameters:
Example 1: juice.events.onload.add(function(){alert("Document loaded");});Example 2: function myfunc = {
alert("document loaded");
};
juice.events.onload.add(myfunc);exec()(Since 0.1.1) Method for body.onload attribute registration, in case the automatic behaviour does not work. Example: juice.events.exec(); juice.events.key(Since 0.1.1) Keyboard event manager. Fires action based on key pressed outside input widgets (textfield, textarea, input). DOES NOT WORK FOR SAFARI unhandleKeys()(Since 0.1.1) Turn off the keyboard handler. handleKeys()(Since 0.1.1) Turn on the keyboard handler. add(symbol, func)(Since 0.1.1) Registers a function to be executed when the given char is pressed Parameters:
Example: juice.events.key.add("A", function(){daler("Key A pressed");}); left(func)(Since 0.1.1) Registers a function to be executed when the left key is pressed Parameters:
Example: juice.events.key.left(function(){alert("left")}); right(func)(Since 0.1.1) Registers a function to be executed when the right key is pressed Parameters:
Example: juice.events.key.right(function(){alert("right")}); up(func)(Since 0.1.1) Registers a function to be executed when the up key is pressed Parameters:
Example: juice.events.key.up(function(){alert("up")}); down(func)(Since 0.1.1) Registers a function to be executed when the down key is pressed Parameters:
Example: juice.events.down.left(function(){alert("down")}); |