Results 1 to 4 of 4

Thread: Slashdot Menu

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

    Default Slashdot Menu

    1) Slashdot Menu

    2) http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

    3) Is there anyway to make the script in a collapse all mode when you first enter the site? Then as you surf the site it remembers the menu?

    I'm using the old version of this script called Slashfiles which i downloaded from DD, and these are the javascript in its menu.js

    Code:
    var remember = true; //Remember menu states, and restore them on next visit.
    var contractall_default = false; //Should all submenus be contracted by default? (true or false)
    
    var menu, titles, submenus, arrows, bypixels;
    var heights = new Array();
    
    var n = navigator.userAgent;
    if(/Opera/.test(n)) bypixels = 2;
    else if(/Firefox/.test(n)) bypixels = 3;
    else if(/MSIE/.test(n)) bypixels = 2;
    
    /////DD added expandall() and contractall() functions/////
    
    function slash_expandall(){
    if (typeof menu!="undefined"){
    	for(i=0; i<Math.max(titles.length, submenus.length); i++){
    		titles[i].className="title";
    		arrows[i].src = "slashfiles/expanded.gif";
    		submenus[i].style.display="";
    		submenus[i].style.height = heights[i]+"px";
    	}
    }
    }
    
    function slash_contractall(){
    if (typeof menu!="undefined"){
    	for(i=0; i<Math.max(titles.length, submenus.length); i++){
    		titles[i].className="titlehidden";
    		arrows[i].src = "slashfiles/collapsed.gif";
    		submenus[i].style.display="none";
    		submenus[i].style.height = 0;
    	}
    }
    }
    
    
    /////End DD added functions///////////////////////////////
    
    
    function init(){
        menu = getElementsByClassName("sdmenu", "div", document)[0];
        titles = getElementsByClassName("title", "span", menu);
        submenus = getElementsByClassName("submenu", "div", menu);
        arrows = getElementsByClassName("arrow", "img", menu);
        for(i=0; i<Math.max(titles.length, submenus.length); i++) {
            titles[i].onclick = gomenu;
            arrows[i].onclick = gomenu;
            heights[i] = submenus[i].offsetHeight;
            submenus[i].style.height = submenus[i].offsetHeight+"px";
        }
        if(remember)
    				restore()
    		else if (contractall_default) //DD added code
    				slash_contractall() //DD added code
    }
    
    function restore() {
        if(getcookie("menu") != null) {
            var hidden = getcookie("menu").split(",");
            for(var i in hidden) {
                titles[hidden[i]].className = "titlehidden";
                submenus[hidden[i]].style.height = "0px";
                submenus[hidden[i]].style.display = "none";
                arrows[hidden[i]].src = "slashfiles/collapsed.gif";
            }
        }
    }
    
    function gomenu(e) {
        if (!e)
            var e = window.event;
        var ce = (e.target) ? e.target : e.srcElement;
        var sm;
        for(var i in titles) {
            if(titles[i] == ce || arrows[i] == ce)
                sm = i;
        }
        if(parseInt(submenus[sm].style.height) > parseInt(heights[sm])-2) {
            hidemenu(sm);
        } else if(parseInt(submenus[sm].style.height) < 2) {
            titles[sm].className = "title";
            showmenu(sm);
        }
    }
    
    function hidemenu(sm) {
        var nr = submenus[sm].getElementsByTagName("a").length*bypixels;
        submenus[sm].style.height = (parseInt(submenus[sm].style.height)-nr)+"px";
        var to = setTimeout("hidemenu("+sm+")", 30);
        if(parseInt(submenus[sm].style.height) <= nr) {
            clearTimeout(to);
            submenus[sm].style.display = "none";
            submenus[sm].style.height = "0px";
            arrows[sm].src = "slashfiles/collapsed.gif";
            titles[sm].className = "titlehidden";
        }
    }
    
    function showmenu(sm) {
        var nr = submenus[sm].getElementsByTagName("a").length*bypixels;
        submenus[sm].style.display = "";
        submenus[sm].style.height = (parseInt(submenus[sm].style.height)+nr)+"px";
        var to = setTimeout("showmenu("+sm+")", 30);
        if(parseInt(submenus[sm].style.height) > (parseInt(heights[sm])-nr)) {
            clearTimeout(to);
            submenus[sm].style.height = heights[sm]+"px";
            arrows[sm].src = "slashfiles/expanded.gif";
        }
            
            
    }
    
    function store() {
        var hidden = new Array();
        for(var i in titles) {
            if(titles[i].className == "titlehidden")
                hidden.push(i);
        }
        putcookie("menu", hidden.join(","), 30);
    }
    
    function getElementsByClassName(strClassName, strTagName, oElm){
        var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
        var arrReturnElements = new Array();
        strClassName = strClassName.replace(/\-/g, "\\-");
        var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
        var oElement;
        for(var i=0; i<arrElements.length; i++){
            oElement = arrElements[i];      
            if(oRegExp.test(oElement.className)){
                arrReturnElements.push(oElement);
            }   
        }
        return (arrReturnElements)
    }
    
    function putcookie(c_name,value,expiredays) {
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate);
    }
    
    function getcookie(c_name) {
        if(document.cookie.length > 0) {
            var c_start = document.cookie.indexOf(c_name + "=");
            if(c_start != -1) {
                c_start = c_start + c_name.length + 1;
                var c_end = document.cookie.indexOf(";",c_start);
                if(c_end == -1)
                    c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return null;
    }
    
    window.onload = init;
    if(remember) window.onunload = store;

    Any help at all regarding this issue would most gladly be appreciated. =)
    Thanks for reading this.

    Lloyd.
    Last edited by lloyd; 04-03-2007 at 05:55 PM.

  2. #2
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Second line of that code:
    Code:
    var contractall_default = false; //Should all submenus be contracted by default? (true or false)

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

    Default Collapse Others

    I really appreciate the Slashdot menu. I am attempting to duplicate AutoCAD's "Properties Pallette" for my website, and believe your menu serves this well, when combined with a slider.

    I DID see in another thread a request for the "collapse others" within an "expand". This appears to now be a default mechanism within the JS, but it is not happenening.

    Am I missing something that activates this added feature?

  4. #4
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by DimX View Post
    Second line of that code:
    Code:
    var contractall_default = false; //Should all submenus be contracted by default? (true or false)
    Hi DimX,

    Thanks so much for replying my post

    however, when i set the settings as both true, the problem still resurfaces. I'm still not able to see a contracted menu when i or any new visitor visits the site. The menu will still be in a expanded mode.

    Code:
    var remember = true; //Remember menu states, and restore them on next visit.
    var contractall_default = true; //Should all submenus be contracted by default? (true or false)


    Thanks so much
    Last edited by lloyd; 04-04-2007 at 10:35 AM.

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
  •