Play with ribbon on Sharepoint

In Sharepoint 2010 and 2013, there are some existing functions to deal with the ribbon.

Below an example of what we can do:

// we need the file "sp.ribbon.js"
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
  // use PageManager
  var pm = SP.Ribbon.PageManager.get_instance();

  // define a function to call when the ribbon is loaded
  var DoSomethingWithRibbon=function(ribbon) {
    // For example, we can select the "Browse" tab
    ribbon.selectTabById("Ribbon.ListForm.Display", true);
    // Note: You can explore the DOM to find the related IDs
    // other example "Edit" tab is "Ribbon.ListForm.Edit"
  
    // We can now remove the "Edit" tab
    ribbon.removeChild("Ribbon.ListForm.Edit");
  }

  // perform an action when the ribbon has been inited
  pm.add_ribbonInited(function () {
    DoSomethingWithRibbon(pm.get_ribbon())
  });

  // if the ribbon is already loaded
  var ribbon = null;
  try {
    // get an instance of the ribbon
    ribbon = pm.get_ribbon();
  } catch (e) {}
  if (!ribbon) {
    if (typeof(_ribbonStartInit) == "function")
      _ribbonStartInit(_ribbon.initialTabId, false, null);
  } else {
    DoSomethingWithRibbon(ribbon);
  }

}, "sp.ribbon.js");

And there are also solutions to add stuff to the ribbon. I have to dig into these solutions… In the meantime you can try this blog post, or this one.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*