Results 1 to 3 of 3

Thread: Contracting menu

  1. #1
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Contracting menu

    1) Script Title: Slashdot's Menu

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

    3) Describe problem: I have a slight problem. Script works fine, but when I decide to load another link that is not a part of this script, but part of the page, menu won't contract on default position (collapse all), and stays open. If someone could help me to work this out, I'd be very appreciated..
    This is the code:
    Code:
    function SDMenu(id) {
    	if (!document.getElementById || !document.getElementsByTagName)
    		return false;
    	this.menu = document.getElementById(id);
    	this.submenus = this.menu.getElementsByTagName("div");
    	this.remember = true;
    	this.speed = 3;
    	this.markCurrent = true;
    	this.oneSmOnly = false;
    }
    SDMenu.prototype.init = function() {
    	var mainInstance = this;
    	for (var i = 0; i < this.submenus.length; i++)
    		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
    			mainInstance.toggleMenu(this.parentNode);
    		};
    	if (this.markCurrent) {
    		var links = this.menu.getElementsByTagName("a");
    		for (var i = 0; i < links.length; i++)
    			if (links[i].href == document.location.href) {
    				links[i].className = "current";
    				break;
    			}
    	}
    	if (this.remember) {
    		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([0123]+)");
    		var match = regex.exec(document.cookie);
    		if (match) {
    			var states = match[1].split("");
    			for (var i = 0; i < states.length; i++) {
    				if (states[i] == 0)
    					this.submenus[i].className = "collapsed";
    				else if (states[i] == 1)
    					this.submenus[i].className = "expanded";
    				else if (states[i] == 2)
    					this.submenus[i].className = "collapsedBig1";
    				else if (states[i] == 3)
    					this.submenus[i].className = "expandedBig1";
    			}
    		}
    	}
    };
    SDMenu.prototype.toggleMenu = function(submenu) {
    	if (submenu.className == "collapsed")	
    		this.expandMenu(submenu);
    	else if (submenu.className == "collapsedBig1")
    		this.expandBig1Menu(submenu);
    	else if (submenu.className == "expandedBig1")
    		this.collapseBig1Menu(submenu);
    	else if (submenu.className == "expanded")
    		this.collapseMenu(submenu);
    };
    SDMenu.prototype.expandMenu = function(submenu) {
    	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
    	var links = submenu.getElementsByTagName("a");
    	for (var i = 0; i < links.length; i++)
    		fullHeight += links[i].offsetHeight;
    	var moveBy = Math.round(this.speed * links.length);
    	
    	var mainInstance = this;
    	var intId = setInterval(function() {
    		var curHeight = submenu.offsetHeight;
    		var newHeight = curHeight + moveBy;
    		if (newHeight < fullHeight)
    			submenu.style.height = newHeight + "px";
    		else {
    			clearInterval(intId);
    			submenu.style.height = "";
    			submenu.className = "expanded";
    			mainInstance.memorize();
    		}
    	}, 30);
    	this.collapseOthers(submenu);
    };
    SDMenu.prototype.expandBig1Menu = function(submenu) {
    	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
    	var links = submenu.getElementsByTagName("a");
    	for (var i = 0; i < links.length; i++)
    		fullHeight += links[i].offsetHeight;
    	var moveBy = Math.round(this.speed * links.length);
    	
    	var mainInstance = this;
    	var intId = setInterval(function() {
    		var curHeight = submenu.offsetHeight;
    		var newHeight = curHeight + moveBy;
    		if (newHeight < fullHeight)
    			submenu.style.height = newHeight + "px";
    		else {
    			clearInterval(intId);
    			submenu.style.height = "";
    			submenu.className = "expandedBig1";
    			mainInstance.memorize();
    		}
    	}, 30);
    	this.collapseOthers(submenu);
    };
    SDMenu.prototype.collapseMenu = function(submenu) {
    	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
    	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
    	var mainInstance = this;
    	var intId = setInterval(function() {
    		var curHeight = submenu.offsetHeight;
    		var newHeight = curHeight - moveBy;
    		if (newHeight > minHeight)
    			submenu.style.height = newHeight + "px";
    		else {
    			clearInterval(intId);
    			submenu.style.height = "";
    			submenu.className = "collapsed";
    			mainInstance.memorize();
    		}
    	}, 30);
    };
    SDMenu.prototype.collapseBig1Menu = function(submenu) {
    	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
    	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
    	var mainInstance = this;
    	var intId = setInterval(function() {
    		var curHeight = submenu.offsetHeight;
    		var newHeight = curHeight - moveBy;
    		if (newHeight > minHeight)
    			submenu.style.height = newHeight + "px";
    		else {
    			clearInterval(intId);
    			submenu.style.height = "";
    			submenu.className = "collapsedBig1";
    			mainInstance.memorize();
    		}
    	}, 30);
    };
    SDMenu.prototype.collapseOthers = function(submenu) {
    	if (this.oneSmOnly) {
    		for (var i = 0; i < this.submenus.length; i++) {
    			if (this.submenus[i] != submenu && this.submenus[i].className == "expanded")
    				this.collapseMenu(this.submenus[i]);
    			if (this.submenus[i] != submenu && this.submenus[i].className == "expandedBig1")
    				this.collapseBig1Menu(this.submenus[i]);
    		}
    	}
    };
    SDMenu.prototype.expandAll = function() {
    	var oldOneSmOnly = this.oneSmOnly;
    	this.oneSmOnly = false;
    	for (var i = 0; i < this.submenus.length; i++) {
    		if (this.submenus[i].className == "collapsedBig1")
    			this.expandBig1Menu(this.submenus[i]);
    		else if (this.submenus[i].className == "collapsed")
    			this.expandMenu(this.submenus[i]);
    	}
    	this.oneSmOnly = oldOneSmOnly;
    };
    SDMenu.prototype.collapseAll = function() {
    	for (var i = 0; i < this.submenus.length; i++) {
    		if (this.submenus[i].className == "expandedBig1")
    			this.collapseBig1Menu(this.submenus[i]);
    		else if (this.submenus[i].className == "expanded")
    			this.collapseMenu(this.submenus[i]);
    	}
    };
    SDMenu.prototype.memorize = function() {
    	if (this.remember) {
    		var states = new Array();
    		for (var i = 0; i < this.submenus.length; i++) {
    			if (this.submenus[i].className == "collapsed")
    				states.push(0);
    			else if (this.submenus[i].className == "expanded")
    				states.push(1);
    			else if (this.submenus[i].className == "collapsedBig1")
    				states.push(2);
    			else if (this.submenus[i].className == "expandedBig1")
    				states.push(3);			
    		}
    		var d = new Date();
    		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
    		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
    	}
    };

  2. #2
    Join Date
    Nov 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    "BUMP"

    I'm also facing the same problem and couldn't find the solution to this.

    I do hope someone could help us out here.

  3. #3
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by konfiguration View Post
    "BUMP"

    I'm also facing the same problem and couldn't find the solution to this.

    I do hope someone could help us out here.

    ..I think this problem that we have, is not related with the main functionality of the script. The script works fine, as I can see. I assume that we need to find a way to tell the script how to behave on each web page. Something that can be done using .asp tehnology, but the fact is that firm that i work for this page, use Oracle database and this web page should work on Oracle portal. How to work this out, i don't really know. And my time is ticking away..

    ..i believe we'll fine the way. And If I do, I will post it here..

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •