Monday 11 March 2013

SharePoint Branding: add a handy function to allow users show/hide quick launch bar

Few days ago I was working with SharePoint Project Server 2010, and with the main page of the project site, which is now in SharePoint.
One really nice feature in Project Server site is to allow users to collapse and expand quick launch to maximize the main area of the site.
The effect is something like this.
This is the look of the site with expanded quick launch:

This is the look with collapsed quick launch:

In fact you can do exactly the same with your team site template, which your users might find really handy.
In here I will make use of the JavaScript library which comes with Project Server 2010 installed – which means, if you don’t have it installed – you will get a JavaScript error if you just follow exact instructions here. Follow the instructions here if you want to use this feature in SharePoint Foundation or Standard without Project Server installed.
Let’s get started. We will be modifying default masterpage in this example to quickly demonstrate the approach. if you’re implementing this in your production environment it’s best to create a copy of the masterpage rather than modify existing one.
1. Open SharePoint Designer 2010 and select your team site, in my case http://intranet.contoso.com
2. Click Masterpages in the left panel of SPD under Site Objects.
3. Select v4.master and check it out. Open the file for editing.
4. Locate the following line of code:
<div id="s4-leftpanel-content">
and add below right after it:
<a onclick="Shell_ExpandCollapseQuickLaunch(); return false;" href="#">
<img id="LeftPaneCollapseImg" style="padding-left: 8px;
padding-right: 8px;" src="/_layouts/images/mewa_left.gif" border="0"/>
</a>
This will take care of the collapsing the quick launch
5. Locate the following line of code:
<a name="mainContent"></a>
and add below right after it:
<a onclick="Shell_ExpandCollapseQuickLaunch(); return false;" href="#">
<img id="LeftPaneExpandImg" style="display: none;"
src="/_layouts/images/mewa_right.gif" border="0"/>
</a>
This will take care of getting the quick launch back once it’s hidden.
6. Now let’s add the reference to the JavaScript file which will do all the work. Remember – you will have this file only if you have installed Project Server service application, we will see how you can achieve the same result using open source tools in my next article.
In your masterpage opened in SharePoint Designer, go to the very top, and right before the </head> tag add:
<script type="text/javascript" src="/_layouts/inc/pwa/library/shell.js"></script>
7. Save the masterpage in SharePoint Designer and refresh the page on your team site, in my case http://intranet.contoso.com you will see a small arrow just like on the project site allowing you to collapse and expand the quick launch.
Enjoy!

3 comments:

  1. sharepoint is a web based collaborative platform.it is basically an intranet and content management system.you can get more information at sharepoint online training.Read More At sharepoint online course india

    ReplyDelete
  2. I am inspired with your post writing style & how continuously you describe this topic on sharepoint training
    . After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.

    ReplyDelete
  3. Kentico 12 migration I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here.

    ReplyDelete