Skip to content

Instantly share code, notes, and snippets.

@tiagoduarte
Created September 24, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagoduarte/425a17637ced534eb95c5c1bf5c02a1b to your computer and use it in GitHub Desktop.
Save tiagoduarte/425a17637ced534eb95c5c1bf5c02a1b to your computer and use it in GitHub Desktop.
make sharepoint ribbon reappear after being hidden from page customization
function showRibbonOnCustomizedPages()
{
if(window.location.href.contains("/Forms/AllItems.aspx"))
{
//console.log("library page");
var listViews = $('.ms-listviewtable');
if(listViews.length === 1)
{
//console.log('only one view found');
//misterious code - find in parents a match that starts by the specified string
var elem = document.getElementById($(listViews).parents('[id^="MSOZoneCell_WebPartWPQ"]').attr('id'));
if (elem != null) {
//console.log("showing ribbon");
var dummyevent = new Array();
dummyevent["target"] = elem;
dummyevent["srcElement"] = elem;
elem.parentNode.click();
WpClick(dummyevent);
//set the Browse button as default
_ribbonStartInit("Ribbon.Browse", true);
}
}
}
else
{
//console.log("non library page");
}
}
jQuery(function ($) {
setTimeout(function(){
showRibbonOnCustomizedPages();
}, 1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment