// ******************************************************************************************** // Expanding Tree Menu - Memory System // This add-in keeps expanded menu sections open between pages via a cookie. // To be used with the Expanding Tree menu from opencube.com // Copyright 2006 Devin Breen (dbreen@westmonroepartners.com) // // USAGE INSTRUCTIONS // 1. In order for this code to work, each LI tag in the menu that expands must have // an ID value set. Ensure this is so. // // 2. You must insert the following lines of code: // // /* ****************************************************************** */ // // REQUIRED for Expanded Menu Memory add-in // // This code sets an onClick action for every normal link in the system. // if (this.cc13[this.ti].tagName == "A") { // this.cc13[this.ti].onclick = saveExpandedItemsToCookie; // } // /* ****************************************************************** */ // // directy after the following section of the source code block: // // this.cc13[this.ti].onmouseout=function(){this.className="";};}} // // 3. Call this JavaScript file AFTER the menu is defined and BEFORE the expanding menu // source code is called. // // ******************************************************************************************** // Open the containing LI for the next menu load. function openContainingLI() { var parentLI = this.parentNode.parentNode; //ERC - Had to add this since out A href is in a DIV parentLI.setAttribute("expanded", 1); saveExpandedItemsToCookie(); } // Save all expanded menu items to a cookie function saveExpandedItemsToCookie() { var delimiter = '|'; var cookieString = ''; // Gather all of the LI elements within this page. arrayLI = document.getElementsByTagName("LI"); // For each LI element, see if it has an expanded attribute set to 1. for (i = 0; i < arrayLI.length; i++) { // If the element is equal to 1, add it to the pipe-delimited string. if ((expandedVal = arrayLI[i].getAttribute("expanded")) && (parseInt(expandedVal))) { if (cookieString.length != 0) { cookieString += delimiter; } cookieString += arrayLI[i].id; } } // If the cookieString has a value in it, write a cookie that lasts for 1 day. if (cookieString.length > 0) { createCookie('expandedMenu', cookieString, 1); // Otherwise, delete the cookie. } else { eraseCookie('expandedMenu'); } } // ******************************************************************************************** // Read and parse all expanded menu items saved within a cookie. // Set the appropriate LI tags to expanded=1. function readExpandedItemsFromCookie() { var delimiter = '|'; var arrExpandedItems; var strExpandedItems = readCookie('expandedMenu'); // If the cookie exists, then expand the values into an array. if (strExpandedItems) { arrExpandedItems = strExpandedItems.split(delimiter); // For each expanded menu item (who has an id length > 0), find the appropriate LI tag and set expanded = 1. for (i = 0; i < arrExpandedItems.length; i++) { if (arrExpandedItems[i].length > 0) { currentLI = document.getElementById(arrExpandedItems[i]); if (currentLI != null) { currentLI.setAttribute("expanded", 1); } } } } } // ******************************************************************************************** // This actually loads the data from the cookie, and is the // only code that is run automatically from this page. readExpandedItemsFromCookie(); // ******************************************************************************************** // Cookie Utility Functions. // Used from the website: http://www.quirksmode.org/js/cookies.html // ******************************************************************************************** // Create a cookie function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } // Read a cookie function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } // Erase a cookie function eraseCookie(name) { createCookie(name,"",-1); } // ******************************************************************************************** // EOF