.Net & SharePoint '07

Technical blog for .Net and all SharePoint 2007 related Information

About the author

Me(Prince) and my wife are B.E in I.T & C.S.E respectively.  I a certified MCPD: Web from 2007 Dec. I am Intrestes in Web Application, MOSS, EPM, etc.
Now working with Deira International School, as IT Application & Help Manager. I have started my career as "Software Developer" @  REACH Sewn Technologies and Consulting Pvt. Ltd, Bangalore India from Oct 2004 to Feb 2006, then as "Web & Intranet Developer" @ Fosroc International Ltd, Dubai from April 2006 to Sep 2009.
You can catch me on mail@jpy-tech.com or mail@princepy.com. Or on 00971 - 50 - 4284530 

Google Translate

Tag cloud

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

RecentComments

Comment RSS

Google Your Location


JQuery for Everyone: Accordion Left Nav

 

Paul Grenier set out on a mission; a mission to create an accordion-style left navigation menu for my WSS test site.  Mission complete.  If you can copy/paste, you can see it in action.  Since I used Google’s API to load jQuery, you don’t even need to download the library file.

First, look at your left nav.  If you changed it from the out-of-the-box setup, make sure you have “headers” and “submenus” that make sense.  For example, Documents should appear on top of a bulleted list of document libraries.

Obviously, if you want the accordion-style menu for all pages, you should work it into the default.master.  For now, we can work with a test page by adding a Content Editor Web Part (CEWP) to the page.  Add the code below to the web part’s Content Editor (source).  Now your menu should look like this.
 

When you click on the menu header box with the down arrow image, it exposes the submenu below it and swaps the image with an ‘x’.  Likewise, clicking the header with the ‘x’ will hide the associated submenu.
   

 

Here’s the code:

[code:js]

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
/* Load jQuery*/
google.load("jquery", "1.2.6");
</script>
<script type="text/javascript">
$(function(){
/*initialize menus*/
var menuRows = $("[id$='QuickLaunchMenu'] > tbody > tr");
var menuHd = menuRows.filter("[id!='']:has(+tr[id=''])");
/*set img path for when submenu is hidden*/
var closedImg = "/_layouts/images/Menu1.gif";
/*set img path for when submenu is visible*/
var openedImg = "/_layouts/images/ptclose.gif";
var cssInit = {
"background-image": "url('"+closedImg+"')",
"background-repeat": "no-repeat",
"background-position": "100% 50%"
}
var cssClosed = {"background-image": "url('"+closedImg+"')"}
var cssOpen = {"background-image": "url('"+openedImg+"')"}
/*hide submenus*/
menuRows.filter("[id='']").hide();
/*apply initial inline style to menu headers*/
menuHd.find("td:last").css(cssInit);
menuHd.click(function () {
var styleElm = $(this).find("td:last")
var nextTR = $(this).next("tr[id='']");
if (nextTR.is(':visible')) {
nextTR.hide();
styleElm.css(cssClosed);
} else {
nextTR.show();
styleElm.css(cssOpen);
}
});
});
</script>

[/code]


Tags: ,
Categories: JQuery | MOSS
Posted by admin on Tuesday, April 21, 2009 2:06 PM
Permalink | Comments (2) | Post RSSRSS comment feed