Tips: Definition av popup menyer i egendefinierad websida

Moderators: hekj, Telldus

Post Reply
hekj
Posts: 992
Joined: Fri Mar 17, 2023 9:45 am
Location: Stockholm
Contact:

Tips: Definition av popup menyer i egendefinierad websida

Post by hekj »

Den som gör sina egna NexaHome websidor och vill ha popup menyer som triggas av att man klickar eller för musen över en länk/bild kan kolla in följande exempel (popup kod hämtad från http://www.dynamicdrive.com).

popup_demo.html

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>NexaHome - Life Made Easy With Home Automation</title>
<link rel="Shortcut Icon" href="http://nexahome.se/favicon32x32.ico">
<meta http-equiv="refresh" content="60;#URL#?mypage=popup_demo&psw=#PSW#">

<style type="text/css">

#popitmenu{
position: absolute;
background-color: white;
border:1px solid black;
font: normal 12px Verdana;
line-height: 18px;
z-index: 100;
visibility: hidden;
}

#popitmenu a{
text-decoration: none;
padding-left: 6px;
color: black;
display: block;
}

#popitmenu a:hover{ /*hover background color*/
background-color: #CCFF9D;
}

</style>

<script type="text/javascript">

/***********************************************
* Pop-it menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var defaultMenuWidth="150px" //set default menu width.

var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

linkset[0]='<a href="#">Page</a>'
linkset[0]+='<hr>' //Optional Separator
linkset[0]+='<a href="#URL#?mypage=demo&psw=#PSW#&rnd=#RND#">Demo</a>'
linkset[0]+='<a href="#URL#?mypage=demo2&psw=#PSW#&rnd=#RND#">Demo2</a>'

linkset[1]='<a href="#">Mode</a>'
linkset[1]+='<hr>' //Optional Separator
linkset[1]+='<a href="#URL#?mypage=popup_demo&mode=Home&psw=#PSW#&rnd=#RND#">Home</a>'
linkset[1]+='<a href="#URL#?mypage=popup_demo&mode=Away&psw=#PSW#&rnd=#RND#">Away</a>'

linkset[2]='<a href="#">Sovrum (sängbord)</a>'
linkset[2]+='<hr>' //Optional Separator
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&cmd=on&rnd=#RND#">ON</a>'
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&level=100&rnd=#RND#">100%</a>'
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&level=90&rnd=#RND#">90%</a>'
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&level=75&rnd=#RND#">75%</a>'
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&level=50&rnd=#RND#">50%</a>'
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&level=25&rnd=#RND#">25%</a>'
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&level=10&rnd=#RND#">10%</a>'
linkset[2]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Sovrum (sängbord)#&cmd=off&rnd=#RND#">OFF</a>'

linkset[3]='<a href="#">Kök (bord)</a>'
linkset[3]+='<hr>' //Optional Separator
linkset[3]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Kök (bord)#&cmd=on&rnd=#RND#">ON</a>'
linkset[3]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Kök (bord)#&cmd=off&rnd=#RND#">OFF</a>'

linkset[4]='<a href="#">Vardagsrum (gul)</a>'
linkset[4]+='<hr>' //Optional Separator
linkset[4]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Vardagsrum (gul)#&cmd=on&rnd=#RND#">ON</a>'
linkset[4]+='<a href="#URL#?mypage=popup_demo&psw=#PSW#&device=#ID#Vardagsrum (gul)#&cmd=off&rnd=#RND#">OFF</a>'

////No need to edit beyond here

var ie5=document.all && !window.opera
var ns6=document.getElementById

if (ie5||ns6)
document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')

function iecompattest(){
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(e, which, optWidth){
if (!document.all&&!document.getElementById)
return
clearhidemenu()
menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
menuobj.innerHTML=which
menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth
menuobj.contentwidth=menuobj.offsetWidth
menuobj.contentheight=menuobj.offsetHeight
eventX=ie5? event.clientX : e.clientX
eventY=ie5? event.clientY : e.clientY
//Find out how close the mouse is to the corner of the window
var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px"
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
else
menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
menuobj.style.visibility="visible"
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.style.visibility="hidden"
}

function dynamichide(e){
if (ie5&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

if (ie5||ns6)
document.onclick=hidemenu

</script>

</head>

<!-- device="Kök (bord)" on="on.png" off="off.png" onoff="onoff.png" -->
<!-- device="Sovrum (fönster)" on="on.png" off="off.png" onoff="onoff.png" -->
<!-- device="Sovrum (sängbord)" on="100.png" off="0.png" onoff="onoff.png" percent="25:25.png, 50:50.png, 75:75.png 100:100.png" -->
<!-- device="Vardagsrum (gul)" on="on.png" off="off.png" onoff="onoff.png" -->

<body bgcolor="#ffffff" background="/nexahome/nexahome_bg.jpg">

<div style="position: absolute; top: 5px; left: 25px">
POPUP MENU DEMO<br>
</div>

<div style="position: absolute; top: 50px; left: 25px">
<a href="#" onMouseover="showmenu(event,linkset[1], '60px')" onMouseout="delayhidemenu()">Change Mode</a>
(onMouseover)
</div>

<div style="position: absolute; top: 100px; left: 25px">
Sovrum (sängbord):
<img src="#IMAGE#Sovrum (sängbord)#" title="Sovrum (sängbord)" alt="?" onMousedown="showmenu(event,linkset[2])" onMouseout="delayhidemenu()" />
(onMousedown)
</div>

<div style="position: absolute; top: 150px; left: 25px">
Kök (bord):
<img src="#IMAGE#Kök (bord)#" title="Kök (bord)" alt="?" onMousedown="showmenu(event,linkset[3], '80px')" onMouseout="delayhidemenu()" />
(onMousedown)
</div>

<div style="position: absolute; top: 200px; left: 25px">
Vardagsrum (gul):
<img src="#IMAGE#Vardagsrum (gul)#" title="Vardagsrum (gul)" alt="?" onMouseover="showmenu(event,linkset[4], '125px')" onMouseout="delayhidemenu()" />
(onMouseover)
</div>

<div style="position: absolute; top: 250px; left: 25px">
<form action="nexahome" method="get">
Sovrum (fönster):
<input type=hidden name="mypage" value="popup_demo">
<input type=hidden name="device" value="Sovrum (fönster)">
<input type=hidden name="cmd" value="#CMD#Sovrum (fönster)#">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=image title="Sovrum (fönster)" alt= "?" src="#IMAGE#Sovrum (fönster)#">
(standard button)
</form>
</div>

<div style="position: absolute; top: 300px; left: 25px">
<a href="#" onMousedown="showmenu(event,linkset[0], '60px')" onMouseout="delayhidemenu()">Goto Page</a>
(onMousedown)
</div>

<div style="position: absolute; top: 350px; left: 25px;">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="popup_demo">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=submit value="#TIMESTAMP#">
</form>
</div>

</body>
</html>
Image
Post Reply