4

I didn't find anything to help me out, so I'm asking your help.

I work with sharepoint 2010. I have a team Site where the ribbon is hidden. (never trust users, thay are evil :p )

On this team site I have a calendar to organise meetings and so. They can create event, edit them, that's all fine. All but one little details... To change the calendar display scope, I need the ribbon (day, week or month view).

My idea would be to create links/buttons that would act like the ones in the ribbon. Is there a way to call a ribbon event, as if the user clicked on the ribbon despite he is hidden ?

thanks,

Marie

Edit 1 :

It seems that ribbon is hidden but still in the page. So, I can access it with javascript. I've created 3 buttons And I simulate clicks on the hidden ribbon.

btnDay .onclick=function(){
    //look if the calendar menu on ribbon is displayed
if(document.getElementById("Ribbon.Calendar.Calendar.Scope")==null)
{
            //If it's not, I simulate a click on the calendar menu of the ribbon
    document.getElementById("Ribbon.Calendar.Calendar-title").firstElementChild.click();
            //and wait for it to take effect
    setTimeout(function(){document.getElementById("Day-Small").click();}, 500);
}
else
{
    //If it is, I simulate a click on the button I want to fire
    document.getElementById("Ribbon.Calendar.Calendar.Scope").firstChild.firstChild.firstChild.firstChild.firstChild.childNodes[0].click();
}
}

The "firstChild.firstChild.firstCh..." thing can look like odd, but the names of his childs change with the size of display. So if I want it to work all the time, I have to use this.

Now, it works when the calendar is selected. User have to click on calendar and then click on my button. Thats better than nothing, but not acceptable.

Launching a click event on my webpart don't seems to select it and don't make the calendar menu "appear" on my ribbon. Any clue about this ?

3

thanks to this : Showing the tab on button click I created a function that click on my calendar. So, I simulate three clicks and it does what I wanted. Even though the ribbon is Hidden.

  • click on webpart to make the contextual ribbon appear (still hidden)
  • click on ribbon menu
  • click on link in ribbon

here is the code :

function calendarClick(){
    var elem = document.getElementById("MSOZoneCell_WebPartWPQ3");
    if (elem != null) {
        var dummyevent = new Array();
        dummyevent["target"] = elem;
        dummyevent["srcElement"] = elem;
        elem.parentNode.click(); 
        WpClick(dummyevent);
    }
}
  • 1
    It's better if you add the answer to the answer section rather than the question section. Would you like to do that, please?! Thank you! – Benny Skogberg Mar 7 '14 at 16:13
1

It's even easier than all that, according to this other article: http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/MS-SharePoint/Q_26306542.html

You just use a known javascript function MoveView like so:

href="javascript:MoveView('month');"  or   onclick="MoveView('month')"

You use arguments such as 'month', 'week', 'day'. I've tried it and it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.