You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sv...@apache.org on 2005/05/30 11:28:45 UTC

svn commit: r179040 - /myfaces/trunk/src/components/org/apache/myfaces/custom/navmenu/resource/jscookmenu/JSCookMenu.js

Author: svieujot
Date: Mon May 30 02:28:44 2005
New Revision: 179040

URL: http://svn.apache.org/viewcvs?rev=179040&view=rev
Log:
Upgrade JSCookMenu.js to version 1.31.

Modified:
    myfaces/trunk/src/components/org/apache/myfaces/custom/navmenu/resource/jscookmenu/JSCookMenu.js

Modified: myfaces/trunk/src/components/org/apache/myfaces/custom/navmenu/resource/jscookmenu/JSCookMenu.js
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/navmenu/resource/jscookmenu/JSCookMenu.js?rev=179040&r1=179039&r2=179040&view=diff
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/navmenu/resource/jscookmenu/JSCookMenu.js (original)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/navmenu/resource/jscookmenu/JSCookMenu.js Mon May 30 02:28:44 2005
@@ -1,5 +1,5 @@
 /*
-	JSCookMenu v1.24.  (c) Copyright 2002 by Heng Yuan
+	JSCookMenu v1.31.  (c) Copyright 2002-2005 by Heng Yuan
 
 	Permission is hereby granted, free of charge, to any person obtaining a
 	copy of this software and associated documentation files (the "Software"),
@@ -28,6 +28,7 @@
 var _cmCurrentItem = null;		// the current menu item being selected;
 
 var _cmNoAction = new Object ();	// indicate that the item cannot be hovered.
+var _cmNoClick = new Object ();		// similar to _cmNoAction but does not respond to mouseup/mousedown events
 var _cmSplit = new Object ();		// indicate that the item is a menu split
 
 var _cmItemList = new Array ();		// a simple list of items
@@ -66,7 +67,7 @@
 	mainSpacing: 0,
 	// cell spacing for sub menus
 	subSpacing: 0,
-	// auto dispear time for submenus in milli-seconds
+	// auto disappear time for submenus in milli-seconds
 	delay: 500
 };
 
@@ -98,6 +99,21 @@
 	return ' onmouseover="cmItemMouseOver (this,' + prefix + ',' + isMain + ',' + idSub + ',' + orient + ',' + index + ')" onmouseout="cmItemMouseOut (this,' + nodeProperties.delay + ')" onmousedown="cmItemMouseDown (this,' + index + ')" onmouseup="cmItemMouseUp (this,' + index + ')"';
 }
 
+//
+// this one is used by _cmNoClick to only take care of onmouseover and onmouseout
+// events which are associated with menu but not actions associated with menu clicking/closing
+//
+function cmNoClickItem (item, prefix, isMain, idSub, orient, nodeProperties)
+{
+	// var index = _cmItemList.push (item) - 1;
+	_cmItemList[_cmItemList.length] = item;
+	var index = _cmItemList.length - 1;
+	idSub = (!idSub) ? 'null' : ('\'' + idSub + '\'');
+	orient = '\'' + orient + '\'';
+	prefix = '\'' + prefix + '\'';
+	return ' onmouseover="cmItemMouseOver (this,' + prefix + ',' + isMain + ',' + idSub + ',' + orient + ',' + index + ')" onmouseout="cmItemMouseOut (this,' + nodeProperties.delay + ')"';
+}
+
 function cmNoActionItem (item, prefix)
 {
 	return item[1];
@@ -145,7 +161,12 @@
 		hasChild = (item.length > 5);
 		idSub = hasChild ? cmNewID () : null;
 
-		str += '<tr class="' + prefix + 'MenuItem"' + cmActionItem (item, prefix, 0, idSub, orient, nodeProperties) + '>';
+		str += '<tr class="' + prefix + 'MenuItem"';
+		if (item[0] != _cmNoClick)
+			str += cmActionItem (item, prefix, 0, idSub, orient, nodeProperties);
+		else
+			str += cmNoClickItem (item, prefix, 0, idSub, orient, nodeProperties);
+		str += '>'
 
 		if (item == _cmSplit)
 		{
@@ -154,7 +175,7 @@
 			continue;
 		}
 
-		if (item[0] == _cmNoAction)
+		if (item[0] == _cmNoAction || item[0] == _cmNoClick)
 		{
 			str += cmNoActionItem (item, prefix);
 			str += '</tr>';
@@ -165,16 +186,13 @@
 		classStr += hasChild ? 'Folder' : 'Item';
 
 		str += '<td class="' + classStr + 'Left">';
-		if (item[0] != null && item[0] != _cmNoAction) {
+
+		if (item[0] != null)
 			str += item[0];
-	    }
 		else
-		{
 			str += hasChild ? nodeProperties.folderLeft : nodeProperties.itemLeft;
-        }
-        str +=  '</td>';
 
-		str += '<td class="' + classStr + 'Text">' + item[1] + '</td>';
+		str += '<td class="' + classStr + 'Text">' + item[1];
 
 		str += '<td class="' + classStr + 'Right">';
 
@@ -263,7 +281,7 @@
 			continue;
 		}
 
-		if (item[0] == _cmNoAction)
+		if (item[0] == _cmNoAction || item[0] == _cmNoClick)
 		{
 			str += cmNoActionItem (item, prefix);
 			str += vertical? '</tr>' : '</td>';
@@ -434,11 +452,7 @@
 
 	if (link != null)
 	{
-	    // changes by royalts (Thomas Spiegl)
-	    var dummyForm = document.forms['linkDummyForm'];
-	    dummyForm.elements['jscook_action'].value = link;
-	    dummyForm.submit();
-		//window.open (link, target);
+		window.open (link, target);
 	}
 
 	var prefix = obj.cmPrefix;
@@ -485,28 +499,72 @@
 {
 	var mode = String (orient);
 	var p = subMenu.offsetParent;
+	var subMenuWidth = cmGetWidth (subMenu);
+	var horiz = cmGetHorizontalAlign (obj, mode, p, subMenuWidth);
 	if (mode.charAt (0) == 'h')
 	{
 		if (mode.charAt (1) == 'b')
-			subMenu.style.top = (cmGetYAt (obj, p) + obj.offsetHeight) + 'px';
+			subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj)) + 'px';
 		else
-			subMenu.style.top = (cmGetYAt (obj, p) - subMenu.offsetHeight) + 'px';
-		if (mode.charAt (2) == 'r')
+			subMenu.style.top = (cmGetYAt (obj, p) - cmGetHeight (subMenu)) + 'px';
+		if (horiz == 'r')
 			subMenu.style.left = (cmGetXAt (obj, p)) + 'px';
 		else
-			subMenu.style.left = (cmGetXAt (obj, p) + obj.offsetWidth - subMenu.offsetWidth) + 'px';
+			subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj) - subMenuWidth) + 'px';
 	}
 	else
 	{
-		if (mode.charAt (2) == 'r')
-			subMenu.style.left = (cmGetXAt (obj, p) + obj.offsetWidth) + 'px';
+		if (horiz == 'r')
+			subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj)) + 'px';
 		else
-			subMenu.style.left = (cmGetXAt (obj, p) - subMenu.offsetWidth) + 'px';
+			subMenu.style.left = (cmGetXAt (obj, p) - subMenuWidth) + 'px';
 		if (mode.charAt (1) == 'b')
 			subMenu.style.top = (cmGetYAt (obj, p)) + 'px';
 		else
-			subMenu.style.top = (cmGetYAt (obj, p) + obj.offsetHeight - subMenu.offsetHeight) + 'px';
-		//alert (subMenu.style.top + ', ' + cmGetY (obj) + ', ' + obj.offsetHeight);
+			subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj) - cmGetHeight (subMenu)) + 'px';
+	}
+}
+
+//
+// automatically re-adjust the menu position based on available screen size.
+//
+function cmGetHorizontalAlign (obj, mode, p, subMenuWidth)
+{
+	var horiz = mode.charAt (2);
+	if (!(document.body))
+		return horiz;
+	var body = document.body;
+	var browserLeft;
+	var browserRight;
+	if (window.innerWidth)
+	{
+		// DOM window attributes
+		browserLeft = window.pageXOffset;
+		browserRight = window.innerWidth + browserLeft;
+	}
+	else if (body.clientWidth)
+	{
+		// IE attributes
+		browserLeft = body.clientLeft;
+		browserRight = body.clientWidth + browserLeft;
+	}
+	else
+		return horiz;
+	if (mode.charAt (0) == 'h')
+	{
+		if (horiz == 'r' && (cmGetXAt (obj) + subMenuWidth) > browserRight)
+			horiz = 'l';
+		if (horiz == 'l' && (cmGetXAt (obj) + cmGetWidth (obj) - subMenuWidth) < browserLeft)
+			horiz = 'r';
+		return horiz;
+	}
+	else
+	{
+		if (horiz == 'r' && (cmGetXAt (obj, p) + cmGetWidth (obj) + subMenuWidth) > browserRight)
+			horiz = 'l';
+		if (horiz == 'l' && (cmGetXAt (obj, p) - subMenuWidth) < browserLeft)
+			horiz = 'r';
+		return horiz;
 	}
 }
 
@@ -537,10 +595,11 @@
 
 	//
 	// On IE, controls such as SELECT, OBJECT, IFRAME (before 5.5)
-	// are window based controls.  So, if sub menu and these controls
-	// overlap, sub menu would be hidden behind them.  Thus, one needs
-	// to turn the visibility of these controls off when the
+	// are window based controls.  So, if the sub menu and these
+	// controls overlap, sub menu would be hidden behind them.  Thus
+	// one needs to turn the visibility of these controls off when the
 	// sub menu is showing, and turn their visibility back on
+	// when the sub menu is hiding.
 	//
 	if (document.all)	// it is IE
 	{
@@ -726,7 +785,7 @@
 //
 function cmIsDefaultItem (item)
 {
-	if (item == _cmSplit || item[0] == _cmNoAction)
+	if (item == _cmSplit || item[0] == _cmNoAction || item[0] == _cmNoClick)
 		return false;
 	return true;
 }
@@ -742,6 +801,37 @@
 }
 
 //
+// functions that obtain the width of an HTML element.
+//
+function cmGetWidth (obj)
+{
+	var width = obj.offsetWidth;
+	if (width > 0 || !cmIsTRNode (obj))
+		return width;
+	if (!obj.firstChild)
+		return 0;
+	// use TABLE's length can cause an extra pixel gap
+	//return obj.parentNode.parentNode.offsetWidth;
+
+	// use the left and right child instead
+	return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + cmGetWidth (obj.lastChild);
+}
+
+//
+// functions that obtain the height of an HTML element.
+//
+function cmGetHeight (obj)
+{
+	var height = obj.offsetHeight;
+	if (height > 0 || !cmIsTRNode (obj))
+		return height;
+	if (!obj.firstChild)
+		return 0;
+	// use the first child's height
+	return obj.firstChild.offsetHeight;
+}
+
+//
 // functions that obtain the coordinates of an HTML element
 //
 function cmGetX (obj)
@@ -766,7 +856,9 @@
 		x += obj.offsetLeft;
 		obj = obj.offsetParent;
 	}
-	return x;
+	if (obj == elm)
+		return x;
+	return x - cmGetX (elm);
 }
 
 function cmGetY (obj)
@@ -781,16 +873,36 @@
 	return y;
 }
 
+function cmIsTRNode (obj)
+{
+	var tagName = obj.tagName;
+	return tagName == "TR" || tagName == "tr" || tagName == "Tr" || tagName == "tR";
+}
+
+//
+// get the Y position of the object.  In case of TR element though,
+// we attempt to adjust the value.
+//
 function cmGetYAt (obj, elm)
 {
 	var y = 0;
 
+	if (!obj.offsetHeight && cmIsTRNode (obj))
+	{
+		var firstTR = obj.parentNode.firstChild;
+		obj = obj.firstChild;
+		y -= firstTR.firstChild.offsetTop;
+	}
+
 	while (obj && obj != elm)
 	{
 		y += obj.offsetTop;
 		obj = obj.offsetParent;
 	}
-	return y;
+
+	if (obj == elm)
+		return y;
+	return y - cmGetY (elm);
 }
 
 //
@@ -808,45 +920,4 @@
 	for (i in obj)
 		msg += i + ' = ' + obj[i] + '; ';
 	return msg;
-}
-
-/*
-   did some changes in function cmItemMouseUp by royalts to work wiht jsf-component
-   HtmlCommandJSCookMenu
-*/
-
-/* JSCookMenu v1.24	1. fix window based control hiding bug
-					   thanks to Felix Zaslavskiy <fe...@bebinary.com> for the fix.
-*/
-/* JSCookMenu v1.23	1. correct a position bug when the container is positioned.
-					  thanks to Andre <an...@netspace.net.au> for narrowing down
-					  the problem.
-*/
-/* JSCookMenu v1.22	1. change Array.push (obj) call to Array[length] = obj.
-					   Suggestion from Dick van der Kaaden <di...@netrex.nl> to
-					   make the script compatible with IE 5.0
-					2. Changed theme files a little to add z-index: 100 for sub
-					   menus.  This change is necessary for Netscape to avoid
-					   a display problem.
-					3. some changes to the DOM structure to make this menu working
-					   on Netscape 6.0 (tested).  The main reason is that NN6 does
-					   not do absolute positioning with tables.  Therefore an extra
-					   div layer must be put around the table.
-*/
-/* JSCookMenu v1.21	1. fixed a bug that didn't add 'px' as part of coordinates.
-					   JSCookMenu should be XHTML validator friendly now.
-					2. removed unnecessary display attribute and corresponding
-					   theme entry to fix a problem that Netscape sometimes
-					   render Office theme incorrectly
-*/
-/* JSCookMenu v1.2.	1. fix the problem of showing status in Netscape
-					2. changed the handler parameters a bit to allow
-					   string literals to be passed to javascript based
-					   links
-					3. having null in target field would cause the link
-					   to be opened in the current window, but this behavior
-					   could change in the future releases
-*/
-/* JSCookMenu v1.1.		added ability to hide controls in IE to show submenus properly */
-/* JSCookMenu v1.01.	cmDraw generates XHTML code */
-/* JSCookMenu v1.0.		(c) Copyright 2002 by Heng Yuan */
+}
\ No newline at end of file