About Pi Downloads Documentation Plugins Developer Forum Issues

pi.util2009-01-06 09:23:27

Summary

pi.util is an object that contains some essential javascript tools.

Methods

Curry pi.util.Curry(function,scope,arguments ...)
Returns a generic curried version of specified function.
Extend var className = pi.util.Extend( superClass, { "$Init":Constructor, property name:value, private member:value }, boolean skipClonning (optional) )
Provides creating javascript classes by using pi.base.With this function, you can extend a class with other classes. If not another class will be extended, pi.base should be send as the first parameter.
IsArray pi.util.IsArray(value);
Finds whether a variable is an array
IsHash pi.util.IsHash(value);
Finds whether a variable is a hash.
Init pi.util.Init.push(function);
An array containing functions that runs when DOM document is loaded.
Import pi.util.Import(file url,fileType (optional));
Includes a JS or CSS file to the page with a synchronous request.
AddEvent pi.util.AddEvent(target,type,listener,useCapture);
Allows the registration of event listeners on the event target.
RemoveEvent pi.util.RemoveEvent(target,type,listener,useCapture);
Allows the removal of event listeners on the event target.
Include pi.util.Include(url,callback);
A Function that loads and executes javascript files using an HTTP GET request and allows cross domain JSON transfers.
GetViewport pi.util.GetViewport();
Returns size of available space on the screen.

Examples

Example #1: Get mouse coordinates of mouse pointer when user click anywhere.

Source files of the above example:

examples/findCoordinates.html

<label>X Coordinate:</label><input id='x' type='text' />
<label>Y Coordinate:</label><input id='y' type='text' />

<button id='removeButton'>Remove Event</button>

examples/findCoordinates.js

var getCoordinates = function(_event){
	pi.get('x').value = _event.clientX;
	pi.get('y').value = _event.clientY;
};

var removeEvent = function(){
	pi.util.RemoveEvent(document.body,'click',getCoordinates);
};

/*
	Set events when dom content is ready.
*/

pi.util.AddEvent(document.body,'click',getCoordinates);
pi.util.AddEvent( pi.get('removeButton'), 'click', removeEvent )