Zapatec.Transport

Overview | File | Class | Tree | Index | Help

Zapatec Utils

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## Class Zapatec.Transport

    Object
       |
       +--Zapatec.Transport

class Zapatec.Transport

Defined in transport.js

Field Summary
`<static> Object` | `pickActiveXVersion`

Constructor Summary
`Zapatec.Transport()`

Method Summary
`<static> object` | `createXmlHttpRequest()` Creates cross browser XMLHttpRequest object.
`<static> void` | `evalGlobalScope(<string> sScript)` Evaluates javascript in global scope.
`<static> object` | `fetch(<object> oArg)` Fetches specified URL using new XMLHttpRequest object.
`<static> object` | `fetchJsonObj(<object> oArg)` Fetches and parses JSON object from the specified URL.
`<static> object` | `fetchXmlDoc(<object> oArg)` Fetches and parses XML document from the specified URL.
`<static> string` | `getPath(<string> sScriptFileName)` Returns path to the specified js file.
`<static> void` | `include(<string> sSrc, <string> sId, <boolean> bForce)` Writes script tag to the document.
`<static> void` | `includeCSS(<string> sHref)` Includes CSS file into the page.
`<static> void` | `includeJS(<string> sSrc, <string> sId)` Includes JS file into the page.
`<static> void` | `loadCss(<object> oArg)` Fetches style sheet using fetch and loads it into the document.
`<static> void` | `loadCssList(<object> oArg)` Loads several CSS files one by one it into the document.
`<static> void` | `loadJS(<object> oArg)` Fetches JS file using fetch and evaluates it in global scope.
`<static> object` | `parseHtml(<string> sHtml)` Parses HTML fragment into HTMLElement object.
`<static> object` | `parseJson(<object> oArg)` Parses JSON string into object.
`<static> object` | `parseXml(<object> oArg)` Parses XML string into XMLDocument object.
`<static> void` | `preloadImages(<object> oArg)` Preloads one or several images at once.
`<static> void` | `removeBusy(<object> oArg)` Removes animated GIF which was put by Zapatec.Transport.showBusy() from the specified div.
`<static> string` | `serializeJsonObj(<object> v)` Serializes JSON object into JSON string.
`<static> string` | `serializeXmlDoc(<object> oDoc)` Serializes XMLDocument object into XML string.
`<static> void` | `setInnerHtml(<object> oArg)` Assigns passed HTML fragment to the specified element's innerHTML property and evaluates in global scope javascripts found in the fragment.
`<static> void` | `showBusy(<object> oArg)` Shows animated GIF in the specified div.
`<static> string` | `translateUrl(<object> oArg)` Translates a URL to the URL relative to the specified or to absolute URL.

Field Detail

### pickActiveXVersion

    <static> Object pickActiveXVersion

Constructor Detail

### Zapatec.Transport

    Zapatec.Transport()

Method Detail

### createXmlHttpRequest

    <static> object createXmlHttpRequest()

Creates cross browser XMLHttpRequest object.

Returns:

New XMLHttpRequest object.

### evalGlobalScope

    <static> void evalGlobalScope(<string> sScript)

Evaluates javascript in global scope.

Note: Global variables must be declared without "var" keyword. Otherwise they will be ignored by Safari.

Parameters:

`sScript` - Script to evaluate

### fetch

    <static> object fetch(<object> oArg)

