Class Index | File Index

Classes


Namespace pwlib

Holds methods and properties necessary throughout the entire application.
Defined in: lib.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
<static>  
pwlib.extend(overwrite, destination, source)
This function extends objects.
<static>  
pwlib.isSameHost(url, host)
Check if an URL points to a resource from the same host as the desired one.
<static>  
pwlib.jsonParse(str)
Parse a JSON string.
<static>  
pwlib.strf(str, vars)
Retrieve a string formatted with the provided variables.
<static>  
pwlib.xhrLoad(url, handler, method, send, headers)
Load a file from a given URL using XMLHttpRequest.
Namespace Detail
pwlib
Method Detail
<static> pwlib.extend(overwrite, destination, source)
This function extends objects.
var obj1 = {a: 'a1', b: 'b1', d: 'd1'},
    obj2 = {a: 'a2', b: 'b2', c: 'c2'};

pwlib.extend(obj1, obj2);

// Now obj1.c == 'c2', while obj1.a, obj1.b
// and obj1.d remain the same.

// If pwlib.extend(true, obj1, obj2) is
// called, then obj1.a, obj1.b, obj1.c
// become all the same as in obj2.
var obj1 = {a: 'a1', b: 'b1', extend: pwlib.extend};
obj1.extend({c: 'c1', d: 'd1'});

// In this case the destination object which is to be extend is
// obj1.
Parameters:
{Boolean} overwrite Optional, Default: false
If the first argument is a boolean, then it will be considered as a boolean flag for overwriting (or not) any existing methods and properties in the destination object. Thus, any method and property from the source object will take over those in the destination. The argument is optional, and if it's omitted, then no method/property will be overwritten.
{Object} destination Optional, Default: this
The second argument is the optional destination object: the object which will be extended. By default, the this object will be extended.
{Object} source
The third argument must provide list of methods and properties which will be added to the destination object.

<static> {Boolean} pwlib.isSameHost(url, host)
Check if an URL points to a resource from the same host as the desired one.

Note that data URIs always return true.

Parameters:
{String} url
The URL you want to check.
{String} host
The host you want in the URL. The host name can include the port definition as well.
Returns:
{Boolean} True if the url points to a resource from the host given, or false otherwise.

<static> pwlib.jsonParse(str)
Parse a JSON string. This method uses the global JSON parser provided by the browser natively. The small difference is that this method allows normal JavaScript comments in the JSON string.
Parameters:
{String} str
The JSON string to parse.
Returns:
The JavaScript object that was parsed.

<static> {String} pwlib.strf(str, vars)
Retrieve a string formatted with the provided variables.

The language string must be available in the global lang object.

The string can contain any number of variables in the form of {var_name}.

lang.table_cells = "The table {name} has {n} cells.";

// later ...
console.log(pwlib.strf(lang.table_cells, {'name' : 'tbl1', 'n' : 11}));
// The output is 'The table tbl1 has 11 cells.'
Parameters:
{String} str
The string you want to output.
{Object} vars Optional
The variables you want to set in the language string.
Returns:
{String} The string updated with the variables you provided.

<static> {XMLHttpRequest} pwlib.xhrLoad(url, handler, method, send, headers)
Load a file from a given URL using XMLHttpRequest.
Parameters:
{String} url
The URL you want to load.
{Function} handler
The onreadystatechange event handler for the XMLHttpRequest object. Your event handler will always receive the XMLHttpRequest object as the first parameter.
{String} method Optional, Default: "GET"
The HTTP method to use for loading the URL.
{String} send Optional, Default: null
The string you want to send in an HTTP POST request.
{Object} headers Optional
An object holding the header names and values you want to set for the request.
Throws:
{TypeError}
If the url is not a string.
Returns:
{XMLHttpRequest} The XMLHttpRequest object created by this method.

Documentation generated by JsDoc Toolkit 2.3.0 on Sat Jun 26 2010 21:56:59 GMT+0300 (EEST)