JS-GIS 2 API reference

HTML objects

Table of contents


TStyle object

Description

TStyle represents the stylesheet attributes for an object.

Properties

units

Units for representing coordinates; the default is 'px' (pixels).

autoClip

Tells wether a clipping rectangle must be automatically recalculated before drawing according to the box property and the current border width.

box

The box object is created by the setBox() method. It has the x, y, width and height properties.

clip

The clip object is created by the setClip method. It has the top, right, bottom and left properties.

border

The border object is created by the setBorder method. It has the width, color and style properties. If width is set to 0, the border will not be drawn.

background

The background object is created by the setBackground method. It has the color and image properties.

Methods

TStyle()

The class constructor returns a new instance of a TStyle object. Once created, calls to TStyle methods allow to set separate attributes, like border or dimensions.

An object containing a TStyle object should call its toString() method like

szBuf += 'style="' + this.style.toString() + '"'
or directly the getDef() method:
szBuf += this.style.getDef()

toString()

Returns a string representation of the syle attributes, in the form "proerty1:value1; property2:value2..."

getDef()

Returns the style definition in the form style="...", or an empty string if the style object has no attributes.

setBox(x, y, width, height)

Creates a TStyle.box object given the upper-left corner coordinates and rect size.

setClip(top, right, bottom, left)

Sets the clipping area. If parameters are omitted, the clipping area is calculated according to the box property and the border width.

Creates a TStyle.clip object.

setBorder(width, style, color)

Sets the object border attributes, creating a TStyle.border object.

setBackground(color, image)

Sets the background color and/or image, creating a TStyle.background object.


TFrame object

Description

The TFrame class implements <DIV> tags, which can be viewed as "layers" or "frames" possibly containing other objects.

Properties

rect

TRect object representing size and position of the frame on the web page. rect.min returns the upper-left corner in the style.units units (default to 'px', pixels).

varName

An optional string used to identify the object in the case it has to handle events (see onClickHandler and anchor). It should be equal to the name of a variable pointing to the instance of the TFrame object, fully qualified in case the frame is placed in a page different from the one the frame variable is defined into (i.e. parent.variable_name).

className

Returns "TFrame".

isFrame

Boolean, returns true.

style

A TStyle object holding the stylesheet attributes for the frame. The box attributes and the autoClip values are created by the constructor function TFrame().

anchor

A TAnchor object holding the hyperlink information for the frame.

contents

Contents can hold a reference to a string or an object implementing the toString() method, and represents the HTML code contained in the <div></div> tag.

visible

Boolean value indicating wether the frame object is visible or not. If visible equals zero, the toString() method returns an empty string.

Event handlers

beforeDraw

This pointer can be assigned to a function accepting no parameters. The function is called at the beginning of the toString() method. If the function doesn't return true (1) value, an empty string is returned by toString().

The function can be used either to cancel object drawing, or to do some calculation before drawing.

The visible property is checked after the beforeDraw() event; if the event handler doesn't cancel object drawing, it must also ensure that visible is set to 1.

Methods

TFrame(aX, aY, aWidth, aHeight, aVarName)

The class constructor. Size and position are defined by the upper left corner coordinates, width and height of the bounding rectangle. aVarName can be set to a valid variable name (see varName property description).

toString()

Returns the HTML code needed to draw the object on the page.

updateBox()

Updates the style.box object with the rect object coordinates. Automatically called by the TFrame constructor and resize method.

resize(newW, newH, newX, newY)

Resizes the frame by changing size and/or position of the rect object and updating the style.box accordingly.

setClickHandler(handlerObjName)

Specify that the frame object will respond to mouse click events calling the onClickHandler method of the handler object pointed by the global variable which name is contained in the handlerObjName string.

For example, the TMap class calls the setClickHandler method of its frame object passing it the instance name:

this.frame.setClickHandler(this.varName)
The previous example assumes that the TMap object has been created passing it the global variable name containing a reference to it:
var Map = new TProjectMap(Project, 'parent.Map', 450, 450, 3, 3, 0, 0)

The method creates an anchor with an onclick event pointing to the objectClick(event, handler) global function. objectClick eventually calls handler.onClickHandler(p), where p is a TPoint object containing the graphic coordinates of the point where the left mouse button has been pressed on the frame object. A "parent." qualified reference to the Map variable is used since Map is defined in a file included in the main frameset, while the mouse click is handled by a frame drawn in the map window frame.


TImage object

Description

TImage represents an image included in an HTML file with the <img> tag.

Properties

src

String, holds the path to the image file. If a relative path is used, it should be relative to the path of the page whre the image has to be inserted.

width

Integer, image width in pixels.

height

Integer, image height in pixels.

borderW

Integer, the border width in pixels. If set to 0 (zero), no border will be displayed.

alt

String, the alternate text for the image.

imgmap

String, name of an imagemap, if any, that has to be associated with the image, as defined in the <map name="xxx"> tag.

className

String, returns "TImage"

isImage

Boolean, returns true.

style

Points to a TStyle object defining CSS styles for the image..

anchor

A TAnchor object holding the hyperlink information for the image.

Methods

TImage(src, w, h, x, y)

The class constructor returns a new instance of a TImage object.

toString()

Returns a string representation of the <img> tag.

TAnchor object

Description

TAnchor represents an <A> anchor tag for associating an hypertext link or onclick handler with a Image or Frame object.

Properties

href

String, holds the address of the hypertext link. If a relative path is used, it should be relative to the path of the page where the owner object has to be inserted.

target

String, specifies the target part of the anchor element. If none is specified, the caller document is assumed. Target should not be specified when using JavaScript HREFs or onClick handlers.

useOnClick

Boolean, specifies wether a onclick handler has to be used instead of the HREF tag.

enabled

Boolean, specifies wether or not the link is enabled. If disabled, the toString() metod will not return the <A> command.

className

String, returns "TAnchor"

isAnchor

Boolean, returns true.

Methods

TAnchor(href, target, useOnClick, disabled)

The class constructor returns a new instance of a TAnchor object. Only the href parameter is compulsory.

Note that href is used for both HREFs and onclick handlers. The useOnClick property decides which one will be used.

toString(contents)

Returns a string representation of the <A> tag. Unlike other onString methods, the TAnchor.onString() function accepts one parameter, which can be either a string or an object providing a toString() method. If a null parameter is passed, toString() returns only the opening <A> tag; otherwise, contents is returned embedded in <A></A> tags.


JS-GIS © 2001, 2002 by Luca S. Percich (mailto:luca.percich@reacoop.it)
Last updated: dec 26, 2002