Fetches specified URL using new XMLHttpRequest object.

     Asynchronous mode is recommended because it is safer and there is no risk of
     having your script hang in case of network problem. Synchronous mode means
     that the code will hang until a response comes back.

     When request is completed, one of provided callback functions is called:
     onLoad on success or onError on error. In synchronous mode onLoad callback
     can be omitted. Instead use returned object.

     onLoad callback function receives XMLHttpRequest object as argument and may
     use its various properties like responseText, responseXML, etc.

     onError callback function receives following object:
     {
       errorCode: server status number (404, etc.) [number],
       errorDescription: human readable error description [string]
     }

     Note: Some browsers implement caching for GET requests. Caching can be
     prevented by adding 'r=' + Math.random() parameter to URL.

     If you use POST method, content argument should be something like
     'var1=value1&var2=value2' with urlencoded values. If you wish to send other
     content, set appropriate contentType. E.g. 'multipart/form-data', 'text/xml',
     etc.

     If server response contains non-ASCII characters, server must send
     corresponding content-type header. E.g.
     "Content-type: text/plain; charset=utf-8" or
     "Content-type: text/plain; charset=windows-1251".

     Arguments object format:
     {
       url: [string] relative or absolute URL to fetch,
       method: [string, optional] method ('GET', 'POST', 'HEAD', 'PUT'),
       async: [boolean, optional] use asynchronous mode (default: true),
       contentType: [string, optional] content type when using POST,
       content: [string or object, optional] postable string or DOM object data
        when using POST,
       onLoad: [function, optional] function reference to call on success,
       onError: [function, optional] function reference to call on error,
       username: [string, optional] username,
       password: [string, optional] password,
       busyContainer: [object or string, optional] element or id of element where
        to put "Busy" animated GIF,
       busyImage: [string, optional] standard image name or custom image URL,
       busyImageWidth: [number or string, optional] image width,
       busyImageHeight: [number or string, optional] image height
     }

Parameters:

`oArg` - Arguments object

Returns:

In synchronous mode XMLHttpRequest object or null. In asynchronous mode always null.

### fetchJsonObj

    <static> object fetchJsonObj(<object> oArg)

Fetches and parses JSON object from the specified URL.

     When JSON object is fetched and parsed, one of provided callback functions
     is called: onLoad on success or onError on error. In synchronous mode onLoad
     callback can be omitted. Instead use returned object.

     onLoad callback function receives JSON object as argument.

     onError callback function receives following object:
     {
       errorCode: error code [number],
       errorDescription: human readable error description [string]
     }
     Error code will be 0 unless there was a problem during fetching.

     Note: Some browsers implement caching for GET requests. Caching can be
     prevented by adding 'r=' + Math.random() parameter to URL.

     If you use POST method, content argument should be something like
     'var1=value1&var2=value'. If you wish to send other content, set appropriate
     contentType. E.g. to send XML string, you should set contentType: 'text/xml'.

     If server response contains non-ASCII characters, server must send
     corresponding content-type header. E.g.
     "Content-type: text/plain; charset=utf-8" or
     "Content-type: text/plain; charset=windows-1251".

     Arguments object format:
     {
       url: [string] relative or absolute URL to fetch,
       reliable: [boolean, optional] false (string will be parsed) or true
       (evaluated) (default: false),
       method: [string, optional] method ('GET', 'POST', 'HEAD', 'PUT'),
       async: [boolean, optional] use asynchronous mode (default: true),
       contentType: [string, optional] content type when using POST,
       content: [string or object, optional] postable string or DOM object data
        when using POST,
       onLoad: [function, optional] function reference to call on success,
       onError: [function, optional] function reference to call on error,
       username: [string, optional] username,
       password: [string, optional] password,
       busyContainer: [object or string, optional] element or id of element where
        to put "Busy" animated GIF,
       busyImage: [string, optional] standard image name or custom image URL,
       busyImageWidth: [number or string, optional] image width,
       busyImageHeight: [number or string, optional] image height
     }

Parameters:

`oArg` - Arguments object

Returns:

In synchronous mode JSON object or null. In asynchronous mode always null.

### fetchXmlDoc

    <static> object fetchXmlDoc(<object> oArg)

