An Experimental Emulation API for Layers
Bob Clary, Netscape Communications
Last Modified: December 16, 2002
This proof of concept illustrates the possibilities of using the Mozilla DOM prototypes to extend the underlying DOM in Netscape 6/Mozilla to support proprietary features. Layers.js extends the Netscape 6/Mozilla DOM to support Layers with only minimal modifications to the original Navigator 4 HTML and JavaScript required. This Layer emulation API is currently under development and not all of the Layer API is currently emulated. Please check back often to get the latest news and updates.
<script type="text/javascript"> if (document.layers) createLayer = new Function('width', 'parentLayer', 'return new Layer(width, parentLayer);'); else if (navigator.product == 'Gecko') document.write('<script type="text/javascript" src="Layers.js"><\/script>') </script>
<script type="text/javascript"> <!-- if (navigator.product == 'Gecko')) initializeLayers(); // --> </script>
layertest.html illustrates a simple example of the use of the Layer Emulation API using the following source:
<html> <head> <title>Test Layers.js</title> <script type="text/javascript"> if (document.layers) createLayer = new Function('width', 'parentLayer', 'return new Layer(width, parentLayer);'); else if (navigator.product == 'Gecko') document.write('<script type="text/javascript" src="Layers.js"><\/script>') </script> <script type="text/javascript"> <!-- function init() { alert('click to modify test layer'); document.testLayer.bgColor = 'red'; document.testLayer.moveBy(100, 100); document.testLayer.clip.right = 50; } // --> </script> </head> <body onload="init()"> <div name="testLayer" id="testLayer" style="position:absolute;"> This is a test layer </div> <script type="text/javascript"> <!-- initializeLayers(); // --> </script> </body> </html>
This approach has been used to take Michael Bostock's original Layer based Collapsible List example that was supported by Navigator 4, Internet Explorer 4+ but not Netscape 6 or Mozilla.
Do not work in Netscape 6/Mozilla due to Layers
and modify it according to the above instructions to give a version that is supported by Navigator 4, Internet Explorer 4+ and Mozilla/Netscape 6.
Do work in Netscape 6/Mozilla using the Layer Emulation API
Name | Status |
---|---|
Global Functions | |
Constructor | createLayer(width, parentLayer) |
Initializer | initializeLayers |
Properties | |
Layer.above | not implemented |
Layer.below | not implemented |
Layer.background | read/write |
Layer.bgColor | read/write |
Layer.clip | read |
Layer.clip.top | read/write |
Layer.clip.right | read/write |
Layer.clip.bottom | read/write |
Layer.clip.left | read/write |
Layer.clip.width | read/write |
Layer.clip.height | read/write |
Layer.document | read |
Layer.document.open | implemented |
Layer.document.close | implemented |
Layer.document.write | implemented |
Layer.document.writeln | implemented |
Layer.document.bgColor | read/write |
Layer.document.layers | read |
Layer.document.images | read |
Layer.hidden | read/write |
Layer.left | read/write |
Layer.name | read |
Layer.pageX | read/write |
Layer.pageY | read/write |
Layer.parentLayer | read |
Layer.siblingAbove | not implemented |
Layer.src | not implemented |
Layer.top | read/write |
Layer.visibility | read/write |
Layer.zIndex | read/write |
Methods | |
Layer.captureEvents | not implemented |
Layer.handleEvents | not implemented |
Layer.load | not implemented |
Layer.moveAbove | implemented |
Layer.moveBelow | implemented |
Layer.moveBy | implemented |
Layer.MoveTo | not implemented |
Layer.moveAbsolute | implemented |
Layer.releaseEvents | not implemented |
Layer.resizeBy | implemented |
Layer.resizeTo | implemented |
Layer.routeEvent | not implemented |
This API will only work in limited circumstances:
Note these limitations exclude the famous and widely used Smith 1 and 2 menus, since they rely on loading after the onload fires for Netscape Navigator 4.x and on loading before the onload fires in Internet Explorer 4.
The use of the Advanced JavaScript and DOM implementation in Netscape 6/Mozilla, make it possible for JavaScript library developers to modify and extend the basic DOM support in Mozilla/Netscape 6 to support a variety of proprietary features available in legacy browsers.
This Layer Emulation API extension to the Mozilla DOM was developed quickly for demonstration purposes. It is not guaranteed to work for you and is subject to major modifications. It is provided here for informational purposes only.
Modified License to MPL, GPL, LGPL tri license
Revision 1.3 added computation to determine effective CSS Style position property which fixes problems where DIVs positioned via CSS rules and not inline STYLE attributes where not detected as Layers.
Revision 1.2 first attempt to get document.layerName.images.imageName
working
Fix error in _Document getter for layer where a reference to this._div was inadvertantly written as just div. Thanks to Chris Houghten for pointing this out.