5.2 LyrObj

  Download source    View color-coded source    Launch example

Content of LyrObj.js:
LyrObj
This class encapsulates a DIV element and provides cross-browser access to its properties such as position, visibility, and clipping. This implementation is the lean core class for working with layers.


function LyrObj(lyrName, nestedRef)
Constructs a new LyrObj wrapping the layer lyrName. If the layer is nested within another, you have to specify the parent layer's name in the nestedRef parameter, otherwise Netscape 4.5x won't be able to find it in the document's object hierarchy.

Parameters
    String lyrName - the name of the layer as in <div id="(layername)"></div>
    String [nestedRef] - path to a nested layer
Returns
    LyrObj - a new LyrObj object for the layer lyrName



function getRef(layerName)
Returns the reference to the actual DIV element

Parameters
    String layerName - the layer's name
Returns
    object - layer reference



function getPos(which)
Returns the current position of the layer, use the CSS names, "left" for x and "top" for y.

Parameters
    String which - "left" or "top" to retrieve the respective value
Returns
    int - the value (without the "px" suffix)



function setPos(which, pos)
Sets the position of the layer, again, this works with CSS names, "left" for x and "top" for y.

Parameters
    String which - "left" or "top"
    int pos - the new value



function getClip(which)
Returns the current clip value of the layer. The value has to be set beforehand, otherwise the result is undefined.

Parameters
    String which - "left", "top", "right", "bottom"
Returns
    int - the current clip value



function setClip(left, top, right, bottom)
Sets the layer's clip rect property to the rectangle (left, top, right, bottom).

Parameters
    int left - left clip
    int top - top clip
    int right - right clip
    int bottom - bottom clip



function getVisibility()
Returns the layer's current visibility.

Returns
    bool - True if it's visible



function setVisibility(visible)
Sets the layer's visibility.

Parameters
    bool visible - true to make it visible, false to hide it



function show() {
Shows the layer. Shortcut to setVisibility(true).


function hide()
Hides the layer. Shortcut to setVisibility(false).


function getzIndex()
Returns the layer's current z-Index.

Returns
    int - the layer's z-Index



function setzIndex(zIndex)
Sets the layer's z-Index.

Parameters
    int zIndex



function getX()
Returns the current x position of the layer. Shortcut to getPos("left").

Returns
    int x



function getY()
Returns the current y position of the layer. Shortcut to getPos("top").

Returns
    int y



function moveTo(x, y)
Sets the layer to the target position (x, y).

Parameters
    int x - target x position
    int y - target y position



function moveBy(dx, dy)
Moves the layer by the specified diffences, relative to its current position.

Parameters
    int dx - x amount
    int dy - y amount



function toString(html)
Returns a string representation of the current LyrObj.
The html parameter determines the kind of line breaks:
true for HTML line breaks,
false for normal text.

Parameters
    bool [html] - true=HTML, false=TEXT
Returns
    String - the layer's position, z-Index, clipping and visibility



Helper functions

function fixNetscape()
Intention: After starting Netscape 4.x, the first call to the constructor fails, throwing an error.
This is a fix that simply causes a reload of the page in case the test layer couldn't be accessed. To apply, make sure the page contains the line
<div id="fixnetscape" style="position:absolute;visibility:hidden"></div> and call this function in your onLoad-handler.