Fetches and parses XML document from the specified URL.

     When XML document is fetched and parsed, one of provided callback functions
     is called: onLoad on success or onError on error. In synchronous mode onLoad
     callback can be omitted. Instead use returned object.

     onLoad callback function receives XMLDocument object as argument and may use
     its documentElement and other properties.

     onError callback function receives following object:
     {
       errorCode: error code [number],
       errorDescription: human readable error description [string]
     }
     Error code will be 0 unless Zapatec.Transport.fetch was used to fetch URL
     and there was a problem during fetching.

     If method argument is not defined, more efficient XMLDOM in IE and
     document.implementation.createDocument in Mozilla will be used to fetch
     and parse document. Otherwise Zapatec.Transport.fetch will be used to fetch
     document and Zapatec.Transport.parseXml to parse.

     Note: Some browsers implement caching for GET requests. Caching can be
     prevented by adding 'r=' + Math.random() parameter to URL.

     If you use POST method, content argument should be something like
     'var1=value1&var2=value'. If you wish to send other content, set appropriate
     contentType. E.g. to send XML string, you should set contentType: 'text/xml'.

     If server response contains non-ASCII characters, encoding must be specified.
     E.g.  or
     .

     If server response contains non-ASCII characters, server must send
     corresponding content-type header. E.g.
     "Content-type: text/xml; charset=utf-8" or
     "Content-type: text/xml; charset=windows-1251".

     Arguments object format:
     {
       url: [string] relative or absolute URL to fetch,
       method: [string, optional] method ('GET', 'POST', 'HEAD', 'PUT'),
       async: [boolean, optional] use asynchronous mode (default: true),
       contentType: [string, optional] content type when using POST,
       content: [string or object, optional] postable string or DOM object data
        when using POST,
       onLoad: [function, optional] function reference to call on success,
       onError: [function, optional] function reference to call on error,
       username: [string, optional] username,
       password: [string, optional] password,
       busyContainer: [object or string, optional] element or id of element where
        to put "Busy" animated GIF,
       busyImage: [string, optional] standard image name or custom image URL,
       busyImageWidth: [number or string, optional] image width,
       busyImageHeight: [number or string, optional] image height
     }

Parameters:

`oArg` - Arguments object

Returns:

In synchronous mode XMLDocument object or null. In asynchronous mode always null.

### getPath

    <static> string getPath(<string> sScriptFileName)

Returns path to the specified js file. Iterates over all loaded script elements starting from the end. Finds specified js file in src attribute of the script element. Splits src attribute value and returns path without js file name.

Parameters:

`sScriptFileName` - Script file name, e.g. 'zpmywidget.js'

Returns:

Path to the script, e.g. '../src/' or '' if path is not found

### include

    <static> void include(<string> sSrc, <string> sId, <boolean> bForce)

Writes script tag to the document. Checks if specified JS file is already loaded unless bForce argument is true.

     Note: This function must be invoked during page load because it uses
     document.write method.

     If special Zapatec.doNotInclude flag is set, this function does nothing.

Parameters:

`sSrc` - Src attribute value of the script element

`sId` - Optional. Id of the script element

`bForce` - Optional. Force reload if it is already loaded

### includeCSS

    <static> void includeCSS(<string> sHref)

Includes CSS file into the page. Allows URLs from foreign domains. Doesn't check if the CSS file is already included. File is loaded asynchronously. Requires that head section of the page already exists because link tag may appear only inside head.

Parameters:

`sHref` - Href attribute value of the link element

### includeJS

    <static> void includeJS(<string> sSrc, <string> sId)

Includes JS file into the page. Allows URLs from foreign domains. Doesn't check if the JS file is already included. File is loaded asynchronously.

Parameters:

`sSrc` - Src attribute value of the script element

`sId` - Optional. Id of the script element

### loadCss

    <static> void loadCss(<object> oArg)

Fetches style sheet using fetch and loads it into the document. Requires utils/stylesheet.js module.

     When stylesheet is loaded successfully, onLoad callback function is called
     without arguments. URL is added into Zapatec.Transport.loadedCss array
     and will not be fetched again on next function call unless force argument is
     set to true.

     onError callback function receives following object:
     {
       errorCode: server status number (404, etc.) [number],
       errorDescription: human readable error description [string]
     }

     Arguments object format:
     {
       url: absolute or relative URL of CSS file [string],
       async: [boolean, optional] use asynchronous mode (default: true),
       force: [boolean, optional] force reload if it is already loaded,
       onLoad: [function, optional] function reference to call on success,
       onError: [function, optional] function reference to call on error
     }

     Note: If "force" is used, you should add 'r=' + Math.random() parameter to
     URL to prevent loading from browser cache.

