Thursday, February 2, 2012

SharePoint 2010 - Documents Tab

while trying to make the transition from sharepoint 2007 to 2010, I've found that the default view of the ribon is confusing. What is the point of the browse tab? Especially if you're in a document library/list? In 07, useres have quick access to upload a document or create a new list item. In 2010, they must click a tab on the ribbon to be able to see that button.
To solve that problem, I want the documents or list items tab to be automatically selected for them.

I found two blogs that talk about this issue. I found that neither one really did what I want.

This site talks about how to set it as the default using the query string. Thought this might work for some, I can't change every link on every page to pass this as a parameter.
http://www.iotap.com/Blog/tabid/673/entryid/149/Displaying-default-tab-in-Sharepoint-2010-Ribbon.aspx
This second page talks about using javascript to set it to a custom tab based on some rules you setup in the javascript. I simplified this code for my use:
http://code.bkwdesign.com/2011/01/11/using-jquery-to-activate-default-sharepoint-tab/

There is probably a better way to do this using some built in sharepoint javascript funciton. I found one blog post that mentioned something like that, but I was unable to get it to work.

The following code will automatically select the Documents tab in a document library and the List Item tab in a list. In any other case it should not do anything, so it's safe to put on every page. You could also add in other options to handle pages librarys or some other case I haven't run into yet.
I added this code to my master page, but you could easily add it to a javascript file and add a reference to your master page or page layout or whatever, even put it in a Content Editor for one particular page.



Here's the code:


<script type="text/javascript">

function setTabDefault(tabid){
$("li[id=" + tabid + "] a span.ms-cui-tt-span").trigger('click');
}
$(document).ready(function () {

setTimeout("setTabDefault('Ribbon.Document-title');",150);
setTimeout("setTabDefault('Ribbon.ListItem-title');",150);

});

</script>