Thursday, December 3, 2015

Button Display Over Folder Level

Hi,

We have a document library with top 3 parent folders i.e. folder1,folder2 and folder3

Now this document library has been added to the page through list view web part.
We had a requirement of displaying custom button over folder level i.e.

Once user navigates to page, user shouldn’t be able to see the button.

Post clicking on the folder1,user should be able to see the button

Post clicking on the folder2, user shouldn’t be able to see the button.
Post clicking on the sub folder inside folder2, user should be able to see the button.

Post clicking on the folder3, user shouldn’t be able to see the button.
Post clicking on the sub folder inside folder3, user should be able to see the button.

For this we have added the below script

<script>
$(document).ready(function() {
setTimeout(function(){
var qstring = window.location.search.substring(1);
var url = window.location.href; //console.log(url.split('%2F'));   
var getQueryLength=0;

if(qstring.indexOf('%2F') > -1)
{
getQueryLength = qstring.split('%2F');
}
else
{
getQueryLength = qstring.split('/');
}

if(getQueryLength.length > 5 || (qstring.indexOf('folder1') > -1) )

{
$('.create_subfolder_sec .save-btn').css('display','block');
$('#Hero-WPQ3').css('display','block');

}
else
{
$('.create_subfolder_sec .save-btn').css('display','none');
$('#Hero-WPQ3').css('display','none');
}

}, 5);

});



</script>