Parameters:

`oArg` - Arguments object

### loadCssList

    <static> void loadCssList(<object> oArg)

Loads several CSS files one by one it into the document.

     This function behaves differently from other Zapatec.Transport functions.
     onLoad callback function will be called in any case, even if errors occured
     during loading. If there are multiple errors, onError callback function will
     be called once for every passed URL that wasn't loaded successfully.

     onLoad callback function is called without arguments.

     onError callback function receives following object:
     {
       errorCode: server status number (404, etc.) [number],
       errorDescription: human readable error description [string]
     }

     Arguments object format:
     {
       urls: array of absolute or relative URLs of CSS files to load [object]
        (files will be loaded in order they appear in the array),
       async: [boolean, optional] use asynchronous mode (default: true),
       force: [boolean, optional] force reload if it is already loaded,
       onLoad: function reference to call on completion [function] (optional),
       onError: function reference to call on error [function] (optional)
     }

     Note: If "force" is used, you should add 'r=' + Math.random() parameter to
     URL to prevent loading from browser cache.

Parameters:

`oArg` - Arguments object

### loadJS

    <static> void loadJS(<object> oArg)

Fetches JS file using fetch and evaluates it in global scope.

     When JS file is loaded successfully, onLoad callback function is called
     without arguments. URL is added into Zapatec.Transport.loadedJS array
     and will not be fetched again on next function call unless force argument is
     set to true.

     onError callback function receives following object:
     {
       errorCode: [number] server status number (404, etc.),
       errorDescription: [string] human readable error description
     }

     One of the arguments: module or url is required. When url is passed,
     module argument is ignored.

     If module argument is used, function gets all "script" elements using
     getElementsByTagName and searches for the first element having "src"
     attribute value ending with (relativeModule + ".js") (default relativeModule
     value is "transport"). Path to the module is taken from that src attribute
     value and will be the same as path to relativeModule file.

     Arguments object format:
     {
       url: [string, optional] absolute or relative URL of JS file,
       module: [string, optional] module name (file name without .js extension);
        ignored when "url" is defined,
       path: [string, optional] path where to search "module" (default is
        Zapatec.zapatecPath if it is defined); ignored when "url" is defined,
       async: [boolean, optional] use asynchronous mode (default: true),
       force: [boolean, optional] force reload if it is already loaded,
       onLoad: [function, optional] function reference to call on success,
       onError: [function, optional] function reference to call on error
     }

     Note: If "force" is used, you should add 'r=' + Math.random() parameter to
     URL to prevent loading from browser cache.

     Note: Global variables must be declared without "var" keyword. Otherwise
     they will be ignored by Safari.

     If special Zapatec.doNotInclude flag is set, this function just calls onLoad
     callback function.

Parameters:

`oArg` - Arguments object

### parseHtml

    <static> object parseHtml(<string> sHtml)

Parses HTML fragment into HTMLElement object.

Parameters:

`sHtml` - HTML fragment

Returns:

Div element which contains parsed HTML fragment

### parseJson

    <static> object parseJson(<object> oArg)

Parses JSON string into object.

     When JSON string is parsed, one of provided callback functions is called:
     onLoad on success or onError on error.

     onLoad callback function receives JSON object as argument.

     onError callback function receives following object:
     {
       errorCode: error code [number],
       errorDescription: human readable error description [string]
     }
     Error code will be always 0.

     Returns JSON object, so onLoad callback function is optional.
     Returned value should be checked before use because it can be null.

     Arguments object format:
     {
       strJson: JSON string to parse [string],
       reliable: false (string will be parsed) or true (evaluated) [boolean]
       (optional, false by default),
       onLoad: function reference to call on success [function] (optional),
       onError: function reference to call on error [function] (optional)
     }

