View Full Version : Mission Impossible - a Riddle ???
sanuk
07-15-2002, 08:54 AM
Hi,
This problem really seems like a mission impossible.
This JS-script consist of a Script in the HEAD-part of the document and a DIV container in the BODY-part of the document.
The problem is that I want to put the complete DIV-container in a external JS-script called "mymenu.js" so that I can put this in the Body of all my pages.
This seems impossible !!!!
Have tried in many different ways to document.write('...') this DIV-container.
It just does not work.
Could someone find the solution for making an external mymenu.js out of this <DIV>-container.
(making a menu.js file out of the HEAD-script is no problem, this works OK)
I have here attached the complete htm-page with script
Regards,
Sanuk
neil.c
07-15-2002, 10:13 AM
well, i put your div into an external js and it works fine - the menus pop up and disappear as expected. it just needs the following code in your page:
<body onmouseout=hide(event)>
<script src=mymenu.js>
</script>
<!--etc-->
and here is the stuff in mymenu.js:
function fMouseOver(what,which){
what.style.color="#ffff00"
show(eval("m" + which))
}
function fMouseOut(what){
what.style.colour="#ffffff"
}
var vToWrite = ""
vToWrite += "<div ID='mymenu' style='width=750;background-color:#603399;padding:0 0 4 8;position:absolute;left:15px;top:18px'>"
vToWrite += "<FONT class=Tmenu onmouseout='fMouseOut(this)' onmouseover='fMouseOver(this,1)'>Go To Submenu 1 </FONT>"
vToWrite += "<FONT class=Tmenu onmouseout='fMouseOut(this)' onmouseover='fMouseOver(this,2)'>Go To Submenu 2 </FONT>"
vToWrite += "<FONT class=Tmenu onmouseout='fMouseOut(this)' onmouseover='fMouseOver(this,3)'>Go To Submenu 3 </FONT>"
vToWrite += "<FONT class=Tmenu onmouseout='fMouseOut(this)' onmouseover='fMouseOver(this,4)'>Go To Submenu 4 </FONT>"
vToWrite += "<FONT class=Tmenu onmouseout='fMouseOut(this)' onmouseover='fMouseOver(this,5)'>Go To Submenu 5 </FONT>"
vToWrite += "</div>"
document.write(vToWrite)
i put the mouseover and mouseout into separate functions to stop the problems with nested quote marks (" " ' ').
this worked fine when i tested it. the stuff is all in the attached .zip. i changed the php to a htm file.
only one problem - the menu headings won't go back to white onmouseout. i stuck some alerts in the fMouseOut function, it looked like it was trying to work but they still stay yellow. i'll keep working on it.
:thumbsup:
neil.c
07-15-2002, 10:14 AM
here is the .zip
Cloudski
07-15-2002, 10:40 AM
Niel, your problem is in the funtion, you spelled color as colour. I tested it and it works fine now.
So, in the mymenu.js:
function fMouseOut(what){
what.style.color="#ffffff"
Not:
function fMouseOut(what){
what.style.colour="#ffffff"
:thumbsup:
Cloudski
07-15-2002, 10:46 AM
Well, apon further testing of the menu, I found a small error, if your not going really fast, the menu closes the submenue when you try to get your mouse to the links :)
It is probably editable in the .js file, but I wanted to make you aware for a say... default version of it :)
sanuk
07-15-2002, 12:30 PM
Hi Guys,
Thanks a lot, Yes, now it works fine.
I really have learned someting from the code Mr. Neil made !!
In Neil's code I have changed COLOUR to COLOR.
Concerning the closing of the submenus, YES, the reason is that the submenu is not positioned high enough and is adaptable in the script by changing the height of the submenu at:
var menuTopPixels=37 - Change to 33 or something.
In any Case Thanks a lot for helping me out,
Regards,
Sanuk
neil.c
07-15-2002, 12:39 PM
you spelled color as colour
hey, sorry i'm a brit!
i always run into these things.
conozco345
07-16-2002, 04:25 AM
Well, I fixed one part of it, I made copy go down to the next line of the menu, Im still trying to figure out why the menu changes size when you rollover the links, fortunately after you roll over them once, the problem goes away.
<style>
a{text-decoration:none}
.menuLayer{
color:brown; border:2px solid;
background-color: orange;
border-color:gold darkorange darkorange gold;
position:absolute;
}
.menuItemout{
color:brown;
padding:5px 7px 5px 7px;
margin:5px 7px 5px 7px;
font-family:verdana;
font-size:12;
cursor:default;
margin: 1px;
}
.menuItemactive{
color:brown;
border:1px solid;
border-color:darkorange gold gold darkorange;
padding:5px 7px 5px 7px;
margin:5px 7px 5px 7px;
font-family:verdana;
font-size:12;
cursor:default;
background-color:darkorange;
margin: 1px;
}
.menuItemhover{
color:brown;
border:1px solid;
border-color:gold darkorange darkorange gold;
padding:5px 7px 5px 7px;
margin:5px 7px 5px 7px;
font-family:verdana;
font-size:12;
cursor:default;
margin: 1px;
}
.menuchilditemout{
color:brown;
background-color:transparent;
font-family:verdana;
font-size:12;
cursor:default;
padding: 3px 1em;
display:block;
}
.menuchilditemhover{
color:brown;
background-color:darkorange;
font-family:verdana;
font-size:12;
cursor:default;
padding: 3px 1em;
display:block;
}
.menusep{
border:1px solid;
border-color:darkorange gold gold darkorange;
font-size:1;
height:1;
width:100%;
position:relative;
}
</style>
<script>
var activeButton = null;
//document.onmousedown=pageMouseDown(event);
function pageMouseDown(event){
if(activeButton==null){
var el=document.getElementsByTagName('A');
for(var i=0;i<el.length;i++){
el[i].className="menuItemout";
}
}
else{
var el2=document.getElementsByTagName('DIV');
for(var j=0;j<el2.length;j++){
if(el2[j].className=="menuLayer" && el2[j].id!="menubar")
el2[j].style.visibility="hidden";}
var el3=document.getElementsByTagName('A');
for(var k=0;k<el3.length;k++){
if(el3[k].className.substring(0,8)=="menuItem")
el3[k].className="menuItemout";}
}
activeButton=null;
}
function replaceClassName(el,name){
var button=document.getElementById(el);
el.className=name;
}
function resetButton(button){
button.menu.style.visibility="hidden";
button.className="menuItemout";
activeButton = null;
}
function buttonClick(menuId){
var button=event.srcElement;
button.blur();
if (button.menu==null){button.menu=document.getElementById(menuId);}
if (activeButton==null){
depressButton(button);
activeButton=button;
}
else if (activeButton != null && activeButton!=button){
resetButton(activeButton);
depressButton(button);
activeButton=button;
}
else if(activeButton!=null && activeButton==button){
resetButton(activeButton);
activeButton=null;
replaceClassName(button,'menuItemhover');
}
else{
activeButton=null;
return false;
}
}
function depressButton(button){
var x,y;
x = getPageOffsetLeft(button);
y = getPageOffsetTop(button) + button.offsetHeight;
x += button.offsetParent.clientLeft;
y += button.offsetParent.clientTop;
button.menu.style.top=y;
button.menu.style.left=x;
button.className="menuItemactive";
button.menu.style.visibility="visible";
}
function buttonOver(menuId){
var button=event.srcElement;
if(activeButton!=null && activeButton==button){
null;
}
else if(activeButton==null){
var el=document.getElementsByTagName('A');
for(var i=0;i<el.length;i++){
el[i].className="menuItemout";
button.className="menuItemhover";
}
}
else{
buttonClick(menuId);
}
}
function buttonOut(menuId){
var button=event.srcElement;
if(activeButton==null)
button.className="menuItemout";
}
function getPageOffsetLeft(el) {
var x;
x = el.offsetLeft;
if (el.offsetParent != null)
x += getPageOffsetLeft(el.offsetParent);
return x;
}
function getPageOffsetTop(el) {
var y;
y = el.offsetTop;
if (el.offsetParent != null)
y += getPageOffsetTop(el.offsetParent);
return y;
}
</script>
<body>
<div id="menubar" class="menuLayer" style="width:100%;position:absolute; top:0;left:5;height:28">
<a id="menubtnedit" href="#" class="menuItemout"
onclick="buttonClick('menuedit')"
onmouseover="buttonOver('menuedit')"
onmouseout="buttonOut('menuedit')"
>Edit</a>
</div>
<div id="menuedit" class="menuLayer" style="width:18%;visibility:hidden">
<a href="#" class="menuchilditemout"
onmouseover="this.className='menuchilditemhover'"
onmouseout="this.className='menuchilditemout'">Script...</a>
<a href="#" class="menuchilditemout"
onmouseover="this.className='menuchilditemhover'"
onmouseout="this.className='menuchilditemout'"style="display:block">Style Sheet...</a>
<div class="menusep"> </div>
<a href="#" class="menuchilditemout"
onmouseover="this.className='menuchilditemhover'"
onmouseout="this.className='menuchilditemout'">Select All</a>
<a href="#" class="menuchilditemout"
onmouseover="this.className='menuchilditemhover'"
onmouseout="this.className='menuchilditemout'"style="display:block">Copy</a>
<a href="#" class="menuchilditemout"
onmouseover="this.className='menuchilditemhover'"
onmouseout="this.className='menuchilditemout'"style="display:block">Paste</a>
<div class="menusep"> </div>
<a href="#" class="menuchilditemout"
onmouseover="this.className='menuchilditemhover'"
onmouseout="this.className='menuchilditemout'">Preferences</a>
</div>
</body>
Cloudski
07-16-2002, 04:33 AM
Originally posted by neil.c
hey, sorry i'm a brit!
i always run into these things.
:( Sorry if I have offended you in some way... I didn't even know British spelled color as colour... I am very sorry if I hurt your feelings....
neil.c
07-16-2002, 09:27 AM
hey cloudski, what u on about? offended? theres nowt wrong with joking about our language :D !
anyways, this hasnt got much to do with the thread.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.