Node

The Node.js API v0.2

Introduction

This is the draft of the coming new Node.js API.

See also the Node.js API overview.

Functions

createTree

createTree()

Creates a tree, which relies on xmlbuilder, and is intended to be passed as the tree parameter of the setLayoutXSL() method of the DOM object (see below).

headUp

headUp(html)

If this function is needed, has to be called before the first setLayout[XSL](...) call.

This puts the content of html (string) in the head section of the application's HTML main page. You can put here the link to CSS files.

launch

launch(createCallback,newSessionAction,callbacks[,gui])

Launches the server.

createCallback is called for each new session. This callback must return an instantiation of the DOM class (see below), or a subclass of it.

newSessionAction (string) is one of the tag from the callbacks parameter, whose callback will be called for each new connection.

callbacks contains for each event tag (data-xdh-onevent(s)) the callback to be called. It must be of following form:

{
    'tag1': callback1,
    'tag2': callback2,
    'tag3': callback3,
    ...
}

tagx are the event tag as defined in data-xdh-onevent(s) HTML attributes, and callbackx, callbacks which receive as first parameter the object returned by createCallback, and, as second parameter, the id of the element which receives the event.

gui, if given, must be guis.DESKTOP to launch the desktop interface or guis.WEB (the default one) to launch the web one.

DOM object

The object containing data for each users' session, and with method to manipulate the DOM displayed by the web browser.

All methods with a parameter callback are called asynchronously, and callback is called once the method is achieved, with no parameter unless specified otherwise.

Global

DOM constructor

Takes no parameter.

alert

alert(message[,callback])

Displays an alert box with the string message as message.

confirm

confirm(message[,callback])

Displays a confirmation box with the string message as message. Optional callback is called with a boolean parameter set to true when the user clicks the OK button, and false when the user clicks the cancel button.

focus

focus(id[,callback])

Gives the focus to element of id id (string).

Attribute

getAttribute

getAttribute(id,name[,callback])

Calls optional callback callback with, as parameter, a string with the value of attribute named name (string) of the element of id id (string).

removeAttribute

removeAttribute(id,name[,callback])

Removes attribute named name (string) from element of id id (string).

setAttribute

setAttribute(id,name,value[,callback])

Set value as value (string) for the attribute named name (string) of the element of id id (string).

Class

Following methods allows to handle classes (the CSS related class attributes of HTML tags), by respectively add, remove or toggle (i.e. adds if not present, otherwise removes) a class to elements identified by their ids (the content of the id attribute from HTML tags).

idsAndClasses must have following form:

{
    'id1': 'class1',
    'id2': 'class2',
    'id3': 'class3',
    ...
}

addClass

addClass(id,class[,callback])

addClasses

addClasses(idsAndClasses[,callback])

removeClass

removeClass(id,class[,callback])

removeClasses

removeClasses(idsAndClasses[,callback])

toggleClass

toggleClass(id,class[,callback])

toggleClasses

toggleClasses(idsAndClasses[,callback])

Content

getContent

getContent(id[,callback])

Retrieve the content of the element of id id (string) and calls optional callback callback with, as parameter, the asked content (as string).

getContents

getContents(ids[,callback])

Retrieves the content of the elements of ids ids (array of strings) and calls optional callback callback with, as parameter, an array of strings containing the asked contents, in the same order as ids.

setContent

setContent(id,value[,callback])

Set the content of element of id id (string) to value (string).

setContents

setContents(idsAndValues[,callback])

Set the content all element which id are in idsAndValues to corresponding value.

idsAndValues must have following form:

{
    'id1': 'value1',
    'id2': 'value2',
    'id3': 'value3',
    ...
}

idx is the id as set as value for the id attribute of the concerned HTML tag, and valuex the string corresponding to the content.

Element

enableElement

enableElement(id[,callback])

Enable element of id id.

enableElements

enableElements(ids[,callback])

Enable element of ids ids (array of strings).

disableElement

disableElement(id[,callback])

Disable element of if id.

disableElements

disableElements(ids[,callback])

Disable element of ids ids (array of strings).

Layout

setLayout

setLayout(id,html[,callback])

Replaces the content of element with string id as id with the content of html (string).

If id is an empty string, the content of the entire document is replaced by the resulting transformation.

The content of html can be generated with the template engine of your choice. For XSL(T), you can used the dedicated method setLayoutXSL(...).

setLayoutXSL

setLayout(id,tree,xslFilename[,callback])

Replaces the content of element with string id as id with the result of the transformation of the XSL file with name xslFilename (string) applied to the content of tree, which is created with the createTree() function (see above), and relies on xmlbuilder.

If id is an empty string, the content of the entire document is replaced by the resulting transformation.

Property

getProperty

getProperty(id,name[,callback])

Calls optional callback callback with, as parameter, a string with the value of property named name (string) of the element of id id (string).

setProperty

setProperty(id,name,value[,callback])

Set value as value (string) for the property named name (string) of the element of id id (string).

Widget

dressWidgets

dressWidgets(id[,callback])

Create the widget for each elements which are children of the element of id id (string) and which have a data-xdh-widget attribute.