Parameters:

`oArg` - Arguments object

Returns:

JSON object or null

### parseXml

    <static> object parseXml(<object> oArg)

Parses XML string into XMLDocument object.

     When XML string is parsed, one of provided callback functions is called:
     onLoad on success or onError on error. In synchronous mode onLoad callback
     can be omitted. Instead use returned object.

     onLoad callback function receives XMLDocument object as argument and may use
     its documentElement and other properties.

     onError callback function receives following object:
     {
       errorCode: error code [number],
       errorDescription: human readable error description [string]
     }
     Error code will be always 0.

     Returns XMLDocument object, so onLoad callback function is optional.
     Returned value and its documentElement property should be checked before
     use because they can be null or undefined.

     If XML string contains non-ASCII characters, encoding must be specified.
     E.g.  or
     .

     Arguments object format:
     {
       strXml: XML string to parse [string],
       onLoad: function reference to call on success [function] (optional),
       onError: function reference to call on error [function] (optional)
     }

Parameters:

`oArg` - Arguments object

Returns:

XMLDocument object or null

### preloadImages

    <static> void preloadImages(<object> oArg)

Preloads one or several images at once. Requires utils/preloadimages.js module. See Zapatec.PreloadImages class (utils/preloadimages.js) for details.

     Arguments object format:
     {
       urls: [object] array of absolute or relative image URLs to preload,
       onLoad: [function, optional] onload event handler,
       timeout: [number, optional] number of milliseconds to wait for onload
        event before forcing it
     }

Parameters:

`oArg` - Arguments object

### removeBusy

    <static> void removeBusy(<object> oArg)

Removes animated GIF which was put by Zapatec.Transport.showBusy() from the specified div.

     Arguments object format:
     {
       busyContainer: [object or string] element where to put animated GIF,
       busyImage: [string, optional] standard image name or custom image URL
     }

Parameters:

`oArg` - Arguments object

### serializeJsonObj

    <static> string serializeJsonObj(<object> v)

Serializes JSON object into JSON string. Was taken with changes from http://json.org/json.js.

Parameters:

`v` - JSON object

Returns:

JSON string

### serializeXmlDoc

    <static> string serializeXmlDoc(<object> oDoc)

Serializes XMLDocument object into XML string.

Parameters:

`oDoc` - XMLDocument object

Returns:

XML string

### setInnerHtml

    <static> void setInnerHtml(<object> oArg)

Assigns passed HTML fragment to the specified element's innerHTML property and evaluates in global scope javascripts found in the fragment.

     Arguments object format:
     {
       html: [string] HTML fragment,
       container: [object or string, optional] element or id of element to put
        HTML fragment into
     }

Note: Scripts are executed after HTML fragment is assigned to innerHTML. If external scripts are used, they are loaded asynchronously and execution sequence is not preserved.

Note: Global variables must be declared without "var" keyword. Otherwise they will be ignored by Safari.

Parameters:

`oArg` - Arguments object

### showBusy

    <static> void showBusy(<object> oArg)

Shows animated GIF in the specified div.

     Arguments object format:
     {
       busyContainer: [object or string] element where to put animated GIF,
       busyImage: [string, optional] standard image name or custom image URL,
       busyImageWidth: [number or string, optional] image width,
       busyImageHeight: [number or string, optional] image height
     }

Parameters:

`oArg` - Arguments object

### translateUrl

    <static> string translateUrl(<object> oArg)

Translates a URL to the URL relative to the specified or to absolute URL.

     Arguments object format:
     {
       url [string]: absolute or relative URL to translate; if absolute, will be
        returned as is,
       relativeTo [string, optional]: "url" will be translated to the URL relative
        to this absolute or relative URL; default: current page URL
     }

Parameters:

`oArg` - Arguments object

Returns:

Translated URL

Overview | File | Class | Tree | Index | Help

Zapatec Utils

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Documentation generated by JSDoc on Thu Aug 16 12:18:39 2007