2

When user click on an item display view (DispForm.aspx) the "View" ribbon is always expanded by default. It is annoying sometimes. How can I to make it collapse (not hide) by default? When user need the ribbon buttons he can click the "View" link at top to expand it.

Mark L
  • 4,065
  • 7
  • 66
  • 128

2 Answers2

5

By using the hints Anders provided and the reference here. I can make it work with below script. Simply put it into a Script Editor Webpart for the page you need it.

<script language="javascript" type="text/javascript">       
function DoSomethingWithRibbon() {         
// Gets a reference to a CUI.Ribbon object (CUI.js)         
var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();          
// Show me which tab is selected - will show         
// 'Ribbon.Read' if the Browse tab is selected.         
//alert(ribbon.get_selectedTabId());
SelectRibbonTab("Ribbon.Read", true);
}       
// Note: 'SOD' is an abbreviation for "Script on Demand"      
SP.SOD.executeOrDelayUntilScriptLoaded(function() {          
var pm = SP.Ribbon.PageManager.get_instance();          
pm.add_ribbonInited(function() {            
DoSomethingWithRibbon();         
});          
var ribbon = null;         
try         {            
    ribbon = pm.get_ribbon();         
}         catch (e) { }          
if (!ribbon) {            
    if (typeof(_ribbonStartInit) == "function")               
        _ribbonStartInit(_ribbon.initialTabId, false, null);         
    }         
    else {            
        DoSomethingWithRibbon();         
    }      
    },      
    "sp.ribbon.js");   
</script>
Mark L
  • 4,065
  • 7
  • 66
  • 128
4

You could do it with javascript I guess, the name of View is Ribbon.Read, so this should work:

 SelectRibbonTab('Ribbon.Read', true);
Anders Aune
  • 6,268
  • 1
  • 22
  • 31
  • By adding SP.SOD.executeOrDelayUntilScriptLoaded(myfunction, "sp.ribbon.js") The ribbon.read view is selected. However it is not collapsed. – Mark L May 20 '15 at 08:15
  • I got "Attempting to attach to Id: Ribbon.Read but this id is not present in the DOM" error in F12 tool. – Mark L May 20 '15 at 08:24
  • Ah, yeah. And i meant the "Browse" tab, not "View" btw :) – Anders Aune May 20 '15 at 09:52