Layer Emulation API for Mozilla
An Experimental Emulation API for Layers
Bob Clary, Netscape Communications
Last Modified: January 28, 2003
Contents
- Required Modifications to existing Layer based code
- Examples
- Current Implementation
- Limitations
- Conclusion
- Caveat Emptor
- See Also
- Document History
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.
Required Modifications to existing Layer based code
- Insert the following into the HTML page before any other scripts
<script language="javascript" type="text/javascript"> if (document.layers) createLayer = new Function('width', 'parentLayer', 'return new Layer(width, parentLayer);'); else if (navigator.product == 'Gecko') document.write('<script language="javascript" type="text/javascript" src="Layers.js"><\/script>') </script> - Insert the following into the HTML page just before the ending BODY tag
<script language="javascript" type="text/javascript"> <!-- if (navigator.product == 'Gecko')) initializeLayers(); // --> </script>
- Edit the existing Layer based JavaScript by replacing all occurrences of new Layer(...) with createLayer(...)
Examples
Simple Layer example
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 language="javascript" type="text/javascript">
if (document.layers)
createLayer = new Function('width', 'parentLayer', 'return new Layer(width, parentLayer);');
else if (navigator.product == 'Gecko')
document.write('<script language="javascript" type="text/javascript" src="Layers.js"><\/script>')
</script>
<script language="javascript" 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 language="javascript" type="text/javascript">
<!--
initializeLayers();
// -->
</script>
</body>
</html>
Michael Bostock's Original JS DHTML Collapsible List
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
Current Implementation
| 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 |
Limitations
This API will only work in limited circumstances:
- The HTML Source should use positioned DIVs rather than LAYER tags since Mozilla does not recognize LAYER tags at all.
- The DHTML JavaScript which manipulates LAYERS must not run until the HTML Document has completed loading... i.e., in an onload handler.
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.
Conclusion
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.
Caveat Emptor
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.
See also
- Layeremu at mozdev.org
- Using the W3C DOM Level 2 Range Object as Implemented by Mozilla
- IE Emu for Moz
- DMOZ: Upgrading Navigator 4 and IE Content
- DMOZ: Upgrading Navigator 4 and IE Content: Navigator 4 Emulation
Document History
- June 13, 2002
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.
- June 06, 2002
Revision 1.2 first attempt to get
document.layerName.images.imageNameworking - Sept 29, 2001
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.
