stever
17 Apr 2007, 5:48 PM
Below is a sample file. I want to be able to construct a menu using inline script. In IE7 you can see the very different widths that are rendered in this example (FF is fine).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Toolbar with Menus</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<!-- LIBS -->
<script type="text/javascript" src="../../yui-utilities.js"></script>
<script type="text/javascript" src="../../ext-yui-adapter.js"></script>
<!-- ENDLIBS -->
<script type="text/javascript" src="../../ext-all-debug.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
function handleMenu(item)
{
if (item.link)
{
if (item.link.substring(0,11)=="javascript:")
eval(item.link.substring(11));
else
document.location.href = item.link;
}
}
function constructMenu(e) {
var items = [ ];
Ext.get(e).select('>li').each( function() {
// set current item properties
var img = this.select('>img');
var link = this.select('>a');
var icon = null;
var cls = null;
if (img.elements.length)
{
icon = img.item(0).dom.src;
cls = 'x-btn-icon';
}
if (img.elements.length && link.elements.length && link.item(0).dom.firstChild)
{
cls = 'x-btn-text-icon';
}
var currentItem={};
if (link.elements.length)
{
link = link.item(0).dom;
currentItem = {
text: link.innerHTML,
cls: cls,
id: link.id,
link: link.href,
icon: icon,
disabled: this.hasClass('disabled'),
handler: handleMenu
};
}
else if (img.elements.length)
currentItem = {
icon: icon,
cls: cls,
disabled: this.hasClass('disabled')
};
else
currentItem ='-';
// Check for sub menu.
var s = this.select('>ul');
if (s.elements.length) {
currentItem.menu = {items: constructMenu(s.item(0))};
}
items.push(currentItem);
});
return items;
}
/*]]>*/
</script>
</head>
<body>
<!-- YUI Document -->
<div id="yui-doc">
<!-- Header Section -->
<div id="yui-hd"></div>
<!-- Body Section -->
<div id="yui-bd">
<script type="text/javascript" src="../examples.js"></script><!-- EXAMPLES -->
<br>
<br>
<br>
<br>
<br>
<br>
<table cellpadding="0" cellspacing="0" border="0" class="Navigation">
<tr class="Row">
<td class="Cell Left">
<ul id='menudata' style='display:none'><li><a href="/Support/" id="ctl0"><u>V3 Community</u></a></li><li><a href="/Support/General/Forum/" id="ctl7"><u>Test Forum</u></a></li></ul>
<div id="menuspot"></div>
<div id="menuspot2"></div>
<div id="menuspot3"></div>
<div id="menuspot4"></div>
<script type="text/javascript">
/*<![CDATA[*/
var menu = new Ext.Toolbar('menuspot', constructMenu("menudata"));
//});
</script>
</td>
</tr></table>
<br /><br /><br /><br /><br />
<!-- End Body Section -->
</div>
<!-- Footer Section -->
<div id="yui-ft"></div>
<!-- End YUI Document -->
</div>
<script type="text/javascript">
/*<![CDATA[*/
var menu2 = new Ext.Toolbar('menuspot2', constructMenu("menudata"));
Ext.onReady(function(){
var menu3 = new Ext.Toolbar('menuspot3', constructMenu("menudata"));
});
/*]]>*/
</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Toolbar with Menus</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<!-- LIBS -->
<script type="text/javascript" src="../../yui-utilities.js"></script>
<script type="text/javascript" src="../../ext-yui-adapter.js"></script>
<!-- ENDLIBS -->
<script type="text/javascript" src="../../ext-all-debug.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
function handleMenu(item)
{
if (item.link)
{
if (item.link.substring(0,11)=="javascript:")
eval(item.link.substring(11));
else
document.location.href = item.link;
}
}
function constructMenu(e) {
var items = [ ];
Ext.get(e).select('>li').each( function() {
// set current item properties
var img = this.select('>img');
var link = this.select('>a');
var icon = null;
var cls = null;
if (img.elements.length)
{
icon = img.item(0).dom.src;
cls = 'x-btn-icon';
}
if (img.elements.length && link.elements.length && link.item(0).dom.firstChild)
{
cls = 'x-btn-text-icon';
}
var currentItem={};
if (link.elements.length)
{
link = link.item(0).dom;
currentItem = {
text: link.innerHTML,
cls: cls,
id: link.id,
link: link.href,
icon: icon,
disabled: this.hasClass('disabled'),
handler: handleMenu
};
}
else if (img.elements.length)
currentItem = {
icon: icon,
cls: cls,
disabled: this.hasClass('disabled')
};
else
currentItem ='-';
// Check for sub menu.
var s = this.select('>ul');
if (s.elements.length) {
currentItem.menu = {items: constructMenu(s.item(0))};
}
items.push(currentItem);
});
return items;
}
/*]]>*/
</script>
</head>
<body>
<!-- YUI Document -->
<div id="yui-doc">
<!-- Header Section -->
<div id="yui-hd"></div>
<!-- Body Section -->
<div id="yui-bd">
<script type="text/javascript" src="../examples.js"></script><!-- EXAMPLES -->
<br>
<br>
<br>
<br>
<br>
<br>
<table cellpadding="0" cellspacing="0" border="0" class="Navigation">
<tr class="Row">
<td class="Cell Left">
<ul id='menudata' style='display:none'><li><a href="/Support/" id="ctl0"><u>V3 Community</u></a></li><li><a href="/Support/General/Forum/" id="ctl7"><u>Test Forum</u></a></li></ul>
<div id="menuspot"></div>
<div id="menuspot2"></div>
<div id="menuspot3"></div>
<div id="menuspot4"></div>
<script type="text/javascript">
/*<![CDATA[*/
var menu = new Ext.Toolbar('menuspot', constructMenu("menudata"));
//});
</script>
</td>
</tr></table>
<br /><br /><br /><br /><br />
<!-- End Body Section -->
</div>
<!-- Footer Section -->
<div id="yui-ft"></div>
<!-- End YUI Document -->
</div>
<script type="text/javascript">
/*<![CDATA[*/
var menu2 = new Ext.Toolbar('menuspot2', constructMenu("menudata"));
Ext.onReady(function(){
var menu3 = new Ext.Toolbar('menuspot3', constructMenu("menudata"));
});
/*]]>*/
</script>
</body>
</html>