MediaWiki:Common.js

From TLKMuck Wiki

(Difference between revisions)
Jump to: navigation, search
m
 
Line 2: Line 2:
//<source lang="javascript">
//<source lang="javascript">
/* Custom dropdown menu script */
/* Custom dropdown menu script */
-
window.onerror = null;
+
// Copyright 2006-2007 javascript-array.com
-
var bName = navigator.appName;
+
-
var bVer = parseInt(navigator.appVersion);
+
-
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
+
-
var menuActive = 0;
+
-
var menuOn = 0;
+
-
var onLayer;
+
-
var timeOn = null;
+
-
function showLayer(layerName,aa){
+
var timeout = 500;
-
var x =document.getElementById(aa);
+
var closetimer = 0;
-
var tt =findPosX(x);
+
var ddmenuitem = 0;
-
var ww =findPosY(x)+20;
+
-
if (timeOn != null) {
+
// open hidden layer
-
clearTimeout(timeOn);
+
function mopen(id)
-
hideLayer(onLayer);
+
{
-
}
+
// cancel close timer
-
if (IE4) {
+
mcancelclosetime();
-
var layers = eval('document.all["'+layerName+'"].style');
+
-
layers.left = tt;
+
-
eval('document.all["'+layerName+'"].style.visibility="visible"');
+
-
}
+
-
else {
+
-
if(document.getElementById){
+
-
var elementRef = document.getElementById(layerName);
+
-
if((elementRef.style)&& (elementRef.style.visibility!=null)){
+
-
elementRef.style.visibility = 'visible';
+
-
elementRef.style.left = tt;
+
-
elementRef.style.top = ww;
+
-
}
+
-
}
+
-
}
+
-
onLayer = layerName
+
-
}
+
-
function hideLayer(layerName){
+
// close old layer
-
if (menuActive == 0)
+
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
-
{
+
-
if (IE4){
+
-
eval('document.all["'+layerName+'"].style.visibility="hidden"');
+
-
}
+
-
else{
+
-
if(document.getElementById){
+
-
var elementRef = document.getElementById(layerName);
+
-
if((elementRef.style)&& (elementRef.style.visibility!=null)){
+
-
elementRef.style.visibility = 'hidden';
+
-
}
+
-
}
+
-
}
+
-
}
+
-
}
+
-
function btnTimer() {
+
// get new layer and show it
-
timeOn = setTimeout("btnOut()",600)
+
ddmenuitem = document.getElementById(id);
-
}
+
ddmenuitem.style.visibility = 'visible';
-
function btnOut(layerName){
 
-
if (menuActive == 0){
 
-
hideLayer(onLayer)
 
}
}
 +
// close showed layer
 +
function mclose()
 +
{
 +
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
}
-
var item;
+
// go close timer
-
function menuOver(itemName,ocolor){
+
function mclosetime()
-
item=itemName;
+
{
-
itemName.style.backgroundColor = ocolor; //background color change on mouse over
+
closetimer = window.setTimeout(mclose, timeout);
-
clearTimeout(timeOn);
+
-
menuActive = 1
+
}
}
-
function menuOut(itemName,ocolor){
+
// cancel close timer
-
if(item)
+
function mcancelclosetime()
-
itemName.style.backgroundColor = ocolor;
+
-
menuActive = 0
+
-
timeOn = setTimeout("hideLayer(onLayer)", 100)
+
-
}
+
-
 
+
-
function findPosX(obj)
+
-
{
+
-
var curleft = 0;
+
-
if (obj.offsetParent)
+
-
{
+
-
while (obj.offsetParent)
+
{
{
-
curleft += obj.offsetLeft
+
if(closetimer)
-
obj = obj.offsetParent;
+
{
-
}
+
window.clearTimeout(closetimer);
-
}
+
closetimer = null;
-
else if (obj.x)
+
}
-
curleft += obj.x;
+
-
return curleft;
+
}
}
-
function findPosY(obj)
+
// close layer when click-out
-
{
+
document.onclick = mclose;  
-
var curtop = 0;
+
-
if (obj.offsetParent)
+
-
{
+
-
while (obj.offsetParent)
+
-
{
+
-
curtop += obj.offsetTop
+
-
obj = obj.offsetParent;
+
-
}
+
-
}
+
-
else if (obj.y)
+
-
curtop += obj.y;
+
-
return curtop;
+
-
}
+
//</source>
//</source>

Latest revision as of 05:14, 20 June 2010

/* Any JavaScript here will be loaded for all users on every page load. */
//<source lang="javascript">
/* Custom dropdown menu script */
// Copyright 2006-2007 javascript-array.com

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 
//</source>
Personal tools
TOOLBOX
LANGUAGES