Finally, I managed to make it work on the 3 browsers. I had to use a composite parent for each button though or the events where not correctly handled. Don't see why...
Here is what it does in 2 words.
Takes html code and puts 2 buttons in the 2 div elements.
when the button is clicked, an ActionMenu is displayed next to the button.
Here is the full javascript code:
Code:
function MenuExample() {
}
MenuExample.prototype.run = function () {
// Create the shell
var shell = new DwtShell("MainShell", false, null, null, null, true);
shell.setSize(0, 0);
// composite for button 1 and actionMenu 1
var composite = new DwtComposite(shell, null, Dwt.ABSOLUTE_STYLE);
this.createButtonMenu(composite, 5, 1);
composite.zShow(true);
// composite for button 2 and actionMenu 2
composite = new DwtComposite(shell, null, Dwt.ABSOLUTE_STYLE);
this.createButtonMenu(composite, 4, 2);
composite.zShow(true);
}
MenuExample.prototype._myListener = function(ev) {
DBG.println("_myListener: " + ev.item.menuItemId);
var actionMenu = ev.item.parent;
}
MenuExample.prototype._buttonListener = function(ev) {
DBG.println("_buttonListener called");
var bounds = ev.item.getBounds();
ev.item._actionMenu.popup(null, bounds.x + bounds.width, bounds.y);
}
MenuExample.prototype.createButtonMenu = function (composite, menuItems, index) {
var menu = new DvListViewActionMenu(composite);
menu.setBounds(Dwt.LOC_NOWHERE, Dwt.LOC_NOWHERE);
for (var i = 0; i < menuItems; i++) {
menu.createMenuItem(i, null, "Item " + i, null, null, DwtMenuItem.SELECT_STYLE);
menu.addSelectionListener(i, this._myListener);
}
var b = new DwtButton(composite);
b.setText("Button " + index);
b.addSelectionListener(new AjxListener(this, this._buttonListener));
b._actionMenu = menu;
b.setSize(100, 25);
document.getElementById("menu"+index).appendChild(composite.getHtmlElement());
} JSP code:
Code:
...snip...
<body>
<noscript><p><b>Javascript must be enabled to use this.</b></p></noscript>
<script type="text/javascript" language="javascript">
function launch() {
DBG = new AjxDebug(AjxDebug.DBG3, null, false);
Instance = new MenuExample();
Instance.run();
}
AjxCore.addOnloadListener(launch);
</script>
<table>
<tr>
<td width="200"> </td>
<td>
<p>Menu should be below</p>
<div class="actionMenuDiv" id="menu1"></div>
<p>Menu should be above</p>
<p>Menu should be below</p>
<div class="actionMenuDiv" id="menu2"></div>
<p>Menu should be above</p>
</td>
</tr>
</table>
</body>
...snip... CSS class:
Code:
.actionMenuDiv {
display: block;
height: 25px;
} Any comment is welcome...