0
votes

One of the Requirements I am working for, I am getting a list of all the Document libraries present in the SharePoint site using JSOM. Now I have to hide these document libraries from all the users, Just FYI, this is not permissions based. The behavior will be uniform across all users.

I am using below code to get the list of all the libraries.

<script type="text/javascript">

    var currentcontext = null;
    var currentweb = null;
    ExecuteOrDelayUntilScriptLoaded(GetLibrariesOnly, "sp.js");

    //to get the list of document libraries.
    function GetLibrariesOnly()
    {
    currentcontext = new SP.ClientContext.get_current();
    currentweb = currentcontext.get_web();
    this.listCollection = currentweb.get_lists();
    listCollection.set_hidden(true);
    currentcontext.load(listCollection);
    currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
    Function.createDelegate(this, this.ExecuteOnFailure));
    }
    function ExecuteOnSuccess(sender, args) {
    var listEnumerator = this.listCollection.getEnumerator();
       var allLibs ="";
       while (listEnumerator.moveNext()) 
       {
                var list = listEnumerator.get_current();
                if(list.get_baseTemplate() == '101')
                {
                 allLibs+= list.get_title() + '\n';                
                }
       }
        alert("All Libraries:" + '\n' + allLibs);
     }
    function ExecuteOnFailure(sender, args) {
    alert("Error in Getting Libraries");
    }

What should I add/change to hide the libraries except the Documents and Site Assets library that appear in the Alert.

I would want to hide all the libraries except site assets and default documents library. Please see below screenshot. I am working with SharePoint online/Office 365. Thanks in advance.

Alert Console in Chrome

1

1 Answers

1
votes

following css will hide all the tiles site contents:

<style>
.ms-vl-apptile.ms-vl-apptilehover {display :none;}
</style>

following javascript will help to display your required tiles and this will work for all tiles:

<script>
$('a[title="Documents"]').parent('div').parent('div').parent('div').parent('div').css("display","inline-block");
$('a[title="Site Assets"]').parent('div').parent('div').parent('div').parent('div').css("display","inline-block");
$('a[title="Style Library"]').parent('div').parent('div').parent('div').parent('div').css("display","inline-block");
</script>

Note: you have to add this javascript and css reference or js and css code themselves in your MasterPage. Don't forget to include jquery references.